Skip to content

Commit 018cd1b

Browse files
committed
More op refactors
1 parent da3e85d commit 018cd1b

File tree

9 files changed

+37
-17
lines changed

9 files changed

+37
-17
lines changed

kernels/portable/cpu/op_clamp.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,19 @@ ET_NODISCARD bool check_bounds(
4040
const char* val_name) {
4141
auto is_valid = true;
4242

43+
// @lint-ignore CLANGTIDY facebook-hte-CArray
44+
static constexpr const char op_name[] = "clamp.out";
45+
4346
if (isIntegralType(out_type, /*includeBool=*/false)) {
4447
const long val_long = utils::scalar_to<long>(val_scalar);
45-
ET_SWITCH_INT_TYPES(out_type, ctx, "clamp.out", CTYPE_OUT, [&]() {
48+
ET_SWITCH_INT_TYPES(out_type, ctx, op_name, CTYPE_OUT, [&]() {
4649
if (is_out_of_bounds<CTYPE_OUT, long>(val_long)) {
4750
ET_LOG(Error, "%s value out of bounds", val_name);
4851
is_valid = false;
4952
}
5053
});
5154
} else if (isFloatingType(out_type)) {
52-
ET_SWITCH_FLOATHBF16_TYPES(out_type, ctx, "clamp.out", CTYPE_OUT, [&]() {
55+
ET_SWITCH_FLOATHBF16_TYPES(out_type, ctx, op_name, CTYPE_OUT, [&]() {
5356
const double val_double = utils::scalar_to<double>(val_scalar);
5457
if (std::isfinite(val_double) &&
5558
is_out_of_bounds<CTYPE_OUT, double>(val_double)) {

kernels/portable/cpu/op_constant_pad_nd.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ Tensor& constant_pad_nd_out(
184184

185185
ScalarType in_type = in.scalar_type();
186186

187-
ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, "constant_pad_nd.out", CTYPE, [&]() {
187+
// @lint-ignore CLANGTIDY facebook-hte-CArray
188+
static constexpr const char op_name[] = "constant_pad_nd.out";
189+
190+
ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, op_name, CTYPE, [&]() {
188191
auto opt_value_casted =
189192
utils::internal::check_overflow_scalar_cast<CTYPE>(value);
190193
ET_KERNEL_CHECK(ctx, opt_value_casted.has_value(), InvalidArgument, );

kernels/portable/cpu/op_copy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Tensor& copy_out(
5252
src.numel() > 0) {
5353
std::memcpy(out.mutable_data_ptr(), src.const_data_ptr(), src.nbytes());
5454
} else {
55-
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, "copy.out", CTYPE, [&]() {
55+
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&]() {
5656
utils::apply_bitensor_elementwise_fn<
5757
CTYPE,
5858
op_name,
@@ -94,7 +94,7 @@ Tensor& copy_(
9494
src.numel() > 0) {
9595
std::memcpy(in.mutable_data_ptr(), src.const_data_ptr(), in.nbytes());
9696
} else {
97-
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, "copy_", CTYPE, [&]() {
97+
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&]() {
9898
utils::apply_bitensor_elementwise_fn<
9999
CTYPE,
100100
op_name,

kernels/portable/cpu/op_diagonal_copy.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ Tensor& diagonal_copy_out(
9898
InvalidArgument,
9999
out);
100100

101-
constexpr auto name = "diagonal_copy.out";
102101

103-
ET_SWITCH_ALL_TYPES(in.scalar_type(), ctx, name, CTYPE, [&] {
102+
// @lint-ignore CLANGTIDY facebook-hte-CArray
103+
static constexpr const char op_name[] = "diagonal_copy.out";
104+
105+
ET_SWITCH_ALL_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&] {
104106
diagonal_copy_impl<CTYPE>(in, offset, dim1, dim2, out);
105107
});
106108

kernels/portable/cpu/op_embedding.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ Tensor& embedding_out(
116116
ix_type == ScalarType::Long || ix_type == ScalarType::Int,
117117
"Expected indices tensor to have Long or Int scalar types");
118118

119+
// @lint-ignore CLANGTIDY facebook-hte-CArray
120+
static constexpr const char op_name[] = "op_embedding.out";
121+
119122
ET_SWITCH_TWO_TYPES(
120-
Long, Int, ix_type, ctx, "op_embedding.out", CTYPE, [&]() {
123+
Long, Int, ix_type, ctx, op_name, CTYPE, [&]() {
121124
embedding_kernel<CTYPE>(ctx, weight, indices, out);
122125
});
123126

kernels/portable/cpu/op_fill.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ Tensor& fill_scalar_out(
4141
out,
4242
"Failed to resize output tensor.");
4343

44-
ET_SWITCH_REALHBBF16_TYPES(a_type, ctx, "fill.Scalar_out", CTYPE_A, [&] {
44+
// @lint-ignore CLANGTIDY facebook-hte-CArray
45+
static constexpr const char op_name[] = "fill.Scalar_out";
46+
47+
ET_SWITCH_REALHBBF16_TYPES(a_type, ctx, op_name, CTYPE_A, [&] {
4548
auto opt_b_casted = utils::internal::check_overflow_scalar_cast<CTYPE_A>(b);
4649
ET_KERNEL_CHECK(ctx, opt_b_casted.has_value(), InvalidArgument, );
4750
auto b_casted = opt_b_casted.value();
@@ -83,9 +86,12 @@ Tensor& fill_tensor_out(
8386
out,
8487
"Failed to resize output tensor.");
8588

86-
ET_SWITCH_REALHBBF16_TYPES(a_type, ctx, "fill.Tensor_out", CTYPE_A, [&] {
89+
// @lint-ignore CLANGTIDY facebook-hte-CArray
90+
static constexpr const char op_name[] = "fill.Tensor_out";
91+
92+
ET_SWITCH_REALHBBF16_TYPES(a_type, ctx, op_name, CTYPE_A, [&] {
8793
CTYPE_A b_casted;
88-
ET_SWITCH_REALHBBF16_TYPES(b_type, ctx, "fill.Tensor_out", CTYPE_B, [&] {
94+
ET_SWITCH_REALHBBF16_TYPES(b_type, ctx, op_name, CTYPE_B, [&] {
8995
CTYPE_B b_val;
9096
ET_EXTRACT_SCALAR_TENSOR(b, b_val);
9197
b_casted = static_cast<CTYPE_A>(b_val);

kernels/portable/cpu/op_flip.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ Tensor& flip_out(
6565
size_t flip_dim_length = static_cast<size_t>(in.dim()); // NOLINT
6666
ArrayRef<bool> flip_dim(flip_dim_data, flip_dim_length);
6767

68-
constexpr auto name = "flip.out";
68+
// @lint-ignore CLANGTIDY facebook-hte-CArray
69+
static constexpr const char op_name[] = "flip_out";
6970

70-
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, name, CTYPE, [&] {
71+
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&] {
7172
const CTYPE* in_data = in.const_data_ptr<CTYPE>();
7273
CTYPE* out_data = out.mutable_data_ptr<CTYPE>();
7374

kernels/portable/cpu/op_full.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ Tensor& full_out(
3434
out,
3535
"Failed to resize output tensor.");
3636

37-
constexpr auto name = "full.out";
37+
// @lint-ignore CLANGTIDY facebook-hte-CArray
38+
static constexpr const char op_name[] = "full.out";
3839

39-
ET_SWITCH_REALHBBF16_TYPES(out_type, ctx, name, CTYPE_OUT, [&] {
40+
ET_SWITCH_REALHBBF16_TYPES(out_type, ctx, op_name, CTYPE_OUT, [&] {
4041
auto opt_val_casted =
4142
utils::internal::check_overflow_scalar_cast<CTYPE_OUT>(fill_value);
4243
ET_KERNEL_CHECK(ctx, opt_val_casted.has_value(), InvalidArgument, );

kernels/portable/cpu/op_full_like.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ Tensor& full_like_out(
5050

5151
ScalarType out_type = out.scalar_type();
5252

53-
constexpr auto name = "full_like.out";
53+
// @lint-ignore CLANGTIDY facebook-hte-CArray
54+
static constexpr const char op_name[] = "full_like.out";
5455

55-
ET_SWITCH_REALHBBF16_TYPES(out_type, ctx, name, CTYPE_OUT, [&] {
56+
ET_SWITCH_REALHBBF16_TYPES(out_type, ctx, op_name, CTYPE_OUT, [&] {
5657
auto opt_val_casted =
5758
utils::internal::check_overflow_scalar_cast<CTYPE_OUT>(fill_value);
5859
ET_KERNEL_CHECK(ctx, opt_val_casted.has_value(), InvalidArgument, );

0 commit comments

Comments
 (0)