Skip to content
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

[ExecuTorch] Unbreak optimized sub in the case where one input is a scalar and both are Half #5940

Merged
merged 1 commit into from
Oct 9, 2024
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
2 changes: 1 addition & 1 deletion kernels/optimized/cpu/op_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ Tensor& opt_sub_out(
}
});
});
return out;
}
return out;
}

auto selected_optimized_path = select_optimized_path(a, b, out);
Expand Down
36 changes: 23 additions & 13 deletions kernels/test/op_sub_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ class OpSubOutTest : public OperatorTest {

#undef ENUMERATE_TEST_ENTRY
}

template <ScalarType DTYPE>
void test_broadcast_rank1_scalar() {
TensorFactory<DTYPE> tf;

Tensor a = tf.make({2, 1, 3}, {2, 3, 4, 5, 6, 7});
Tensor b = tf.make({1}, {2});

// Destination for the broadcasting div. Follow the broadcasting rules in
// https://fburl.com/n9wl4d0o
Tensor out = tf.zeros({2, 1, 3});

op_sub_out(a, b, 1, out);

Tensor ret = tf.make({2, 1, 3}, {0, 1, 2, 3, 4, 5});
EXPECT_TENSOR_EQ(out, ret);

op_sub_out(b, a, 1, out);
ret = tf.make({2, 1, 3}, {0, -1, -2, -3, -4, -5});
EXPECT_TENSOR_EQ(out, ret);
}
};

class OpSubScalarOutTest : public OperatorTest {
Expand Down Expand Up @@ -171,19 +192,8 @@ TEST_F(OpSubOutTest, BroadcastSupported2) {
}

TEST_F(OpSubOutTest, BroadcastScalarSupported1) {
TensorFactory<ScalarType::Float> tf;

Tensor a = tf.make({2, 1, 3}, {2, 3, 4, 5, 6, 7});
Tensor b = tf.make({1}, {2});

// Destination for the broadcasting div. Follow the broadcasting rules in
// https://fburl.com/n9wl4d0o
Tensor out = tf.zeros({2, 1, 3});

op_sub_out(a, b, 1, out);

Tensor ret = tf.make({2, 1, 3}, {0, 1, 2, 3, 4, 5});
EXPECT_TENSOR_EQ(out, ret);
test_broadcast_rank1_scalar<ScalarType::Float>();
test_broadcast_rank1_scalar<ScalarType::Half>();
}

TEST_F(OpSubOutTest, BroadcastScalarSupported2) {
Expand Down
Loading