From ded5b182675e3166e947a8eb637b5b1e925816ab Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Wed, 2 Aug 2023 14:23:00 +0000 Subject: thread_local _custom_scheduler Resolves ONCPUML-1331 This patch adds an option to make _custom_scheduler thread_local to support usage of multiple schedulers handled outside of ACL. It also adds num_threads() function to Scheduler which reverts to querying CPUInfo if no scheduler has been set. Change-Id: Iff706165d8d091895331a5bb3a76f6cabe048912 Signed-off-by: David Svantesson-Yeung Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10748 Comments-Addressed: Arm Jenkins Reviewed-by: SiCong Li Tested-by: Arm Jenkins Benchmark: Arm Jenkins --- arm_compute/runtime/Scheduler.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'arm_compute') diff --git a/arm_compute/runtime/Scheduler.h b/arm_compute/runtime/Scheduler.h index bd29cbb31f..481e5e9b60 100644 --- a/arm_compute/runtime/Scheduler.h +++ b/arm_compute/runtime/Scheduler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Arm Limited. +* Copyright (c) 2017-2019, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -21,8 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef ARM_COMPUTE_SCHEDULER_H -#define ARM_COMPUTE_SCHEDULER_H +#ifndef ACL_ARM_COMPUTE_RUNTIME_SCHEDULER_H +#define ACL_ARM_COMPUTE_RUNTIME_SCHEDULER_H #include "arm_compute/runtime/IScheduler.h" @@ -72,13 +72,27 @@ public: * @return true if the given scheduler type is supported. False otherwise. */ static bool is_available(Type t); + /** Returns true if a scheduler has been set. + * + * @return true if a scheduler has been set. False otherwise. + */ + static bool is_set(); + /** Returns number of threads from scheduler if scheduler is set, otherwise queries CPUInfo. + * + * @return number of threads from scheduler if scheduler is set, otherwise queries CPUInfo. + */ + static unsigned int num_threads(); private: - static Type _scheduler_type; - static std::shared_ptr _custom_scheduler; + static Type _scheduler_type; +#ifndef ARM_COMPUTE_THREAD_LOCAL_SCHEDULER + static std::shared_ptr _custom_scheduler; +#else // ARM_COMPUTE_THREAD_LOCAL_SCHEDULER + static std::shared_ptr thread_local _custom_scheduler; +#endif // ARM_COMPUTE_THREAD_LOCAL_SCHEDULER static std::map> _schedulers; Scheduler(); }; } // namespace arm_compute -#endif /* ARM_COMPUTE_SCHEDULER_H */ +#endif // ACL_ARM_COMPUTE_RUNTIME_SCHEDULER_H -- cgit v1.2.1