-
Notifications
You must be signed in to change notification settings - Fork 748
Add EXECUTORCH_THREADPOOL_SIZE options, default to using only performance cores #14090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #include <executorch/extension/threadpool/cpuinfo_utils.h> | ||
| #include <executorch/extension/threadpool/threadpool.h> | ||
|
|
||
| #include <algorithm> | ||
|
|
@@ -14,9 +15,26 @@ | |
|
|
||
| #include <executorch/extension/threadpool/threadpool_guard.h> | ||
| #include <executorch/runtime/platform/assert.h> | ||
| #include <executorch/runtime/platform/runtime.h> | ||
|
|
||
| #include <cpuinfo.h> | ||
|
|
||
| // At most one mode should be set. | ||
| #if ( \ | ||
| defined(EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES) && \ | ||
| defined(EXECUTORCH_THREADPOOL_USE_PERFORMANCE_CORES)) | ||
| #error Multiple \ | ||
| threadpool size specifiers are set.At most one of \ | ||
| EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES, \ | ||
| and EXECUTORCH_THREADPOOL_USE_PERFORMANCE_CORES may be defined. | ||
| #endif | ||
|
|
||
| // Default to EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES if no mode is set. | ||
| #if !defined(EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES) && \ | ||
| !defined(EXECUTORCH_THREADPOOL_USE_PERFORMANCE_CORES) | ||
| #define EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES 1 | ||
| #endif | ||
|
|
||
| namespace executorch::extension::threadpool { | ||
|
|
||
| #if !(defined(WIN32)) | ||
|
|
@@ -96,12 +114,25 @@ void ThreadPool::run( | |
| // get_threadpool is not thread safe due to leak_corrupted_threadpool | ||
| // Make this part threadsafe: TODO(kimishpatel) | ||
| ThreadPool* get_threadpool() { | ||
| executorch::runtime::runtime_init(); | ||
|
|
||
| if (!cpuinfo_initialize()) { | ||
| ET_LOG(Error, "cpuinfo initialization failed"); | ||
| return nullptr; // NOLINT(facebook-hte-NullableReturn) | ||
| } | ||
|
|
||
| int num_threads = cpuinfo_get_processors_count(); | ||
| // Choose the number of threads according to the EXECUTORCH_THREADPOOL_ | ||
| // options. See the description in threadpool.h. | ||
|
|
||
| #if defined(EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES) | ||
| // Use threads=cores. | ||
| static int num_threads = cpuinfo_get_processors_count(); | ||
| #else | ||
| // Set threads equal to the number of performance cores. | ||
| static int num_threads = | ||
| ::executorch::extension::cpuinfo::get_num_performant_cores(); | ||
| #endif | ||
|
Comment on lines
+127
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default behavior than seems get num performance cores? I thought you would want this the other way around. That is by default you have logical cores and in oss cmake we can make performant core as default build option. Issue is that for internal uses now you only have performant cores
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In extension/threadpool/targets.bzl, I changed it to define EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES when not in OSS, so that should cover this case. If there's a better way to ensure this, I'm definitely open to it. I could add an API to retrieve the threadpool size and add an internal test to verify the behavior, if you'd like. |
||
|
|
||
| /* | ||
| * For llvm-tsan, holding limit for the number of locks for a single thread | ||
| * is 63 (because of comparison < 64 instead of <=). pthreadpool's worst | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.