Skip to content

Support Half/BFloat16 in select_scatter #7865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions kernels/portable/cpu/op_select_scatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,20 @@ Tensor& select_scatter_out(
ScalarType in_type = in.scalar_type();
ScalarType src_type = src.scalar_type();

ET_SWITCH_REAL_TYPES_AND(
Bool, in_type, ctx, "select_scatter.out", CTYPE, [&]() {
ET_SWITCH_REAL_TYPES_AND(
Bool, src_type, ctx, "select_scatter.out", CTYPE_SRC, [&]() {
CTYPE* const out_data = out.mutable_data_ptr<CTYPE>();
const CTYPE_SRC* const src_data = src.const_data_ptr<CTYPE_SRC>();

for (size_t i = 0; i < leading_dims; ++i) {
for (size_t j = 0; j < trailing_stride; ++j) {
out_data[start_offset + i * out_step + j] =
convert<CTYPE, CTYPE_SRC>(
src_data[i * trailing_stride + j]);
}
}
});
});
ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, "select_scatter.out", CTYPE, [&]() {
ET_SWITCH_REALHBBF16_TYPES(
src_type, ctx, "select_scatter.out", CTYPE_SRC, [&]() {
CTYPE* const out_data = out.mutable_data_ptr<CTYPE>();
const CTYPE_SRC* const src_data = src.const_data_ptr<CTYPE_SRC>();

for (size_t i = 0; i < leading_dims; ++i) {
for (size_t j = 0; j < trailing_stride; ++j) {
out_data[start_offset + i * out_step + j] =
convert<CTYPE, CTYPE_SRC>(src_data[i * trailing_stride + j]);
}
}
});
});

return out;
}
Expand Down
4 changes: 2 additions & 2 deletions kernels/test/op_select_scatter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ TEST_F(OpSelectScatterOutTest, OutputDynamicShape) {
/// zeros().
TEST_F(OpSelectScatterOutTest, AllDtypesSupported) {
#define TEST_ENTRY(ctype, dtype) test_dtype<ctype, ScalarType::dtype>();
ET_FORALL_REAL_TYPES_AND(Bool, TEST_ENTRY);
ET_FORALL_REALHBBF16_TYPES(TEST_ENTRY);
#undef TEST_ENTRY
// TODO: Also add tests for half, complex, quantized, and other types. Easiest
// TODO: Also add tests for complex, quantized, and other types. Easiest
// way to do that would be to make TensorFactory support zeros() and ones()
// for those types.
}
Expand Down
Loading