From 385dad2bffecbf395aa9aad257809de81c727ac7 Mon Sep 17 00:00:00 2001 From: Milos Puzovic Date: Wed, 27 Jul 2022 18:35:28 +0000 Subject: Fix for OpenMP scheduler work breakdown If number of work items is greater than number of available threads then OpenMP scheduler will only execute as many work items as there are threads. This fix makes sure that we iterate through all work items and execute all of them. Change-Id: I3ad4b732c01fadc70dacaf09af3007d2b31086c7 Signed-off-by: Milos Puzovic Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/8001 Comments-Addressed: Arm Jenkins Benchmark: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Pablo Marquez Tello --- src/runtime/OMP/OMPScheduler.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/runtime/OMP/OMPScheduler.cpp b/src/runtime/OMP/OMPScheduler.cpp index e9b0bf4426..aad24b4f01 100644 --- a/src/runtime/OMP/OMPScheduler.cpp +++ b/src/runtime/OMP/OMPScheduler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2021 Arm Limited. + * Copyright (c) 2017-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -89,20 +89,21 @@ void OMPScheduler::schedule_op(ICPPKernel *kernel, const Hints &hints, const Win #ifndef DOXYGEN_SKIP_THIS void OMPScheduler::run_workloads(std::vector &workloads) { - const unsigned int num_threads = std::min(_num_threads, static_cast(workloads.size())); - if(num_threads < 1) + const unsigned int amount_of_work = static_cast(workloads.size()); + if(amount_of_work < 1 || _num_threads == 1) { return; } ThreadInfo info; info.cpu_info = &cpu_info(); - info.num_threads = num_threads; - #pragma omp parallel firstprivate(info) num_threads(num_threads) + info.num_threads = _num_threads; + #pragma omp parallel for firstprivate(info) num_threads(_num_threads) default(shared) proc_bind(close) schedule(static, 1) + for(unsigned int wid = 0; wid < amount_of_work; ++wid) { const int tid = omp_get_thread_num(); info.thread_id = tid; - workloads[tid](info); + workloads[wid](info); } } #endif /* DOXYGEN_SKIP_THIS */ -- cgit v1.2.1