[ONCPUML-7] Improvement to Window::split_window
authorJoseph Dobson <joseph.dobson@arm.com>
Tue, 11 Feb 2020 13:10:39 +0000 (13:10 +0000)
committerGian Marco Iodice <gianmarco.iodice@arm.com>
Fri, 1 May 2020 08:08:11 +0000 (08:08 +0000)
If the total passed to split window did not fit
nicely into the selected Dimensions size then
the size of of the window return will vary considerably
for different ids

This change means that the amount of work each id
will vary by the minimal amount.

For example:
If total was 10 and a Dimensions size was 19

With then with the old code :
* id 0 - 8 would get back 1,
* id 9 would get 10

With the new code:
* id 0-8 would get 2
* id 9 would get 1

Change-Id: I6b74b81d7ddcea06db7aa9fbaf8cb47a659994c1
Signed-off-by: Joseph Dobson <joseph.dobson@arm.com>
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/c/VisualCompute/ComputeLibrary/+/224448
Tested-by: bsgcomp <bsgcomp@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Comments-Addressed: bsgcomp <bsgcomp@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2961
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>

arm_compute/core/Window.inl

index c2131816a6d3a58deb4f20658f5328e08a2179b5..70c4f80ac2a7a3c52a37a6886af7906dff1ffbeb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2019 ARM Limited.
+ * Copyright (c) 2016-2020 ARM Limited.
  *
  * SPDX-License-Identifier: MIT
  *
@@ -197,18 +197,30 @@ inline Window Window::split_window(size_t dimension, size_t id, size_t total) co
     {
         if(d == dimension)
         {
-            int start          = _dims[d].start();
-            int end            = _dims[d].end();
-            int per_sub_window = (num_iterations(d) / total) * _dims[d].step();
+            int start        = _dims[d].start();
+            int end          = _dims[d].end();
+            const int step   = _dims[d].step();
 
-            start += id * per_sub_window;
+            const int num_it = num_iterations(d);
+            const int rem    = num_it % total;
+            int work         = num_it / total;
 
-            if(id != total - 1)
+            int it_start     = work * id;
+
+            if(int(id) < rem)
+            {
+                ++work;
+                it_start += id;
+            }
+            else
             {
-                end = start + per_sub_window;
+                it_start += rem;
             }
 
-            out.set(d, Dimension(start, end, _dims[d].step()));
+            start += it_start * step;
+            end = std::min(end, start + work * step);
+
+            out.set(d, Dimension(start, end, step));
         }
         else
         {