aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Svantesson <david.svantesson@arm.com>2023-08-02 14:23:00 +0000
committerDavid Svantesson <david.svantesson-yeung@arm.com>2023-11-24 15:03:05 +0000
commitded5b182675e3166e947a8eb637b5b1e925816ab (patch)
treec7bc082e7e8d80f0d33c69fc903be9dcb342e7f3 /src
parente30c8740d2da7af52ae1320f4d597ffc73d41c5e (diff)
downloadComputeLibrary-ded5b182675e3166e947a8eb637b5b1e925816ab.tar.gz
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 <david.svantesson-yeung@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10748 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: SiCong Li <sicong.li@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Benchmark: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src')
-rw-r--r--src/cpu/operators/CpuDepthwiseConv2dAssemblyDispatch.cpp4
-rw-r--r--src/cpu/operators/CpuPool2d.cpp4
-rw-r--r--src/cpu/operators/CpuWinogradConv2d.cpp6
-rw-r--r--src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp24
-rw-r--r--src/runtime/Scheduler.cpp32
5 files changed, 48 insertions, 22 deletions
diff --git a/src/cpu/operators/CpuDepthwiseConv2dAssemblyDispatch.cpp b/src/cpu/operators/CpuDepthwiseConv2dAssemblyDispatch.cpp
index 8d3741de96..8507c59e6b 100644
--- a/src/cpu/operators/CpuDepthwiseConv2dAssemblyDispatch.cpp
+++ b/src/cpu/operators/CpuDepthwiseConv2dAssemblyDispatch.cpp
@@ -60,8 +60,8 @@ void CpuDepthwiseConv2dAssemblyDispatch::configure(const ITensorInfo *src,
const ConvolutionInfo &info)
{
ARM_COMPUTE_LOG_PARAMS(src, weights, bias, dst, info);
- const CPUInfo &ci = NEScheduler::get().cpu_info();
- const unsigned int num_threads = NEScheduler::get().num_threads();
+ const CPUInfo &ci = CPUInfo::get();
+ const unsigned int num_threads = NEScheduler::num_threads();
_pImpl->is_prepared = false;
_pImpl->are_weights_const = weights->are_values_constant();
diff --git a/src/cpu/operators/CpuPool2d.cpp b/src/cpu/operators/CpuPool2d.cpp
index b72bde6978..d00efd191d 100644
--- a/src/cpu/operators/CpuPool2d.cpp
+++ b/src/cpu/operators/CpuPool2d.cpp
@@ -69,8 +69,8 @@ void CpuPool2d::configure(ITensorInfo *src, ITensorInfo *dst, const PoolingLayer
if (run_optimised)
{
- const CPUInfo &ci = NEScheduler::get().cpu_info();
- const unsigned int num_threads = NEScheduler::get().num_threads();
+ const CPUInfo &ci = CPUInfo::get();
+ const unsigned int num_threads = NEScheduler::num_threads();
auto pooling_wrapper = std::make_unique<kernels::CpuPool2dAssemblyWrapperKernel>();
ARM_COMPUTE_ERROR_ON(pooling_wrapper == nullptr);
diff --git a/src/cpu/operators/CpuWinogradConv2d.cpp b/src/cpu/operators/CpuWinogradConv2d.cpp
index e4bcdc0b64..1fb6d33a61 100644
--- a/src/cpu/operators/CpuWinogradConv2d.cpp
+++ b/src/cpu/operators/CpuWinogradConv2d.cpp
@@ -103,7 +103,7 @@ bool get_winograd_kernel_implementation(const ITensorInfo
Tensor4DShape in_shape{internal_get_shape(src)};
Tensor4DShape out_shape{internal_get_shape(dst)};
Tensor4DShape kernel_shape{internal_get_shape(weights)};
- uint32_t nthreads = NEScheduler::get().num_threads();
+ uint32_t nthreads = NEScheduler::num_threads();
// Get configuration arguments for Winograd
winograd_cfg.output_rows = 0;
winograd_cfg.output_cols = 0;
@@ -183,7 +183,7 @@ void CpuWinogradConv2d::configure(const ITensorInfo *src,
ARM_COMPUTE_LOG_PARAMS(src, weights, biases, dst, conv_info, act_info, enable_fast_math);
ARM_COMPUTE_UNUSED(biases);
const DataType data_type = src->data_type();
- uint32_t nthreads = NEScheduler::get().num_threads();
+ uint32_t nthreads = NEScheduler::num_threads();
_data_layout = src->data_layout();
const Tensor4DShape kernel_shape{internal_get_shape(weights)};
@@ -361,7 +361,7 @@ void CpuWinogradConv2d::run(ITensorPack &tensors)
auto output = tensors.get_tensor(ACL_DST);
Window win;
- const uint32_t nthreads = NEScheduler::get().num_threads();
+ const uint32_t nthreads = NEScheduler::num_threads();
// The Winograd transform implementation does fine-grain threading inside the transforms. Just pass thread_id and nthreads.
win.set(Window::DimX, Window::Dimension(0, nthreads, 1));
diff --git a/src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp b/src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp
index 611bc76463..7f851aa755 100644
--- a/src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp
+++ b/src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp
@@ -579,9 +579,8 @@ void Fallback<TypeInput, TypeOutput, OutputStage>::prepare(ITensorPack &tensors)
CpuAuxTensorHandler pretranspose(offset_int_vec(Pretranspose), _pretranspose_info, tensors, false);
ARM_COMPUTE_ERROR_ON(pretranspose.get()->buffer() == nullptr);
- run_parallel_pretranspose_B_array<TypeInput, TypeOutput>(_gemm_kernel_asm.get(), pretranspose.get(),
- in1_ptr, ldb, multi_stride_b,
- NEScheduler::get().num_threads());
+ run_parallel_pretranspose_B_array<TypeInput, TypeOutput>(
+ _gemm_kernel_asm.get(), pretranspose.get(), in1_ptr, ldb, multi_stride_b, NEScheduler::num_threads());
b->mark_as_unused();
// Note that we don't need to mark b_to_use as unused, as if it's been assigned to pre_pretransposed_b, its memory will be auto-managed by the handler
@@ -691,9 +690,8 @@ void Fallback<TypeInput, TypeOutput, OutputStage>::run(ITensorPack &tensors)
}
else
{
- run_parallel_pretranspose_B_array<TypeInput, TypeOutput>(_gemm_kernel_asm.get(), pretranspose.get(),
- b_ptr, ldb, multi_stride_b,
- NEScheduler::get().num_threads());
+ run_parallel_pretranspose_B_array<TypeInput, TypeOutput>(
+ _gemm_kernel_asm.get(), pretranspose.get(), b_ptr, ldb, multi_stride_b, NEScheduler::num_threads());
}
}
}
@@ -707,7 +705,7 @@ void Fallback<TypeInput, TypeOutput, OutputStage>::run(ITensorPack &tensors)
_gemm_kernel_asm->set_working_space(reinterpret_cast<void *>(workspace.get()->buffer()));
const unsigned int split_dim = scheduling_hint.split_dimension();
const unsigned int window_size = _gemm_kernel_asm->get_window_size().total_size();
- unsigned int num_threads = NEScheduler::get().num_threads();
+ unsigned int num_threads = NEScheduler::num_threads();
if (window_size < num_threads)
{
num_threads = window_size;
@@ -756,8 +754,8 @@ void create_arm_gemm(std::unique_ptr<CpuGemmAssemblyDispatch::IFallback> &arm_ge
const AsmGemmInfo &info)
{
Params p = extract_parameters(a, b, d, info);
- const CPUInfo &ci = NEScheduler::get().cpu_info();
- unsigned int num_threads = NEScheduler::get().num_threads();
+ const CPUInfo &ci = CPUInfo::get();
+ unsigned int num_threads = NEScheduler::num_threads();
arm_gemm::GemmConfig cfg;
cfg.weight_format = assembly_utils::map_to_arm_gemm_weight_format(info.weight_format);
@@ -781,8 +779,8 @@ void create_arm_gemm_quant(std::unique_ptr<CpuGemmAssemblyDispatch::IFallback> &
{
ARM_COMPUTE_UNUSED(activation);
Params p = extract_parameters(a, b, d, info);
- const CPUInfo &ci = NEScheduler::get().cpu_info();
- const unsigned int num_threads = NEScheduler::get().num_threads();
+ const CPUInfo &ci = CPUInfo::get();
+ const unsigned int num_threads = NEScheduler::num_threads();
arm_gemm::GemmConfig cfg;
cfg.weight_format = assembly_utils::map_to_arm_gemm_weight_format(info.weight_format);
@@ -836,8 +834,8 @@ Status CpuGemmAssemblyDispatch::has_opt_impl(arm_compute::WeightFormat &expected
ARM_COMPUTE_UNUSED(c);
arm_gemm::Activation act = assembly_utils::map_to_arm_gemm_activation(info.activation_info);
Params p = extract_parameters(a, b, d, info);
- const CPUInfo &ci = NEScheduler::get().cpu_info();
- unsigned int num_threads = NEScheduler::get().num_threads();
+ const CPUInfo &ci = CPUInfo::get();
+ unsigned int num_threads = NEScheduler::num_threads();
arm_gemm::GemmConfig cfg;
cfg.weight_format = assembly_utils::map_to_arm_gemm_weight_format(info.weight_format);
arm_gemm::WeightFormat arm_gemm_expected_wf = assembly_utils::map_to_arm_gemm_weight_format(expected_weight_format);
diff --git a/src/runtime/Scheduler.cpp b/src/runtime/Scheduler.cpp
index e52fb59940..6d961f29a5 100644
--- a/src/runtime/Scheduler.cpp
+++ b/src/runtime/Scheduler.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2020 Arm Limited.
+* Copyright (c) 2017-2020, 2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -40,14 +40,18 @@ using namespace arm_compute;
#if !ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER
Scheduler::Type Scheduler::_scheduler_type = Scheduler::Type::OMP;
#elif ARM_COMPUTE_CPP_SCHEDULER && !ARM_COMPUTE_OPENMP_SCHEDULER
-Scheduler::Type Scheduler::_scheduler_type = Scheduler::Type::CPP;
+Scheduler::Type Scheduler::_scheduler_type = Scheduler::Type::CPP;
#elif ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER
Scheduler::Type Scheduler::_scheduler_type = Scheduler::Type::CPP;
#else /* ARM_COMPUTE_*_SCHEDULER */
Scheduler::Type Scheduler::_scheduler_type = Scheduler::Type::ST;
#endif /* ARM_COMPUTE_*_SCHEDULER */
+#ifndef ARM_COMPUTE_THREAD_LOCAL_SCHEDULER
std::shared_ptr<IScheduler> Scheduler::_custom_scheduler = nullptr;
+#else // ARM_COMPUTE_THREAD_LOCAL_SCHEDULER
+std::shared_ptr<IScheduler> thread_local Scheduler::_custom_scheduler = nullptr;
+#endif // ARM_COMPUTE_THREAD_LOCAL_SCHEDULER
namespace
{
@@ -74,6 +78,30 @@ void Scheduler::set(Type t)
_scheduler_type = t;
}
+bool Scheduler::is_set()
+{
+ if (_scheduler_type == Type::CUSTOM)
+ {
+ return _custom_scheduler != nullptr;
+ }
+ else
+ {
+ return !_schedulers.empty();
+ }
+}
+
+unsigned int Scheduler::num_threads()
+{
+ if (Scheduler::is_set())
+ {
+ return Scheduler::get().num_threads();
+ }
+ else
+ {
+ return CPUInfo::get().get_cpu_num();
+ }
+}
+
bool Scheduler::is_available(Type t)
{
if (t == Type::CUSTOM)