File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ def define_common_targets():
5656 exported_headers = ["thread_parallel_interface.h" ],
5757 exported_deps = [
5858 "//executorch/runtime/core:core" ,
59+ "//executorch/runtime/core/portable_type/c10/c10:c10" ,
5960 "//executorch/runtime/platform:platform" ,
6061 ],
6162 visibility = [
Original file line number Diff line number Diff line change 1111#include < cstdint>
1212#include < functional>
1313
14+ #include < c10/util/irange.h>
1415#include < executorch/runtime/core/error.h>
1516#include < executorch/runtime/platform/assert.h>
1617
@@ -29,7 +30,17 @@ inline bool parallel_for_no_threadpool(
2930 begin,
3031 end);
3132 ET_CHECK_OR_RETURN_FALSE (grain_size > 0 , " grain_size = %" PRId64, grain_size);
33+ #ifndef NDEBUG
34+ // Go backwards through the range elementwise to catch code that
35+ // assumes parallel_for is in order like a regular for loop.
36+ for (const auto i : c10::irange (begin, end)) {
37+ const auto offset = i - begin;
38+ const auto idx = end - offset - 1 ;
39+ f (idx, idx + 1 );
40+ }
41+ #else // NDEBUG
3242 f (begin, end);
43+ #endif
3344 return true ;
3445}
3546
You can’t perform that action at this time.
0 commit comments