blob: 7e8ef6b22de595f9cdfc9e49b92866c2c07fd659 [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" },
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100155 { "arithmetic_sub_quantized", "arithmetic_op_quantized.cl" },
Michalis Spyrou0a887922018-06-11 16:30:23 +0100156 { "arithmetic_div", "arithmetic_op.cl" },
Michalis Spyrouf1addb62018-09-11 11:16:47 +0100157 { "batch_to_space_nchw", "batch_to_space.cl" },
158 { "batch_to_space_static_nchw", "batch_to_space.cl" },
159 { "batch_to_space_nhwc", "batch_to_space.cl" },
160 { "batch_to_space_static_nhwc", "batch_to_space.cl" },
Michele Di Giorgiobf3c6622018-03-08 11:52:27 +0000161 { "batchnormalization_layer_nchw", "batchnormalization_layer.cl" },
162 { "batchnormalization_layer_nhwc", "batchnormalization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100163 { "bitwise_or", "bitwise_op.cl" },
164 { "bitwise_and", "bitwise_op.cl" },
165 { "bitwise_xor", "bitwise_op.cl" },
166 { "bitwise_not", "bitwise_op.cl" },
167 { "channel_combine_NV", "channel_combine.cl" },
168 { "channel_combine_RGB888", "channel_combine.cl" },
169 { "channel_combine_RGBA8888", "channel_combine.cl" },
170 { "channel_combine_UYVY422", "channel_combine.cl" },
171 { "channel_combine_YUYV422", "channel_combine.cl" },
Michele Di Giorgio72175632018-05-01 16:52:00 +0100172 { "channel_shuffle_nchw", "channel_shuffle.cl" },
Gian Marco Iodice8bab0ee2018-09-13 11:51:56 +0100173 { "channel_shuffle_nhwc", "channel_shuffle.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100174 { "channel_extract_NV12", "channel_extract.cl" },
175 { "channel_extract_NV21", "channel_extract.cl" },
176 { "channel_extract_RGB888", "channel_extract.cl" },
177 { "channel_extract_RGBA8888", "channel_extract.cl" },
178 { "channel_extract_UYVY422", "channel_extract.cl" },
179 { "channel_extract_YUYV422", "channel_extract.cl" },
180 { "combine_gradients_L1", "canny.cl" },
181 { "combine_gradients_L2", "canny.cl" },
182 { "concatenate_depth", "concatenate.cl" },
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100183 { "concatenate_width", "concatenate.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100184 { "convolution_rectangle", "convolution_rectangle.cl" },
Gian Marco76faef82018-01-29 12:15:32 +0000185 { "col2im", "col2im.cl" },
Giorgio Arena657bdb32018-04-26 18:52:01 +0100186 { "convert_depth_down", "depth_convert.cl" },
187 { "convert_depth_up", "depth_convert.cl" },
188 { "convert_fc_weights", "convert_fc_weights.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189 { "convolution3x3_static", "convolution3x3.cl" },
190 { "convolution5x5_static", "convolution5x5.cl" },
191 { "convolution7x7_static", "convolution7x7.cl" },
192 { "convolution9x9_static", "convolution9x9.cl" },
193 { "convolution_separable1x5_static", "convolution5x5.cl" },
194 { "convolution_separable5x1_static", "convolution5x5.cl" },
195 { "convolution_separable1x7_static", "convolution7x7.cl" },
196 { "convolution_separable7x1_static", "convolution7x7.cl" },
197 { "convolution_separable1x9_static", "convolution9x9.cl" },
198 { "convolution_separable9x1_static", "convolution9x9.cl" },
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000199 { "copy_tensor", "copy_tensor.cl" },
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100200 { "copy_pad_tensor", "copy_tensor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100201 { "copy_plane", "channel_extract.cl" },
202 { "copy_planes_3p", "channel_combine.cl" },
203 { "copy_to_keypoint", "fast_corners.cl" },
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000204 { "deconvolution_upsample", "deconvolution_layer.cl" },
Giorgio Arena93a690e2017-08-01 16:09:33 +0100205 { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
Michele Di Giorgio933fe862018-02-19 15:42:12 +0000206 { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
Giorgio Arenad051e972018-06-20 11:46:42 +0100207 { "depthwise_convolution_3x3_nhwc", "depthwise_convolution.cl" },
208 { "depthwise_convolution_3x3_nhwc_stride1", "depthwise_convolution.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000209 { "depthwise_convolution_3x3_quantized_nchw", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100210 { "depthwise_convolution_3x3_quantized_nhwc", "depthwise_convolution_quantized.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000211 { "depthwise_convolution_3x3_quantized_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100212 { "depthwise_convolution_3x3_quantized_dot8_nchw", "depthwise_convolution_quantized.cl" },
213 { "depthwise_convolution_3x3_quantized_dot8_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Michele Di Giorgio3ebef322018-02-21 10:02:58 +0000214 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16", "depthwise_convolution.cl" },
215 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16", "depthwise_convolution.cl" },
216 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32", "depthwise_convolution.cl" },
217 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32", "depthwise_convolution.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100218 { "depthwise_im2col", "depthwise_convolution.cl" },
219 { "depthwise_vector_to_tensor", "depthwise_convolution.cl" },
220 { "depthwise_weights_reshape", "depthwise_convolution.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100221 { "dequantization_layer", "dequantization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100222 { "derivative", "derivative.cl" },
223 { "dilate", "dilate.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100224 { "direct_convolution1x1", "direct_convolution1x1.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100225 { "direct_convolution1x1_nhwc", "direct_convolution1x1.cl" },
Gian Marco Iodice1c8409d2017-09-06 17:24:25 +0100226 { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100227 { "direct_convolution3x3", "direct_convolution3x3.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100228 { "direct_convolution3x3_nhwc", "direct_convolution3x3.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100229 { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
steniu01db006682017-08-09 16:26:22 +0100230 { "direct_convolution5x5", "direct_convolution5x5.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100231 { "direct_convolution5x5_nhwc", "direct_convolution5x5.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100232 { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
Chunosovd621bca2017-11-03 17:33:15 +0700233 { "direct_convolution_1x1_3x3_5x5_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100234 { "erode", "erode.cl" },
235 { "fast_corners", "fast_corners.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100236 { "flatten", "flatten.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100237 { "fill_image_borders_constant", "fill_border.cl" },
238 { "fill_image_borders_replicate", "fill_border.cl" },
239 { "finalize", "optical_flow_pyramid_lk.cl" },
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100240 { "floor_layer", "floor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100241 { "gaussian1x5_sub_x", "gaussian_pyramid.cl" },
242 { "gaussian5x1_sub_y", "gaussian_pyramid.cl" },
Gian Marco Iodice578ab612017-06-23 09:34:33 +0100243 { "gemm_accumulate_biases", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000244 { "gemm_interleave4x4", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100245 { "gemm_ma_f16", "gemm.cl" },
246 { "gemm_ma_f32", "gemm.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100247 { "gemm_mv", "gemv.cl" },
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +0000248 { "gemm_mv_quantized", "gemv.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100249 { "gemm_mm_interleaved_transposed_f16", "gemm.cl" },
Gian Marco Iodicebb36a8e2018-04-19 12:05:08 +0100250 { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm.cl" },
251 { "gemm_mm_interleaved_transposed_f32", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100252 { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100253 { "gemm_mm_floating_point", "gemm.cl" },
Gian Marco Iodicefd683112018-04-17 09:52:44 +0100254 { "gemm_mm_floating_point_f16_bifrost", "gemm.cl" },
Anton Lokhmotov3e80c7f2017-11-20 11:02:10 +0000255 { "gemm_mm_floating_point_f32_bifrost", "gemm.cl" },
256 { "gemm_mm_floating_point_f32_bifrost_1000", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100257 { "gemm_lc_vm_f32", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000258 { "gemm_transpose1xW", "gemm.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000259 { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
260 { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000261 { "gemmlowp_mm_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100262 { "gemmlowp_mm_bifrost_dot8", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000263 { "gemmlowp_mm_midgard", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000264 { "gemmlowp_mm_interleaved_transposed_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100265 { "gemmlowp_mm_interleaved_transposed_bifrost_dot8", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000266 { "gemmlowp_mm_interleaved_transposed_midgard", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000267 { "gemmlowp_offset_contribution", "gemmlowp.cl" },
268 { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
Gian Marco58c57942017-11-28 09:10:03 +0000269 { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100270 { "harris_score_3x3", "harris_corners.cl" },
271 { "harris_score_5x5", "harris_corners.cl" },
272 { "harris_score_7x7", "harris_corners.cl" },
273 { "hist_border_kernel", "histogram.cl" },
274 { "hist_border_kernel_fixed", "histogram.cl" },
275 { "hist_local_kernel", "histogram.cl" },
276 { "hist_local_kernel_fixed", "histogram.cl" },
277 { "hog_block_normalization", "hog.cl" },
278 { "hog_detector", "hog.cl" },
279 { "hog_orientation_binning", "hog.cl" },
280 { "hysteresis", "canny.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100281 { "im2col1x1_stridex1_nchw", "im2col.cl" },
282 { "im2col3x3_nchw", "im2col.cl" },
283 { "im2col5x5_nchw", "im2col.cl" },
284 { "im2col11x11_padx0_pady0_nchw", "im2col.cl" },
285 { "im2col_generic_nchw", "im2col.cl" },
286 { "im2col_generic_padx0_pady0_nchw", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100287 { "im2col3x3_nhwc", "im2col.cl" },
288 { "im2col_generic_nhwc", "im2col.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100289 { "init_level", "optical_flow_pyramid_lk.cl" },
290 { "init_level_max", "optical_flow_pyramid_lk.cl" },
291 { "init_level_max_initial_estimate", "optical_flow_pyramid_lk.cl" },
292 { "integral_horizontal", "integral_image.cl" },
293 { "integral_vertical", "integral_image.cl" },
294 { "IYUV_to_NV12_bt709", "color_convert.cl" },
295 { "IYUV_to_RGB888_bt709", "color_convert.cl" },
296 { "IYUV_to_RGBA8888_bt709", "color_convert.cl" },
297 { "IYUV_to_YUV444_bt709", "color_convert.cl" },
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100298 { "l2_normalize", "l2_normalize.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100299 { "lktracker_stage0", "optical_flow_pyramid_lk.cl" },
300 { "lktracker_stage1", "optical_flow_pyramid_lk.cl" },
301 { "magnitude_phase", "magnitude_phase.cl" },
302 { "mean_stddev_accumulate", "mean_stddev.cl" },
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100303 { "memset", "memset.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100304 { "minmax", "minmaxloc.cl" },
305 { "minmax_border", "minmaxloc.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100306 { "minmax_layer", "minmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100307 { "minmaxloc", "minmaxloc.cl" },
308 { "non_linear_filter_box3x3", "non_linear_filter3x3.cl" },
309 { "non_linear_filter_cross3x3", "non_linear_filter3x3.cl" },
310 { "non_linear_filter_disk3x3", "non_linear_filter3x3.cl" },
311 { "non_linear_filter_box5x5", "non_linear_filter5x5.cl" },
312 { "non_linear_filter_cross5x5", "non_linear_filter5x5.cl" },
313 { "non_linear_filter_disk5x5", "non_linear_filter5x5.cl" },
314 { "non_max_suppression", "nonmax.cl" },
315 { "normalization_layer_cross_map", "normalization_layer.cl" },
Georgios Pinitas01624362017-11-30 10:53:31 +0000316 { "normalization_layer_in_map", "normalization_layer.cl" },
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100317 { "normalize_planar_yuv_layer_nchw", "normalize_planar_yuv_layer.cl" },
318 { "normalize_planar_yuv_layer_nhwc", "normalize_planar_yuv_layer.cl" },
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100319 { "normalize_planar_yuv_layer_q8_nchw", "normalize_planar_yuv_layer_quantized.cl" },
320 { "normalize_planar_yuv_layer_q8_nhwc", "normalize_planar_yuv_layer_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100321 { "NV12_to_IYUV_bt709", "color_convert.cl" },
322 { "NV12_to_RGB888_bt709", "color_convert.cl" },
323 { "NV12_to_RGBA8888_bt709", "color_convert.cl" },
324 { "NV12_to_YUV444_bt709", "color_convert.cl" },
325 { "NV21_to_IYUV_bt709", "color_convert.cl" },
326 { "NV21_to_RGB888_bt709", "color_convert.cl" },
327 { "NV21_to_RGBA8888_bt709", "color_convert.cl" },
328 { "NV21_to_YUV444_bt709", "color_convert.cl" },
Giorgio Arenaa086a0a2018-02-16 12:42:16 +0000329 { "output_stage_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Michalis Spyrou5237e012018-01-17 09:40:27 +0000330 { "permute_201", "permute.cl" },
331 { "permute_120", "permute.cl" },
332 { "permute_3201", "permute.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100333 { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
334 { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100335 { "pixelwise_mul_quantized", "pixelwise_mul_int.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100336 { "pooling_layer_2", "pooling_layer.cl" },
337 { "pooling_layer_3", "pooling_layer.cl" },
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000338 { "pooling_layer_optimized_3", "pooling_layer.cl" },
Georgios Pinitasce093142017-06-19 16:11:53 +0100339 { "pooling_layer_7", "pooling_layer.cl" },
Michalis Spyroue74b2012018-04-18 09:49:16 +0100340 { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
341 { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
342 { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
343 { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100344 { "quantization_layer", "quantization_layer.cl" },
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100345 { "reduction_operation", "reduction_operation.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100346 { "remap_nearest_neighbour", "remap.cl" },
347 { "remap_bilinear", "remap.cl" },
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100348 { "reorg_layer_nchw", "reorg_layer.cl" },
349 { "reorg_layer_nhwc", "reorg_layer.cl" },
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100350 { "reshape_layer", "reshape_layer.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100351 { "reshape_to_columns", "convolution_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100352 { "RGB888_to_IYUV_bt709", "color_convert.cl" },
353 { "RGB888_to_NV12_bt709", "color_convert.cl" },
354 { "RGB888_to_RGBA8888_bt709", "color_convert.cl" },
355 { "RGB888_to_YUV444_bt709", "color_convert.cl" },
356 { "RGBA8888_to_IYUV_bt709", "color_convert.cl" },
357 { "RGBA8888_to_NV12_bt709", "color_convert.cl" },
358 { "RGBA8888_to_RGB888_bt709", "color_convert.cl" },
359 { "RGBA8888_to_YUV444_bt709", "color_convert.cl" },
SiCong Li3e363692017-07-04 15:02:10 +0100360 { "roi_pooling_layer", "roi_pooling_layer.cl" },
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100361 { "scale_nearest_neighbour_nchw", "scale.cl" },
362 { "scale_nearest_neighbour_nhwc", "scale.cl" },
363 { "scale_bilinear_nchw", "scale.cl" },
364 { "scale_bilinear_nhwc", "scale.cl" },
Michalis Spyrou17220e22018-09-12 13:35:38 +0100365 { "scale_bilinear_quantized_nchw", "scale_quantized.cl" },
366 { "scale_bilinear_quantized_nhwc", "scale_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100367 { "scharr3x3", "scharr_filter.cl" },
368 { "sobel3x3", "sobel_filter.cl" },
369 { "sobel_separable5x1", "sobel_filter.cl" },
370 { "sobel_separable1x5", "sobel_filter.cl" },
371 { "sobel_separable7x1", "sobel_filter.cl" },
372 { "sobel_separable1x7", "sobel_filter.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100373 { "softmax_layer_norm", "softmax_layer.cl" },
Chunosovf450caa2017-11-08 16:09:35 +0700374 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
Giorgio Arena4402cb92018-02-15 13:37:40 +0000375 { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
376 { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700377 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100378 { "space_to_batch_nchw", "space_to_batch.cl" },
379 { "space_to_batch_static_nchw", "space_to_batch.cl" },
380 { "space_to_batch_nhwc", "space_to_batch.cl" },
381 { "space_to_batch_static_nhwc", "space_to_batch.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700382 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100383 { "strided_slice", "slice_ops.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100384 { "suppress_non_maximum", "canny.cl" },
385 { "tablelookup_U8", "tablelookup.cl" },
386 { "tablelookup_S16", "tablelookup.cl" },
387 { "threshold_binary", "threshold.cl" },
388 { "threshold_range", "threshold.cl" },
389 { "transpose", "transpose.cl" },
390 { "UYVY422_to_IYUV_bt709", "color_convert.cl" },
391 { "UYVY422_to_NV12_bt709", "color_convert.cl" },
392 { "UYVY422_to_RGB888_bt709", "color_convert.cl" },
393 { "UYVY422_to_RGBA8888_bt709", "color_convert.cl" },
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100394 { "upsample_layer_nchw", "upsample_layer.cl" },
395 { "upsample_layer_nhwc", "upsample_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100396 { "warp_affine_nearest_neighbour", "warp_affine.cl" },
397 { "warp_affine_bilinear", "warp_affine.cl" },
398 { "warp_perspective_nearest_neighbour", "warp_perspective.cl" },
399 { "warp_perspective_bilinear", "warp_perspective.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100400 { "winograd_filter_transform_2x2_3x3_nchw", "winograd_filter_transform.cl" },
401 { "winograd_filter_transform_2x1_3x1_nchw", "winograd_filter_transform.cl" },
402 { "winograd_filter_transform_1x2_1x3_nchw", "winograd_filter_transform.cl" },
403 { "winograd_filter_transform_4x4_3x3_nchw", "winograd_filter_transform.cl" },
404 { "winograd_filter_transform_4x1_3x1_nchw", "winograd_filter_transform.cl" },
405 { "winograd_filter_transform_1x4_1x3_nchw", "winograd_filter_transform.cl" },
406 { "winograd_filter_transform_4x4_5x5_nchw", "winograd_filter_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100407 { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
408 { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100409 { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
410 { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100411 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
412 { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100413 { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
414 { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100415 { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd_input_transform.cl" },
416 { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd_input_transform.cl" },
417 { "winograd_input_transform_2x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
418 { "winograd_input_transform_2x1_3x1_stepz2_nchw", "winograd_input_transform.cl" },
419 { "winograd_input_transform_1x2_1x3_stepz1_nchw", "winograd_input_transform.cl" },
420 { "winograd_input_transform_1x2_1x3_stepz2_nchw", "winograd_input_transform.cl" },
421 { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd_input_transform.cl" },
422 { "winograd_input_transform_4x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
423 { "winograd_input_transform_1x4_1x3_stepz1_nchw", "winograd_input_transform.cl" },
424 { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd_input_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100425 { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
426 { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100427 { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
428 { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100429 { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
430 { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100431 { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
432 { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100433 { "winograd_output_transform_2x2_3x3_nchw", "winograd_output_transform.cl" },
434 { "winograd_output_transform_2x1_3x1_nchw", "winograd_output_transform.cl" },
435 { "winograd_output_transform_1x2_1x3_nchw", "winograd_output_transform.cl" },
436 { "winograd_output_transform_4x4_3x3_nchw", "winograd_output_transform.cl" },
437 { "winograd_output_transform_4x1_3x1_nchw", "winograd_output_transform.cl" },
438 { "winograd_output_transform_1x4_1x3_nchw", "winograd_output_transform.cl" },
439 { "winograd_output_transform_4x4_5x5_nchw", "winograd_output_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100440 { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
441 { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100442 { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
443 { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100444 { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
445 { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100446 { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
447 { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
Giorgio Arena73023022018-09-04 14:55:55 +0100448 { "yolo_layer_nchw", "yolo_layer.cl" },
449 { "yolo_layer_nhwc", "yolo_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100450 { "YUYV422_to_IYUV_bt709", "color_convert.cl" },
451 { "YUYV422_to_NV12_bt709", "color_convert.cl" },
452 { "YUYV422_to_RGB888_bt709", "color_convert.cl" },
453 { "YUYV422_to_RGBA8888_bt709", "color_convert.cl" },
454};
455
456const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
457{
458#ifdef EMBEDDED_KERNELS
459 {
460 "absdiff.cl",
461#include "./cl_kernels/absdiff.clembed"
462 },
463 {
464 "accumulate.cl",
465#include "./cl_kernels/accumulate.clembed"
466 },
467 {
468 "activation_layer.cl",
469#include "./cl_kernels/activation_layer.clembed"
470 },
471 {
Michel Iwaniec00633802017-10-12 14:14:15 +0100472 "activation_layer_qa8.cl",
473#include "./cl_kernels/activation_layer_qa8.clembed"
474 },
475 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100476 "arithmetic_op.cl",
477#include "./cl_kernels/arithmetic_op.clembed"
478 },
479 {
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100480 "arithmetic_op_quantized.cl",
481#include "./cl_kernels/arithmetic_op_quantized.clembed"
482 },
483 {
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100484 "batch_to_space.cl",
485#include "./cl_kernels/batch_to_space.clembed"
486 },
487 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100488 "bitwise_op.cl",
489#include "./cl_kernels/bitwise_op.clembed"
490 },
491 {
492 "canny.cl",
493#include "./cl_kernels/canny.clembed"
494 },
495 {
496 "channel_combine.cl",
497#include "./cl_kernels/channel_combine.clembed"
498 },
499 {
500 "channel_extract.cl",
501#include "./cl_kernels/channel_extract.clembed"
502 },
503 {
Michele Di Giorgio72175632018-05-01 16:52:00 +0100504 "channel_shuffle.cl",
505#include "./cl_kernels/channel_shuffle.clembed"
506 },
507 {
Gian Marco76faef82018-01-29 12:15:32 +0000508 "col2im.cl",
509#include "./cl_kernels/col2im.clembed"
510 },
511 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100512 "concatenate.cl",
513#include "./cl_kernels/concatenate.clembed"
514 },
515 {
516 "color_convert.cl",
517#include "./cl_kernels/color_convert.clembed"
518 },
519 {
Giorgio Arena657bdb32018-04-26 18:52:01 +0100520 "convert_fc_weights.cl",
521#include "./cl_kernels/convert_fc_weights.clembed"
522 },
523 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100524 "convolution3x3.cl",
525#include "./cl_kernels/convolution3x3.clembed"
526 },
527 {
528 "convolution5x5.cl",
529#include "./cl_kernels/convolution5x5.clembed"
530 },
531 {
532 "convolution7x7.cl",
533#include "./cl_kernels/convolution7x7.clembed"
534 },
535 {
536 "convolution9x9.cl",
537#include "./cl_kernels/convolution9x9.clembed"
538 },
539 {
540 "convolution_layer.cl",
541#include "./cl_kernels/convolution_layer.clembed"
542 },
543 {
544 "convolution_rectangle.cl",
545#include "./cl_kernels/convolution_rectangle.clembed"
546 },
547 {
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000548 "copy_tensor.cl",
549#include "./cl_kernels/copy_tensor.clembed"
550 },
551 {
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100552 "upsample_layer.cl",
553#include "./cl_kernels/upsample_layer.clembed"
554 },
555 {
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000556 "deconvolution_layer.cl",
557#include "./cl_kernels/deconvolution_layer.clembed"
558 },
559 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100560 "depth_convert.cl",
561#include "./cl_kernels/depth_convert.clembed"
562 },
563 {
Giorgio Arena93a690e2017-08-01 16:09:33 +0100564 "depthwise_convolution.cl",
565#include "./cl_kernels/depthwise_convolution.clembed"
566 },
567 {
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700568 "depthwise_convolution_quantized.cl",
569#include "./cl_kernels/depthwise_convolution_quantized.clembed"
570 },
571 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100572 "dequantization_layer.cl",
573#include "./cl_kernels/dequantization_layer.clembed"
574 },
575 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100576 "derivative.cl",
577#include "./cl_kernels/derivative.clembed"
578 },
579 {
580 "dilate.cl",
581#include "./cl_kernels/dilate.clembed"
582 },
583 {
SiCong Lic51b72f2017-07-28 14:46:20 +0100584 "direct_convolution1x1.cl",
585#include "./cl_kernels/direct_convolution1x1.clembed"
586 },
587 {
588 "direct_convolution3x3.cl",
589#include "./cl_kernels/direct_convolution3x3.clembed"
steniu0127b386c2017-07-18 17:37:43 +0100590 },
591 {
steniu01db006682017-08-09 16:26:22 +0100592 "direct_convolution5x5.cl",
593#include "./cl_kernels/direct_convolution5x5.clembed"
594 },
595 {
Chunosovd621bca2017-11-03 17:33:15 +0700596 "direct_convolution_1x1_3x3_5x5_quantized.cl",
597#include "./cl_kernels/direct_convolution_1x1_3x3_5x5_quantized.clembed"
598 },
599 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100600 "erode.cl",
601#include "./cl_kernels/erode.clembed"
602 },
603 {
604 "fast_corners.cl",
605#include "./cl_kernels/fast_corners.clembed"
606 },
607 {
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100608 "flatten.cl",
609#include "./cl_kernels/flatten.clembed"
610 },
611 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100612 "fill_border.cl",
613#include "./cl_kernels/fill_border.clembed"
614 },
615 {
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100616 "floor.cl",
617#include "./cl_kernels/floor.clembed"
618 },
619 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100620 "gaussian_pyramid.cl",
621#include "./cl_kernels/gaussian_pyramid.clembed"
622 },
623 {
624 "gemm.cl",
625#include "./cl_kernels/gemm.clembed"
626 },
627 {
Gian Marco05288a22017-11-21 10:57:50 +0000628 "gemmlowp.cl",
629#include "./cl_kernels/gemmlowp.clembed"
630 },
631 {
Giorgio Arena9fe41442017-08-23 16:36:24 +0100632 "gemv.cl",
633#include "./cl_kernels/gemv.clembed"
634 },
635 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100636 "harris_corners.cl",
637#include "./cl_kernels/harris_corners.clembed"
638 },
639 {
640 "helpers.h",
641#include "./cl_kernels/helpers.hembed"
642 },
643 {
Chunosovd621bca2017-11-03 17:33:15 +0700644 "helpers_asymm.h",
645#include "./cl_kernels/helpers_asymm.hembed"
646 },
647 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100648 "histogram.cl",
649#include "./cl_kernels/histogram.clembed"
650 },
651 {
652 "hog.cl",
653#include "./cl_kernels/hog.clembed"
654 },
655 {
Gian Marco76faef82018-01-29 12:15:32 +0000656 "im2col.cl",
657#include "./cl_kernels/im2col.clembed"
658 },
659 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100660 "integral_image.cl",
661#include "./cl_kernels/integral_image.clembed"
662 },
663 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100664 "l2_normalize.cl",
665#include "./cl_kernels/l2_normalize.clembed"
666 },
667 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100668 "magnitude_phase.cl",
669#include "./cl_kernels/magnitude_phase.clembed"
670 },
671 {
672 "mean_stddev.cl",
673#include "./cl_kernels/mean_stddev.clembed"
674 },
675 {
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100676 "memset.cl",
677#include "./cl_kernels/memset.clembed"
678 },
679 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100680 "minmaxloc.cl",
681#include "./cl_kernels/minmaxloc.clembed"
682 },
683 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100684 "minmax_layer.cl",
685#include "./cl_kernels/minmax_layer.clembed"
686 },
687 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100688 "non_linear_filter3x3.cl",
689#include "./cl_kernels/non_linear_filter3x3.clembed"
690 },
691 {
692 "non_linear_filter5x5.cl",
693#include "./cl_kernels/non_linear_filter5x5.clembed"
694 },
695 {
696 "non_linear_filter_helpers.h",
697#include "./cl_kernels/non_linear_filter_helpers.hembed"
698 },
699 {
700 "nonmax.cl",
701#include "./cl_kernels/nonmax.clembed"
702 },
703 {
704 "normalization_layer.cl",
705#include "./cl_kernels/normalization_layer.clembed"
706 },
707 {
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100708 "normalize_planar_yuv_layer.cl",
709#include "./cl_kernels/normalize_planar_yuv_layer.clembed"
710 },
711 {
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100712 "normalize_planar_yuv_layer_quantized.cl",
713#include "./cl_kernels/normalize_planar_yuv_layer_quantized.clembed"
714 },
715 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100716 "batchnormalization_layer.cl",
717#include "./cl_kernels/batchnormalization_layer.clembed"
718 },
719 {
720 "optical_flow_pyramid_lk.cl",
721#include "./cl_kernels/optical_flow_pyramid_lk.clembed"
722 },
723 {
Michalis Spyrou5237e012018-01-17 09:40:27 +0000724 "permute.cl",
725#include "./cl_kernels/permute.clembed"
726 },
727 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100728 "pixelwise_mul_float.cl",
729#include "./cl_kernels/pixelwise_mul_float.clembed"
730 },
731 {
732 "pixelwise_mul_int.cl",
733#include "./cl_kernels/pixelwise_mul_int.clembed"
734 },
735 {
736 "pooling_layer.cl",
737#include "./cl_kernels/pooling_layer.clembed"
738 },
739 {
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000740 "pooling_layer_quantized.cl",
741#include "./cl_kernels/pooling_layer_quantized.clembed"
742 },
743 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100744 "quantization_layer.cl",
745#include "./cl_kernels/quantization_layer.clembed"
746 },
747 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100748 "reduction_operation.cl",
749#include "./cl_kernels/reduction_operation.clembed"
750 },
751 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100752 "remap.cl",
753#include "./cl_kernels/remap.clembed"
754 },
755 {
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100756 "reorg_layer.cl",
757#include "./cl_kernels/reorg_layer.clembed"
758 },
759 {
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100760 "reshape_layer.cl",
761#include "./cl_kernels/reshape_layer.clembed"
762 },
763 {
SiCong Li3e363692017-07-04 15:02:10 +0100764 "roi_pooling_layer.cl",
765#include "./cl_kernels/roi_pooling_layer.clembed"
766 },
767 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100768 "scale.cl",
769#include "./cl_kernels/scale.clembed"
770 },
771 {
Michalis Spyrou17220e22018-09-12 13:35:38 +0100772 "scale_quantized.cl",
773#include "./cl_kernels/scale_quantized.clembed"
774 },
775 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100776 "scharr_filter.cl",
777#include "./cl_kernels/scharr_filter.clembed"
778 },
779 {
780 "sobel_filter.cl",
781#include "./cl_kernels/sobel_filter.clembed"
782 },
783 {
784 "softmax_layer.cl",
785#include "./cl_kernels/softmax_layer.clembed"
786 },
787 {
Chunosovf450caa2017-11-08 16:09:35 +0700788 "softmax_layer_quantized.cl",
789#include "./cl_kernels/softmax_layer_quantized.clembed"
790 },
791 {
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100792 "slice_ops.cl",
793#include "./cl_kernels/slice_ops.clembed"
Georgios Pinitas77589b52018-08-21 14:41:35 +0100794 },
795 {
Michalis Spyrou16934a52018-08-21 18:03:58 +0100796 "space_to_batch.cl",
797#include "./cl_kernels/space_to_batch.clembed"
798 },
799 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100800 "tablelookup.cl",
801#include "./cl_kernels/tablelookup.clembed"
802 },
803 {
804 "threshold.cl",
805#include "./cl_kernels/threshold.clembed"
806 },
807 {
808 "transpose.cl",
809#include "./cl_kernels/transpose.clembed"
810 },
811 {
812 "types.h",
813#include "./cl_kernels/types.hembed"
814 },
815 {
816 "warp_affine.cl",
817#include "./cl_kernels/warp_affine.clembed"
818 },
819 {
820 "warp_helpers.h",
821#include "./cl_kernels/warp_helpers.hembed"
822 },
823 {
824 "warp_perspective.cl",
825#include "./cl_kernels/warp_perspective.clembed"
Michalis Spyroud7e82812017-06-20 15:00:14 +0100826 },
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000827 {
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100828 "winograd_filter_transform.cl",
829#include "./cl_kernels/winograd_filter_transform.clembed"
830 },
831 {
832 "winograd_input_transform.cl",
833#include "./cl_kernels/winograd_input_transform.clembed"
834 },
835 {
836 "winograd_output_transform.cl",
837#include "./cl_kernels/winograd_output_transform.clembed"
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000838 },
Giorgio Arena73023022018-09-04 14:55:55 +0100839 {
840 "yolo_layer.cl",
841#include "./cl_kernels/yolo_layer.clembed"
842 },
Anthony Barbierac69aa12017-07-03 17:39:37 +0100843#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100844};
845
846CLKernelLibrary::CLKernelLibrary()
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100847 : _context(), _device(), _kernel_path("."), _programs_map(), _built_programs_map()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100848{
Anthony Barbierecb1c622018-04-17 11:45:10 +0100849 opencl_is_available(); // Make sure the OpenCL symbols are initialised *before* the CLKernelLibrary is built
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100850}
851
852CLKernelLibrary &CLKernelLibrary::get()
853{
854 static CLKernelLibrary _kernel_library;
855 return _kernel_library;
856}
857
858Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const StringSet &build_options_set) const
859{
860 // Find which program contains the kernel
861 auto kernel_program_it = _kernel_program_map.find(kernel_name);
862
863 if(_kernel_program_map.end() == kernel_program_it)
864 {
865 ARM_COMPUTE_ERROR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
866 }
steniu0134702472017-07-11 09:22:58 +0100867 std::string concat_str;
868
Georgios Pinitasdf473ea2018-05-31 18:53:52 +0100869#if defined(ARM_COMPUTE_DEBUG_ENABLED)
870 // Enable debug properties in CL kernels
871 concat_str += " -DARM_COMPUTE_DEBUG_ENABLED";
872#endif // defined(ARM_COMPUTE_DEBUG_ENABLED)
873
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100874 if(fp16_supported())
Matthew Bentham6f31f8c2017-10-27 11:50:06 +0100875 {
876 concat_str += " -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 ";
877 }
878
Michalis Spyroue03342e2018-01-15 14:39:13 +0000879 if(dot8_supported(_device))
880 {
881 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ENABLED=1 ";
882 }
883
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100884 if(dot8_acc_supported(_device))
885 {
886 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED=1 ";
887 }
888
Pablo Telloe86a09f2018-01-11 15:44:48 +0000889 if(get_cl_version(_device) == CLVersion::CL20)
steniu0134702472017-07-11 09:22:58 +0100890 {
891 concat_str += " -cl-std=CL2.0 ";
892 }
Anthony Barbierd727e852018-04-20 11:05:29 +0100893 else if(arm_non_uniform_workgroup_supported(_device))
Pablo Telloe86a09f2018-01-11 15:44:48 +0000894 {
895 concat_str += " -cl-arm-non-uniform-work-group-size ";
896 }
steniu0134702472017-07-11 09:22:58 +0100897 else
898 {
899 ARM_COMPUTE_ERROR("Non uniform workgroup size is not supported!!");
900 }
901
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100902 // Check if the program has been built before with same build options.
steniu0134702472017-07-11 09:22:58 +0100903 const std::string program_name = kernel_program_it->second;
904 const std::string build_options = stringify_set(build_options_set) + concat_str;
905
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100906 const std::string built_program_name = program_name + "_" + build_options;
907 auto built_program_it = _built_programs_map.find(built_program_name);
908
909 cl::Program cl_program;
910
911 if(_built_programs_map.end() != built_program_it)
912 {
913 // If program has been built, retrieve to create kernel from it
914 cl_program = built_program_it->second;
915 }
916 else
917 {
918 // Get program
919 Program program = load_program(program_name);
920
921 // Build program
922 cl_program = program.build(build_options);
923
924 // Add built program to internal map
925 _built_programs_map.emplace(built_program_name, cl_program);
926 }
927
928 // Create and return kernel
929 return Kernel(kernel_name, cl_program);
930}
931
Anthony Barbier7da55aa2018-04-13 16:58:43 +0100932void CLKernelLibrary::add_built_program(const std::string &built_program_name, cl::Program program)
933{
934 _built_programs_map.emplace(built_program_name, program);
935}
936
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100937bool CLKernelLibrary::fp16_supported() const
938{
939 return ::fp16_supported(_device);
940}
941
Vidhya Sudhan Loganathan76c85642018-05-25 13:53:02 +0100942bool CLKernelLibrary::int64_base_atomics_supported() const
943{
944 return device_supports_extension(_device, "cl_khr_int64_base_atomics");
945}
946
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100947const Program &CLKernelLibrary::load_program(const std::string &program_name) const
948{
949 const auto program_it = _programs_map.find(program_name);
950
951 if(program_it != _programs_map.end())
952 {
953 return program_it->second;
954 }
955
956 Program program;
957
958#ifdef EMBEDDED_KERNELS
959 const auto program_source_it = _program_source_map.find(program_name);
960
961 if(_program_source_map.end() == program_source_it)
962 {
963 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
964 }
965
966 program = Program(_context, program_name, program_source_it->second);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100967#else /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100968 // Check for binary
969 std::string source_name = _kernel_path + program_name;
970 std::string binary_name = source_name + "bin";
971
972 if(std::ifstream(binary_name).is_open())
973 {
974 const std::string program_binary = read_file(binary_name, true);
975 program = Program(_context, _device, program_name, std::vector<unsigned char>(program_binary.begin(), program_binary.end()));
976 }
977 else if(std::ifstream(source_name).is_open())
978 {
979 program = Program(_context, program_name, read_file(source_name, false));
980 }
981 else
982 {
983 ARM_COMPUTE_ERROR("Kernel file %s does not exist.", source_name.c_str());
984 }
Anthony Barbierac69aa12017-07-03 17:39:37 +0100985#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100986
987 // Insert program to program map
988 const auto new_program = _programs_map.emplace(program_name, std::move(program));
989
990 return new_program.first->second;
991}
992
993std::string CLKernelLibrary::stringify_set(const StringSet &s) const
994{
steniu0134702472017-07-11 09:22:58 +0100995 std::string concat_set;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100996
997#ifndef EMBEDDED_KERNELS
998 concat_set += "-I" + _kernel_path + " ";
999#endif /* EMBEDDED_KERNELS */
1000
1001 // Concatenate set
1002 for(const auto &el : s)
1003 {
1004 concat_set += " " + el;
1005 }
1006
1007 return concat_set;
1008}
Michalis Spyroud7e82812017-06-20 15:00:14 +01001009
1010std::string CLKernelLibrary::get_program_source(const std::string &program_name)
1011{
1012 const auto program_source_it = _program_source_map.find(program_name);
1013
1014 if(program_source_it == _program_source_map.end())
1015 {
1016 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
1017 }
1018
1019 return program_source_it->second;
1020}
steniu015f910722017-08-23 10:15:22 +01001021
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001022size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const
steniu015f910722017-08-23 10:15:22 +01001023{
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001024 size_t result;
steniu015f910722017-08-23 10:15:22 +01001025
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001026 size_t err = kernel.getWorkGroupInfo(_device, CL_KERNEL_WORK_GROUP_SIZE, &result);
1027 ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel");
1028 ARM_COMPUTE_UNUSED(err);
1029
1030 return result;
steniu015f910722017-08-23 10:15:22 +01001031}
1032
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001033cl::NDRange CLKernelLibrary::default_ndrange() const
steniu015f910722017-08-23 10:15:22 +01001034{
Anthony Barbierb6eb3532018-08-08 13:20:04 +01001035 GPUTarget _target = get_target_from_device(_device);
Michalis Spyroua9676112018-02-22 18:07:43 +00001036 cl::NDRange default_range;
1037
1038 switch(_target)
1039 {
1040 case GPUTarget::MIDGARD:
1041 case GPUTarget::T600:
1042 case GPUTarget::T700:
1043 case GPUTarget::T800:
1044 default_range = cl::NDRange(128u, 1);
1045 break;
1046 default:
1047 default_range = cl::NullRange;
1048 }
1049
1050 return default_range;
steniu015f910722017-08-23 10:15:22 +01001051}
Anthony Barbier847864d2018-03-07 11:35:53 +00001052
1053std::string CLKernelLibrary::get_device_version()
1054{
1055 return _device.getInfo<CL_DEVICE_VERSION>();
1056}