blob: 1d53b9a09361458bb2cc707a077fa34c9436ecbc [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Gunes Bayirbbeef722023-03-20 10:19:10 +00002 * Copyright (c) 2016-2023 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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#include "arm_compute/core/CL/CLHelpers.h"
Gian Marco Iodice8155c022021-04-16 15:08:59 +010025#include "arm_compute/core/CL/CLKernelLibrary.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026#include "arm_compute/core/CL/CLTypes.h"
27#include "arm_compute/core/Error.h"
Georgios Pinitas3faea252017-10-30 14:13:50 +000028#include "arm_compute/core/Log.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/core/Types.h"
Matthew Bentham043613f2023-05-30 16:43:14 +000030#include "arm_compute/core/Utils.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010031#include "src/gpu/cl/ClCompileContext.h"
Georgios Pinitas908f6162021-05-04 10:11:09 +010032
Georgios Pinitas7891a732021-08-20 21:39:25 +010033#include "src/gpu/cl/ClKernelLibrary.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +010035#include <utility>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036#include <vector>
37
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038namespace arm_compute
39{
40std::string get_cl_type_from_data_type(const DataType &dt)
41{
42 switch(dt)
43 {
44 case DataType::U8:
Michel Iwaniec00633802017-10-12 14:14:15 +010045 case DataType::QASYMM8:
46 return "uchar";
Georgios Pinitas3d13af82019-06-04 13:04:16 +010047 case DataType::S8:
Michele Di Giorgiof9179d32019-11-27 16:17:30 +000048 case DataType::QASYMM8_SIGNED:
Georgios Pinitas3d13af82019-06-04 13:04:16 +010049 case DataType::QSYMM8:
Michalis Spyrou3f632f32019-08-22 16:52:00 +010050 case DataType::QSYMM8_PER_CHANNEL:
Georgios Pinitas3d13af82019-06-04 13:04:16 +010051 return "char";
Anthony Barbier6ff3b192017-09-04 18:44:23 +010052 case DataType::U16:
Michele Di Giorgio4aff98f2019-08-28 16:27:26 +010053 case DataType::QASYMM16:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054 return "ushort";
55 case DataType::S16:
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010056 case DataType::QSYMM16:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010057 return "short";
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 case DataType::U32:
59 return "uint";
60 case DataType::S32:
61 return "int";
62 case DataType::U64:
63 return "ulong";
64 case DataType::S64:
65 return "long";
66 case DataType::F16:
67 return "half";
68 case DataType::F32:
69 return "float";
70 default:
71 ARM_COMPUTE_ERROR("Unsupported input data type.");
72 return "";
73 }
74}
75
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010076std::string get_cl_promoted_type_from_data_type(const DataType &dt)
77{
78 switch(dt)
79 {
80 case DataType::U8:
81 case DataType::QASYMM8:
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010082 return "ushort";
83 case DataType::S8:
Michele Di Giorgiof9179d32019-11-27 16:17:30 +000084 case DataType::QASYMM8_SIGNED:
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010085 case DataType::QSYMM8:
86 case DataType::QSYMM8_PER_CHANNEL:
87 return "short";
88 case DataType::U16:
89 case DataType::QASYMM16:
90 return "uint";
91 case DataType::S16:
92 case DataType::QSYMM16:
93 return "int";
94 case DataType::U32:
95 return "ulong";
96 case DataType::S32:
97 return "long";
98 case DataType::F16:
99 return "float";
100 default:
101 ARM_COMPUTE_ERROR("Cannot get promoted OpenCL type for the input data type.");
102 return "";
103 }
104}
105
106std::string get_cl_unsigned_type_from_element_size(size_t element_size)
107{
108 switch(element_size)
109 {
110 case 1:
111 return "uchar";
112 case 2:
113 return "ushort";
114 case 4:
115 return "uint";
116 case 8:
117 return "ulong";
118 default:
119 ARM_COMPUTE_ERROR("Data type not supported");
120 return "";
121 }
122}
123
Michalis Spyrou7317e392020-01-17 11:27:49 +0000124std::string get_cl_signed_type_from_element_size(size_t element_size)
125{
126 switch(element_size)
127 {
128 case 1:
129 return "char";
130 case 2:
131 return "short";
132 case 4:
133 return "int";
134 case 8:
135 return "long";
136 default:
137 ARM_COMPUTE_ERROR("Data type not supported");
138 return "";
139 }
140}
141
Giorgio Arena73023022018-09-04 14:55:55 +0100142std::string get_cl_select_type_from_data_type(const DataType &dt)
143{
144 switch(dt)
145 {
146 case DataType::U8:
Giorgio Arena73023022018-09-04 14:55:55 +0100147 case DataType::QASYMM8:
148 return "uchar";
Georgios Pinitas3d13af82019-06-04 13:04:16 +0100149 case DataType::S8:
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000150 case DataType::QASYMM8_SIGNED:
Georgios Pinitas3d13af82019-06-04 13:04:16 +0100151 case DataType::QSYMM8:
Michalis Spyrou3f632f32019-08-22 16:52:00 +0100152 case DataType::QSYMM8_PER_CHANNEL:
Georgios Pinitas3d13af82019-06-04 13:04:16 +0100153 return "char";
Giorgio Arena73023022018-09-04 14:55:55 +0100154 case DataType::U16:
Michele Di Giorgio4aff98f2019-08-28 16:27:26 +0100155 case DataType::QASYMM16:
Giorgio Arena73023022018-09-04 14:55:55 +0100156 return "ushort";
157 case DataType::F16:
158 case DataType::S16:
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100159 case DataType::QSYMM16:
Giorgio Arena73023022018-09-04 14:55:55 +0100160 return "short";
161 case DataType::U32:
162 return "uint";
163 case DataType::F32:
164 case DataType::S32:
165 return "int";
166 case DataType::U64:
167 return "ulong";
168 case DataType::S64:
169 return "long";
170 default:
171 ARM_COMPUTE_ERROR("Unsupported input data type.");
172 return "";
173 }
174}
175
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000176std::string get_cl_dot8_acc_type_from_data_type(const DataType &dt)
177{
178 switch(dt)
179 {
180 case DataType::U8:
181 case DataType::QASYMM8:
182 return "uint";
183 case DataType::S8:
184 case DataType::QASYMM8_SIGNED:
185 case DataType::QSYMM8:
186 case DataType::QSYMM8_PER_CHANNEL:
187 return "int";
188 default:
189 ARM_COMPUTE_ERROR("Unsupported data type.");
190 return "";
191 }
192}
193
SiCong Lic51b72f2017-07-28 14:46:20 +0100194std::string get_data_size_from_data_type(const DataType &dt)
195{
196 switch(dt)
197 {
198 case DataType::U8:
SiCong Lic51b72f2017-07-28 14:46:20 +0100199 case DataType::S8:
Georgios Pinitas3d13af82019-06-04 13:04:16 +0100200 case DataType::QSYMM8:
Michel Iwaniec00633802017-10-12 14:14:15 +0100201 case DataType::QASYMM8:
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000202 case DataType::QASYMM8_SIGNED:
Michalis Spyrou3f632f32019-08-22 16:52:00 +0100203 case DataType::QSYMM8_PER_CHANNEL:
SiCong Lic51b72f2017-07-28 14:46:20 +0100204 return "8";
205 case DataType::U16:
206 case DataType::S16:
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100207 case DataType::QSYMM16:
Michele Di Giorgio4aff98f2019-08-28 16:27:26 +0100208 case DataType::QASYMM16:
SiCong Lic51b72f2017-07-28 14:46:20 +0100209 case DataType::F16:
210 return "16";
211 case DataType::U32:
212 case DataType::S32:
213 case DataType::F32:
214 return "32";
215 case DataType::U64:
216 case DataType::S64:
217 return "64";
218 default:
219 ARM_COMPUTE_ERROR("Unsupported input data type.");
220 return "0";
221 }
222}
223
Anthony Barbierb6eb3532018-08-08 13:20:04 +0100224GPUTarget get_target_from_device(const cl::Device &device)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100225{
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100226 // Query device name size
Anthony Barbier30a63422018-02-28 18:18:24 +0000227 std::string device_name = device.getInfo<CL_DEVICE_NAME>();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100228
Michalis Spyroua9676112018-02-22 18:07:43 +0000229 return get_target_from_name(device_name);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100230}
231
Anthony Barbierd727e852018-04-20 11:05:29 +0100232bool arm_non_uniform_workgroup_supported(const cl::Device &device)
steniu0134702472017-07-11 09:22:58 +0100233{
Vidhya Sudhan Loganathaneb8a3992018-04-10 12:23:22 +0100234 return device_supports_extension(device, "cl_arm_non_uniform_work_group_size");
Matthew Bentham6f31f8c2017-10-27 11:50:06 +0100235}
steniu0134702472017-07-11 09:22:58 +0100236
Anthony Barbierd727e852018-04-20 11:05:29 +0100237bool fp16_supported(const cl::Device &device)
Matthew Bentham6f31f8c2017-10-27 11:50:06 +0100238{
Vidhya Sudhan Loganathaneb8a3992018-04-10 12:23:22 +0100239 return device_supports_extension(device, "cl_khr_fp16");
steniu0134702472017-07-11 09:22:58 +0100240}
241
Michalis Spyroue03342e2018-01-15 14:39:13 +0000242bool dot8_supported(const cl::Device &device)
243{
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100244 std::string device_name = device.getInfo<CL_DEVICE_NAME>();
245 const GPUTarget gpu_target = get_target_from_name(device_name);
246
247 // SW_WORKAROUND: Workaround for DDK revision r14p0.to enable cl_arm_integer_dot_product_int8
giuros018b6b4a92018-12-18 19:01:33 +0000248 std::set<GPUTarget> sw_workaround_issue = { GPUTarget::G76 };
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100249 return (device_supports_extension(device, "cl_arm_integer_dot_product_int8") || sw_workaround_issue.count(gpu_target) != 0);
Michalis Spyroue03342e2018-01-15 14:39:13 +0000250}
251
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100252bool dot8_acc_supported(const cl::Device &device)
253{
254 return device_supports_extension(device, "cl_arm_integer_dot_product_accumulate_int8");
255}
256
steniu0134702472017-07-11 09:22:58 +0100257CLVersion get_cl_version(const cl::Device &device)
258{
Anthony Barbier30a63422018-02-28 18:18:24 +0000259 std::string version_str = device.getInfo<CL_DEVICE_VERSION>();
Viet-Hoa Dof8bb0922022-05-30 15:15:15 +0100260 if(version_str.find("OpenCL 3") != std::string::npos)
261 {
262 return CLVersion::CL30;
263 }
264 else if(version_str.find("OpenCL 2") != std::string::npos)
steniu0134702472017-07-11 09:22:58 +0100265 {
266 return CLVersion::CL20;
267 }
268 else if(version_str.find("OpenCL 1.2") != std::string::npos)
269 {
270 return CLVersion::CL12;
271 }
272 else if(version_str.find("OpenCL 1.1") != std::string::npos)
273 {
274 return CLVersion::CL11;
275 }
276 else if(version_str.find("OpenCL 1.0") != std::string::npos)
277 {
278 return CLVersion::CL10;
279 }
280
281 return CLVersion::UNKNOWN;
282}
283
Vidhya Sudhan Loganathaneb8a3992018-04-10 12:23:22 +0100284bool device_supports_extension(const cl::Device &device, const char *extension_name)
285{
286 std::string extensions = device.getInfo<CL_DEVICE_EXTENSIONS>();
287 auto pos = extensions.find(extension_name);
288 return (pos != std::string::npos);
289}
290
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100291bool cl_winograd_convolution_layer_supported(const Size2D &output_tile, const Size2D &kernel_size, DataLayout data_layout)
292{
293 ARM_COMPUTE_ERROR_ON(data_layout == DataLayout::UNKNOWN);
294
295 using WinogradConfiguration = std::pair<std::pair<int, int>, std::pair<int, int>>;
296
Giorgio Arena149fdf32018-07-04 17:03:33 +0100297 std::vector<WinogradConfiguration> winograd_configs_nchw =
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100298 {
299 WinogradConfiguration(std::pair<int, int>(1, 2), std::pair<int, int>(1, 3)),
300 WinogradConfiguration(std::pair<int, int>(1, 4), std::pair<int, int>(1, 3)),
301 WinogradConfiguration(std::pair<int, int>(2, 1), std::pair<int, int>(3, 1)),
302 WinogradConfiguration(std::pair<int, int>(4, 1), std::pair<int, int>(3, 1)),
303 WinogradConfiguration(std::pair<int, int>(2, 2), std::pair<int, int>(3, 3)),
304 WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(3, 3)),
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100305 WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(5, 5)),
306 WinogradConfiguration(std::pair<int, int>(4, 1), std::pair<int, int>(5, 1)),
307 WinogradConfiguration(std::pair<int, int>(1, 4), std::pair<int, int>(1, 5))
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100308 };
309
Giorgio Arena149fdf32018-07-04 17:03:33 +0100310 std::vector<WinogradConfiguration> winograd_configs_nhwc =
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100311 {
312 WinogradConfiguration(std::pair<int, int>(2, 2), std::pair<int, int>(3, 3)),
Giorgio Arena149fdf32018-07-04 17:03:33 +0100313 WinogradConfiguration(std::pair<int, int>(1, 4), std::pair<int, int>(1, 3)),
314 WinogradConfiguration(std::pair<int, int>(4, 1), std::pair<int, int>(3, 1)),
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100315 WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(3, 3)),
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100316 WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(5, 5)),
317 WinogradConfiguration(std::pair<int, int>(4, 1), std::pair<int, int>(5, 1)),
Michele Di Giorgiof955d512019-02-27 14:26:51 +0000318 WinogradConfiguration(std::pair<int, int>(1, 4), std::pair<int, int>(1, 5)),
319 WinogradConfiguration(std::pair<int, int>(1, 2), std::pair<int, int>(1, 7)),
320 WinogradConfiguration(std::pair<int, int>(2, 1), std::pair<int, int>(7, 1)),
321 WinogradConfiguration(std::pair<int, int>(2, 2), std::pair<int, int>(7, 7)),
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100322 };
323
324 auto p = std::make_pair(std::pair<int, int>(output_tile.width, output_tile.height),
325 std::pair<int, int>(kernel_size.width, kernel_size.height));
326
327 // Return true if supported
328 if(data_layout == DataLayout::NCHW)
329 {
Giorgio Arena149fdf32018-07-04 17:03:33 +0100330 return (std::find(winograd_configs_nchw.begin(), winograd_configs_nchw.end(), p) != winograd_configs_nchw.end());
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100331 }
332 else
333 {
Giorgio Arena149fdf32018-07-04 17:03:33 +0100334 return (std::find(winograd_configs_nhwc.begin(), winograd_configs_nhwc.end(), p) != winograd_configs_nhwc.end());
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100335 }
336}
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +0000337
338size_t preferred_vector_width(const cl::Device &device, const DataType dt)
339{
340 switch(dt)
341 {
342 case DataType::U8:
343 case DataType::S8:
344 case DataType::QASYMM8:
Michele Di Giorgiof9179d32019-11-27 16:17:30 +0000345 case DataType::QASYMM8_SIGNED:
Georgios Pinitas3d13af82019-06-04 13:04:16 +0100346 case DataType::QSYMM8:
Michalis Spyrou3f632f32019-08-22 16:52:00 +0100347 case DataType::QSYMM8_PER_CHANNEL:
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +0000348 return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR>();
349 case DataType::U16:
350 case DataType::S16:
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100351 case DataType::QSYMM16:
Michele Di Giorgio4aff98f2019-08-28 16:27:26 +0100352 case DataType::QASYMM16:
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +0000353 return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT>();
354 case DataType::U32:
355 case DataType::S32:
356 return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT>();
357 case DataType::F16:
358 case DataType::F32:
359 return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT>();
360 case DataType::U64:
361 case DataType::S64:
362 return device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG>();
363 default:
364 return 1;
365 }
366}
Gian Marco Iodiceb0c50372019-03-15 10:13:05 +0000367
368bool preferred_dummy_work_items_support(const cl::Device &device)
369{
370 ARM_COMPUTE_UNUSED(device);
371 // TODO (COMPMID-2044)
372 return true;
373}
Pablo Tellodb8485a2019-09-24 11:03:47 +0100374
Gian Marco Iodicea98dee22020-06-02 12:12:35 +0100375bool image2d_from_buffer_supported(const cl::Device &device)
376{
377 return device_supports_extension(device, "cl_khr_image2d_from_buffer");
378}
379
380size_t get_cl_image_pitch_alignment(const cl::Device &device)
381{
382 cl_uint pixel_aligment = 0;
383
384 cl_int err = clGetDeviceInfo(device(), CL_DEVICE_IMAGE_PITCH_ALIGNMENT, sizeof(cl_uint), &pixel_aligment, nullptr);
385
386 if(err == CL_SUCCESS)
387 {
388 return pixel_aligment;
389 }
390 else
391 {
392 return 0;
393 }
394}
395
Viet-Hoa Dof8bb0922022-05-30 15:15:15 +0100396bool get_cl_non_uniform_work_group_supported(const cl::Device &device)
397{
398 cl_bool supported = CL_FALSE;
399
400 cl_int err = clGetDeviceInfo(device(), CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, sizeof(cl_bool), &supported, nullptr);
401
402 return (err == CL_SUCCESS && supported == CL_TRUE);
403}
404
Manuel Bottini256c0b92020-04-21 13:29:30 +0100405cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set<std::string> &build_opts)
Michalis Spyrou11d49182020-03-26 10:31:32 +0000406{
Georgios Pinitas908f6162021-05-04 10:11:09 +0100407 opencl::ClKernelLibrary &klib = opencl::ClKernelLibrary::get();
408
409 const std::string program_name = klib.program_name(kernel_name);
410 auto kernel_src = klib.program(program_name);
411 const std::string kernel_path = klib.kernel_path();
412
413 return static_cast<cl::Kernel>(ctx.create_kernel(kernel_name, program_name, kernel_src.program, kernel_path, build_opts, kernel_src.is_binary));
Michalis Spyrou11d49182020-03-26 10:31:32 +0000414}
415
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100416cl::NDRange create_lws_hint_parallel_implementations(unsigned int input_dimension, unsigned int vector_size)
417{
418 const unsigned int width_leftover = input_dimension % vector_size;
419 const unsigned int border_width = (width_leftover != 0) ? vector_size - width_leftover : 0;
420 const unsigned int num_of_threads = ((input_dimension + border_width) / 16);
421 return cl::NDRange(std::min(8U, num_of_threads));
422}
Manuel Bottinibe9f9f92021-01-25 15:07:17 +0000423
424bool get_wbsm_support_info(const cl::Device &device)
425{
426 cl_bitfield capabilities = 0;
Sheri Zhang79cb9452021-09-07 14:51:49 +0100427 cl_int err = clGetDeviceInfo(device.get(), CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, sizeof(cl_bitfield), &capabilities, nullptr);
428 if((err == CL_SUCCESS) && (capabilities & CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM))
Manuel Bottinibe9f9f92021-01-25 15:07:17 +0000429 {
430 return true;
431 }
432 return false;
433}
434
435void set_wbsm(cl::Kernel &kernel, cl_int wbsm_hint)
436{
437 cl_int err = clSetKernelExecInfo(kernel.get(),
Sheri Zhang79cb9452021-09-07 14:51:49 +0100438 CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM,
Manuel Bottinibe9f9f92021-01-25 15:07:17 +0000439 sizeof(cl_int),
440 &wbsm_hint);
441 ARM_COMPUTE_UNUSED(err);
442 ARM_COMPUTE_ERROR_ON(err != CL_SUCCESS);
443}
444
Gian Marco Iodicead9a7ed2022-09-16 14:14:21 +0100445bool export_to_cl_image(const ITensorInfo *tensor)
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100446{
Gunes Bayirbbeef722023-03-20 10:19:10 +0000447 if(tensor->tensor_shape()[0] % 4 != 0)
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100448 {
449 return false;
450 }
451
452 // If not floating point
453 if(!is_data_type_float(tensor->data_type()))
454 {
455 return false;
456 }
457
458 // Check if the cl_khr_image2d_from_buffer extension is supported on the target platform
459 if(!image2d_from_buffer_supported(CLKernelLibrary::get().get_device()))
460 {
461 return false;
462 }
463
464 // Check cl image pitch alignment
465 if(get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device()) == 0)
466 {
467 return false;
468 }
469
470 const size_t image_w = tensor->tensor_shape()[0] / 4;
Gunes Bayirbbeef722023-03-20 10:19:10 +0000471 const size_t image_h = tensor->tensor_shape().total_size() / tensor->tensor_shape()[0];
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100472 const size_t max_image_w = CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_IMAGE2D_MAX_WIDTH>();
473 const size_t max_image_h = CLKernelLibrary::get().get_device().getInfo<CL_DEVICE_IMAGE2D_MAX_HEIGHT>();
474
475 if(image_w > max_image_w || image_h > max_image_h)
476 {
477 return false;
478 }
479
480 return true;
481}
482
Gian Marco Iodice5e281812021-07-06 13:19:41 +0100483void set_unroll_with_pragma(CLBuildOptions &built_opts, std::initializer_list<int> values)
484{
485 for(const int value : values)
486 {
487 if(value > max_manual_loop_unrolling)
488 {
489 built_opts.add_option("-DUNROLL_WITH_PRAGMA");
490 return;
491 }
492 }
493}
494
Gunes Bayir4bfc70e2021-12-10 16:17:56 +0000495bool arm_matrix_multiply_supported(const cl::Device &device)
496{
497 return device_supports_extension(device, "cl_arm_matrix_multiply");
498}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100499} // namespace arm_compute