From d7154dbf0f4a347f2f35f2475a893f1631c5ee1a Mon Sep 17 00:00:00 2001 From: Dana Zlotnik Date: Wed, 10 Nov 2021 11:50:58 +0200 Subject: Implement 1D Adaptive Workload Splitting in CPPScheduler Resolves COMPMID-4649 Change-Id: I941d2f8a40737ff05c49f6695a42884731ef2dc9 Signed-off-by: Dana Zlotnik Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6656 Tested-by: Arm Jenkins Reviewed-by: SiCong Li Comments-Addressed: Arm Jenkins --- src/runtime/IScheduler.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/runtime/IScheduler.cpp') diff --git a/src/runtime/IScheduler.cpp b/src/runtime/IScheduler.cpp index 004b8a46b6..1d068c9b38 100644 --- a/src/runtime/IScheduler.cpp +++ b/src/runtime/IScheduler.cpp @@ -25,6 +25,7 @@ #include "arm_compute/core/CPP/ICPPKernel.h" #include "arm_compute/core/Error.h" +#include "arm_compute/core/Log.h" #include "arm_compute/core/Window.h" #include "src/common/cpuinfo/CpuInfo.h" #include "src/runtime/SchedulerUtils.h" @@ -138,6 +139,9 @@ void IScheduler::schedule_common(ICPPKernel *kernel, const Hints &hints, const W default: ARM_COMPUTE_ERROR("Unknown strategy"); } + // Make sure the smallest window is larger than minimim workload size + num_windows = adjust_num_of_windows(max_window, hints.split_dimension(), num_windows, *kernel, cpu_info()); + std::vector workloads(num_windows); for(unsigned int t = 0; t < num_windows; ++t) { @@ -171,4 +175,37 @@ void IScheduler::run_tagged_workloads(std::vector &workloads, const ch run_workloads(workloads); } +std::size_t IScheduler::adjust_num_of_windows(const Window &window, std::size_t split_dimension, std::size_t init_num_windows, const ICPPKernel &kernel, const CPUInfo &cpu_info) +{ + // Mitigation of the narrow split issue, which occurs when the split dimension is too small to split (hence "narrow"). + if(window.num_iterations(split_dimension) < init_num_windows ) + { + auto recommended_split_dim = Window::DimX; + for(std::size_t dims = Window::DimY; dims <= Window::DimW; ++dims) + { + if(window.num_iterations(recommended_split_dim) < window.num_iterations(dims)) + { + recommended_split_dim = dims; + } + } + ARM_COMPUTE_LOG_INFO_MSG_WITH_FORMAT_CORE("%lu dimension is not a suitable dimension to split the workload. Recommended: %lu recommended_split_dim", split_dimension, + recommended_split_dim); + } + + for(auto t = init_num_windows; t > 0; --t) // Trying the highest number of windows ,init_num_windows, first + { + // Try splitting the workload into t, subject to each subworkload size <= mws. + if((window.num_iterations(split_dimension) / kernel.get_mws(cpu_info, t)) >= t) + { + if(t != init_num_windows) + { + ARM_COMPUTE_LOG_INFO_MSG_CORE("The scheduler is using a different thread count than the one assigned by the user."); + } + return t; + } + } + ARM_COMPUTE_LOG_INFO_MSG_CORE("The scheduler is using single thread instead of the thread count assigned by the user."); + return 1; // If the workload is so small that it can't be split, we should run a single thread +} + } // namespace arm_compute -- cgit v1.2.1