Skip to content

Commit 5b18ec4

Browse files
committed
Adopt runtime::FunctionRef in thread_parallel_interface.h and thread_parallel.h
This saves a *ton* of size by no longer requiring callers to create std::function. Test Plan: bash test/build_optimized_size_test.sh && size test/size_test_all_optimized_ops before: ``` ExecuTorch with no ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 153928 Apr 24 13:11 cmake-out/test/size_test ExecuTorch with portable ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 2150960 Apr 24 13:11 cmake-out/test/size_test_all_ops ExecuTorch with optimized ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 11182136 Apr 24 13:11 cmake-out/test/size_test_all_optimized_ops __TEXT __DATA __OBJC others dec hex 5341184 98304 0 4300800000 4306239488 100ac0000 ``` after: ``` ExecuTorch with no ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 153928 Apr 24 13:07 cmake-out/test/size_test ExecuTorch with portable ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 2150960 Apr 24 13:07 cmake-out/test/size_test_all_ops ExecuTorch with optimized ops binary size, unstripped: -rwxr-xr-x 1 swolchok staff 5927336 Apr 24 13:07 cmake-out/test/size_test_all_optimized_ops __TEXT __DATA __OBJC others dec hex 4505600 98304 0 4296376320 4300980224 1005bc000 ```` `__TEXT` size improvement is 835584 bytes, or 15%. ghstack-source-id: 516b5a7eaf65bd0e41ede47f636d1ecbeecca57b ghstack-comment-id: 2828755250 Pull-Request-resolved: #10442
1 parent 15680fe commit 5b18ec4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

extension/threadpool/thread_parallel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool parallel_for(
5454
const int64_t begin,
5555
const int64_t end,
5656
const int64_t grain_size,
57-
const std::function<void(int64_t, int64_t)>& f) {
57+
runtime::FunctionRef<void(int64_t, int64_t)> f) {
5858
ET_CHECK_OR_RETURN_FALSE(
5959
begin >= 0 && end >= 0 && end >= begin,
6060
"begin = %" PRId64 ", end = %" PRId64,

runtime/kernel/thread_parallel_interface.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <c10/util/irange.h>
1515
#include <executorch/runtime/core/error.h>
16+
#include <executorch/runtime/core/function_ref.h>
1617
#include <executorch/runtime/platform/assert.h>
1718

1819
namespace executorch {
@@ -69,7 +70,7 @@ bool parallel_for(
6970
const int64_t begin,
7071
const int64_t end,
7172
const int64_t grain_size,
72-
const std::function<void(int64_t, int64_t)>& f);
73+
runtime::FunctionRef<void(int64_t, int64_t)> f);
7374

7475
int64_t get_thread_num();
7576

0 commit comments

Comments
 (0)