Skip to content

Commit da3e85d

Browse files
committed
Started refactoring operators to use op_name format
1 parent fead7c7 commit da3e85d

File tree

12 files changed

+71
-37
lines changed

12 files changed

+71
-37
lines changed

kernels/portable/cpu/op__to_dim_order_copy.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,16 @@ Tensor& _to_dim_order_copy_out(
7777
return out;
7878
}
7979

80-
ET_SWITCH_REALHBBF16_TYPES(
81-
self.scalar_type(),
82-
ctx,
83-
"dim_order_ops::_to_dim_order_copy.out",
84-
CTYPE_IN,
85-
[&] {
86-
ET_SWITCH_REALHBBF16_TYPES(
87-
out.scalar_type(),
88-
ctx,
89-
"dim_order_ops::_to_dim_order_copy.out",
90-
CTYPE_OUT,
91-
[&] { _to_dim_order_copy_impl<CTYPE_IN, CTYPE_OUT>(self, out); });
80+
// @lint-ignore CLANGTIDY facebook-hte-CArray
81+
static constexpr const char op_name[] = "dim_order_ops::_to_dim_order_copy.out";
82+
83+
ET_SWITCH_REALHBBF16_TYPES(self.scalar_type(), ctx, op_name, CTYPE_IN, [&] {
84+
ET_SWITCH_REALHBBF16_TYPES(
85+
out.scalar_type(),
86+
ctx,
87+
op_name,
88+
CTYPE_OUT,
89+
[&] { _to_dim_order_copy_impl<CTYPE_IN, CTYPE_OUT>(self, out); });
9290
});
9391

9492
return out;

kernels/portable/cpu/op_abs.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ Tensor& abs_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
3737
ET_KERNEL_CHECK(
3838
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);
3939

40+
// @lint-ignore CLANGTIDY facebook-hte-CArray
41+
static constexpr const char op_name[] = "abs.out";
42+
4043
if (in_is_complex) {
4144
// NOTE: Elected not to add COMPLEXH to dtype_util.h for now
4245
// because I am not planning wide rollout of complex support; if
4346
// we do add SupportedTensorDtypes::COMPLEXH support, then we
4447
// should use it here.
45-
ET_SWITCH_COMPLEXH_TYPES(in.scalar_type(), ctx, "abs.out", CTYPE_IN, [&] {
46-
ET_SWITCH_FLOATH_TYPES(out.scalar_type(), ctx, "abs.out", CTYPE_OUT, [&] {
48+
ET_SWITCH_COMPLEXH_TYPES(in.scalar_type(), ctx, op_name, CTYPE_IN, [&] {
49+
ET_SWITCH_FLOATH_TYPES(out.scalar_type(), ctx, op_name, CTYPE_OUT, [&] {
4750
apply_unary_map_fn<CTYPE_IN, CTYPE_OUT>(
4851
[](const CTYPE_IN val_in) -> CTYPE_OUT {
4952
return sqrt(
@@ -55,7 +58,7 @@ Tensor& abs_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
5558
});
5659
});
5760
} else {
58-
ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, "abs.out", CTYPE, [&] {
61+
ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&] {
5962
apply_unary_map_fn(
6063
[](const CTYPE val_in) {
6164
if (val_in < 0) {

kernels/portable/cpu/op_amax.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ Tensor& amax_out(
4444
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);
4545

4646
ReduceOverDimListPlan plan(in, dim_list);
47-
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, "amax.out", CTYPE, [&]() {
47+
48+
// @lint-ignore CLANGTIDY facebook-hte-CArray
49+
static constexpr const char op_name[] = "amax.out";
50+
51+
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&]() {
4852
CTYPE* out_data = out.mutable_data_ptr<CTYPE>();
4953
const bool success = parallel_for_each_reduce_over_dim_list_output_index(
5054
in, dim_list, out, [&](const auto begin, const auto end) {

kernels/portable/cpu/op_amin.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ Tensor& amin_out(
4343
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);
4444

4545
ReduceOverDimListPlan plan(in, dim_list);
46-
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, "amin.out", CTYPE, [&]() {
46+
47+
// @lint-ignore CLANGTIDY facebook-hte-CArray
48+
static constexpr const char op_name[] = "amin.out";
49+
50+
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&]() {
4751
CTYPE* out_data = out.mutable_data_ptr<CTYPE>();
4852
const bool success = parallel_for_each_reduce_over_dim_list_output_index(
4953
in, dim_list, out, [&](const auto begin, const auto end) {

kernels/portable/cpu/op_any.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ Tensor& any_all_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
3030

3131
ScalarType in_type = in.scalar_type();
3232
ScalarType out_type = out.scalar_type();
33-
constexpr auto name = "any.all_out";
3433

35-
ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, name, CTYPE_IN, [&] {
36-
ET_SWITCH_TWO_TYPES(Bool, Byte, out_type, ctx, name, CTYPE_OUT, [&] {
34+
// @lint-ignore CLANGTIDY facebook-hte-CArray
35+
static constexpr const char op_name[] = "any.all_out";
36+
37+
ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, op_name, CTYPE_IN, [&] {
38+
ET_SWITCH_TWO_TYPES(Bool, Byte, out_type, ctx, op_name, CTYPE_OUT, [&] {
3739
const auto data_in = in.const_data_ptr<CTYPE_IN>();
3840
auto data_out = out.mutable_data_ptr<CTYPE_OUT>();
3941
data_out[0] = static_cast<CTYPE_OUT>(false);
@@ -79,15 +81,17 @@ Tensor& any_dims_out(
7981

8082
ScalarType in_type = in.scalar_type();
8183
ScalarType out_type = out.scalar_type();
82-
constexpr auto name = "any.dims_out";
84+
85+
// @lint-ignore CLANGTIDY facebook-hte-CArray
86+
static constexpr const char op_name[] = "any.dims_out";
8387

8488
const bool in_not_empty = in.numel() > 0;
8589
std::optional<MapReduceOverDimListPlan> plan;
8690
if ((!dim_list.has_value() || !dim_list.value().empty()) && in_not_empty) {
8791
plan.emplace(in, dim_list);
8892
}
89-
ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, name, CTYPE_IN, [&] {
90-
ET_SWITCH_TWO_TYPES(Bool, Byte, out_type, ctx, name, CTYPE_OUT, [&] {
93+
ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, op_name, CTYPE_IN, [&] {
94+
ET_SWITCH_TWO_TYPES(Bool, Byte, out_type, ctx, op_name, CTYPE_OUT, [&] {
9195
CTYPE_OUT* out_data = out.mutable_data_ptr<CTYPE_OUT>();
9296
if (dim_list.has_value() && dim_list.value().empty()) {
9397
const CTYPE_IN* in_data = in.const_data_ptr<CTYPE_IN>();
@@ -144,10 +148,12 @@ Tensor& any_out(
144148

145149
ScalarType in_type = in.scalar_type();
146150
ScalarType out_type = out.scalar_type();
147-
constexpr auto name = "any.out";
148151

149-
ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, name, CTYPE_IN, [&] {
150-
ET_SWITCH_TWO_TYPES(Bool, Byte, out_type, ctx, name, CTYPE_OUT, [&] {
152+
// @lint-ignore CLANGTIDY facebook-hte-CArray
153+
static constexpr const char op_name[] = "any.out";
154+
155+
ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, op_name, CTYPE_IN, [&] {
156+
ET_SWITCH_TWO_TYPES(Bool, Byte, out_type, ctx, op_name, CTYPE_OUT, [&] {
151157
CTYPE_OUT* out_data = out.mutable_data_ptr<CTYPE_OUT>();
152158
const bool success = parallel_for_each_reduce_over_dim_output_index(
153159
in, dim, out, [&](const auto begin, const auto end) {

kernels/portable/cpu/op_argmax.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ Tensor& argmax_out(
4444
ET_KERNEL_CHECK(
4545
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);
4646

47-
ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, "argmax.out", CTYPE, [&] {
47+
// @lint-ignore CLANGTIDY facebook-hte-CArray
48+
static constexpr const char op_name[] = "argmax.out";
49+
50+
ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&] {
4851
long* out_data = out.mutable_data_ptr<long>();
4952

5053
const bool success = parallel_for_each_reduce_over_dim_output_index(

kernels/portable/cpu/op_argmin.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ Tensor& argmin_out(
4444
ET_KERNEL_CHECK(
4545
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);
4646

47-
ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, "argmin.out", CTYPE, [&] {
47+
// @lint-ignore CLANGTIDY facebook-hte-CArray
48+
static constexpr const char op_name[] = "argmin.out";
49+
50+
ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&] {
4851
long* out_data = out.mutable_data_ptr<long>();
4952

5053
const bool success = parallel_for_each_reduce_over_dim_output_index(

kernels/portable/cpu/op_avg_pool2d.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ Tensor& avg_pool2d_out(
6767
out);
6868

6969
ScalarType in_type = in.scalar_type();
70+
71+
// @lint-ignore CLANGTIDY facebook-hte-CArray
72+
static constexpr const char op_name[] = "avg_pool2d.out";
73+
7074
ET_SWITCH_FLOATHBF16_TYPES_AND(
71-
Long, in_type, ctx, "avg_pool2d.out", CTYPE, [&]() {
75+
Long, in_type, ctx, op_name, CTYPE, [&]() {
7276
if (divisor_override.has_value()) {
7377
int64_t divisor = divisor_override.value();
7478
// If divisor_override is specified, then we don't need to use `count`

kernels/portable/cpu/op_bitwise_not.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ bitwise_not_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
3737
ET_KERNEL_CHECK(
3838
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);
3939

40+
// @lint-ignore CLANGTIDY facebook-hte-CArray
41+
static constexpr const char op_name[] = "bitwise_not.out";
4042
if (in.scalar_type() == executorch::aten::ScalarType::Bool) {
4143
apply_unary_map_fn(
4244
[](const bool val_in) { return !val_in; },
4345
in.const_data_ptr<bool>(),
4446
out.mutable_data_ptr<bool>(),
4547
in.numel());
4648
} else if (isIntegralType(in.scalar_type(), /*includeBool=*/false)) {
47-
ET_SWITCH_INT_TYPES(in.scalar_type(), ctx, "bitwise_not.out", CTYPE, [&] {
49+
ET_SWITCH_INT_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&] {
4850
apply_unary_map_fn(
4951
[](const CTYPE val_in) { return ~val_in; },
5052
in.const_data_ptr<CTYPE>(),

kernels/portable/cpu/op_bmm.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ Tensor& bmm_out(
3636
InvalidArgument,
3737
out);
3838

39-
constexpr auto name = "bmm.out";
39+
// @lint-ignore CLANGTIDY facebook-hte-CArray
40+
static constexpr const char op_name[] = "bmm.out";
4041

4142
auto in_type = in.scalar_type();
4243

4344
if (executorch::runtime::isComplexType(in_type)) {
44-
ET_SWITCH_COMPLEXH_TYPES(in_type, ctx, name, CTYPE, [&]() {
45+
ET_SWITCH_COMPLEXH_TYPES(in_type, ctx, op_name, CTYPE, [&]() {
4546
internal::bmm_out_impl<CTYPE>(in, mat2, out);
4647
});
4748
} else {
48-
ET_SWITCH_REALH_TYPES(in_type, ctx, name, CTYPE, [&]() {
49+
ET_SWITCH_REALH_TYPES(in_type, ctx, op_name, CTYPE, [&]() {
4950
internal::bmm_out_impl<CTYPE>(in, mat2, out);
5051
});
5152
}

0 commit comments

Comments
 (0)