Skip to content

Commit b98c3ab

Browse files
authored
Save some size in pattern/{bitwise,comparison}_op.h (#10489)
bloaty told me that we were paying a noticeable size cost for the ::value members of these structs (at least after the PR in this stack that reapplies #9841) and now we're not. Test Plan: bash test/build_optimized_size_test.sh ``` before: adopt functionref ========== ExecuTorch with no ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 153928 Apr 25 11:08 cmake-out/test/size_test ExecuTorch with portable ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 2150960 Apr 25 11:08 cmake-out/test/size_test_all_ops ExecuTorch with optimized ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 5927336 Apr 25 11:08 cmake-out/test/size_test_all_optimized_ops (.venv) swolchok@swolchok-mac ~/src/executorch> size cmake-out/test/size_test* __TEXT __DATA __OBJC others dec hex 81920 81920 0 4295049216 4295213056 10003c000 cmake-out/test/size_test 1474560 81920 0 4295655424 4297211904 100224000 cmake-out/test/size_test_all_ops 4505600 98304 0 4296376320 4300980224 1005bc000 cmake-out/test/size_test_all_optimized_ops after: ExecuTorch with no ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 153928 Apr 25 12:24 cmake-out/test/size_test ExecuTorch with portable ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 2150960 Apr 25 12:24 cmake-out/test/size_test_all_ops ExecuTorch with optimized ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 5887368 Apr 25 12:24 cmake-out/test/size_test_all_optimized_ops (.venv) swolchok@swolchok-mac ~/src/executorch> size cmake-out/test/size_test* __TEXT __DATA __OBJC others dec hex 81920 81920 0 4295049216 4295213056 10003c000 cmake-out/test/size_test 1474560 81920 0 4295655424 4297211904 100224000 cmake-out/test/size_test_all_ops 4489216 98304 0 4296359936 4300947456 1005b4000 cmake-out/test/size_test_all_optimized_ops ``` (yes it's neutral; improves size results for further diffs)
1 parent f7c906f commit b98c3ab

File tree

12 files changed

+63
-75
lines changed

12 files changed

+63
-75
lines changed

.lintrunner.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ exclude_patterns = [
220220
'extension/**',
221221
'kernels/optimized/**',
222222
# Justified <functional> include.
223+
'kernels/portable/cpu/op_bitwise*.cpp',
224+
'kernels/portable/cpu/op_eq.cpp',
225+
'kernels/portable/cpu/op_ge.cpp',
226+
'kernels/portable/cpu/op_gt.cpp',
227+
'kernels/portable/cpu/op_le.cpp',
228+
'kernels/portable/cpu/op_lt.cpp',
229+
'kernels/portable/cpu/op_ne.cpp',
223230
'runtime/kernel/thread_parallel_interface.h',
224231
'scripts/**',
225232
'third-party/**',

kernels/portable/cpu/op_bitwise_and.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <executorch/kernels/portable/cpu/pattern/bitwise_op.h>
1010

11+
#include <functional>
12+
1113
namespace torch {
1214
namespace executor {
1315
namespace native {
@@ -19,7 +21,7 @@ Tensor& bitwise_and_Tensor_out(
1921
Tensor& out) {
2022
// @lint-ignore CLANGTIDY facebook-hte-CArray
2123
static constexpr const char op_name[] = "bitwise_and.Tensor_out";
22-
return internal::bitwise_tensor_out<op_name>(ctx, a, b, out);
24+
return internal::bitwise_tensor_out<std::bit_and, op_name>(ctx, a, b, out);
2325
}
2426

2527
Tensor& bitwise_and_Scalar_out(
@@ -29,7 +31,7 @@ Tensor& bitwise_and_Scalar_out(
2931
Tensor& out) {
3032
// @lint-ignore CLANGTIDY facebook-hte-CArray
3133
static constexpr const char op_name[] = "bitwise_and.Scalar_out";
32-
return internal::bitwise_scalar_out<op_name>(ctx, a, b, out);
34+
return internal::bitwise_scalar_out<std::bit_and, op_name>(ctx, a, b, out);
3335
}
3436

3537
} // namespace native

kernels/portable/cpu/op_bitwise_or.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <executorch/kernels/portable/cpu/pattern/bitwise_op.h>
1010

11+
#include <functional>
12+
1113
namespace torch {
1214
namespace executor {
1315
namespace native {
@@ -19,7 +21,7 @@ Tensor& bitwise_or_Tensor_out(
1921
Tensor& out) {
2022
// @lint-ignore CLANGTIDY facebook-hte-CArray
2123
static constexpr const char op_name[] = "bitwise_or.Tensor_out";
22-
return internal::bitwise_tensor_out<op_name>(ctx, a, b, out);
24+
return internal::bitwise_tensor_out<std::bit_or, op_name>(ctx, a, b, out);
2325
}
2426

2527
Tensor& bitwise_or_Scalar_out(
@@ -29,7 +31,7 @@ Tensor& bitwise_or_Scalar_out(
2931
Tensor& out) {
3032
// @lint-ignore CLANGTIDY facebook-hte-CArray
3133
static constexpr const char op_name[] = "bitwise_or.Scalar_out";
32-
return internal::bitwise_scalar_out<op_name>(ctx, a, b, out);
34+
return internal::bitwise_scalar_out<std::bit_or, op_name>(ctx, a, b, out);
3335
}
3436

3537
} // namespace native

kernels/portable/cpu/op_bitwise_xor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <executorch/kernels/portable/cpu/pattern/bitwise_op.h>
1010

11+
#include <functional>
12+
1113
namespace torch {
1214
namespace executor {
1315
namespace native {
@@ -19,7 +21,7 @@ Tensor& bitwise_xor_Tensor_out(
1921
Tensor& out) {
2022
// @lint-ignore CLANGTIDY facebook-hte-CArray
2123
static constexpr const char op_name[] = "bitwise_xor.Tensor_out";
22-
return internal::bitwise_tensor_out<op_name>(ctx, a, b, out);
24+
return internal::bitwise_tensor_out<std::bit_xor, op_name>(ctx, a, b, out);
2325
}
2426

2527
Tensor& bitwise_xor_Scalar_out(
@@ -29,7 +31,7 @@ Tensor& bitwise_xor_Scalar_out(
2931
Tensor& out) {
3032
// @lint-ignore CLANGTIDY facebook-hte-CArray
3133
static constexpr const char op_name[] = "bitwise_xor.Scalar_out";
32-
return internal::bitwise_scalar_out<op_name>(ctx, a, b, out);
34+
return internal::bitwise_scalar_out<std::bit_xor, op_name>(ctx, a, b, out);
3335
}
3436

3537
} // namespace native

kernels/portable/cpu/op_eq.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <executorch/kernels/portable/cpu/pattern/comparison_op.h>
1010

11+
#include <functional>
12+
1113
namespace torch {
1214
namespace executor {
1315
namespace native {
@@ -19,7 +21,8 @@ Tensor& eq_tensor_out(
1921
Tensor& out) {
2022
// @lint-ignore CLANGTIDY facebook-hte-CArray
2123
static constexpr const char op_name[] = "eq.Tensor_out";
22-
return internal::comparison_tensor_out<op_name>(ctx, a, b, out);
24+
return internal::comparison_tensor_out<std::equal_to, op_name>(
25+
ctx, a, b, out);
2326
}
2427

2528
Tensor& eq_scalar_out(
@@ -29,7 +32,8 @@ Tensor& eq_scalar_out(
2932
Tensor& out) {
3033
// @lint-ignore CLANGTIDY facebook-hte-CArray
3134
static constexpr const char op_name[] = "eq.Scalar_out";
32-
return internal::comparison_scalar_out<op_name>(ctx, a, b, out);
35+
return internal::comparison_scalar_out<std::equal_to, op_name>(
36+
ctx, a, b, out);
3337
}
3438

3539
} // namespace native

kernels/portable/cpu/op_ge.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <executorch/kernels/portable/cpu/pattern/comparison_op.h>
1010

11+
#include <functional>
12+
1113
namespace torch {
1214
namespace executor {
1315
namespace native {
@@ -19,7 +21,8 @@ Tensor& ge_tensor_out(
1921
Tensor& out) {
2022
// @lint-ignore CLANGTIDY facebook-hte-CArray
2123
static constexpr const char op_name[] = "ge.Tensor_out";
22-
return internal::comparison_tensor_out<op_name>(ctx, a, b, out);
24+
return internal::comparison_tensor_out<std::greater_equal, op_name>(
25+
ctx, a, b, out);
2326
}
2427

2528
Tensor& ge_scalar_out(
@@ -29,7 +32,8 @@ Tensor& ge_scalar_out(
2932
Tensor& out) {
3033
// @lint-ignore CLANGTIDY facebook-hte-CArray
3134
static constexpr const char op_name[] = "ge.Scalar_out";
32-
return internal::comparison_scalar_out<op_name>(ctx, a, b, out);
35+
return internal::comparison_scalar_out<std::greater_equal, op_name>(
36+
ctx, a, b, out);
3337
}
3438

3539
} // namespace native

kernels/portable/cpu/op_gt.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <executorch/kernels/portable/cpu/pattern/comparison_op.h>
1010

11+
#include <functional>
12+
1113
namespace torch {
1214
namespace executor {
1315
namespace native {
@@ -19,7 +21,7 @@ Tensor& gt_tensor_out(
1921
Tensor& out) {
2022
// @lint-ignore CLANGTIDY facebook-hte-CArray
2123
static constexpr const char op_name[] = "gt.Tensor_out";
22-
return internal::comparison_tensor_out<op_name>(ctx, a, b, out);
24+
return internal::comparison_tensor_out<std::greater, op_name>(ctx, a, b, out);
2325
}
2426

2527
Tensor& gt_scalar_out(
@@ -29,7 +31,7 @@ Tensor& gt_scalar_out(
2931
Tensor& out) {
3032
// @lint-ignore CLANGTIDY facebook-hte-CArray
3133
static constexpr const char op_name[] = "gt.Scalar_out";
32-
return internal::comparison_scalar_out<op_name>(ctx, a, b, out);
34+
return internal::comparison_scalar_out<std::greater, op_name>(ctx, a, b, out);
3335
}
3436

3537
} // namespace native

kernels/portable/cpu/op_le.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <executorch/kernels/portable/cpu/pattern/comparison_op.h>
1010

11+
#include <functional>
12+
1113
namespace torch {
1214
namespace executor {
1315
namespace native {
@@ -19,7 +21,8 @@ Tensor& le_tensor_out(
1921
Tensor& out) {
2022
// @lint-ignore CLANGTIDY facebook-hte-CArray
2123
static constexpr const char op_name[] = "le.Tensor_out";
22-
return internal::comparison_tensor_out<op_name>(ctx, a, b, out);
24+
return internal::comparison_tensor_out<std::less_equal, op_name>(
25+
ctx, a, b, out);
2326
}
2427

2528
Tensor& le_scalar_out(
@@ -29,7 +32,8 @@ Tensor& le_scalar_out(
2932
Tensor& out) {
3033
// @lint-ignore CLANGTIDY facebook-hte-CArray
3134
static constexpr const char op_name[] = "le.Scalar_out";
32-
return internal::comparison_scalar_out<op_name>(ctx, a, b, out);
35+
return internal::comparison_scalar_out<std::less_equal, op_name>(
36+
ctx, a, b, out);
3337
}
3438

3539
} // namespace native

kernels/portable/cpu/op_lt.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <executorch/kernels/portable/cpu/pattern/comparison_op.h>
1010

11+
#include <functional>
12+
1113
namespace torch {
1214
namespace executor {
1315
namespace native {
@@ -19,7 +21,7 @@ Tensor& lt_tensor_out(
1921
Tensor& out) {
2022
// @lint-ignore CLANGTIDY facebook-hte-CArray
2123
static constexpr const char op_name[] = "lt.Tensor_out";
22-
return internal::comparison_tensor_out<op_name>(ctx, a, b, out);
24+
return internal::comparison_tensor_out<std::less, op_name>(ctx, a, b, out);
2325
}
2426

2527
Tensor& lt_scalar_out(
@@ -29,7 +31,7 @@ Tensor& lt_scalar_out(
2931
Tensor& out) {
3032
// @lint-ignore CLANGTIDY facebook-hte-CArray
3133
static constexpr const char op_name[] = "lt.Scalar_out";
32-
return internal::comparison_scalar_out<op_name>(ctx, a, b, out);
34+
return internal::comparison_scalar_out<std::less, op_name>(ctx, a, b, out);
3335
}
3436

3537
} // namespace native

kernels/portable/cpu/op_ne.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <executorch/kernels/portable/cpu/pattern/comparison_op.h>
1010

11+
#include <functional>
12+
1113
namespace torch {
1214
namespace executor {
1315
namespace native {
@@ -19,7 +21,8 @@ Tensor& ne_tensor_out(
1921
Tensor& out) {
2022
// @lint-ignore CLANGTIDY facebook-hte-CArray
2123
static constexpr const char op_name[] = "ne.Tensor_out";
22-
return internal::comparison_tensor_out<op_name>(ctx, a, b, out);
24+
return internal::comparison_tensor_out<std::not_equal_to, op_name>(
25+
ctx, a, b, out);
2326
}
2427

2528
Tensor& ne_scalar_out(
@@ -29,7 +32,8 @@ Tensor& ne_scalar_out(
2932
Tensor& out) {
3033
// @lint-ignore CLANGTIDY facebook-hte-CArray
3134
static constexpr const char op_name[] = "ne.Scalar_out";
32-
return internal::comparison_scalar_out<op_name>(ctx, a, b, out);
35+
return internal::comparison_scalar_out<std::not_equal_to, op_name>(
36+
ctx, a, b, out);
3337
}
3438

3539
} // namespace native

0 commit comments

Comments
 (0)