From 72349cca95c720b09c69bc091b1e642cfb2a0b44 Mon Sep 17 00:00:00 2001 From: Hyeongseok Oh Date: Thu, 5 Sep 2024 16:41:51 +0900 Subject: [PATCH] [onert] Introduce NUM_THREADS config (#13929) This commit introduces `NUM_THREADS`. `NUM_THREADS` replaces `RUY_THREADS` and `XNNPACK_THREADS`. ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh --- runtime/onert/backend/cpu/ExternalContext.h | 2 +- runtime/onert/backend/ruy/ExternalContext.h | 2 +- runtime/onert/backend/xnnpack/BackendContext.h | 2 +- runtime/onert/core/include/util/Config.lst | 3 +-- runtime/onert/core/src/backend/builtin/ExternalContext.h | 2 +- tools/stab/backend_scheduler.py | 3 +-- tools/stab/remote.py | 3 +-- 7 files changed, 7 insertions(+), 10 deletions(-) diff --git a/runtime/onert/backend/cpu/ExternalContext.h b/runtime/onert/backend/cpu/ExternalContext.h index 6ed4799a80c..8c1f4ccf16c 100644 --- a/runtime/onert/backend/cpu/ExternalContext.h +++ b/runtime/onert/backend/cpu/ExternalContext.h @@ -37,7 +37,7 @@ class ExternalContext public: ExternalContext() : _ruy_context(new ruy::Context) { - setMaxNumThreads(onert::util::getConfigInt(onert::util::config::RUY_THREADS)); + setMaxNumThreads(onert::util::getConfigInt(onert::util::config::NUM_THREADS)); } void setMaxNumThreads(int max_num_threads) diff --git a/runtime/onert/backend/ruy/ExternalContext.h b/runtime/onert/backend/ruy/ExternalContext.h index c73ae636efb..e8502378a00 100644 --- a/runtime/onert/backend/ruy/ExternalContext.h +++ b/runtime/onert/backend/ruy/ExternalContext.h @@ -37,7 +37,7 @@ class ExternalContext public: ExternalContext() : _ruy_context(new ::ruy::Context) { - setMaxNumThreads(onert::util::getConfigInt(onert::util::config::RUY_THREADS)); + setMaxNumThreads(onert::util::getConfigInt(onert::util::config::NUM_THREADS)); } void setMaxNumThreads(int max_num_threads) diff --git a/runtime/onert/backend/xnnpack/BackendContext.h b/runtime/onert/backend/xnnpack/BackendContext.h index e3b66eef374..a88e0b9a6d2 100644 --- a/runtime/onert/backend/xnnpack/BackendContext.h +++ b/runtime/onert/backend/xnnpack/BackendContext.h @@ -42,7 +42,7 @@ class BackendContext : public onert::backend::BackendContext : onert::backend::BackendContext(backend, std::move(data), tensor_registry), tensor_builder{tensor_builder}, kernel_gen{kernel_gen}, _external_context(nullptr) { - int num_threads = util::getConfigInt(util::config::XNNPACK_THREADS); + int num_threads = util::getConfigInt(util::config::NUM_THREADS); if (num_threads < 1) num_threads = kDefaultNumThreadpoolThreads; // default num of threads _external_context.reset(new ExternalContext(static_cast(num_threads))); diff --git a/runtime/onert/core/include/util/Config.lst b/runtime/onert/core/include/util/Config.lst index 07479b70c74..bae8a30b2df 100644 --- a/runtime/onert/core/include/util/Config.lst +++ b/runtime/onert/core/include/util/Config.lst @@ -31,8 +31,7 @@ CONFIG(USE_SCHEDULER , bool , "0") CONFIG(TRACING_MODE , bool , "0") CONFIG(MINMAX_DUMP , bool , "0") CONFIG(FP16_ENABLE , bool , "0") -CONFIG(RUY_THREADS , int , "-1") -CONFIG(XNNPACK_THREADS , int , "-1") +CONFIG(NUM_THREADS , int , "-1") CONFIG(USE_MMAPED_DATA , bool , "0") CONFIG(WORKSPACE_DIR , std::string , ".") diff --git a/runtime/onert/core/src/backend/builtin/ExternalContext.h b/runtime/onert/core/src/backend/builtin/ExternalContext.h index 390dbb5799e..9ec222e5c56 100644 --- a/runtime/onert/core/src/backend/builtin/ExternalContext.h +++ b/runtime/onert/core/src/backend/builtin/ExternalContext.h @@ -42,7 +42,7 @@ class ExternalContext public: ExternalContext() : _ruy_context(std::make_unique()) { - setMaxNumThreads(onert::util::getConfigInt(onert::util::config::RUY_THREADS)); + setMaxNumThreads(onert::util::getConfigInt(onert::util::config::NUM_THREADS)); initPerThreadState(); } diff --git a/tools/stab/backend_scheduler.py b/tools/stab/backend_scheduler.py index b5a77f72727..57d1a15e183 100644 --- a/tools/stab/backend_scheduler.py +++ b/tools/stab/backend_scheduler.py @@ -145,8 +145,7 @@ def schedule(self): for op in op_list: cmd += [f"OP_BACKEND_{op}={default_backend}"] cmd += [f"BACKENDS={';'.join(backend_list)}"] - cmd += [f"RUY_THREADS={self.num_threads}"] - cmd += [f"XNNPACK_THREADS={self.num_threads}"] + cmd += [f"NUM_THREADS={self.num_threads}"] logging.info(' '.join(cmd)) # Create nnpackage with backend mapping diff --git a/tools/stab/remote.py b/tools/stab/remote.py index 4189bef9991..957c66cd227 100644 --- a/tools/stab/remote.py +++ b/tools/stab/remote.py @@ -74,8 +74,7 @@ def profile_backend(self, backend, backend_op_list): if backend == target_backend: for op in op_list: cmd += [f"OP_BACKEND_{op}={backend}"] - cmd += [f"XNNPACK_THREADS={self.num_threads}"] - cmd += [f"RUY_THREADS={self.num_threads}"] + cmd += [f"NUM_THREADS={self.num_threads}"] cmd += [f"BACKENDS=\'{';'.join(['cpu', backend])}\'"] cmd += [f"{nnpkg_run_path}"] cmd += [f"-w5 -r50"]