Skip to content
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

Add build-time config for threadpool size #7773

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions extension/threadpool/targets.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
load("@fbsource//xplat/executorch/backends/xnnpack/third-party:third_party_libs.bzl", "third_party_dep")
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

def get_threadpool_size():
return native.read_config("executorch", "threadpool_size")

def get_threadpool_flags():
flags = []
threadpool_size = get_threadpool_size()
if threadpool_size != None:
flags += ["-DET_THREADPOOL_SIZE=" + threadpool_size]
return flags

def define_common_targets():
"""Defines targets that should be shared between fbcode and xplat.
Expand Down Expand Up @@ -32,6 +42,7 @@ def define_common_targets():
exported_preprocessor_flags = [
"-DET_USE_THREADPOOL",
],
preprocessor_flags = get_threadpool_flags(),
visibility = [
"//executorch/...",
"//executorch/backends/...",
Expand Down
6 changes: 6 additions & 0 deletions extension/threadpool/threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ void ThreadPool::run(
// Make this part threadsafe: TODO(kimishpatel)
ThreadPool* get_threadpool() {
ET_CHECK_MSG(cpuinfo_initialize(), "cpuinfo initialization failed");

#ifdef ET_THREADPOOL_SIZE
int num_threads = ET_THREADPOOL_SIZE;
#else
int num_threads = cpuinfo_get_processors_count();
#endif

/*
* 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
Expand Down
Loading