blob: 29b01e6ceaf87cd8e645a6df75457544f255e967 [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" },
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100152 { "arithmetic_add_quantized", "arithmetic_op_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100153 { "arithmetic_add", "arithmetic_op.cl" },
154 { "arithmetic_sub", "arithmetic_op.cl" },
Michalis Spyrou0a887922018-06-11 16:30:23 +0100155 { "arithmetic_div", "arithmetic_op.cl" },
Michele Di Giorgiobf3c6622018-03-08 11:52:27 +0000156 { "batchnormalization_layer_nchw", "batchnormalization_layer.cl" },
157 { "batchnormalization_layer_nhwc", "batchnormalization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100158 { "bitwise_or", "bitwise_op.cl" },
159 { "bitwise_and", "bitwise_op.cl" },
160 { "bitwise_xor", "bitwise_op.cl" },
161 { "bitwise_not", "bitwise_op.cl" },
162 { "channel_combine_NV", "channel_combine.cl" },
163 { "channel_combine_RGB888", "channel_combine.cl" },
164 { "channel_combine_RGBA8888", "channel_combine.cl" },
165 { "channel_combine_UYVY422", "channel_combine.cl" },
166 { "channel_combine_YUYV422", "channel_combine.cl" },
Michele Di Giorgio72175632018-05-01 16:52:00 +0100167 { "channel_shuffle_nchw", "channel_shuffle.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100168 { "channel_extract_NV12", "channel_extract.cl" },
169 { "channel_extract_NV21", "channel_extract.cl" },
170 { "channel_extract_RGB888", "channel_extract.cl" },
171 { "channel_extract_RGBA8888", "channel_extract.cl" },
172 { "channel_extract_UYVY422", "channel_extract.cl" },
173 { "channel_extract_YUYV422", "channel_extract.cl" },
174 { "combine_gradients_L1", "canny.cl" },
175 { "combine_gradients_L2", "canny.cl" },
176 { "concatenate_depth", "concatenate.cl" },
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100177 { "concatenate_width", "concatenate.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100178 { "convolution_rectangle", "convolution_rectangle.cl" },
Gian Marco76faef82018-01-29 12:15:32 +0000179 { "col2im", "col2im.cl" },
Giorgio Arena657bdb32018-04-26 18:52:01 +0100180 { "convert_depth_down", "depth_convert.cl" },
181 { "convert_depth_up", "depth_convert.cl" },
182 { "convert_fc_weights", "convert_fc_weights.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100183 { "convolution3x3_static", "convolution3x3.cl" },
184 { "convolution5x5_static", "convolution5x5.cl" },
185 { "convolution7x7_static", "convolution7x7.cl" },
186 { "convolution9x9_static", "convolution9x9.cl" },
187 { "convolution_separable1x5_static", "convolution5x5.cl" },
188 { "convolution_separable5x1_static", "convolution5x5.cl" },
189 { "convolution_separable1x7_static", "convolution7x7.cl" },
190 { "convolution_separable7x1_static", "convolution7x7.cl" },
191 { "convolution_separable1x9_static", "convolution9x9.cl" },
192 { "convolution_separable9x1_static", "convolution9x9.cl" },
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000193 { "copy_tensor", "copy_tensor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100194 { "copy_plane", "channel_extract.cl" },
195 { "copy_planes_3p", "channel_combine.cl" },
196 { "copy_to_keypoint", "fast_corners.cl" },
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000197 { "deconvolution_upsample", "deconvolution_layer.cl" },
Giorgio Arena93a690e2017-08-01 16:09:33 +0100198 { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
Michele Di Giorgio933fe862018-02-19 15:42:12 +0000199 { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
Giorgio Arenad051e972018-06-20 11:46:42 +0100200 { "depthwise_convolution_3x3_nhwc", "depthwise_convolution.cl" },
201 { "depthwise_convolution_3x3_nhwc_stride1", "depthwise_convolution.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000202 { "depthwise_convolution_3x3_quantized_nchw", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100203 { "depthwise_convolution_3x3_quantized_nhwc", "depthwise_convolution_quantized.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000204 { "depthwise_convolution_3x3_quantized_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100205 { "depthwise_convolution_3x3_quantized_dot8_nchw", "depthwise_convolution_quantized.cl" },
206 { "depthwise_convolution_3x3_quantized_dot8_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Michele Di Giorgio3ebef322018-02-21 10:02:58 +0000207 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16", "depthwise_convolution.cl" },
208 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16", "depthwise_convolution.cl" },
209 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32", "depthwise_convolution.cl" },
210 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32", "depthwise_convolution.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100211 { "depthwise_im2col", "depthwise_convolution.cl" },
212 { "depthwise_vector_to_tensor", "depthwise_convolution.cl" },
213 { "depthwise_weights_reshape", "depthwise_convolution.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100214 { "dequantization_layer", "dequantization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100215 { "derivative", "derivative.cl" },
216 { "dilate", "dilate.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100217 { "direct_convolution1x1", "direct_convolution1x1.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100218 { "direct_convolution1x1_nhwc", "direct_convolution1x1.cl" },
Gian Marco Iodice1c8409d2017-09-06 17:24:25 +0100219 { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100220 { "direct_convolution3x3", "direct_convolution3x3.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100221 { "direct_convolution3x3_nhwc", "direct_convolution3x3.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100222 { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
steniu01db006682017-08-09 16:26:22 +0100223 { "direct_convolution5x5", "direct_convolution5x5.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100224 { "direct_convolution5x5_nhwc", "direct_convolution5x5.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100225 { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
Chunosovd621bca2017-11-03 17:33:15 +0700226 { "direct_convolution_1x1_3x3_5x5_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100227 { "erode", "erode.cl" },
228 { "fast_corners", "fast_corners.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100229 { "flatten", "flatten.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100230 { "fill_image_borders_constant", "fill_border.cl" },
231 { "fill_image_borders_replicate", "fill_border.cl" },
232 { "finalize", "optical_flow_pyramid_lk.cl" },
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100233 { "floor_layer", "floor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100234 { "gaussian1x5_sub_x", "gaussian_pyramid.cl" },
235 { "gaussian5x1_sub_y", "gaussian_pyramid.cl" },
Gian Marco Iodice578ab612017-06-23 09:34:33 +0100236 { "gemm_accumulate_biases", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000237 { "gemm_interleave4x4", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100238 { "gemm_ma_f16", "gemm.cl" },
239 { "gemm_ma_f32", "gemm.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100240 { "gemm_mv", "gemv.cl" },
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +0000241 { "gemm_mv_quantized", "gemv.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100242 { "gemm_mm_interleaved_transposed_f16", "gemm.cl" },
Gian Marco Iodicebb36a8e2018-04-19 12:05:08 +0100243 { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm.cl" },
244 { "gemm_mm_interleaved_transposed_f32", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100245 { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100246 { "gemm_mm_floating_point", "gemm.cl" },
Gian Marco Iodicefd683112018-04-17 09:52:44 +0100247 { "gemm_mm_floating_point_f16_bifrost", "gemm.cl" },
Anton Lokhmotov3e80c7f2017-11-20 11:02:10 +0000248 { "gemm_mm_floating_point_f32_bifrost", "gemm.cl" },
249 { "gemm_mm_floating_point_f32_bifrost_1000", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100250 { "gemm_lc_vm_f32", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000251 { "gemm_transpose1xW", "gemm.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000252 { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
253 { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000254 { "gemmlowp_mm_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100255 { "gemmlowp_mm_bifrost_dot8", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000256 { "gemmlowp_mm_midgard", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000257 { "gemmlowp_mm_interleaved_transposed_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100258 { "gemmlowp_mm_interleaved_transposed_bifrost_dot8", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000259 { "gemmlowp_mm_interleaved_transposed_midgard", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000260 { "gemmlowp_offset_contribution", "gemmlowp.cl" },
261 { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
Gian Marco58c57942017-11-28 09:10:03 +0000262 { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100263 { "harris_score_3x3", "harris_corners.cl" },
264 { "harris_score_5x5", "harris_corners.cl" },
265 { "harris_score_7x7", "harris_corners.cl" },
266 { "hist_border_kernel", "histogram.cl" },
267 { "hist_border_kernel_fixed", "histogram.cl" },
268 { "hist_local_kernel", "histogram.cl" },
269 { "hist_local_kernel_fixed", "histogram.cl" },
270 { "hog_block_normalization", "hog.cl" },
271 { "hog_detector", "hog.cl" },
272 { "hog_orientation_binning", "hog.cl" },
273 { "hysteresis", "canny.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100274 { "im2col1x1_stridex1_nchw", "im2col.cl" },
275 { "im2col3x3_nchw", "im2col.cl" },
276 { "im2col5x5_nchw", "im2col.cl" },
277 { "im2col11x11_padx0_pady0_nchw", "im2col.cl" },
278 { "im2col_generic_nchw", "im2col.cl" },
279 { "im2col_generic_padx0_pady0_nchw", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100280 { "im2col3x3_nhwc", "im2col.cl" },
281 { "im2col_generic_nhwc", "im2col.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100282 { "init_level", "optical_flow_pyramid_lk.cl" },
283 { "init_level_max", "optical_flow_pyramid_lk.cl" },
284 { "init_level_max_initial_estimate", "optical_flow_pyramid_lk.cl" },
285 { "integral_horizontal", "integral_image.cl" },
286 { "integral_vertical", "integral_image.cl" },
287 { "IYUV_to_NV12_bt709", "color_convert.cl" },
288 { "IYUV_to_RGB888_bt709", "color_convert.cl" },
289 { "IYUV_to_RGBA8888_bt709", "color_convert.cl" },
290 { "IYUV_to_YUV444_bt709", "color_convert.cl" },
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100291 { "l2_normalize", "l2_normalize.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100292 { "lktracker_stage0", "optical_flow_pyramid_lk.cl" },
293 { "lktracker_stage1", "optical_flow_pyramid_lk.cl" },
294 { "magnitude_phase", "magnitude_phase.cl" },
295 { "mean_stddev_accumulate", "mean_stddev.cl" },
296 { "minmax", "minmaxloc.cl" },
297 { "minmax_border", "minmaxloc.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100298 { "minmax_layer", "minmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100299 { "minmaxloc", "minmaxloc.cl" },
300 { "non_linear_filter_box3x3", "non_linear_filter3x3.cl" },
301 { "non_linear_filter_cross3x3", "non_linear_filter3x3.cl" },
302 { "non_linear_filter_disk3x3", "non_linear_filter3x3.cl" },
303 { "non_linear_filter_box5x5", "non_linear_filter5x5.cl" },
304 { "non_linear_filter_cross5x5", "non_linear_filter5x5.cl" },
305 { "non_linear_filter_disk5x5", "non_linear_filter5x5.cl" },
306 { "non_max_suppression", "nonmax.cl" },
307 { "normalization_layer_cross_map", "normalization_layer.cl" },
Georgios Pinitas01624362017-11-30 10:53:31 +0000308 { "normalization_layer_in_map", "normalization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100309 { "NV12_to_IYUV_bt709", "color_convert.cl" },
310 { "NV12_to_RGB888_bt709", "color_convert.cl" },
311 { "NV12_to_RGBA8888_bt709", "color_convert.cl" },
312 { "NV12_to_YUV444_bt709", "color_convert.cl" },
313 { "NV21_to_IYUV_bt709", "color_convert.cl" },
314 { "NV21_to_RGB888_bt709", "color_convert.cl" },
315 { "NV21_to_RGBA8888_bt709", "color_convert.cl" },
316 { "NV21_to_YUV444_bt709", "color_convert.cl" },
Giorgio Arenaa086a0a2018-02-16 12:42:16 +0000317 { "output_stage_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Michalis Spyrou5237e012018-01-17 09:40:27 +0000318 { "permute_201", "permute.cl" },
319 { "permute_120", "permute.cl" },
320 { "permute_3201", "permute.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100321 { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
322 { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
323 { "pooling_layer_2", "pooling_layer.cl" },
324 { "pooling_layer_3", "pooling_layer.cl" },
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000325 { "pooling_layer_optimized_3", "pooling_layer.cl" },
Georgios Pinitasce093142017-06-19 16:11:53 +0100326 { "pooling_layer_7", "pooling_layer.cl" },
Michalis Spyroue74b2012018-04-18 09:49:16 +0100327 { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
328 { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
329 { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
330 { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100331 { "quantization_layer", "quantization_layer.cl" },
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100332 { "reduction_operation", "reduction_operation.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100333 { "remap_nearest_neighbour", "remap.cl" },
334 { "remap_bilinear", "remap.cl" },
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100335 { "reshape_layer", "reshape_layer.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100336 { "reshape_to_columns", "convolution_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100337 { "RGB888_to_IYUV_bt709", "color_convert.cl" },
338 { "RGB888_to_NV12_bt709", "color_convert.cl" },
339 { "RGB888_to_RGBA8888_bt709", "color_convert.cl" },
340 { "RGB888_to_YUV444_bt709", "color_convert.cl" },
341 { "RGBA8888_to_IYUV_bt709", "color_convert.cl" },
342 { "RGBA8888_to_NV12_bt709", "color_convert.cl" },
343 { "RGBA8888_to_RGB888_bt709", "color_convert.cl" },
344 { "RGBA8888_to_YUV444_bt709", "color_convert.cl" },
SiCong Li3e363692017-07-04 15:02:10 +0100345 { "roi_pooling_layer", "roi_pooling_layer.cl" },
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100346 { "scale_nearest_neighbour_nchw", "scale.cl" },
347 { "scale_nearest_neighbour_nhwc", "scale.cl" },
348 { "scale_bilinear_nchw", "scale.cl" },
349 { "scale_bilinear_nhwc", "scale.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100350 { "scharr3x3", "scharr_filter.cl" },
351 { "sobel3x3", "sobel_filter.cl" },
352 { "sobel_separable5x1", "sobel_filter.cl" },
353 { "sobel_separable1x5", "sobel_filter.cl" },
354 { "sobel_separable7x1", "sobel_filter.cl" },
355 { "sobel_separable1x7", "sobel_filter.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100356 { "softmax_layer_norm", "softmax_layer.cl" },
Chunosovf450caa2017-11-08 16:09:35 +0700357 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
Giorgio Arena4402cb92018-02-15 13:37:40 +0000358 { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
359 { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700360 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
361 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100362 { "suppress_non_maximum", "canny.cl" },
363 { "tablelookup_U8", "tablelookup.cl" },
364 { "tablelookup_S16", "tablelookup.cl" },
365 { "threshold_binary", "threshold.cl" },
366 { "threshold_range", "threshold.cl" },
367 { "transpose", "transpose.cl" },
368 { "UYVY422_to_IYUV_bt709", "color_convert.cl" },
369 { "UYVY422_to_NV12_bt709", "color_convert.cl" },
370 { "UYVY422_to_RGB888_bt709", "color_convert.cl" },
371 { "UYVY422_to_RGBA8888_bt709", "color_convert.cl" },
372 { "warp_affine_nearest_neighbour", "warp_affine.cl" },
373 { "warp_affine_bilinear", "warp_affine.cl" },
374 { "warp_perspective_nearest_neighbour", "warp_perspective.cl" },
375 { "warp_perspective_bilinear", "warp_perspective.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100376 { "winograd_filter_transform_2x2_3x3_nchw", "winograd_filter_transform.cl" },
377 { "winograd_filter_transform_2x1_3x1_nchw", "winograd_filter_transform.cl" },
378 { "winograd_filter_transform_1x2_1x3_nchw", "winograd_filter_transform.cl" },
379 { "winograd_filter_transform_4x4_3x3_nchw", "winograd_filter_transform.cl" },
380 { "winograd_filter_transform_4x1_3x1_nchw", "winograd_filter_transform.cl" },
381 { "winograd_filter_transform_1x4_1x3_nchw", "winograd_filter_transform.cl" },
382 { "winograd_filter_transform_4x4_5x5_nchw", "winograd_filter_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100383 { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
384 { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100385 { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
386 { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100387 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
388 { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100389 { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
390 { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100391 { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd_input_transform.cl" },
392 { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd_input_transform.cl" },
393 { "winograd_input_transform_2x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
394 { "winograd_input_transform_2x1_3x1_stepz2_nchw", "winograd_input_transform.cl" },
395 { "winograd_input_transform_1x2_1x3_stepz1_nchw", "winograd_input_transform.cl" },
396 { "winograd_input_transform_1x2_1x3_stepz2_nchw", "winograd_input_transform.cl" },
397 { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd_input_transform.cl" },
398 { "winograd_input_transform_4x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
399 { "winograd_input_transform_1x4_1x3_stepz1_nchw", "winograd_input_transform.cl" },
400 { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd_input_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100401 { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
402 { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100403 { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
404 { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100405 { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
406 { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100407 { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
408 { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100409 { "winograd_output_transform_2x2_3x3_nchw", "winograd_output_transform.cl" },
410 { "winograd_output_transform_2x1_3x1_nchw", "winograd_output_transform.cl" },
411 { "winograd_output_transform_1x2_1x3_nchw", "winograd_output_transform.cl" },
412 { "winograd_output_transform_4x4_3x3_nchw", "winograd_output_transform.cl" },
413 { "winograd_output_transform_4x1_3x1_nchw", "winograd_output_transform.cl" },
414 { "winograd_output_transform_1x4_1x3_nchw", "winograd_output_transform.cl" },
415 { "winograd_output_transform_4x4_5x5_nchw", "winograd_output_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100416 { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
417 { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100418 { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
419 { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100420 { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
421 { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100422 { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
423 { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100424 { "YUYV422_to_IYUV_bt709", "color_convert.cl" },
425 { "YUYV422_to_NV12_bt709", "color_convert.cl" },
426 { "YUYV422_to_RGB888_bt709", "color_convert.cl" },
427 { "YUYV422_to_RGBA8888_bt709", "color_convert.cl" },
428};
429
430const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
431{
432#ifdef EMBEDDED_KERNELS
433 {
434 "absdiff.cl",
435#include "./cl_kernels/absdiff.clembed"
436 },
437 {
438 "accumulate.cl",
439#include "./cl_kernels/accumulate.clembed"
440 },
441 {
442 "activation_layer.cl",
443#include "./cl_kernels/activation_layer.clembed"
444 },
445 {
Michel Iwaniec00633802017-10-12 14:14:15 +0100446 "activation_layer_qa8.cl",
447#include "./cl_kernels/activation_layer_qa8.clembed"
448 },
449 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100450 "arithmetic_op.cl",
451#include "./cl_kernels/arithmetic_op.clembed"
452 },
453 {
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100454 "arithmetic_op_quantized.cl",
455#include "./cl_kernels/arithmetic_op_quantized.clembed"
456 },
457 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100458 "bitwise_op.cl",
459#include "./cl_kernels/bitwise_op.clembed"
460 },
461 {
462 "canny.cl",
463#include "./cl_kernels/canny.clembed"
464 },
465 {
466 "channel_combine.cl",
467#include "./cl_kernels/channel_combine.clembed"
468 },
469 {
470 "channel_extract.cl",
471#include "./cl_kernels/channel_extract.clembed"
472 },
473 {
Michele Di Giorgio72175632018-05-01 16:52:00 +0100474 "channel_shuffle.cl",
475#include "./cl_kernels/channel_shuffle.clembed"
476 },
477 {
Gian Marco76faef82018-01-29 12:15:32 +0000478 "col2im.cl",
479#include "./cl_kernels/col2im.clembed"
480 },
481 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100482 "concatenate.cl",
483#include "./cl_kernels/concatenate.clembed"
484 },
485 {
486 "color_convert.cl",
487#include "./cl_kernels/color_convert.clembed"
488 },
489 {
Giorgio Arena657bdb32018-04-26 18:52:01 +0100490 "convert_fc_weights.cl",
491#include "./cl_kernels/convert_fc_weights.clembed"
492 },
493 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100494 "convolution3x3.cl",
495#include "./cl_kernels/convolution3x3.clembed"
496 },
497 {
498 "convolution5x5.cl",
499#include "./cl_kernels/convolution5x5.clembed"
500 },
501 {
502 "convolution7x7.cl",
503#include "./cl_kernels/convolution7x7.clembed"
504 },
505 {
506 "convolution9x9.cl",
507#include "./cl_kernels/convolution9x9.clembed"
508 },
509 {
510 "convolution_layer.cl",
511#include "./cl_kernels/convolution_layer.clembed"
512 },
513 {
514 "convolution_rectangle.cl",
515#include "./cl_kernels/convolution_rectangle.clembed"
516 },
517 {
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000518 "copy_tensor.cl",
519#include "./cl_kernels/copy_tensor.clembed"
520 },
521 {
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000522 "deconvolution_layer.cl",
523#include "./cl_kernels/deconvolution_layer.clembed"
524 },
525 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100526 "depth_convert.cl",
527#include "./cl_kernels/depth_convert.clembed"
528 },
529 {
Giorgio Arena93a690e2017-08-01 16:09:33 +0100530 "depthwise_convolution.cl",
531#include "./cl_kernels/depthwise_convolution.clembed"
532 },
533 {
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700534 "depthwise_convolution_quantized.cl",
535#include "./cl_kernels/depthwise_convolution_quantized.clembed"
536 },
537 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100538 "dequantization_layer.cl",
539#include "./cl_kernels/dequantization_layer.clembed"
540 },
541 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100542 "derivative.cl",
543#include "./cl_kernels/derivative.clembed"
544 },
545 {
546 "dilate.cl",
547#include "./cl_kernels/dilate.clembed"
548 },
549 {
SiCong Lic51b72f2017-07-28 14:46:20 +0100550 "direct_convolution1x1.cl",
551#include "./cl_kernels/direct_convolution1x1.clembed"
552 },
553 {
554 "direct_convolution3x3.cl",
555#include "./cl_kernels/direct_convolution3x3.clembed"
steniu0127b386c2017-07-18 17:37:43 +0100556 },
557 {
steniu01db006682017-08-09 16:26:22 +0100558 "direct_convolution5x5.cl",
559#include "./cl_kernels/direct_convolution5x5.clembed"
560 },
561 {
Chunosovd621bca2017-11-03 17:33:15 +0700562 "direct_convolution_1x1_3x3_5x5_quantized.cl",
563#include "./cl_kernels/direct_convolution_1x1_3x3_5x5_quantized.clembed"
564 },
565 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100566 "erode.cl",
567#include "./cl_kernels/erode.clembed"
568 },
569 {
570 "fast_corners.cl",
571#include "./cl_kernels/fast_corners.clembed"
572 },
573 {
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100574 "flatten.cl",
575#include "./cl_kernels/flatten.clembed"
576 },
577 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100578 "fill_border.cl",
579#include "./cl_kernels/fill_border.clembed"
580 },
581 {
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100582 "floor.cl",
583#include "./cl_kernels/floor.clembed"
584 },
585 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100586 "gaussian_pyramid.cl",
587#include "./cl_kernels/gaussian_pyramid.clembed"
588 },
589 {
590 "gemm.cl",
591#include "./cl_kernels/gemm.clembed"
592 },
593 {
Gian Marco05288a22017-11-21 10:57:50 +0000594 "gemmlowp.cl",
595#include "./cl_kernels/gemmlowp.clembed"
596 },
597 {
Giorgio Arena9fe41442017-08-23 16:36:24 +0100598 "gemv.cl",
599#include "./cl_kernels/gemv.clembed"
600 },
601 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100602 "harris_corners.cl",
603#include "./cl_kernels/harris_corners.clembed"
604 },
605 {
606 "helpers.h",
607#include "./cl_kernels/helpers.hembed"
608 },
609 {
Chunosovd621bca2017-11-03 17:33:15 +0700610 "helpers_asymm.h",
611#include "./cl_kernels/helpers_asymm.hembed"
612 },
613 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100614 "histogram.cl",
615#include "./cl_kernels/histogram.clembed"
616 },
617 {
618 "hog.cl",
619#include "./cl_kernels/hog.clembed"
620 },
621 {
Gian Marco76faef82018-01-29 12:15:32 +0000622 "im2col.cl",
623#include "./cl_kernels/im2col.clembed"
624 },
625 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100626 "integral_image.cl",
627#include "./cl_kernels/integral_image.clembed"
628 },
629 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100630 "l2_normalize.cl",
631#include "./cl_kernels/l2_normalize.clembed"
632 },
633 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100634 "magnitude_phase.cl",
635#include "./cl_kernels/magnitude_phase.clembed"
636 },
637 {
638 "mean_stddev.cl",
639#include "./cl_kernels/mean_stddev.clembed"
640 },
641 {
642 "minmaxloc.cl",
643#include "./cl_kernels/minmaxloc.clembed"
644 },
645 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100646 "minmax_layer.cl",
647#include "./cl_kernels/minmax_layer.clembed"
648 },
649 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100650 "non_linear_filter3x3.cl",
651#include "./cl_kernels/non_linear_filter3x3.clembed"
652 },
653 {
654 "non_linear_filter5x5.cl",
655#include "./cl_kernels/non_linear_filter5x5.clembed"
656 },
657 {
658 "non_linear_filter_helpers.h",
659#include "./cl_kernels/non_linear_filter_helpers.hembed"
660 },
661 {
662 "nonmax.cl",
663#include "./cl_kernels/nonmax.clembed"
664 },
665 {
666 "normalization_layer.cl",
667#include "./cl_kernels/normalization_layer.clembed"
668 },
669 {
670 "batchnormalization_layer.cl",
671#include "./cl_kernels/batchnormalization_layer.clembed"
672 },
673 {
674 "optical_flow_pyramid_lk.cl",
675#include "./cl_kernels/optical_flow_pyramid_lk.clembed"
676 },
677 {
Michalis Spyrou5237e012018-01-17 09:40:27 +0000678 "permute.cl",
679#include "./cl_kernels/permute.clembed"
680 },
681 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100682 "pixelwise_mul_float.cl",
683#include "./cl_kernels/pixelwise_mul_float.clembed"
684 },
685 {
686 "pixelwise_mul_int.cl",
687#include "./cl_kernels/pixelwise_mul_int.clembed"
688 },
689 {
690 "pooling_layer.cl",
691#include "./cl_kernels/pooling_layer.clembed"
692 },
693 {
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000694 "pooling_layer_quantized.cl",
695#include "./cl_kernels/pooling_layer_quantized.clembed"
696 },
697 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100698 "quantization_layer.cl",
699#include "./cl_kernels/quantization_layer.clembed"
700 },
701 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100702 "reduction_operation.cl",
703#include "./cl_kernels/reduction_operation.clembed"
704 },
705 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100706 "remap.cl",
707#include "./cl_kernels/remap.clembed"
708 },
709 {
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100710 "reshape_layer.cl",
711#include "./cl_kernels/reshape_layer.clembed"
712 },
713 {
SiCong Li3e363692017-07-04 15:02:10 +0100714 "roi_pooling_layer.cl",
715#include "./cl_kernels/roi_pooling_layer.clembed"
716 },
717 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100718 "scale.cl",
719#include "./cl_kernels/scale.clembed"
720 },
721 {
722 "scharr_filter.cl",
723#include "./cl_kernels/scharr_filter.clembed"
724 },
725 {
726 "sobel_filter.cl",
727#include "./cl_kernels/sobel_filter.clembed"
728 },
729 {
730 "softmax_layer.cl",
731#include "./cl_kernels/softmax_layer.clembed"
732 },
733 {
Chunosovf450caa2017-11-08 16:09:35 +0700734 "softmax_layer_quantized.cl",
735#include "./cl_kernels/softmax_layer_quantized.clembed"
736 },
737 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100738 "tablelookup.cl",
739#include "./cl_kernels/tablelookup.clembed"
740 },
741 {
742 "threshold.cl",
743#include "./cl_kernels/threshold.clembed"
744 },
745 {
746 "transpose.cl",
747#include "./cl_kernels/transpose.clembed"
748 },
749 {
750 "types.h",
751#include "./cl_kernels/types.hembed"
752 },
753 {
754 "warp_affine.cl",
755#include "./cl_kernels/warp_affine.clembed"
756 },
757 {
758 "warp_helpers.h",
759#include "./cl_kernels/warp_helpers.hembed"
760 },
761 {
762 "warp_perspective.cl",
763#include "./cl_kernels/warp_perspective.clembed"
Michalis Spyroud7e82812017-06-20 15:00:14 +0100764 },
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000765 {
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100766 "winograd_filter_transform.cl",
767#include "./cl_kernels/winograd_filter_transform.clembed"
768 },
769 {
770 "winograd_input_transform.cl",
771#include "./cl_kernels/winograd_input_transform.clembed"
772 },
773 {
774 "winograd_output_transform.cl",
775#include "./cl_kernels/winograd_output_transform.clembed"
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000776 },
Anthony Barbierac69aa12017-07-03 17:39:37 +0100777#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100778};
779
780CLKernelLibrary::CLKernelLibrary()
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100781 : _context(), _device(), _kernel_path("."), _programs_map(), _built_programs_map()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100782{
Anthony Barbierecb1c622018-04-17 11:45:10 +0100783 opencl_is_available(); // Make sure the OpenCL symbols are initialised *before* the CLKernelLibrary is built
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100784}
785
786CLKernelLibrary &CLKernelLibrary::get()
787{
788 static CLKernelLibrary _kernel_library;
789 return _kernel_library;
790}
791
792Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const StringSet &build_options_set) const
793{
794 // Find which program contains the kernel
795 auto kernel_program_it = _kernel_program_map.find(kernel_name);
796
797 if(_kernel_program_map.end() == kernel_program_it)
798 {
799 ARM_COMPUTE_ERROR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
800 }
steniu0134702472017-07-11 09:22:58 +0100801 std::string concat_str;
802
Georgios Pinitasdf473ea2018-05-31 18:53:52 +0100803#if defined(ARM_COMPUTE_DEBUG_ENABLED)
804 // Enable debug properties in CL kernels
805 concat_str += " -DARM_COMPUTE_DEBUG_ENABLED";
806#endif // defined(ARM_COMPUTE_DEBUG_ENABLED)
807
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100808 if(fp16_supported())
Matthew Bentham6f31f8c2017-10-27 11:50:06 +0100809 {
810 concat_str += " -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 ";
811 }
812
Michalis Spyroue03342e2018-01-15 14:39:13 +0000813 if(dot8_supported(_device))
814 {
815 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ENABLED=1 ";
816 }
817
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100818 if(dot8_acc_supported(_device))
819 {
820 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED=1 ";
821 }
822
Pablo Telloe86a09f2018-01-11 15:44:48 +0000823 if(get_cl_version(_device) == CLVersion::CL20)
steniu0134702472017-07-11 09:22:58 +0100824 {
825 concat_str += " -cl-std=CL2.0 ";
826 }
Anthony Barbierd727e852018-04-20 11:05:29 +0100827 else if(arm_non_uniform_workgroup_supported(_device))
Pablo Telloe86a09f2018-01-11 15:44:48 +0000828 {
829 concat_str += " -cl-arm-non-uniform-work-group-size ";
830 }
steniu0134702472017-07-11 09:22:58 +0100831 else
832 {
833 ARM_COMPUTE_ERROR("Non uniform workgroup size is not supported!!");
834 }
835
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100836 // Check if the program has been built before with same build options.
steniu0134702472017-07-11 09:22:58 +0100837 const std::string program_name = kernel_program_it->second;
838 const std::string build_options = stringify_set(build_options_set) + concat_str;
839
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100840 const std::string built_program_name = program_name + "_" + build_options;
841 auto built_program_it = _built_programs_map.find(built_program_name);
842
843 cl::Program cl_program;
844
845 if(_built_programs_map.end() != built_program_it)
846 {
847 // If program has been built, retrieve to create kernel from it
848 cl_program = built_program_it->second;
849 }
850 else
851 {
852 // Get program
853 Program program = load_program(program_name);
854
855 // Build program
856 cl_program = program.build(build_options);
857
858 // Add built program to internal map
859 _built_programs_map.emplace(built_program_name, cl_program);
860 }
861
862 // Create and return kernel
863 return Kernel(kernel_name, cl_program);
864}
865
Anthony Barbier7da55aa2018-04-13 16:58:43 +0100866void CLKernelLibrary::add_built_program(const std::string &built_program_name, cl::Program program)
867{
868 _built_programs_map.emplace(built_program_name, program);
869}
870
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100871bool CLKernelLibrary::fp16_supported() const
872{
873 return ::fp16_supported(_device);
874}
875
Vidhya Sudhan Loganathan76c85642018-05-25 13:53:02 +0100876bool CLKernelLibrary::int64_base_atomics_supported() const
877{
878 return device_supports_extension(_device, "cl_khr_int64_base_atomics");
879}
880
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100881const Program &CLKernelLibrary::load_program(const std::string &program_name) const
882{
883 const auto program_it = _programs_map.find(program_name);
884
885 if(program_it != _programs_map.end())
886 {
887 return program_it->second;
888 }
889
890 Program program;
891
892#ifdef EMBEDDED_KERNELS
893 const auto program_source_it = _program_source_map.find(program_name);
894
895 if(_program_source_map.end() == program_source_it)
896 {
897 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
898 }
899
900 program = Program(_context, program_name, program_source_it->second);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100901#else /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100902 // Check for binary
903 std::string source_name = _kernel_path + program_name;
904 std::string binary_name = source_name + "bin";
905
906 if(std::ifstream(binary_name).is_open())
907 {
908 const std::string program_binary = read_file(binary_name, true);
909 program = Program(_context, _device, program_name, std::vector<unsigned char>(program_binary.begin(), program_binary.end()));
910 }
911 else if(std::ifstream(source_name).is_open())
912 {
913 program = Program(_context, program_name, read_file(source_name, false));
914 }
915 else
916 {
917 ARM_COMPUTE_ERROR("Kernel file %s does not exist.", source_name.c_str());
918 }
Anthony Barbierac69aa12017-07-03 17:39:37 +0100919#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100920
921 // Insert program to program map
922 const auto new_program = _programs_map.emplace(program_name, std::move(program));
923
924 return new_program.first->second;
925}
926
927std::string CLKernelLibrary::stringify_set(const StringSet &s) const
928{
steniu0134702472017-07-11 09:22:58 +0100929 std::string concat_set;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100930
931#ifndef EMBEDDED_KERNELS
932 concat_set += "-I" + _kernel_path + " ";
933#endif /* EMBEDDED_KERNELS */
934
935 // Concatenate set
936 for(const auto &el : s)
937 {
938 concat_set += " " + el;
939 }
940
941 return concat_set;
942}
Michalis Spyroud7e82812017-06-20 15:00:14 +0100943
944std::string CLKernelLibrary::get_program_source(const std::string &program_name)
945{
946 const auto program_source_it = _program_source_map.find(program_name);
947
948 if(program_source_it == _program_source_map.end())
949 {
950 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
951 }
952
953 return program_source_it->second;
954}
steniu015f910722017-08-23 10:15:22 +0100955
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100956size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const
steniu015f910722017-08-23 10:15:22 +0100957{
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100958 size_t result;
steniu015f910722017-08-23 10:15:22 +0100959
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100960 size_t err = kernel.getWorkGroupInfo(_device, CL_KERNEL_WORK_GROUP_SIZE, &result);
961 ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel");
962 ARM_COMPUTE_UNUSED(err);
963
964 return result;
steniu015f910722017-08-23 10:15:22 +0100965}
966
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100967cl::NDRange CLKernelLibrary::default_ndrange() const
steniu015f910722017-08-23 10:15:22 +0100968{
Michalis Spyroua9676112018-02-22 18:07:43 +0000969 cl::Device device = cl::Device::getDefault();
970 GPUTarget _target = get_target_from_device(device);
971 cl::NDRange default_range;
972
973 switch(_target)
974 {
975 case GPUTarget::MIDGARD:
976 case GPUTarget::T600:
977 case GPUTarget::T700:
978 case GPUTarget::T800:
979 default_range = cl::NDRange(128u, 1);
980 break;
981 default:
982 default_range = cl::NullRange;
983 }
984
985 return default_range;
steniu015f910722017-08-23 10:15:22 +0100986}
Anthony Barbier847864d2018-03-07 11:35:53 +0000987
988std::string CLKernelLibrary::get_device_version()
989{
990 return _device.getInfo<CL_DEVICE_VERSION>();
991}