blob: 009d4db5351306e11bb176c9073b3a36b9af4b97 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrou5237e012018-01-17 09:40:27 +00002 * Copyright (c) 2016-2018 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/CLKernelLibrary.h"
25
steniu0134702472017-07-11 09:22:58 +010026#include "arm_compute/core/CL/CLHelpers.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Error.h"
28#include "arm_compute/core/Utils.h"
29
steniu015f910722017-08-23 10:15:22 +010030#include <algorithm>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include <fstream>
32#include <iostream>
33#include <utility>
34#include <vector>
35
36using namespace arm_compute;
37
Georgios Pinitas388d3ec2017-11-02 12:17:56 +000038CLBuildOptions::CLBuildOptions()
39 : _build_opts()
40{
41}
42
43void CLBuildOptions::add_option(std::string option)
44{
45 _build_opts.emplace(std::move(option));
46}
47
48void CLBuildOptions::add_option_if(bool cond, std::string option)
49{
50 if(cond)
51 {
52 add_option(std::move(option));
53 }
54}
55
56void CLBuildOptions::add_option_if_else(bool cond, std::string option_true, std::string option_false)
57{
58 (cond) ? add_option(std::move(option_true)) : add_option(std::move(option_false));
59}
60
Chunosovf450caa2017-11-08 16:09:35 +070061void CLBuildOptions::add_options(const StringSet &options)
62{
63 _build_opts.insert(options.begin(), options.end());
64}
65
66void CLBuildOptions::add_options_if(bool cond, const StringSet &options)
67{
68 if(cond)
69 {
70 add_options(options);
71 }
72}
73
Chunosovd621bca2017-11-03 17:33:15 +070074const CLBuildOptions::StringSet &CLBuildOptions::options() const
Georgios Pinitas388d3ec2017-11-02 12:17:56 +000075{
76 return _build_opts;
77}
78
Anthony Barbier6ff3b192017-09-04 18:44:23 +010079Program::Program()
80 : _context(), _device(), _is_binary(false), _name(), _source(), _binary()
81{
82}
83
84Program::Program(cl::Context context, std::string name, std::string source)
85 : _context(std::move(context)), _device(), _is_binary(false), _name(std::move(name)), _source(std::move(source)), _binary()
86{
87}
88
89Program::Program(cl::Context context, cl::Device device, std::string name, std::vector<unsigned char> binary)
90 : _context(std::move(context)), _device(std::move(device)), _is_binary(true), _name(std::move(name)), _source(), _binary(std::move(binary))
91{
92}
93
94Program::operator cl::Program() const
95{
96 if(_is_binary)
97 {
98 return cl::Program(_context, { _device }, { _binary });
99 }
100 else
101 {
102 return cl::Program(_context, _source, false);
103 }
104}
105
106bool Program::build(const cl::Program &program, const std::string &build_options)
107{
108 try
109 {
110 return program.build(build_options.c_str()) == CL_SUCCESS;
111 }
112 catch(const cl::Error &e)
113 {
114 cl_int err = CL_SUCCESS;
115 const auto build_info = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&err);
116
117 for(auto &pair : build_info)
118 {
119 std::cerr << pair.second << std::endl;
120 }
121
122 return false;
123 }
124}
125
126cl::Program Program::build(const std::string &build_options) const
127{
128 cl::Program cl_program = static_cast<cl::Program>(*this);
129 build(cl_program, build_options);
130 return cl_program;
131}
132
133Kernel::Kernel()
134 : _name(), _kernel()
135{
136}
137
138Kernel::Kernel(std::string name, const cl::Program &program)
139 : _name(std::move(name)),
140 _kernel(cl::Kernel(program, _name.c_str()))
141{
142}
143
144const std::map<std::string, std::string> CLKernelLibrary::_kernel_program_map =
145{
146 { "absdiff", "absdiff.cl" },
147 { "accumulate", "accumulate.cl" },
148 { "accumulate_squared", "accumulate.cl" },
149 { "accumulate_weighted", "accumulate.cl" },
150 { "activation_layer", "activation_layer.cl" },
Michel Iwaniec00633802017-10-12 14:14:15 +0100151 { "activation_layer_qa8", "activation_layer_qa8.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152 { "arithmetic_add", "arithmetic_op.cl" },
153 { "arithmetic_sub", "arithmetic_op.cl" },
Michele Di Giorgiobf3c6622018-03-08 11:52:27 +0000154 { "batchnormalization_layer_nchw", "batchnormalization_layer.cl" },
155 { "batchnormalization_layer_nhwc", "batchnormalization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100156 { "bitwise_or", "bitwise_op.cl" },
157 { "bitwise_and", "bitwise_op.cl" },
158 { "bitwise_xor", "bitwise_op.cl" },
159 { "bitwise_not", "bitwise_op.cl" },
160 { "channel_combine_NV", "channel_combine.cl" },
161 { "channel_combine_RGB888", "channel_combine.cl" },
162 { "channel_combine_RGBA8888", "channel_combine.cl" },
163 { "channel_combine_UYVY422", "channel_combine.cl" },
164 { "channel_combine_YUYV422", "channel_combine.cl" },
Michele Di Giorgio72175632018-05-01 16:52:00 +0100165 { "channel_shuffle_nchw", "channel_shuffle.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100166 { "channel_extract_NV12", "channel_extract.cl" },
167 { "channel_extract_NV21", "channel_extract.cl" },
168 { "channel_extract_RGB888", "channel_extract.cl" },
169 { "channel_extract_RGBA8888", "channel_extract.cl" },
170 { "channel_extract_UYVY422", "channel_extract.cl" },
171 { "channel_extract_YUYV422", "channel_extract.cl" },
172 { "combine_gradients_L1", "canny.cl" },
173 { "combine_gradients_L2", "canny.cl" },
174 { "concatenate_depth", "concatenate.cl" },
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100175 { "concatenate_width", "concatenate.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100176 { "convolution_rectangle", "convolution_rectangle.cl" },
Gian Marco76faef82018-01-29 12:15:32 +0000177 { "col2im", "col2im.cl" },
Giorgio Arena657bdb32018-04-26 18:52:01 +0100178 { "convert_depth_down", "depth_convert.cl" },
179 { "convert_depth_up", "depth_convert.cl" },
180 { "convert_fc_weights", "convert_fc_weights.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100181 { "convolution3x3_static", "convolution3x3.cl" },
182 { "convolution5x5_static", "convolution5x5.cl" },
183 { "convolution7x7_static", "convolution7x7.cl" },
184 { "convolution9x9_static", "convolution9x9.cl" },
185 { "convolution_separable1x5_static", "convolution5x5.cl" },
186 { "convolution_separable5x1_static", "convolution5x5.cl" },
187 { "convolution_separable1x7_static", "convolution7x7.cl" },
188 { "convolution_separable7x1_static", "convolution7x7.cl" },
189 { "convolution_separable1x9_static", "convolution9x9.cl" },
190 { "convolution_separable9x1_static", "convolution9x9.cl" },
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000191 { "copy_tensor", "copy_tensor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100192 { "copy_plane", "channel_extract.cl" },
193 { "copy_planes_3p", "channel_combine.cl" },
194 { "copy_to_keypoint", "fast_corners.cl" },
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000195 { "deconvolution_upsample", "deconvolution_layer.cl" },
Giorgio Arena93a690e2017-08-01 16:09:33 +0100196 { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
Michele Di Giorgio933fe862018-02-19 15:42:12 +0000197 { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000198 { "depthwise_convolution_3x3_quantized_nchw", "depthwise_convolution_quantized.cl" },
199 { "depthwise_convolution_3x3_quantized_nhwc_stride1", "depthwise_convolution_quantized.cl" },
200 { "depthwise_convolution_3x3_quantized_nhwc_stride2", "depthwise_convolution_quantized.cl" },
Michele Di Giorgio3ebef322018-02-21 10:02:58 +0000201 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16", "depthwise_convolution.cl" },
202 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16", "depthwise_convolution.cl" },
203 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32", "depthwise_convolution.cl" },
204 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32", "depthwise_convolution.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100205 { "depthwise_im2col", "depthwise_convolution.cl" },
206 { "depthwise_vector_to_tensor", "depthwise_convolution.cl" },
207 { "depthwise_weights_reshape", "depthwise_convolution.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100208 { "dequantization_layer", "dequantization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100209 { "derivative", "derivative.cl" },
210 { "dilate", "dilate.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100211 { "direct_convolution1x1", "direct_convolution1x1.cl" },
Gian Marco Iodice1c8409d2017-09-06 17:24:25 +0100212 { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100213 { "direct_convolution3x3", "direct_convolution3x3.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100214 { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
steniu01db006682017-08-09 16:26:22 +0100215 { "direct_convolution5x5", "direct_convolution5x5.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100216 { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
Chunosovd621bca2017-11-03 17:33:15 +0700217 { "direct_convolution_1x1_3x3_5x5_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100218 { "erode", "erode.cl" },
219 { "fast_corners", "fast_corners.cl" },
220 { "fill_image_borders_constant", "fill_border.cl" },
221 { "fill_image_borders_replicate", "fill_border.cl" },
222 { "finalize", "optical_flow_pyramid_lk.cl" },
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100223 { "floor_layer", "floor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100224 { "gaussian1x5_sub_x", "gaussian_pyramid.cl" },
225 { "gaussian5x1_sub_y", "gaussian_pyramid.cl" },
Gian Marco Iodice578ab612017-06-23 09:34:33 +0100226 { "gemm_accumulate_biases", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000227 { "gemm_interleave4x4", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100228 { "gemm_ma_f16", "gemm.cl" },
229 { "gemm_ma_f32", "gemm.cl" },
Gian Marco Iodice3a3066b2017-06-23 13:38:14 +0100230 { "gemm_ma_qs8", "gemm.cl" },
Gian Marco Iodice8a383692017-07-03 17:41:47 +0100231 { "gemm_ma_qs16", "gemm.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100232 { "gemm_mv", "gemv.cl" },
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +0000233 { "gemm_mv_quantized", "gemv.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100234 { "gemm_mm_interleaved_transposed_f16", "gemm.cl" },
Gian Marco Iodicebb36a8e2018-04-19 12:05:08 +0100235 { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm.cl" },
236 { "gemm_mm_interleaved_transposed_f32", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100237 { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm.cl" },
238 { "gemm_mm_interleaved_transposed_qs8", "gemm.cl" },
239 { "gemm_mm_interleaved_transposed_qs16", "gemm.cl" },
240 { "gemm_mm_floating_point", "gemm.cl" },
Gian Marco Iodicefd683112018-04-17 09:52:44 +0100241 { "gemm_mm_floating_point_f16_bifrost", "gemm.cl" },
Anton Lokhmotov3e80c7f2017-11-20 11:02:10 +0000242 { "gemm_mm_floating_point_f32_bifrost", "gemm.cl" },
243 { "gemm_mm_floating_point_f32_bifrost_1000", "gemm.cl" },
Gian Marco Iodice3a3066b2017-06-23 13:38:14 +0100244 { "gemm_mm_qs8", "gemm.cl" },
Gian Marco Iodice8a383692017-07-03 17:41:47 +0100245 { "gemm_mm_qs16", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100246 { "gemm_lc_vm_f32", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000247 { "gemm_transpose1xW", "gemm.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000248 { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
249 { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000250 { "gemmlowp_mm_bifrost", "gemmlowp.cl" },
251 { "gemmlowp_mm_midgard", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000252 { "gemmlowp_mm_interleaved_transposed_bifrost", "gemmlowp.cl" },
253 { "gemmlowp_mm_interleaved_transposed_midgard", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000254 { "gemmlowp_offset_contribution", "gemmlowp.cl" },
255 { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
Gian Marco58c57942017-11-28 09:10:03 +0000256 { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100257 { "harris_score_3x3", "harris_corners.cl" },
258 { "harris_score_5x5", "harris_corners.cl" },
259 { "harris_score_7x7", "harris_corners.cl" },
260 { "hist_border_kernel", "histogram.cl" },
261 { "hist_border_kernel_fixed", "histogram.cl" },
262 { "hist_local_kernel", "histogram.cl" },
263 { "hist_local_kernel_fixed", "histogram.cl" },
264 { "hog_block_normalization", "hog.cl" },
265 { "hog_detector", "hog.cl" },
266 { "hog_orientation_binning", "hog.cl" },
267 { "hysteresis", "canny.cl" },
Gian Marco76faef82018-01-29 12:15:32 +0000268 { "im2col1x1_stridex1_dchw", "im2col.cl" },
269 { "im2col3x3_dchw", "im2col.cl" },
270 { "im2col5x5_dchw", "im2col.cl" },
271 { "im2col11x11_padx0_pady0_dchw", "im2col.cl" },
272 { "im2col_generic_dchw", "im2col.cl" },
273 { "im2col_generic_padx0_pady0_dchw", "im2col.cl" },
274 { "im2col_reduced_dchw", "im2col.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100275 { "init_level", "optical_flow_pyramid_lk.cl" },
276 { "init_level_max", "optical_flow_pyramid_lk.cl" },
277 { "init_level_max_initial_estimate", "optical_flow_pyramid_lk.cl" },
278 { "integral_horizontal", "integral_image.cl" },
279 { "integral_vertical", "integral_image.cl" },
280 { "IYUV_to_NV12_bt709", "color_convert.cl" },
281 { "IYUV_to_RGB888_bt709", "color_convert.cl" },
282 { "IYUV_to_RGBA8888_bt709", "color_convert.cl" },
283 { "IYUV_to_YUV444_bt709", "color_convert.cl" },
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100284 { "l2_normalize", "l2_normalize.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100285 { "lktracker_stage0", "optical_flow_pyramid_lk.cl" },
286 { "lktracker_stage1", "optical_flow_pyramid_lk.cl" },
287 { "magnitude_phase", "magnitude_phase.cl" },
288 { "mean_stddev_accumulate", "mean_stddev.cl" },
289 { "minmax", "minmaxloc.cl" },
290 { "minmax_border", "minmaxloc.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100291 { "minmax_layer", "minmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100292 { "minmaxloc", "minmaxloc.cl" },
293 { "non_linear_filter_box3x3", "non_linear_filter3x3.cl" },
294 { "non_linear_filter_cross3x3", "non_linear_filter3x3.cl" },
295 { "non_linear_filter_disk3x3", "non_linear_filter3x3.cl" },
296 { "non_linear_filter_box5x5", "non_linear_filter5x5.cl" },
297 { "non_linear_filter_cross5x5", "non_linear_filter5x5.cl" },
298 { "non_linear_filter_disk5x5", "non_linear_filter5x5.cl" },
299 { "non_max_suppression", "nonmax.cl" },
300 { "normalization_layer_cross_map", "normalization_layer.cl" },
Georgios Pinitas01624362017-11-30 10:53:31 +0000301 { "normalization_layer_in_map", "normalization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100302 { "NV12_to_IYUV_bt709", "color_convert.cl" },
303 { "NV12_to_RGB888_bt709", "color_convert.cl" },
304 { "NV12_to_RGBA8888_bt709", "color_convert.cl" },
305 { "NV12_to_YUV444_bt709", "color_convert.cl" },
306 { "NV21_to_IYUV_bt709", "color_convert.cl" },
307 { "NV21_to_RGB888_bt709", "color_convert.cl" },
308 { "NV21_to_RGBA8888_bt709", "color_convert.cl" },
309 { "NV21_to_YUV444_bt709", "color_convert.cl" },
Giorgio Arenaa086a0a2018-02-16 12:42:16 +0000310 { "output_stage_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Michalis Spyrou5237e012018-01-17 09:40:27 +0000311 { "permute_201", "permute.cl" },
312 { "permute_120", "permute.cl" },
313 { "permute_3201", "permute.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100314 { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
315 { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
316 { "pooling_layer_2", "pooling_layer.cl" },
317 { "pooling_layer_3", "pooling_layer.cl" },
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000318 { "pooling_layer_optimized_3", "pooling_layer.cl" },
Georgios Pinitasce093142017-06-19 16:11:53 +0100319 { "pooling_layer_7", "pooling_layer.cl" },
Michalis Spyroue74b2012018-04-18 09:49:16 +0100320 { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
321 { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
322 { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
323 { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100324 { "quantization_layer", "quantization_layer.cl" },
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100325 { "reduction_operation", "reduction_operation.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100326 { "remap_nearest_neighbour", "remap.cl" },
327 { "remap_bilinear", "remap.cl" },
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100328 { "reshape_layer", "reshape_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100329 { "reshape_to_columns", "convolution_layer.cl" },
330 { "RGB888_to_IYUV_bt709", "color_convert.cl" },
331 { "RGB888_to_NV12_bt709", "color_convert.cl" },
332 { "RGB888_to_RGBA8888_bt709", "color_convert.cl" },
333 { "RGB888_to_YUV444_bt709", "color_convert.cl" },
334 { "RGBA8888_to_IYUV_bt709", "color_convert.cl" },
335 { "RGBA8888_to_NV12_bt709", "color_convert.cl" },
336 { "RGBA8888_to_RGB888_bt709", "color_convert.cl" },
337 { "RGBA8888_to_YUV444_bt709", "color_convert.cl" },
SiCong Li3e363692017-07-04 15:02:10 +0100338 { "roi_pooling_layer", "roi_pooling_layer.cl" },
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100339 { "scale_nearest_neighbour_nchw", "scale.cl" },
340 { "scale_nearest_neighbour_nhwc", "scale.cl" },
341 { "scale_bilinear_nchw", "scale.cl" },
342 { "scale_bilinear_nhwc", "scale.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343 { "scharr3x3", "scharr_filter.cl" },
344 { "sobel3x3", "sobel_filter.cl" },
345 { "sobel_separable5x1", "sobel_filter.cl" },
346 { "sobel_separable1x5", "sobel_filter.cl" },
347 { "sobel_separable7x1", "sobel_filter.cl" },
348 { "sobel_separable1x7", "sobel_filter.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100349 { "softmax_layer_norm", "softmax_layer.cl" },
Chunosovf450caa2017-11-08 16:09:35 +0700350 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
Giorgio Arena4402cb92018-02-15 13:37:40 +0000351 { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
352 { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700353 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
354 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100355 { "suppress_non_maximum", "canny.cl" },
356 { "tablelookup_U8", "tablelookup.cl" },
357 { "tablelookup_S16", "tablelookup.cl" },
358 { "threshold_binary", "threshold.cl" },
359 { "threshold_range", "threshold.cl" },
360 { "transpose", "transpose.cl" },
361 { "UYVY422_to_IYUV_bt709", "color_convert.cl" },
362 { "UYVY422_to_NV12_bt709", "color_convert.cl" },
363 { "UYVY422_to_RGB888_bt709", "color_convert.cl" },
364 { "UYVY422_to_RGBA8888_bt709", "color_convert.cl" },
365 { "warp_affine_nearest_neighbour", "warp_affine.cl" },
366 { "warp_affine_bilinear", "warp_affine.cl" },
367 { "warp_perspective_nearest_neighbour", "warp_perspective.cl" },
368 { "warp_perspective_bilinear", "warp_perspective.cl" },
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000369 { "winograd_filter_transform_2x2_3x3_nchw", "winograd.cl" },
Giorgio Arena2d9de0a2018-03-15 17:58:20 +0000370 { "winograd_filter_transform_4x4_3x3_nchw", "winograd.cl" },
Giorgio Arena9373c8b2018-04-11 19:07:17 +0100371 { "winograd_filter_transform_4x4_5x5_nchw", "winograd.cl" },
Giorgio Arenadcb5b282018-04-25 12:07:29 +0100372 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd.cl" },
Giorgio Arenafe5ef382018-04-17 10:14:10 +0100373 { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd.cl" },
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000374 { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd.cl" },
375 { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd.cl" },
Gian Marco Iodicee52a3002018-04-11 15:59:10 +0100376 { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd.cl" },
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000377 { "winograd_output_transform_2x2_3x3_nchw", "winograd.cl" },
Gian Marco Iodicee52a3002018-04-11 15:59:10 +0100378 { "winograd_output_transform_4x4_3x3_nchw", "winograd.cl" },
Giorgio Arenadd038702018-04-16 11:20:11 +0100379 { "winograd_output_transform_4x4_5x5_nchw", "winograd.cl" },
Giorgio Arena3695f9a2018-04-23 17:41:22 +0100380 { "winograd_output_transform_4x4_3x3_nhwc", "winograd.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100381 { "YUYV422_to_IYUV_bt709", "color_convert.cl" },
382 { "YUYV422_to_NV12_bt709", "color_convert.cl" },
383 { "YUYV422_to_RGB888_bt709", "color_convert.cl" },
384 { "YUYV422_to_RGBA8888_bt709", "color_convert.cl" },
385};
386
387const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
388{
389#ifdef EMBEDDED_KERNELS
390 {
391 "absdiff.cl",
392#include "./cl_kernels/absdiff.clembed"
393 },
394 {
395 "accumulate.cl",
396#include "./cl_kernels/accumulate.clembed"
397 },
398 {
399 "activation_layer.cl",
400#include "./cl_kernels/activation_layer.clembed"
401 },
402 {
Michel Iwaniec00633802017-10-12 14:14:15 +0100403 "activation_layer_qa8.cl",
404#include "./cl_kernels/activation_layer_qa8.clembed"
405 },
406 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100407 "arithmetic_op.cl",
408#include "./cl_kernels/arithmetic_op.clembed"
409 },
410 {
411 "bitwise_op.cl",
412#include "./cl_kernels/bitwise_op.clembed"
413 },
414 {
415 "canny.cl",
416#include "./cl_kernels/canny.clembed"
417 },
418 {
419 "channel_combine.cl",
420#include "./cl_kernels/channel_combine.clembed"
421 },
422 {
423 "channel_extract.cl",
424#include "./cl_kernels/channel_extract.clembed"
425 },
426 {
Michele Di Giorgio72175632018-05-01 16:52:00 +0100427 "channel_shuffle.cl",
428#include "./cl_kernels/channel_shuffle.clembed"
429 },
430 {
Gian Marco76faef82018-01-29 12:15:32 +0000431 "col2im.cl",
432#include "./cl_kernels/col2im.clembed"
433 },
434 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100435 "concatenate.cl",
436#include "./cl_kernels/concatenate.clembed"
437 },
438 {
439 "color_convert.cl",
440#include "./cl_kernels/color_convert.clembed"
441 },
442 {
Giorgio Arena657bdb32018-04-26 18:52:01 +0100443 "convert_fc_weights.cl",
444#include "./cl_kernels/convert_fc_weights.clembed"
445 },
446 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100447 "convolution3x3.cl",
448#include "./cl_kernels/convolution3x3.clembed"
449 },
450 {
451 "convolution5x5.cl",
452#include "./cl_kernels/convolution5x5.clembed"
453 },
454 {
455 "convolution7x7.cl",
456#include "./cl_kernels/convolution7x7.clembed"
457 },
458 {
459 "convolution9x9.cl",
460#include "./cl_kernels/convolution9x9.clembed"
461 },
462 {
463 "convolution_layer.cl",
464#include "./cl_kernels/convolution_layer.clembed"
465 },
466 {
467 "convolution_rectangle.cl",
468#include "./cl_kernels/convolution_rectangle.clembed"
469 },
470 {
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000471 "copy_tensor.cl",
472#include "./cl_kernels/copy_tensor.clembed"
473 },
474 {
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000475 "deconvolution_layer.cl",
476#include "./cl_kernels/deconvolution_layer.clembed"
477 },
478 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100479 "depth_convert.cl",
480#include "./cl_kernels/depth_convert.clembed"
481 },
482 {
Giorgio Arena93a690e2017-08-01 16:09:33 +0100483 "depthwise_convolution.cl",
484#include "./cl_kernels/depthwise_convolution.clembed"
485 },
486 {
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700487 "depthwise_convolution_quantized.cl",
488#include "./cl_kernels/depthwise_convolution_quantized.clembed"
489 },
490 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100491 "dequantization_layer.cl",
492#include "./cl_kernels/dequantization_layer.clembed"
493 },
494 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100495 "derivative.cl",
496#include "./cl_kernels/derivative.clembed"
497 },
498 {
499 "dilate.cl",
500#include "./cl_kernels/dilate.clembed"
501 },
502 {
SiCong Lic51b72f2017-07-28 14:46:20 +0100503 "direct_convolution1x1.cl",
504#include "./cl_kernels/direct_convolution1x1.clembed"
505 },
506 {
507 "direct_convolution3x3.cl",
508#include "./cl_kernels/direct_convolution3x3.clembed"
steniu0127b386c2017-07-18 17:37:43 +0100509 },
510 {
steniu01db006682017-08-09 16:26:22 +0100511 "direct_convolution5x5.cl",
512#include "./cl_kernels/direct_convolution5x5.clembed"
513 },
514 {
Chunosovd621bca2017-11-03 17:33:15 +0700515 "direct_convolution_1x1_3x3_5x5_quantized.cl",
516#include "./cl_kernels/direct_convolution_1x1_3x3_5x5_quantized.clembed"
517 },
518 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100519 "erode.cl",
520#include "./cl_kernels/erode.clembed"
521 },
522 {
523 "fast_corners.cl",
524#include "./cl_kernels/fast_corners.clembed"
525 },
526 {
527 "fill_border.cl",
528#include "./cl_kernels/fill_border.clembed"
529 },
530 {
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100531 "fixed_point.h",
532#include "./cl_kernels/fixed_point.hembed"
533 },
534 {
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100535 "floor.cl",
536#include "./cl_kernels/floor.clembed"
537 },
538 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100539 "gaussian_pyramid.cl",
540#include "./cl_kernels/gaussian_pyramid.clembed"
541 },
542 {
543 "gemm.cl",
544#include "./cl_kernels/gemm.clembed"
545 },
546 {
Gian Marco05288a22017-11-21 10:57:50 +0000547 "gemmlowp.cl",
548#include "./cl_kernels/gemmlowp.clembed"
549 },
550 {
Giorgio Arena9fe41442017-08-23 16:36:24 +0100551 "gemv.cl",
552#include "./cl_kernels/gemv.clembed"
553 },
554 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100555 "harris_corners.cl",
556#include "./cl_kernels/harris_corners.clembed"
557 },
558 {
559 "helpers.h",
560#include "./cl_kernels/helpers.hembed"
561 },
562 {
Chunosovd621bca2017-11-03 17:33:15 +0700563 "helpers_asymm.h",
564#include "./cl_kernels/helpers_asymm.hembed"
565 },
566 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100567 "histogram.cl",
568#include "./cl_kernels/histogram.clembed"
569 },
570 {
571 "hog.cl",
572#include "./cl_kernels/hog.clembed"
573 },
574 {
Gian Marco76faef82018-01-29 12:15:32 +0000575 "im2col.cl",
576#include "./cl_kernels/im2col.clembed"
577 },
578 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100579 "integral_image.cl",
580#include "./cl_kernels/integral_image.clembed"
581 },
582 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100583 "l2_normalize.cl",
584#include "./cl_kernels/l2_normalize.clembed"
585 },
586 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100587 "magnitude_phase.cl",
588#include "./cl_kernels/magnitude_phase.clembed"
589 },
590 {
591 "mean_stddev.cl",
592#include "./cl_kernels/mean_stddev.clembed"
593 },
594 {
595 "minmaxloc.cl",
596#include "./cl_kernels/minmaxloc.clembed"
597 },
598 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100599 "minmax_layer.cl",
600#include "./cl_kernels/minmax_layer.clembed"
601 },
602 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100603 "non_linear_filter3x3.cl",
604#include "./cl_kernels/non_linear_filter3x3.clembed"
605 },
606 {
607 "non_linear_filter5x5.cl",
608#include "./cl_kernels/non_linear_filter5x5.clembed"
609 },
610 {
611 "non_linear_filter_helpers.h",
612#include "./cl_kernels/non_linear_filter_helpers.hembed"
613 },
614 {
615 "nonmax.cl",
616#include "./cl_kernels/nonmax.clembed"
617 },
618 {
619 "normalization_layer.cl",
620#include "./cl_kernels/normalization_layer.clembed"
621 },
622 {
623 "batchnormalization_layer.cl",
624#include "./cl_kernels/batchnormalization_layer.clembed"
625 },
626 {
627 "optical_flow_pyramid_lk.cl",
628#include "./cl_kernels/optical_flow_pyramid_lk.clembed"
629 },
630 {
Michalis Spyrou5237e012018-01-17 09:40:27 +0000631 "permute.cl",
632#include "./cl_kernels/permute.clembed"
633 },
634 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100635 "pixelwise_mul_float.cl",
636#include "./cl_kernels/pixelwise_mul_float.clembed"
637 },
638 {
639 "pixelwise_mul_int.cl",
640#include "./cl_kernels/pixelwise_mul_int.clembed"
641 },
642 {
643 "pooling_layer.cl",
644#include "./cl_kernels/pooling_layer.clembed"
645 },
646 {
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000647 "pooling_layer_quantized.cl",
648#include "./cl_kernels/pooling_layer_quantized.clembed"
649 },
650 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100651 "quantization_layer.cl",
652#include "./cl_kernels/quantization_layer.clembed"
653 },
654 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100655 "reduction_operation.cl",
656#include "./cl_kernels/reduction_operation.clembed"
657 },
658 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100659 "remap.cl",
660#include "./cl_kernels/remap.clembed"
661 },
662 {
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100663 "reshape_layer.cl",
664#include "./cl_kernels/reshape_layer.clembed"
665 },
666 {
SiCong Li3e363692017-07-04 15:02:10 +0100667 "roi_pooling_layer.cl",
668#include "./cl_kernels/roi_pooling_layer.clembed"
669 },
670 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100671 "scale.cl",
672#include "./cl_kernels/scale.clembed"
673 },
674 {
675 "scharr_filter.cl",
676#include "./cl_kernels/scharr_filter.clembed"
677 },
678 {
679 "sobel_filter.cl",
680#include "./cl_kernels/sobel_filter.clembed"
681 },
682 {
683 "softmax_layer.cl",
684#include "./cl_kernels/softmax_layer.clembed"
685 },
686 {
Chunosovf450caa2017-11-08 16:09:35 +0700687 "softmax_layer_quantized.cl",
688#include "./cl_kernels/softmax_layer_quantized.clembed"
689 },
690 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100691 "tablelookup.cl",
692#include "./cl_kernels/tablelookup.clembed"
693 },
694 {
695 "threshold.cl",
696#include "./cl_kernels/threshold.clembed"
697 },
698 {
699 "transpose.cl",
700#include "./cl_kernels/transpose.clembed"
701 },
702 {
703 "types.h",
704#include "./cl_kernels/types.hembed"
705 },
706 {
707 "warp_affine.cl",
708#include "./cl_kernels/warp_affine.clembed"
709 },
710 {
711 "warp_helpers.h",
712#include "./cl_kernels/warp_helpers.hembed"
713 },
714 {
715 "warp_perspective.cl",
716#include "./cl_kernels/warp_perspective.clembed"
Michalis Spyroud7e82812017-06-20 15:00:14 +0100717 },
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000718 {
719 "winograd.cl",
720#include "./cl_kernels/winograd.clembed"
721 },
Anthony Barbierac69aa12017-07-03 17:39:37 +0100722#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100723};
724
725CLKernelLibrary::CLKernelLibrary()
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100726 : _context(), _device(), _kernel_path("."), _programs_map(), _built_programs_map()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100727{
Anthony Barbierecb1c622018-04-17 11:45:10 +0100728 opencl_is_available(); // Make sure the OpenCL symbols are initialised *before* the CLKernelLibrary is built
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100729}
730
731CLKernelLibrary &CLKernelLibrary::get()
732{
733 static CLKernelLibrary _kernel_library;
734 return _kernel_library;
735}
736
737Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const StringSet &build_options_set) const
738{
739 // Find which program contains the kernel
740 auto kernel_program_it = _kernel_program_map.find(kernel_name);
741
742 if(_kernel_program_map.end() == kernel_program_it)
743 {
744 ARM_COMPUTE_ERROR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
745 }
steniu0134702472017-07-11 09:22:58 +0100746 std::string concat_str;
747
Georgios Pinitasdf473ea2018-05-31 18:53:52 +0100748#if defined(ARM_COMPUTE_DEBUG_ENABLED)
749 // Enable debug properties in CL kernels
750 concat_str += " -DARM_COMPUTE_DEBUG_ENABLED";
751#endif // defined(ARM_COMPUTE_DEBUG_ENABLED)
752
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100753 if(fp16_supported())
Matthew Bentham6f31f8c2017-10-27 11:50:06 +0100754 {
755 concat_str += " -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 ";
756 }
757
Michalis Spyroue03342e2018-01-15 14:39:13 +0000758 if(dot8_supported(_device))
759 {
760 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ENABLED=1 ";
761 }
762
Pablo Telloe86a09f2018-01-11 15:44:48 +0000763 if(get_cl_version(_device) == CLVersion::CL20)
steniu0134702472017-07-11 09:22:58 +0100764 {
765 concat_str += " -cl-std=CL2.0 ";
766 }
Anthony Barbierd727e852018-04-20 11:05:29 +0100767 else if(arm_non_uniform_workgroup_supported(_device))
Pablo Telloe86a09f2018-01-11 15:44:48 +0000768 {
769 concat_str += " -cl-arm-non-uniform-work-group-size ";
770 }
steniu0134702472017-07-11 09:22:58 +0100771 else
772 {
773 ARM_COMPUTE_ERROR("Non uniform workgroup size is not supported!!");
774 }
775
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100776 // Check if the program has been built before with same build options.
steniu0134702472017-07-11 09:22:58 +0100777 const std::string program_name = kernel_program_it->second;
778 const std::string build_options = stringify_set(build_options_set) + concat_str;
779
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100780 const std::string built_program_name = program_name + "_" + build_options;
781 auto built_program_it = _built_programs_map.find(built_program_name);
782
783 cl::Program cl_program;
784
785 if(_built_programs_map.end() != built_program_it)
786 {
787 // If program has been built, retrieve to create kernel from it
788 cl_program = built_program_it->second;
789 }
790 else
791 {
792 // Get program
793 Program program = load_program(program_name);
794
795 // Build program
796 cl_program = program.build(build_options);
797
798 // Add built program to internal map
799 _built_programs_map.emplace(built_program_name, cl_program);
800 }
801
802 // Create and return kernel
803 return Kernel(kernel_name, cl_program);
804}
805
Anthony Barbier7da55aa2018-04-13 16:58:43 +0100806void CLKernelLibrary::add_built_program(const std::string &built_program_name, cl::Program program)
807{
808 _built_programs_map.emplace(built_program_name, program);
809}
810
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100811bool CLKernelLibrary::fp16_supported() const
812{
813 return ::fp16_supported(_device);
814}
815
Vidhya Sudhan Loganathan76c85642018-05-25 13:53:02 +0100816bool CLKernelLibrary::int64_base_atomics_supported() const
817{
818 return device_supports_extension(_device, "cl_khr_int64_base_atomics");
819}
820
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100821const Program &CLKernelLibrary::load_program(const std::string &program_name) const
822{
823 const auto program_it = _programs_map.find(program_name);
824
825 if(program_it != _programs_map.end())
826 {
827 return program_it->second;
828 }
829
830 Program program;
831
832#ifdef EMBEDDED_KERNELS
833 const auto program_source_it = _program_source_map.find(program_name);
834
835 if(_program_source_map.end() == program_source_it)
836 {
837 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
838 }
839
840 program = Program(_context, program_name, program_source_it->second);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100841#else /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100842 // Check for binary
843 std::string source_name = _kernel_path + program_name;
844 std::string binary_name = source_name + "bin";
845
846 if(std::ifstream(binary_name).is_open())
847 {
848 const std::string program_binary = read_file(binary_name, true);
849 program = Program(_context, _device, program_name, std::vector<unsigned char>(program_binary.begin(), program_binary.end()));
850 }
851 else if(std::ifstream(source_name).is_open())
852 {
853 program = Program(_context, program_name, read_file(source_name, false));
854 }
855 else
856 {
857 ARM_COMPUTE_ERROR("Kernel file %s does not exist.", source_name.c_str());
858 }
Anthony Barbierac69aa12017-07-03 17:39:37 +0100859#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100860
861 // Insert program to program map
862 const auto new_program = _programs_map.emplace(program_name, std::move(program));
863
864 return new_program.first->second;
865}
866
867std::string CLKernelLibrary::stringify_set(const StringSet &s) const
868{
steniu0134702472017-07-11 09:22:58 +0100869 std::string concat_set;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100870
871#ifndef EMBEDDED_KERNELS
872 concat_set += "-I" + _kernel_path + " ";
873#endif /* EMBEDDED_KERNELS */
874
875 // Concatenate set
876 for(const auto &el : s)
877 {
878 concat_set += " " + el;
879 }
880
881 return concat_set;
882}
Michalis Spyroud7e82812017-06-20 15:00:14 +0100883
884std::string CLKernelLibrary::get_program_source(const std::string &program_name)
885{
886 const auto program_source_it = _program_source_map.find(program_name);
887
888 if(program_source_it == _program_source_map.end())
889 {
890 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
891 }
892
893 return program_source_it->second;
894}
steniu015f910722017-08-23 10:15:22 +0100895
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100896size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const
steniu015f910722017-08-23 10:15:22 +0100897{
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100898 size_t result;
steniu015f910722017-08-23 10:15:22 +0100899
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100900 size_t err = kernel.getWorkGroupInfo(_device, CL_KERNEL_WORK_GROUP_SIZE, &result);
901 ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel");
902 ARM_COMPUTE_UNUSED(err);
903
904 return result;
steniu015f910722017-08-23 10:15:22 +0100905}
906
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100907cl::NDRange CLKernelLibrary::default_ndrange() const
steniu015f910722017-08-23 10:15:22 +0100908{
Michalis Spyroua9676112018-02-22 18:07:43 +0000909 cl::Device device = cl::Device::getDefault();
910 GPUTarget _target = get_target_from_device(device);
911 cl::NDRange default_range;
912
913 switch(_target)
914 {
915 case GPUTarget::MIDGARD:
916 case GPUTarget::T600:
917 case GPUTarget::T700:
918 case GPUTarget::T800:
919 default_range = cl::NDRange(128u, 1);
920 break;
921 default:
922 default_range = cl::NullRange;
923 }
924
925 return default_range;
steniu015f910722017-08-23 10:15:22 +0100926}
Anthony Barbier847864d2018-03-07 11:35:53 +0000927
928std::string CLKernelLibrary::get_device_version()
929{
930 return _device.getInfo<CL_DEVICE_VERSION>();
931}