blob: fa164542e4f10de4bd97245dccdb0471add83a95 [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" },
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100156 { "batch_to_space", "batch_to_space.cl" },
157 { "batch_to_space_static", "batch_to_space.cl" },
Michele Di Giorgiobf3c6622018-03-08 11:52:27 +0000158 { "batchnormalization_layer_nchw", "batchnormalization_layer.cl" },
159 { "batchnormalization_layer_nhwc", "batchnormalization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100160 { "bitwise_or", "bitwise_op.cl" },
161 { "bitwise_and", "bitwise_op.cl" },
162 { "bitwise_xor", "bitwise_op.cl" },
163 { "bitwise_not", "bitwise_op.cl" },
164 { "channel_combine_NV", "channel_combine.cl" },
165 { "channel_combine_RGB888", "channel_combine.cl" },
166 { "channel_combine_RGBA8888", "channel_combine.cl" },
167 { "channel_combine_UYVY422", "channel_combine.cl" },
168 { "channel_combine_YUYV422", "channel_combine.cl" },
Michele Di Giorgio72175632018-05-01 16:52:00 +0100169 { "channel_shuffle_nchw", "channel_shuffle.cl" },
Gian Marco Iodice8bab0ee2018-09-13 11:51:56 +0100170 { "channel_shuffle_nhwc", "channel_shuffle.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100171 { "channel_extract_NV12", "channel_extract.cl" },
172 { "channel_extract_NV21", "channel_extract.cl" },
173 { "channel_extract_RGB888", "channel_extract.cl" },
174 { "channel_extract_RGBA8888", "channel_extract.cl" },
175 { "channel_extract_UYVY422", "channel_extract.cl" },
176 { "channel_extract_YUYV422", "channel_extract.cl" },
177 { "combine_gradients_L1", "canny.cl" },
178 { "combine_gradients_L2", "canny.cl" },
179 { "concatenate_depth", "concatenate.cl" },
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100180 { "concatenate_width", "concatenate.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100181 { "convolution_rectangle", "convolution_rectangle.cl" },
Gian Marco76faef82018-01-29 12:15:32 +0000182 { "col2im", "col2im.cl" },
Giorgio Arena657bdb32018-04-26 18:52:01 +0100183 { "convert_depth_down", "depth_convert.cl" },
184 { "convert_depth_up", "depth_convert.cl" },
185 { "convert_fc_weights", "convert_fc_weights.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100186 { "convolution3x3_static", "convolution3x3.cl" },
187 { "convolution5x5_static", "convolution5x5.cl" },
188 { "convolution7x7_static", "convolution7x7.cl" },
189 { "convolution9x9_static", "convolution9x9.cl" },
190 { "convolution_separable1x5_static", "convolution5x5.cl" },
191 { "convolution_separable5x1_static", "convolution5x5.cl" },
192 { "convolution_separable1x7_static", "convolution7x7.cl" },
193 { "convolution_separable7x1_static", "convolution7x7.cl" },
194 { "convolution_separable1x9_static", "convolution9x9.cl" },
195 { "convolution_separable9x1_static", "convolution9x9.cl" },
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000196 { "copy_tensor", "copy_tensor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100197 { "copy_plane", "channel_extract.cl" },
198 { "copy_planes_3p", "channel_combine.cl" },
199 { "copy_to_keypoint", "fast_corners.cl" },
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000200 { "deconvolution_upsample", "deconvolution_layer.cl" },
Giorgio Arena93a690e2017-08-01 16:09:33 +0100201 { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
Michele Di Giorgio933fe862018-02-19 15:42:12 +0000202 { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
Giorgio Arenad051e972018-06-20 11:46:42 +0100203 { "depthwise_convolution_3x3_nhwc", "depthwise_convolution.cl" },
204 { "depthwise_convolution_3x3_nhwc_stride1", "depthwise_convolution.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000205 { "depthwise_convolution_3x3_quantized_nchw", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100206 { "depthwise_convolution_3x3_quantized_nhwc", "depthwise_convolution_quantized.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000207 { "depthwise_convolution_3x3_quantized_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100208 { "depthwise_convolution_3x3_quantized_dot8_nchw", "depthwise_convolution_quantized.cl" },
209 { "depthwise_convolution_3x3_quantized_dot8_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Michele Di Giorgio3ebef322018-02-21 10:02:58 +0000210 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16", "depthwise_convolution.cl" },
211 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16", "depthwise_convolution.cl" },
212 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32", "depthwise_convolution.cl" },
213 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32", "depthwise_convolution.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100214 { "depthwise_im2col", "depthwise_convolution.cl" },
215 { "depthwise_vector_to_tensor", "depthwise_convolution.cl" },
216 { "depthwise_weights_reshape", "depthwise_convolution.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100217 { "dequantization_layer", "dequantization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100218 { "derivative", "derivative.cl" },
219 { "dilate", "dilate.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100220 { "direct_convolution1x1", "direct_convolution1x1.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100221 { "direct_convolution1x1_nhwc", "direct_convolution1x1.cl" },
Gian Marco Iodice1c8409d2017-09-06 17:24:25 +0100222 { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100223 { "direct_convolution3x3", "direct_convolution3x3.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100224 { "direct_convolution3x3_nhwc", "direct_convolution3x3.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100225 { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
steniu01db006682017-08-09 16:26:22 +0100226 { "direct_convolution5x5", "direct_convolution5x5.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100227 { "direct_convolution5x5_nhwc", "direct_convolution5x5.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100228 { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
Chunosovd621bca2017-11-03 17:33:15 +0700229 { "direct_convolution_1x1_3x3_5x5_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100230 { "erode", "erode.cl" },
231 { "fast_corners", "fast_corners.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100232 { "flatten", "flatten.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100233 { "fill_image_borders_constant", "fill_border.cl" },
234 { "fill_image_borders_replicate", "fill_border.cl" },
235 { "finalize", "optical_flow_pyramid_lk.cl" },
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100236 { "floor_layer", "floor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100237 { "gaussian1x5_sub_x", "gaussian_pyramid.cl" },
238 { "gaussian5x1_sub_y", "gaussian_pyramid.cl" },
Gian Marco Iodice578ab612017-06-23 09:34:33 +0100239 { "gemm_accumulate_biases", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000240 { "gemm_interleave4x4", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100241 { "gemm_ma_f16", "gemm.cl" },
242 { "gemm_ma_f32", "gemm.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100243 { "gemm_mv", "gemv.cl" },
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +0000244 { "gemm_mv_quantized", "gemv.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100245 { "gemm_mm_interleaved_transposed_f16", "gemm.cl" },
Gian Marco Iodicebb36a8e2018-04-19 12:05:08 +0100246 { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm.cl" },
247 { "gemm_mm_interleaved_transposed_f32", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100248 { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100249 { "gemm_mm_floating_point", "gemm.cl" },
Gian Marco Iodicefd683112018-04-17 09:52:44 +0100250 { "gemm_mm_floating_point_f16_bifrost", "gemm.cl" },
Anton Lokhmotov3e80c7f2017-11-20 11:02:10 +0000251 { "gemm_mm_floating_point_f32_bifrost", "gemm.cl" },
252 { "gemm_mm_floating_point_f32_bifrost_1000", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100253 { "gemm_lc_vm_f32", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000254 { "gemm_transpose1xW", "gemm.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000255 { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
256 { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000257 { "gemmlowp_mm_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100258 { "gemmlowp_mm_bifrost_dot8", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000259 { "gemmlowp_mm_midgard", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000260 { "gemmlowp_mm_interleaved_transposed_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100261 { "gemmlowp_mm_interleaved_transposed_bifrost_dot8", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000262 { "gemmlowp_mm_interleaved_transposed_midgard", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000263 { "gemmlowp_offset_contribution", "gemmlowp.cl" },
264 { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
Gian Marco58c57942017-11-28 09:10:03 +0000265 { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100266 { "harris_score_3x3", "harris_corners.cl" },
267 { "harris_score_5x5", "harris_corners.cl" },
268 { "harris_score_7x7", "harris_corners.cl" },
269 { "hist_border_kernel", "histogram.cl" },
270 { "hist_border_kernel_fixed", "histogram.cl" },
271 { "hist_local_kernel", "histogram.cl" },
272 { "hist_local_kernel_fixed", "histogram.cl" },
273 { "hog_block_normalization", "hog.cl" },
274 { "hog_detector", "hog.cl" },
275 { "hog_orientation_binning", "hog.cl" },
276 { "hysteresis", "canny.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100277 { "im2col1x1_stridex1_nchw", "im2col.cl" },
278 { "im2col3x3_nchw", "im2col.cl" },
279 { "im2col5x5_nchw", "im2col.cl" },
280 { "im2col11x11_padx0_pady0_nchw", "im2col.cl" },
281 { "im2col_generic_nchw", "im2col.cl" },
282 { "im2col_generic_padx0_pady0_nchw", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100283 { "im2col3x3_nhwc", "im2col.cl" },
284 { "im2col_generic_nhwc", "im2col.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100285 { "init_level", "optical_flow_pyramid_lk.cl" },
286 { "init_level_max", "optical_flow_pyramid_lk.cl" },
287 { "init_level_max_initial_estimate", "optical_flow_pyramid_lk.cl" },
288 { "integral_horizontal", "integral_image.cl" },
289 { "integral_vertical", "integral_image.cl" },
290 { "IYUV_to_NV12_bt709", "color_convert.cl" },
291 { "IYUV_to_RGB888_bt709", "color_convert.cl" },
292 { "IYUV_to_RGBA8888_bt709", "color_convert.cl" },
293 { "IYUV_to_YUV444_bt709", "color_convert.cl" },
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100294 { "l2_normalize", "l2_normalize.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100295 { "lktracker_stage0", "optical_flow_pyramid_lk.cl" },
296 { "lktracker_stage1", "optical_flow_pyramid_lk.cl" },
297 { "magnitude_phase", "magnitude_phase.cl" },
298 { "mean_stddev_accumulate", "mean_stddev.cl" },
299 { "minmax", "minmaxloc.cl" },
300 { "minmax_border", "minmaxloc.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100301 { "minmax_layer", "minmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100302 { "minmaxloc", "minmaxloc.cl" },
303 { "non_linear_filter_box3x3", "non_linear_filter3x3.cl" },
304 { "non_linear_filter_cross3x3", "non_linear_filter3x3.cl" },
305 { "non_linear_filter_disk3x3", "non_linear_filter3x3.cl" },
306 { "non_linear_filter_box5x5", "non_linear_filter5x5.cl" },
307 { "non_linear_filter_cross5x5", "non_linear_filter5x5.cl" },
308 { "non_linear_filter_disk5x5", "non_linear_filter5x5.cl" },
309 { "non_max_suppression", "nonmax.cl" },
310 { "normalization_layer_cross_map", "normalization_layer.cl" },
Georgios Pinitas01624362017-11-30 10:53:31 +0000311 { "normalization_layer_in_map", "normalization_layer.cl" },
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100312 { "normalize_planar_yuv_layer_nchw", "normalize_planar_yuv_layer.cl" },
313 { "normalize_planar_yuv_layer_nhwc", "normalize_planar_yuv_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100314 { "NV12_to_IYUV_bt709", "color_convert.cl" },
315 { "NV12_to_RGB888_bt709", "color_convert.cl" },
316 { "NV12_to_RGBA8888_bt709", "color_convert.cl" },
317 { "NV12_to_YUV444_bt709", "color_convert.cl" },
318 { "NV21_to_IYUV_bt709", "color_convert.cl" },
319 { "NV21_to_RGB888_bt709", "color_convert.cl" },
320 { "NV21_to_RGBA8888_bt709", "color_convert.cl" },
321 { "NV21_to_YUV444_bt709", "color_convert.cl" },
Giorgio Arenaa086a0a2018-02-16 12:42:16 +0000322 { "output_stage_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Michalis Spyrou5237e012018-01-17 09:40:27 +0000323 { "permute_201", "permute.cl" },
324 { "permute_120", "permute.cl" },
325 { "permute_3201", "permute.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100326 { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
327 { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
328 { "pooling_layer_2", "pooling_layer.cl" },
329 { "pooling_layer_3", "pooling_layer.cl" },
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000330 { "pooling_layer_optimized_3", "pooling_layer.cl" },
Georgios Pinitasce093142017-06-19 16:11:53 +0100331 { "pooling_layer_7", "pooling_layer.cl" },
Michalis Spyroue74b2012018-04-18 09:49:16 +0100332 { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
333 { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
334 { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
335 { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100336 { "quantization_layer", "quantization_layer.cl" },
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100337 { "reduction_operation", "reduction_operation.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100338 { "remap_nearest_neighbour", "remap.cl" },
339 { "remap_bilinear", "remap.cl" },
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100340 { "reorg_layer_nchw", "reorg_layer.cl" },
341 { "reorg_layer_nhwc", "reorg_layer.cl" },
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100342 { "reshape_layer", "reshape_layer.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100343 { "reshape_to_columns", "convolution_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100344 { "RGB888_to_IYUV_bt709", "color_convert.cl" },
345 { "RGB888_to_NV12_bt709", "color_convert.cl" },
346 { "RGB888_to_RGBA8888_bt709", "color_convert.cl" },
347 { "RGB888_to_YUV444_bt709", "color_convert.cl" },
348 { "RGBA8888_to_IYUV_bt709", "color_convert.cl" },
349 { "RGBA8888_to_NV12_bt709", "color_convert.cl" },
350 { "RGBA8888_to_RGB888_bt709", "color_convert.cl" },
351 { "RGBA8888_to_YUV444_bt709", "color_convert.cl" },
SiCong Li3e363692017-07-04 15:02:10 +0100352 { "roi_pooling_layer", "roi_pooling_layer.cl" },
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100353 { "scale_nearest_neighbour_nchw", "scale.cl" },
354 { "scale_nearest_neighbour_nhwc", "scale.cl" },
355 { "scale_bilinear_nchw", "scale.cl" },
356 { "scale_bilinear_nhwc", "scale.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100357 { "scharr3x3", "scharr_filter.cl" },
358 { "sobel3x3", "sobel_filter.cl" },
359 { "sobel_separable5x1", "sobel_filter.cl" },
360 { "sobel_separable1x5", "sobel_filter.cl" },
361 { "sobel_separable7x1", "sobel_filter.cl" },
362 { "sobel_separable1x7", "sobel_filter.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100363 { "softmax_layer_norm", "softmax_layer.cl" },
Chunosovf450caa2017-11-08 16:09:35 +0700364 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
Giorgio Arena4402cb92018-02-15 13:37:40 +0000365 { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
366 { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700367 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
Michalis Spyrou16934a52018-08-21 18:03:58 +0100368 { "space_to_batch", "space_to_batch.cl" },
369 { "space_to_batch_static", "space_to_batch.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700370 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100371 { "strided_slice", "slice_ops.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100372 { "suppress_non_maximum", "canny.cl" },
373 { "tablelookup_U8", "tablelookup.cl" },
374 { "tablelookup_S16", "tablelookup.cl" },
375 { "threshold_binary", "threshold.cl" },
376 { "threshold_range", "threshold.cl" },
377 { "transpose", "transpose.cl" },
378 { "UYVY422_to_IYUV_bt709", "color_convert.cl" },
379 { "UYVY422_to_NV12_bt709", "color_convert.cl" },
380 { "UYVY422_to_RGB888_bt709", "color_convert.cl" },
381 { "UYVY422_to_RGBA8888_bt709", "color_convert.cl" },
382 { "warp_affine_nearest_neighbour", "warp_affine.cl" },
383 { "warp_affine_bilinear", "warp_affine.cl" },
384 { "warp_perspective_nearest_neighbour", "warp_perspective.cl" },
385 { "warp_perspective_bilinear", "warp_perspective.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100386 { "winograd_filter_transform_2x2_3x3_nchw", "winograd_filter_transform.cl" },
387 { "winograd_filter_transform_2x1_3x1_nchw", "winograd_filter_transform.cl" },
388 { "winograd_filter_transform_1x2_1x3_nchw", "winograd_filter_transform.cl" },
389 { "winograd_filter_transform_4x4_3x3_nchw", "winograd_filter_transform.cl" },
390 { "winograd_filter_transform_4x1_3x1_nchw", "winograd_filter_transform.cl" },
391 { "winograd_filter_transform_1x4_1x3_nchw", "winograd_filter_transform.cl" },
392 { "winograd_filter_transform_4x4_5x5_nchw", "winograd_filter_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100393 { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
394 { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100395 { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
396 { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100397 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
398 { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100399 { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
400 { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100401 { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd_input_transform.cl" },
402 { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd_input_transform.cl" },
403 { "winograd_input_transform_2x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
404 { "winograd_input_transform_2x1_3x1_stepz2_nchw", "winograd_input_transform.cl" },
405 { "winograd_input_transform_1x2_1x3_stepz1_nchw", "winograd_input_transform.cl" },
406 { "winograd_input_transform_1x2_1x3_stepz2_nchw", "winograd_input_transform.cl" },
407 { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd_input_transform.cl" },
408 { "winograd_input_transform_4x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
409 { "winograd_input_transform_1x4_1x3_stepz1_nchw", "winograd_input_transform.cl" },
410 { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd_input_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100411 { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
412 { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100413 { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
414 { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100415 { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
416 { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100417 { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
418 { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100419 { "winograd_output_transform_2x2_3x3_nchw", "winograd_output_transform.cl" },
420 { "winograd_output_transform_2x1_3x1_nchw", "winograd_output_transform.cl" },
421 { "winograd_output_transform_1x2_1x3_nchw", "winograd_output_transform.cl" },
422 { "winograd_output_transform_4x4_3x3_nchw", "winograd_output_transform.cl" },
423 { "winograd_output_transform_4x1_3x1_nchw", "winograd_output_transform.cl" },
424 { "winograd_output_transform_1x4_1x3_nchw", "winograd_output_transform.cl" },
425 { "winograd_output_transform_4x4_5x5_nchw", "winograd_output_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100426 { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
427 { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100428 { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
429 { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100430 { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
431 { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100432 { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
433 { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
Giorgio Arena73023022018-09-04 14:55:55 +0100434 { "yolo_layer_nchw", "yolo_layer.cl" },
435 { "yolo_layer_nhwc", "yolo_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100436 { "YUYV422_to_IYUV_bt709", "color_convert.cl" },
437 { "YUYV422_to_NV12_bt709", "color_convert.cl" },
438 { "YUYV422_to_RGB888_bt709", "color_convert.cl" },
439 { "YUYV422_to_RGBA8888_bt709", "color_convert.cl" },
440};
441
442const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
443{
444#ifdef EMBEDDED_KERNELS
445 {
446 "absdiff.cl",
447#include "./cl_kernels/absdiff.clembed"
448 },
449 {
450 "accumulate.cl",
451#include "./cl_kernels/accumulate.clembed"
452 },
453 {
454 "activation_layer.cl",
455#include "./cl_kernels/activation_layer.clembed"
456 },
457 {
Michel Iwaniec00633802017-10-12 14:14:15 +0100458 "activation_layer_qa8.cl",
459#include "./cl_kernels/activation_layer_qa8.clembed"
460 },
461 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100462 "arithmetic_op.cl",
463#include "./cl_kernels/arithmetic_op.clembed"
464 },
465 {
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100466 "arithmetic_op_quantized.cl",
467#include "./cl_kernels/arithmetic_op_quantized.clembed"
468 },
469 {
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100470 "batch_to_space.cl",
471#include "./cl_kernels/batch_to_space.clembed"
472 },
473 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100474 "bitwise_op.cl",
475#include "./cl_kernels/bitwise_op.clembed"
476 },
477 {
478 "canny.cl",
479#include "./cl_kernels/canny.clembed"
480 },
481 {
482 "channel_combine.cl",
483#include "./cl_kernels/channel_combine.clembed"
484 },
485 {
486 "channel_extract.cl",
487#include "./cl_kernels/channel_extract.clembed"
488 },
489 {
Michele Di Giorgio72175632018-05-01 16:52:00 +0100490 "channel_shuffle.cl",
491#include "./cl_kernels/channel_shuffle.clembed"
492 },
493 {
Gian Marco76faef82018-01-29 12:15:32 +0000494 "col2im.cl",
495#include "./cl_kernels/col2im.clembed"
496 },
497 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100498 "concatenate.cl",
499#include "./cl_kernels/concatenate.clembed"
500 },
501 {
502 "color_convert.cl",
503#include "./cl_kernels/color_convert.clembed"
504 },
505 {
Giorgio Arena657bdb32018-04-26 18:52:01 +0100506 "convert_fc_weights.cl",
507#include "./cl_kernels/convert_fc_weights.clembed"
508 },
509 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100510 "convolution3x3.cl",
511#include "./cl_kernels/convolution3x3.clembed"
512 },
513 {
514 "convolution5x5.cl",
515#include "./cl_kernels/convolution5x5.clembed"
516 },
517 {
518 "convolution7x7.cl",
519#include "./cl_kernels/convolution7x7.clembed"
520 },
521 {
522 "convolution9x9.cl",
523#include "./cl_kernels/convolution9x9.clembed"
524 },
525 {
526 "convolution_layer.cl",
527#include "./cl_kernels/convolution_layer.clembed"
528 },
529 {
530 "convolution_rectangle.cl",
531#include "./cl_kernels/convolution_rectangle.clembed"
532 },
533 {
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000534 "copy_tensor.cl",
535#include "./cl_kernels/copy_tensor.clembed"
536 },
537 {
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000538 "deconvolution_layer.cl",
539#include "./cl_kernels/deconvolution_layer.clembed"
540 },
541 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100542 "depth_convert.cl",
543#include "./cl_kernels/depth_convert.clembed"
544 },
545 {
Giorgio Arena93a690e2017-08-01 16:09:33 +0100546 "depthwise_convolution.cl",
547#include "./cl_kernels/depthwise_convolution.clembed"
548 },
549 {
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700550 "depthwise_convolution_quantized.cl",
551#include "./cl_kernels/depthwise_convolution_quantized.clembed"
552 },
553 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100554 "dequantization_layer.cl",
555#include "./cl_kernels/dequantization_layer.clembed"
556 },
557 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100558 "derivative.cl",
559#include "./cl_kernels/derivative.clembed"
560 },
561 {
562 "dilate.cl",
563#include "./cl_kernels/dilate.clembed"
564 },
565 {
SiCong Lic51b72f2017-07-28 14:46:20 +0100566 "direct_convolution1x1.cl",
567#include "./cl_kernels/direct_convolution1x1.clembed"
568 },
569 {
570 "direct_convolution3x3.cl",
571#include "./cl_kernels/direct_convolution3x3.clembed"
steniu0127b386c2017-07-18 17:37:43 +0100572 },
573 {
steniu01db006682017-08-09 16:26:22 +0100574 "direct_convolution5x5.cl",
575#include "./cl_kernels/direct_convolution5x5.clembed"
576 },
577 {
Chunosovd621bca2017-11-03 17:33:15 +0700578 "direct_convolution_1x1_3x3_5x5_quantized.cl",
579#include "./cl_kernels/direct_convolution_1x1_3x3_5x5_quantized.clembed"
580 },
581 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100582 "erode.cl",
583#include "./cl_kernels/erode.clembed"
584 },
585 {
586 "fast_corners.cl",
587#include "./cl_kernels/fast_corners.clembed"
588 },
589 {
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100590 "flatten.cl",
591#include "./cl_kernels/flatten.clembed"
592 },
593 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100594 "fill_border.cl",
595#include "./cl_kernels/fill_border.clembed"
596 },
597 {
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100598 "floor.cl",
599#include "./cl_kernels/floor.clembed"
600 },
601 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100602 "gaussian_pyramid.cl",
603#include "./cl_kernels/gaussian_pyramid.clembed"
604 },
605 {
606 "gemm.cl",
607#include "./cl_kernels/gemm.clembed"
608 },
609 {
Gian Marco05288a22017-11-21 10:57:50 +0000610 "gemmlowp.cl",
611#include "./cl_kernels/gemmlowp.clembed"
612 },
613 {
Giorgio Arena9fe41442017-08-23 16:36:24 +0100614 "gemv.cl",
615#include "./cl_kernels/gemv.clembed"
616 },
617 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100618 "harris_corners.cl",
619#include "./cl_kernels/harris_corners.clembed"
620 },
621 {
622 "helpers.h",
623#include "./cl_kernels/helpers.hembed"
624 },
625 {
Chunosovd621bca2017-11-03 17:33:15 +0700626 "helpers_asymm.h",
627#include "./cl_kernels/helpers_asymm.hembed"
628 },
629 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100630 "histogram.cl",
631#include "./cl_kernels/histogram.clembed"
632 },
633 {
634 "hog.cl",
635#include "./cl_kernels/hog.clembed"
636 },
637 {
Gian Marco76faef82018-01-29 12:15:32 +0000638 "im2col.cl",
639#include "./cl_kernels/im2col.clembed"
640 },
641 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100642 "integral_image.cl",
643#include "./cl_kernels/integral_image.clembed"
644 },
645 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100646 "l2_normalize.cl",
647#include "./cl_kernels/l2_normalize.clembed"
648 },
649 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100650 "magnitude_phase.cl",
651#include "./cl_kernels/magnitude_phase.clembed"
652 },
653 {
654 "mean_stddev.cl",
655#include "./cl_kernels/mean_stddev.clembed"
656 },
657 {
658 "minmaxloc.cl",
659#include "./cl_kernels/minmaxloc.clembed"
660 },
661 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100662 "minmax_layer.cl",
663#include "./cl_kernels/minmax_layer.clembed"
664 },
665 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100666 "non_linear_filter3x3.cl",
667#include "./cl_kernels/non_linear_filter3x3.clembed"
668 },
669 {
670 "non_linear_filter5x5.cl",
671#include "./cl_kernels/non_linear_filter5x5.clembed"
672 },
673 {
674 "non_linear_filter_helpers.h",
675#include "./cl_kernels/non_linear_filter_helpers.hembed"
676 },
677 {
678 "nonmax.cl",
679#include "./cl_kernels/nonmax.clembed"
680 },
681 {
682 "normalization_layer.cl",
683#include "./cl_kernels/normalization_layer.clembed"
684 },
685 {
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100686 "normalize_planar_yuv_layer.cl",
687#include "./cl_kernels/normalize_planar_yuv_layer.clembed"
688 },
689 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100690 "batchnormalization_layer.cl",
691#include "./cl_kernels/batchnormalization_layer.clembed"
692 },
693 {
694 "optical_flow_pyramid_lk.cl",
695#include "./cl_kernels/optical_flow_pyramid_lk.clembed"
696 },
697 {
Michalis Spyrou5237e012018-01-17 09:40:27 +0000698 "permute.cl",
699#include "./cl_kernels/permute.clembed"
700 },
701 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100702 "pixelwise_mul_float.cl",
703#include "./cl_kernels/pixelwise_mul_float.clembed"
704 },
705 {
706 "pixelwise_mul_int.cl",
707#include "./cl_kernels/pixelwise_mul_int.clembed"
708 },
709 {
710 "pooling_layer.cl",
711#include "./cl_kernels/pooling_layer.clembed"
712 },
713 {
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000714 "pooling_layer_quantized.cl",
715#include "./cl_kernels/pooling_layer_quantized.clembed"
716 },
717 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100718 "quantization_layer.cl",
719#include "./cl_kernels/quantization_layer.clembed"
720 },
721 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100722 "reduction_operation.cl",
723#include "./cl_kernels/reduction_operation.clembed"
724 },
725 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100726 "remap.cl",
727#include "./cl_kernels/remap.clembed"
728 },
729 {
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100730 "reorg_layer.cl",
731#include "./cl_kernels/reorg_layer.clembed"
732 },
733 {
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100734 "reshape_layer.cl",
735#include "./cl_kernels/reshape_layer.clembed"
736 },
737 {
SiCong Li3e363692017-07-04 15:02:10 +0100738 "roi_pooling_layer.cl",
739#include "./cl_kernels/roi_pooling_layer.clembed"
740 },
741 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100742 "scale.cl",
743#include "./cl_kernels/scale.clembed"
744 },
745 {
746 "scharr_filter.cl",
747#include "./cl_kernels/scharr_filter.clembed"
748 },
749 {
750 "sobel_filter.cl",
751#include "./cl_kernels/sobel_filter.clembed"
752 },
753 {
754 "softmax_layer.cl",
755#include "./cl_kernels/softmax_layer.clembed"
756 },
757 {
Chunosovf450caa2017-11-08 16:09:35 +0700758 "softmax_layer_quantized.cl",
759#include "./cl_kernels/softmax_layer_quantized.clembed"
760 },
761 {
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100762 "slice_ops.cl",
763#include "./cl_kernels/slice_ops.clembed"
Georgios Pinitas77589b52018-08-21 14:41:35 +0100764 },
765 {
Michalis Spyrou16934a52018-08-21 18:03:58 +0100766 "space_to_batch.cl",
767#include "./cl_kernels/space_to_batch.clembed"
768 },
769 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100770 "tablelookup.cl",
771#include "./cl_kernels/tablelookup.clembed"
772 },
773 {
774 "threshold.cl",
775#include "./cl_kernels/threshold.clembed"
776 },
777 {
778 "transpose.cl",
779#include "./cl_kernels/transpose.clembed"
780 },
781 {
782 "types.h",
783#include "./cl_kernels/types.hembed"
784 },
785 {
786 "warp_affine.cl",
787#include "./cl_kernels/warp_affine.clembed"
788 },
789 {
790 "warp_helpers.h",
791#include "./cl_kernels/warp_helpers.hembed"
792 },
793 {
794 "warp_perspective.cl",
795#include "./cl_kernels/warp_perspective.clembed"
Michalis Spyroud7e82812017-06-20 15:00:14 +0100796 },
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000797 {
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100798 "winograd_filter_transform.cl",
799#include "./cl_kernels/winograd_filter_transform.clembed"
800 },
801 {
802 "winograd_input_transform.cl",
803#include "./cl_kernels/winograd_input_transform.clembed"
804 },
805 {
806 "winograd_output_transform.cl",
807#include "./cl_kernels/winograd_output_transform.clembed"
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000808 },
Giorgio Arena73023022018-09-04 14:55:55 +0100809 {
810 "yolo_layer.cl",
811#include "./cl_kernels/yolo_layer.clembed"
812 },
Anthony Barbierac69aa12017-07-03 17:39:37 +0100813#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100814};
815
816CLKernelLibrary::CLKernelLibrary()
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100817 : _context(), _device(), _kernel_path("."), _programs_map(), _built_programs_map()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100818{
Anthony Barbierecb1c622018-04-17 11:45:10 +0100819 opencl_is_available(); // Make sure the OpenCL symbols are initialised *before* the CLKernelLibrary is built
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100820}
821
822CLKernelLibrary &CLKernelLibrary::get()
823{
824 static CLKernelLibrary _kernel_library;
825 return _kernel_library;
826}
827
828Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const StringSet &build_options_set) const
829{
830 // Find which program contains the kernel
831 auto kernel_program_it = _kernel_program_map.find(kernel_name);
832
833 if(_kernel_program_map.end() == kernel_program_it)
834 {
835 ARM_COMPUTE_ERROR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
836 }
steniu0134702472017-07-11 09:22:58 +0100837 std::string concat_str;
838
Georgios Pinitasdf473ea2018-05-31 18:53:52 +0100839#if defined(ARM_COMPUTE_DEBUG_ENABLED)
840 // Enable debug properties in CL kernels
841 concat_str += " -DARM_COMPUTE_DEBUG_ENABLED";
842#endif // defined(ARM_COMPUTE_DEBUG_ENABLED)
843
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100844 if(fp16_supported())
Matthew Bentham6f31f8c2017-10-27 11:50:06 +0100845 {
846 concat_str += " -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 ";
847 }
848
Michalis Spyroue03342e2018-01-15 14:39:13 +0000849 if(dot8_supported(_device))
850 {
851 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ENABLED=1 ";
852 }
853
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100854 if(dot8_acc_supported(_device))
855 {
856 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED=1 ";
857 }
858
Pablo Telloe86a09f2018-01-11 15:44:48 +0000859 if(get_cl_version(_device) == CLVersion::CL20)
steniu0134702472017-07-11 09:22:58 +0100860 {
861 concat_str += " -cl-std=CL2.0 ";
862 }
Anthony Barbierd727e852018-04-20 11:05:29 +0100863 else if(arm_non_uniform_workgroup_supported(_device))
Pablo Telloe86a09f2018-01-11 15:44:48 +0000864 {
865 concat_str += " -cl-arm-non-uniform-work-group-size ";
866 }
steniu0134702472017-07-11 09:22:58 +0100867 else
868 {
869 ARM_COMPUTE_ERROR("Non uniform workgroup size is not supported!!");
870 }
871
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100872 // Check if the program has been built before with same build options.
steniu0134702472017-07-11 09:22:58 +0100873 const std::string program_name = kernel_program_it->second;
874 const std::string build_options = stringify_set(build_options_set) + concat_str;
875
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100876 const std::string built_program_name = program_name + "_" + build_options;
877 auto built_program_it = _built_programs_map.find(built_program_name);
878
879 cl::Program cl_program;
880
881 if(_built_programs_map.end() != built_program_it)
882 {
883 // If program has been built, retrieve to create kernel from it
884 cl_program = built_program_it->second;
885 }
886 else
887 {
888 // Get program
889 Program program = load_program(program_name);
890
891 // Build program
892 cl_program = program.build(build_options);
893
894 // Add built program to internal map
895 _built_programs_map.emplace(built_program_name, cl_program);
896 }
897
898 // Create and return kernel
899 return Kernel(kernel_name, cl_program);
900}
901
Anthony Barbier7da55aa2018-04-13 16:58:43 +0100902void CLKernelLibrary::add_built_program(const std::string &built_program_name, cl::Program program)
903{
904 _built_programs_map.emplace(built_program_name, program);
905}
906
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100907bool CLKernelLibrary::fp16_supported() const
908{
909 return ::fp16_supported(_device);
910}
911
Vidhya Sudhan Loganathan76c85642018-05-25 13:53:02 +0100912bool CLKernelLibrary::int64_base_atomics_supported() const
913{
914 return device_supports_extension(_device, "cl_khr_int64_base_atomics");
915}
916
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100917const Program &CLKernelLibrary::load_program(const std::string &program_name) const
918{
919 const auto program_it = _programs_map.find(program_name);
920
921 if(program_it != _programs_map.end())
922 {
923 return program_it->second;
924 }
925
926 Program program;
927
928#ifdef EMBEDDED_KERNELS
929 const auto program_source_it = _program_source_map.find(program_name);
930
931 if(_program_source_map.end() == program_source_it)
932 {
933 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
934 }
935
936 program = Program(_context, program_name, program_source_it->second);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100937#else /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100938 // Check for binary
939 std::string source_name = _kernel_path + program_name;
940 std::string binary_name = source_name + "bin";
941
942 if(std::ifstream(binary_name).is_open())
943 {
944 const std::string program_binary = read_file(binary_name, true);
945 program = Program(_context, _device, program_name, std::vector<unsigned char>(program_binary.begin(), program_binary.end()));
946 }
947 else if(std::ifstream(source_name).is_open())
948 {
949 program = Program(_context, program_name, read_file(source_name, false));
950 }
951 else
952 {
953 ARM_COMPUTE_ERROR("Kernel file %s does not exist.", source_name.c_str());
954 }
Anthony Barbierac69aa12017-07-03 17:39:37 +0100955#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100956
957 // Insert program to program map
958 const auto new_program = _programs_map.emplace(program_name, std::move(program));
959
960 return new_program.first->second;
961}
962
963std::string CLKernelLibrary::stringify_set(const StringSet &s) const
964{
steniu0134702472017-07-11 09:22:58 +0100965 std::string concat_set;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100966
967#ifndef EMBEDDED_KERNELS
968 concat_set += "-I" + _kernel_path + " ";
969#endif /* EMBEDDED_KERNELS */
970
971 // Concatenate set
972 for(const auto &el : s)
973 {
974 concat_set += " " + el;
975 }
976
977 return concat_set;
978}
Michalis Spyroud7e82812017-06-20 15:00:14 +0100979
980std::string CLKernelLibrary::get_program_source(const std::string &program_name)
981{
982 const auto program_source_it = _program_source_map.find(program_name);
983
984 if(program_source_it == _program_source_map.end())
985 {
986 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
987 }
988
989 return program_source_it->second;
990}
steniu015f910722017-08-23 10:15:22 +0100991
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100992size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const
steniu015f910722017-08-23 10:15:22 +0100993{
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100994 size_t result;
steniu015f910722017-08-23 10:15:22 +0100995
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100996 size_t err = kernel.getWorkGroupInfo(_device, CL_KERNEL_WORK_GROUP_SIZE, &result);
997 ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel");
998 ARM_COMPUTE_UNUSED(err);
999
1000 return result;
steniu015f910722017-08-23 10:15:22 +01001001}
1002
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001003cl::NDRange CLKernelLibrary::default_ndrange() const
steniu015f910722017-08-23 10:15:22 +01001004{
Anthony Barbierb6eb3532018-08-08 13:20:04 +01001005 GPUTarget _target = get_target_from_device(_device);
Michalis Spyroua9676112018-02-22 18:07:43 +00001006 cl::NDRange default_range;
1007
1008 switch(_target)
1009 {
1010 case GPUTarget::MIDGARD:
1011 case GPUTarget::T600:
1012 case GPUTarget::T700:
1013 case GPUTarget::T800:
1014 default_range = cl::NDRange(128u, 1);
1015 break;
1016 default:
1017 default_range = cl::NullRange;
1018 }
1019
1020 return default_range;
steniu015f910722017-08-23 10:15:22 +01001021}
Anthony Barbier847864d2018-03-07 11:35:53 +00001022
1023std::string CLKernelLibrary::get_device_version()
1024{
1025 return _device.getInfo<CL_DEVICE_VERSION>();
1026}