Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_ICLKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_ICLKERNEL_H__ |
| 26 | |
steniu01 | 5f91072 | 2017-08-23 10:15:22 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/CL/CLTypes.h" |
| 29 | #include "arm_compute/core/CL/OpenCL.h" |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/GPUTarget.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/IKernel.h" |
| 32 | |
Gian Marco | de691f0 | 2017-09-08 16:13:11 +0100 | [diff] [blame] | 33 | #include <string> |
| 34 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 35 | namespace arm_compute |
| 36 | { |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 37 | template <typename T> |
| 38 | class ICLArray; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | class ICLTensor; |
| 40 | class Window; |
| 41 | |
| 42 | /** Common interface for all the OpenCL kernels */ |
| 43 | class ICLKernel : public IKernel |
| 44 | { |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 45 | private: |
| 46 | /** Returns the number of arguments enqueued per array object. |
| 47 | * |
| 48 | * @return The number of arguments enqueued per array object. |
| 49 | */ |
| 50 | template <unsigned int dimension_size> |
| 51 | constexpr static unsigned int num_arguments_per_array() |
| 52 | { |
| 53 | return num_arguments_per_tensor<dimension_size>(); |
| 54 | } |
| 55 | /** Returns the number of arguments enqueued per tensor object. |
| 56 | * |
| 57 | * @return The number of arguments enqueued per tensor object. |
| 58 | */ |
| 59 | template <unsigned int dimension_size> |
| 60 | constexpr static unsigned int num_arguments_per_tensor() |
| 61 | { |
| 62 | return 2 + 2 * dimension_size; |
| 63 | } |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 64 | using IKernel::configure; //Prevent children from calling IKernel::configure() directly |
Anthony Barbier | 5a65cfd | 2018-08-10 14:10:08 +0100 | [diff] [blame] | 65 | protected: |
| 66 | /** Configure the kernel's window and local workgroup size hint. |
| 67 | * |
| 68 | * @param[in] window The maximum window which will be returned by window() |
| 69 | * @param[in] lws_hint (Optional) Local-Workgroup-Size to use. |
| 70 | */ |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 71 | void configure_internal(const Window &window, cl::NDRange lws_hint = CLKernelLibrary::get().default_ndrange()) |
| 72 | { |
| 73 | _lws_hint = lws_hint; |
| 74 | IKernel::configure(window); |
| 75 | } |
| 76 | |
Anthony Barbier | 5a65cfd | 2018-08-10 14:10:08 +0100 | [diff] [blame] | 77 | public: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 78 | /** Constructor */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 79 | ICLKernel() |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 80 | : _kernel(nullptr), _target(GPUTarget::MIDGARD), _config_id(arm_compute::default_config_id), _max_workgroup_size(0), _lws_hint() |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 81 | { |
| 82 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 83 | /** Returns a reference to the OpenCL kernel of this object. |
| 84 | * |
| 85 | * @return A reference to the OpenCL kernel of this object. |
| 86 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 87 | cl::Kernel &kernel() |
| 88 | { |
| 89 | return _kernel; |
| 90 | } |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 91 | /** Add the passed 1D array's parameters to the object's kernel's arguments starting from the index idx. |
| 92 | * |
| 93 | * @param[in,out] idx Index at which to start adding the array's arguments. Will be incremented by the number of kernel arguments set. |
| 94 | * @param[in] array Array to set as an argument of the object's kernel. |
| 95 | * @param[in] strides @ref Strides object containing stride of each dimension in bytes. |
| 96 | * @param[in] num_dimensions Number of dimensions of the @p array. |
| 97 | * @param[in] window Window the kernel will be executed on. |
| 98 | */ |
| 99 | template <typename T> |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 100 | void add_1D_array_argument(unsigned int &idx, const ICLArray<T> *array, const Strides &strides, unsigned int num_dimensions, const Window &window) |
| 101 | { |
| 102 | add_array_argument<T, 1>(idx, array, strides, num_dimensions, window); |
| 103 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 104 | /** Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 105 | * |
| 106 | * @param[in,out] idx Index at which to start adding the tensor's arguments. Will be incremented by the number of kernel arguments set. |
| 107 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 108 | * @param[in] window Window the kernel will be executed on. |
| 109 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 110 | void add_1D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window) |
| 111 | { |
| 112 | add_tensor_argument<1>(idx, tensor, window); |
| 113 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 114 | /** Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 115 | * |
| 116 | * @param[in,out] idx Index at which to start adding the tensor's arguments. Will be incremented by the number of kernel arguments set. |
| 117 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 118 | * @param[in] window Window the kernel will be executed on. |
| 119 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 120 | void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window) |
| 121 | { |
| 122 | add_tensor_argument<2>(idx, tensor, window); |
| 123 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 124 | /** Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 125 | * |
| 126 | * @param[in,out] idx Index at which to start adding the tensor's arguments. Will be incremented by the number of kernel arguments set. |
| 127 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 128 | * @param[in] window Window the kernel will be executed on. |
| 129 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 130 | void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window) |
| 131 | { |
| 132 | add_tensor_argument<3>(idx, tensor, window); |
| 133 | } |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 134 | /** Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 135 | * |
| 136 | * @param[in,out] idx Index at which to start adding the tensor's arguments. Will be incremented by the number of kernel arguments set. |
| 137 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 138 | * @param[in] window Window the kernel will be executed on. |
| 139 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 140 | void add_4D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window) |
| 141 | { |
| 142 | add_tensor_argument<4>(idx, tensor, window); |
| 143 | } |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 144 | /** Returns the number of arguments enqueued per 1D array object. |
| 145 | * |
| 146 | * @return The number of arguments enqueues per 1D array object. |
| 147 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 148 | constexpr static unsigned int num_arguments_per_1D_array() |
| 149 | { |
| 150 | return num_arguments_per_array<1>(); |
| 151 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 152 | /** Returns the number of arguments enqueued per 1D tensor object. |
| 153 | * |
| 154 | * @return The number of arguments enqueues per 1D tensor object. |
| 155 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 156 | constexpr static unsigned int num_arguments_per_1D_tensor() |
| 157 | { |
| 158 | return num_arguments_per_tensor<1>(); |
| 159 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 160 | /** Returns the number of arguments enqueued per 2D tensor object. |
| 161 | * |
| 162 | * @return The number of arguments enqueues per 2D tensor object. |
| 163 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 164 | constexpr static unsigned int num_arguments_per_2D_tensor() |
| 165 | { |
| 166 | return num_arguments_per_tensor<2>(); |
| 167 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 168 | /** Returns the number of arguments enqueued per 3D tensor object. |
| 169 | * |
| 170 | * @return The number of arguments enqueues per 3D tensor object. |
| 171 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 172 | constexpr static unsigned int num_arguments_per_3D_tensor() |
| 173 | { |
| 174 | return num_arguments_per_tensor<3>(); |
| 175 | } |
steniu01 | 868e541 | 2017-07-17 23:16:00 +0100 | [diff] [blame] | 176 | /** Returns the number of arguments enqueued per 4D tensor object. |
| 177 | * |
| 178 | * @return The number of arguments enqueues per 4D tensor object. |
| 179 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 180 | constexpr static unsigned int num_arguments_per_4D_tensor() |
| 181 | { |
| 182 | return num_arguments_per_tensor<4>(); |
| 183 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 184 | /** Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. |
| 185 | * |
| 186 | * @note The queue is *not* flushed by this method, and therefore the kernel will not have been executed by the time this method returns. |
| 187 | * |
| 188 | * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()). |
| 189 | * @param[in,out] queue Command queue on which to enqueue the kernel. |
| 190 | */ |
| 191 | virtual void run(const Window &window, cl::CommandQueue &queue) = 0; |
| 192 | /** Add the passed parameters to the object's kernel's arguments starting from the index idx. |
| 193 | * |
| 194 | * @param[in,out] idx Index at which to start adding the arguments. Will be incremented by the number of kernel arguments set. |
| 195 | * @param[in] value Value to set as an argument of the object's kernel. |
| 196 | */ |
| 197 | template <typename T> |
| 198 | void add_argument(unsigned int &idx, T value) |
| 199 | { |
| 200 | _kernel.setArg(idx++, value); |
| 201 | } |
| 202 | |
Gian Marco Iodice | 9331aeb | 2017-08-10 17:11:08 +0100 | [diff] [blame] | 203 | /** Set the Local-Workgroup-Size hint |
| 204 | * |
| 205 | * @note This method should be called after the configuration of the kernel |
| 206 | * |
| 207 | * @param[in] lws_hint Local-Workgroup-Size to use |
| 208 | */ |
Anthony Barbier | d727e85 | 2018-04-20 11:05:29 +0100 | [diff] [blame] | 209 | void set_lws_hint(const cl::NDRange &lws_hint) |
Gian Marco Iodice | 9331aeb | 2017-08-10 17:11:08 +0100 | [diff] [blame] | 210 | { |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 211 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); // lws_hint will be overwritten by configure() |
Gian Marco Iodice | 9331aeb | 2017-08-10 17:11:08 +0100 | [diff] [blame] | 212 | _lws_hint = lws_hint; |
| 213 | } |
| 214 | |
Georgios Pinitas | c0d1c86 | 2018-03-23 15:13:15 +0000 | [diff] [blame] | 215 | /** Return the Local-Workgroup-Size hint |
| 216 | * |
| 217 | * @return Current lws hint |
| 218 | */ |
| 219 | cl::NDRange lws_hint() const |
| 220 | { |
| 221 | return _lws_hint; |
| 222 | } |
| 223 | |
Gian Marco | de691f0 | 2017-09-08 16:13:11 +0100 | [diff] [blame] | 224 | /** Get the configuration ID |
| 225 | * |
| 226 | * @note The configuration ID can be used by the caller to distinguish different calls of the same OpenCL kernel |
| 227 | * In particular, this method can be used by CLScheduler to keep track of the best LWS for each configuration of the same kernel. |
| 228 | * The configuration ID should be provided only for the kernels potentially affected by the LWS geometry |
| 229 | * |
| 230 | * @note This method should be called after the configuration of the kernel |
| 231 | * |
| 232 | * @return configuration id string |
| 233 | */ |
| 234 | const std::string &config_id() const |
| 235 | { |
| 236 | return _config_id; |
| 237 | } |
| 238 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 239 | /** Set the targeted GPU architecture |
| 240 | * |
| 241 | * @param[in] target The targeted GPU architecture |
| 242 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 243 | void set_target(GPUTarget target) |
| 244 | { |
| 245 | _target = target; |
| 246 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 247 | |
| 248 | /** Set the targeted GPU architecture according to the CL device |
| 249 | * |
| 250 | * @param[in] device A CL device |
| 251 | */ |
| 252 | void set_target(cl::Device &device); |
| 253 | |
| 254 | /** Get the targeted GPU architecture |
| 255 | * |
| 256 | * @return The targeted GPU architecture. |
| 257 | */ |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 258 | GPUTarget get_target() const |
| 259 | { |
| 260 | return _target; |
| 261 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 262 | |
Abel Bernabeu | 5a6e053 | 2017-09-28 09:53:45 +0100 | [diff] [blame] | 263 | /** Get the maximum workgroup size for the device the CLKernelLibrary uses. |
| 264 | * |
| 265 | * @return The maximum workgroup size value. |
| 266 | */ |
| 267 | size_t get_max_workgroup_size(); |
Georgios Pinitas | 1f378ee | 2017-10-27 13:37:16 +0100 | [diff] [blame] | 268 | /** Get the global work size given an execution window |
| 269 | * |
| 270 | * @param[in] window Execution window |
| 271 | * |
| 272 | * @return Global work size of the given execution window |
| 273 | */ |
| 274 | static cl::NDRange gws_from_window(const Window &window); |
Abel Bernabeu | 5a6e053 | 2017-09-28 09:53:45 +0100 | [diff] [blame] | 275 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 276 | private: |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 277 | /** Add the passed array's parameters to the object's kernel's arguments starting from the index idx. |
| 278 | * |
| 279 | * @param[in,out] idx Index at which to start adding the array's arguments. Will be incremented by the number of kernel arguments set. |
| 280 | * @param[in] array Array to set as an argument of the object's kernel. |
| 281 | * @param[in] strides @ref Strides object containing stride of each dimension in bytes. |
| 282 | * @param[in] num_dimensions Number of dimensions of the @p array. |
| 283 | * @param[in] window Window the kernel will be executed on. |
| 284 | */ |
| 285 | template <typename T, unsigned int dimension_size> |
| 286 | void add_array_argument(unsigned int &idx, const ICLArray<T> *array, const Strides &strides, unsigned int num_dimensions, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 287 | /** Add the passed tensor's parameters to the object's kernel's arguments starting from the index idx. |
| 288 | * |
| 289 | * @param[in,out] idx Index at which to start adding the tensor's arguments. Will be incremented by the number of kernel arguments set. |
| 290 | * @param[in] tensor Tensor to set as an argument of the object's kernel. |
| 291 | * @param[in] window Window the kernel will be executed on. |
| 292 | */ |
| 293 | template <unsigned int dimension_size> |
| 294 | void add_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 295 | |
| 296 | protected: |
Abel Bernabeu | 5a6e053 | 2017-09-28 09:53:45 +0100 | [diff] [blame] | 297 | cl::Kernel _kernel; /**< OpenCL kernel to run */ |
Abel Bernabeu | 5a6e053 | 2017-09-28 09:53:45 +0100 | [diff] [blame] | 298 | GPUTarget _target; /**< The targeted GPU */ |
| 299 | std::string _config_id; /**< Configuration ID */ |
| 300 | size_t _max_workgroup_size; /**< The maximum workgroup size for this kernel */ |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 301 | private: |
| 302 | cl::NDRange _lws_hint; /**< Local workgroup size hint for the OpenCL kernel */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | /** Add the kernel to the command queue with the given window. |
| 306 | * |
| 307 | * @note Depending on the size of the window, this might translate into several jobs being enqueued. |
| 308 | * |
| 309 | * @note If kernel->kernel() is empty then the function will return without adding anything to the queue. |
| 310 | * |
| 311 | * @param[in,out] queue OpenCL command queue. |
| 312 | * @param[in] kernel Kernel to enqueue |
| 313 | * @param[in] window Window the kernel has to process. |
Michalis Spyrou | a967611 | 2018-02-22 18:07:43 +0000 | [diff] [blame] | 314 | * @param[in] lws_hint Local workgroup size requested. Default is based on the device target. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 315 | * |
| 316 | * @note If any dimension of the lws is greater than the global workgroup size then no lws will be passed. |
| 317 | */ |
steniu01 | 5f91072 | 2017-08-23 10:15:22 +0100 | [diff] [blame] | 318 | void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint = CLKernelLibrary::get().default_ndrange()); |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 319 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 320 | /** Add the passed array's parameters to the object's kernel's arguments starting from the index idx. |
| 321 | * |
| 322 | * @param[in,out] idx Index at which to start adding the array's arguments. Will be incremented by the number of kernel arguments set. |
| 323 | * @param[in] array Array to set as an argument of the object's kernel. |
| 324 | * @param[in] strides @ref Strides object containing stride of each dimension in bytes. |
| 325 | * @param[in] num_dimensions Number of dimensions of the @p array. |
| 326 | * @param[in] window Window the kernel will be executed on. |
| 327 | */ |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 328 | template <typename T, unsigned int dimension_size> |
| 329 | void ICLKernel::add_array_argument(unsigned &idx, const ICLArray<T> *array, const Strides &strides, unsigned int num_dimensions, const Window &window) |
| 330 | { |
Diego Lopez Recas | 0021d75 | 2017-12-18 14:42:56 +0000 | [diff] [blame] | 331 | ARM_COMPUTE_ERROR_ON(array == nullptr); |
| 332 | |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 333 | // Calculate offset to the start of the window |
| 334 | unsigned int offset_first_element = 0; |
| 335 | |
| 336 | for(unsigned int n = 0; n < num_dimensions; ++n) |
| 337 | { |
| 338 | offset_first_element += window[n].start() * strides[n]; |
| 339 | } |
| 340 | |
| 341 | unsigned int idx_start = idx; |
| 342 | _kernel.setArg(idx++, array->cl_buffer()); |
| 343 | |
| 344 | for(unsigned int dimension = 0; dimension < dimension_size; dimension++) |
| 345 | { |
| 346 | _kernel.setArg<cl_uint>(idx++, strides[dimension]); |
| 347 | _kernel.setArg<cl_uint>(idx++, strides[dimension] * window[dimension].step()); |
| 348 | } |
| 349 | |
| 350 | _kernel.setArg<cl_uint>(idx++, offset_first_element); |
| 351 | |
| 352 | ARM_COMPUTE_ERROR_ON_MSG(idx_start + num_arguments_per_array<dimension_size>() != idx, |
| 353 | "add_%dD_array_argument() is supposed to add exactly %d arguments to the kernel", dimension_size, num_arguments_per_array<dimension_size>()); |
| 354 | ARM_COMPUTE_UNUSED(idx_start); |
| 355 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 356 | } |
| 357 | #endif /*__ARM_COMPUTE_ICLKERNEL_H__ */ |