blob: ccc9aec0d833d00ef043109a5c8bca89ac8a051b [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" },
giuros01c04a0e82018-10-03 12:44:35 +0100167 { "bounding_box_transform", "bounding_box_transform.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100168 { "channel_combine_NV", "channel_combine.cl" },
169 { "channel_combine_RGB888", "channel_combine.cl" },
170 { "channel_combine_RGBA8888", "channel_combine.cl" },
171 { "channel_combine_UYVY422", "channel_combine.cl" },
172 { "channel_combine_YUYV422", "channel_combine.cl" },
Michele Di Giorgio72175632018-05-01 16:52:00 +0100173 { "channel_shuffle_nchw", "channel_shuffle.cl" },
Gian Marco Iodice8bab0ee2018-09-13 11:51:56 +0100174 { "channel_shuffle_nhwc", "channel_shuffle.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100175 { "channel_extract_NV12", "channel_extract.cl" },
176 { "channel_extract_NV21", "channel_extract.cl" },
177 { "channel_extract_RGB888", "channel_extract.cl" },
178 { "channel_extract_RGBA8888", "channel_extract.cl" },
179 { "channel_extract_UYVY422", "channel_extract.cl" },
180 { "channel_extract_YUYV422", "channel_extract.cl" },
181 { "combine_gradients_L1", "canny.cl" },
182 { "combine_gradients_L2", "canny.cl" },
183 { "concatenate_depth", "concatenate.cl" },
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100184 { "concatenate_width", "concatenate.cl" },
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000185 { "concatenate_width_x2", "concatenate.cl" },
186 { "concatenate_width_x4", "concatenate.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187 { "convolution_rectangle", "convolution_rectangle.cl" },
Gian Marco76faef82018-01-29 12:15:32 +0000188 { "col2im", "col2im.cl" },
Giorgio Arena657bdb32018-04-26 18:52:01 +0100189 { "convert_depth_down", "depth_convert.cl" },
190 { "convert_depth_up", "depth_convert.cl" },
191 { "convert_fc_weights", "convert_fc_weights.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100192 { "convolution3x3_static", "convolution3x3.cl" },
193 { "convolution5x5_static", "convolution5x5.cl" },
194 { "convolution7x7_static", "convolution7x7.cl" },
195 { "convolution9x9_static", "convolution9x9.cl" },
196 { "convolution_separable1x5_static", "convolution5x5.cl" },
197 { "convolution_separable5x1_static", "convolution5x5.cl" },
198 { "convolution_separable1x7_static", "convolution7x7.cl" },
199 { "convolution_separable7x1_static", "convolution7x7.cl" },
200 { "convolution_separable1x9_static", "convolution9x9.cl" },
201 { "convolution_separable9x1_static", "convolution9x9.cl" },
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000202 { "copy_tensor", "copy_tensor.cl" },
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100203 { "copy_pad_tensor", "copy_tensor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100204 { "copy_plane", "channel_extract.cl" },
205 { "copy_planes_3p", "channel_combine.cl" },
206 { "copy_to_keypoint", "fast_corners.cl" },
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000207 { "deconvolution_upsample", "deconvolution_layer.cl" },
Giorgio Arena93a690e2017-08-01 16:09:33 +0100208 { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
Michele Di Giorgio933fe862018-02-19 15:42:12 +0000209 { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
Giorgio Arenad051e972018-06-20 11:46:42 +0100210 { "depthwise_convolution_3x3_nhwc", "depthwise_convolution.cl" },
211 { "depthwise_convolution_3x3_nhwc_stride1", "depthwise_convolution.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000212 { "depthwise_convolution_3x3_quantized_nchw", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100213 { "depthwise_convolution_3x3_quantized_nhwc", "depthwise_convolution_quantized.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000214 { "depthwise_convolution_3x3_quantized_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100215 { "depthwise_convolution_3x3_quantized_dot8_nchw", "depthwise_convolution_quantized.cl" },
216 { "depthwise_convolution_3x3_quantized_dot8_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Michele Di Giorgio3ebef322018-02-21 10:02:58 +0000217 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16", "depthwise_convolution.cl" },
218 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16", "depthwise_convolution.cl" },
219 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32", "depthwise_convolution.cl" },
220 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32", "depthwise_convolution.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100221 { "depthwise_im2col", "depthwise_convolution.cl" },
222 { "depthwise_vector_to_tensor", "depthwise_convolution.cl" },
223 { "depthwise_weights_reshape", "depthwise_convolution.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100224 { "dequantization_layer", "dequantization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100225 { "derivative", "derivative.cl" },
226 { "dilate", "dilate.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100227 { "direct_convolution1x1", "direct_convolution1x1.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100228 { "direct_convolution1x1_nhwc", "direct_convolution1x1.cl" },
Gian Marco Iodice1c8409d2017-09-06 17:24:25 +0100229 { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100230 { "direct_convolution3x3", "direct_convolution3x3.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100231 { "direct_convolution3x3_nhwc", "direct_convolution3x3.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100232 { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
steniu01db006682017-08-09 16:26:22 +0100233 { "direct_convolution5x5", "direct_convolution5x5.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100234 { "direct_convolution5x5_nhwc", "direct_convolution5x5.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100235 { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
Chunosovd621bca2017-11-03 17:33:15 +0700236 { "direct_convolution_1x1_3x3_5x5_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100237 { "erode", "erode.cl" },
238 { "fast_corners", "fast_corners.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100239 { "flatten", "flatten.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100240 { "fill_image_borders_constant", "fill_border.cl" },
241 { "fill_image_borders_replicate", "fill_border.cl" },
242 { "finalize", "optical_flow_pyramid_lk.cl" },
Georgios Pinitasc9369172018-09-26 11:25:40 +0100243 { "fuse_batchnormalization_layer", "batchnormalization_layer.cl" },
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100244 { "floor_layer", "floor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100245 { "gaussian1x5_sub_x", "gaussian_pyramid.cl" },
246 { "gaussian5x1_sub_y", "gaussian_pyramid.cl" },
Gian Marco Iodice578ab612017-06-23 09:34:33 +0100247 { "gemm_accumulate_biases", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000248 { "gemm_interleave4x4", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100249 { "gemm_ma_f16", "gemm.cl" },
250 { "gemm_ma_f32", "gemm.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100251 { "gemm_mv", "gemv.cl" },
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +0000252 { "gemm_mv_quantized", "gemv.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100253 { "gemm_mm_interleaved_transposed_f16", "gemm.cl" },
Gian Marco Iodicebb36a8e2018-04-19 12:05:08 +0100254 { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm.cl" },
255 { "gemm_mm_interleaved_transposed_f32", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100256 { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100257 { "gemm_mm_floating_point", "gemm.cl" },
Gian Marco Iodicefd683112018-04-17 09:52:44 +0100258 { "gemm_mm_floating_point_f16_bifrost", "gemm.cl" },
Anton Lokhmotov3e80c7f2017-11-20 11:02:10 +0000259 { "gemm_mm_floating_point_f32_bifrost", "gemm.cl" },
260 { "gemm_mm_floating_point_f32_bifrost_1000", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100261 { "gemm_lc_vm_f32", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000262 { "gemm_transpose1xW", "gemm.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000263 { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100264 { "gemmlowp_matrix_a_reduction_dot8", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000265 { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000266 { "gemmlowp_mm_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100267 { "gemmlowp_mm_bifrost_dot8", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000268 { "gemmlowp_mm_midgard", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000269 { "gemmlowp_mm_interleaved_transposed_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100270 { "gemmlowp_mm_interleaved_transposed_bifrost_dot8", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000271 { "gemmlowp_mm_interleaved_transposed_midgard", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000272 { "gemmlowp_offset_contribution", "gemmlowp.cl" },
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100273 { "gemmlowp_offset_contribution_quantize_down", "gemmlowp.cl" },
274 { "gemmlowp_offset_contribution_quantize_down_fixedpoint", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000275 { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
Gian Marco58c57942017-11-28 09:10:03 +0000276 { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
Georgios Pinitas51e53a32018-10-22 13:49:08 +0100277 { "gemmlowp_output_stage_quantize_down_float", "gemmlowp.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100278 { "harris_score_3x3", "harris_corners.cl" },
279 { "harris_score_5x5", "harris_corners.cl" },
280 { "harris_score_7x7", "harris_corners.cl" },
281 { "hist_border_kernel", "histogram.cl" },
282 { "hist_border_kernel_fixed", "histogram.cl" },
283 { "hist_local_kernel", "histogram.cl" },
284 { "hist_local_kernel_fixed", "histogram.cl" },
285 { "hog_block_normalization", "hog.cl" },
286 { "hog_detector", "hog.cl" },
287 { "hog_orientation_binning", "hog.cl" },
288 { "hysteresis", "canny.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100289 { "im2col1x1_stridex1_nchw", "im2col.cl" },
290 { "im2col3x3_nchw", "im2col.cl" },
291 { "im2col5x5_nchw", "im2col.cl" },
292 { "im2col11x11_padx0_pady0_nchw", "im2col.cl" },
293 { "im2col_generic_nchw", "im2col.cl" },
294 { "im2col_generic_padx0_pady0_nchw", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100295 { "im2col3x3_nhwc", "im2col.cl" },
296 { "im2col_generic_nhwc", "im2col.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100297 { "init_level", "optical_flow_pyramid_lk.cl" },
298 { "init_level_max", "optical_flow_pyramid_lk.cl" },
299 { "init_level_max_initial_estimate", "optical_flow_pyramid_lk.cl" },
300 { "integral_horizontal", "integral_image.cl" },
301 { "integral_vertical", "integral_image.cl" },
302 { "IYUV_to_NV12_bt709", "color_convert.cl" },
303 { "IYUV_to_RGB888_bt709", "color_convert.cl" },
304 { "IYUV_to_RGBA8888_bt709", "color_convert.cl" },
305 { "IYUV_to_YUV444_bt709", "color_convert.cl" },
Michalis Spyrou5538d342018-11-14 08:10:13 +0000306 { "l2_normalize_x", "l2_normalize.cl" },
307 { "l2_normalize_y", "l2_normalize.cl" },
308 { "l2_normalize_z", "l2_normalize.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100309 { "lktracker_stage0", "optical_flow_pyramid_lk.cl" },
310 { "lktracker_stage1", "optical_flow_pyramid_lk.cl" },
311 { "magnitude_phase", "magnitude_phase.cl" },
312 { "mean_stddev_accumulate", "mean_stddev.cl" },
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100313 { "memset", "memset.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100314 { "minmax", "minmaxloc.cl" },
315 { "minmax_border", "minmaxloc.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100316 { "minmax_layer", "minmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100317 { "minmaxloc", "minmaxloc.cl" },
318 { "non_linear_filter_box3x3", "non_linear_filter3x3.cl" },
319 { "non_linear_filter_cross3x3", "non_linear_filter3x3.cl" },
320 { "non_linear_filter_disk3x3", "non_linear_filter3x3.cl" },
321 { "non_linear_filter_box5x5", "non_linear_filter5x5.cl" },
322 { "non_linear_filter_cross5x5", "non_linear_filter5x5.cl" },
323 { "non_linear_filter_disk5x5", "non_linear_filter5x5.cl" },
324 { "non_max_suppression", "nonmax.cl" },
325 { "normalization_layer_cross_map", "normalization_layer.cl" },
Georgios Pinitas01624362017-11-30 10:53:31 +0000326 { "normalization_layer_in_map", "normalization_layer.cl" },
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100327 { "normalize_planar_yuv_layer_nchw", "normalize_planar_yuv_layer.cl" },
328 { "normalize_planar_yuv_layer_nhwc", "normalize_planar_yuv_layer.cl" },
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100329 { "normalize_planar_yuv_layer_q8_nchw", "normalize_planar_yuv_layer_quantized.cl" },
330 { "normalize_planar_yuv_layer_q8_nhwc", "normalize_planar_yuv_layer_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100331 { "NV12_to_IYUV_bt709", "color_convert.cl" },
332 { "NV12_to_RGB888_bt709", "color_convert.cl" },
333 { "NV12_to_RGBA8888_bt709", "color_convert.cl" },
334 { "NV12_to_YUV444_bt709", "color_convert.cl" },
335 { "NV21_to_IYUV_bt709", "color_convert.cl" },
336 { "NV21_to_RGB888_bt709", "color_convert.cl" },
337 { "NV21_to_RGBA8888_bt709", "color_convert.cl" },
338 { "NV21_to_YUV444_bt709", "color_convert.cl" },
Giorgio Arenaa086a0a2018-02-16 12:42:16 +0000339 { "output_stage_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
Michalis Spyrou5237e012018-01-17 09:40:27 +0000340 { "permute_201", "permute.cl" },
341 { "permute_120", "permute.cl" },
342 { "permute_3201", "permute.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343 { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
344 { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100345 { "pixelwise_mul_quantized", "pixelwise_mul_int.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100346 { "pooling_layer_2", "pooling_layer.cl" },
347 { "pooling_layer_3", "pooling_layer.cl" },
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000348 { "pooling_layer_optimized_3", "pooling_layer.cl" },
Georgios Pinitasce093142017-06-19 16:11:53 +0100349 { "pooling_layer_7", "pooling_layer.cl" },
Michalis Spyroue74b2012018-04-18 09:49:16 +0100350 { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
351 { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
352 { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
353 { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100354 { "prior_box_layer_nchw", "prior_box_layer.cl" },
355 { "prior_box_layer_nhwc", "prior_box_layer.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100356 { "quantization_layer", "quantization_layer.cl" },
Michalis Spyrou7e9391b2018-10-05 14:49:28 +0100357 { "reduction_operation_x", "reduction_operation.cl" },
358 { "reduction_operation_quantized_x", "reduction_operation.cl" },
359 { "reduction_operation_y", "reduction_operation.cl" },
360 { "reduction_operation_z", "reduction_operation.cl" },
361 { "reduction_operation_w", "reduction_operation.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100362 { "remap_nearest_neighbour", "remap.cl" },
363 { "remap_bilinear", "remap.cl" },
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100364 { "reorg_layer_nchw", "reorg_layer.cl" },
365 { "reorg_layer_nhwc", "reorg_layer.cl" },
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100366 { "reshape_layer", "reshape_layer.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100367 { "reshape_to_columns", "convolution_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100368 { "RGB888_to_IYUV_bt709", "color_convert.cl" },
369 { "RGB888_to_NV12_bt709", "color_convert.cl" },
370 { "RGB888_to_RGBA8888_bt709", "color_convert.cl" },
Manuel Bottiniacaf21d2018-09-26 17:38:19 +0100371 { "RGB888_to_U8_bt709", "color_convert.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100372 { "RGB888_to_YUV444_bt709", "color_convert.cl" },
373 { "RGBA8888_to_IYUV_bt709", "color_convert.cl" },
374 { "RGBA8888_to_NV12_bt709", "color_convert.cl" },
375 { "RGBA8888_to_RGB888_bt709", "color_convert.cl" },
376 { "RGBA8888_to_YUV444_bt709", "color_convert.cl" },
giuros0118870812018-09-13 09:31:40 +0100377 { "roi_align_layer", "roi_align_layer.cl" },
SiCong Li3e363692017-07-04 15:02:10 +0100378 { "roi_pooling_layer", "roi_pooling_layer.cl" },
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100379 { "scale_nearest_neighbour_nchw", "scale.cl" },
380 { "scale_nearest_neighbour_nhwc", "scale.cl" },
381 { "scale_bilinear_nchw", "scale.cl" },
382 { "scale_bilinear_nhwc", "scale.cl" },
Michalis Spyrou17220e22018-09-12 13:35:38 +0100383 { "scale_bilinear_quantized_nchw", "scale_quantized.cl" },
384 { "scale_bilinear_quantized_nhwc", "scale_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100385 { "scharr3x3", "scharr_filter.cl" },
386 { "sobel3x3", "sobel_filter.cl" },
387 { "sobel_separable5x1", "sobel_filter.cl" },
388 { "sobel_separable1x5", "sobel_filter.cl" },
389 { "sobel_separable7x1", "sobel_filter.cl" },
390 { "sobel_separable1x7", "sobel_filter.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100391 { "softmax_layer_norm", "softmax_layer.cl" },
Chunosovf450caa2017-11-08 16:09:35 +0700392 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
Giorgio Arena4402cb92018-02-15 13:37:40 +0000393 { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
394 { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700395 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100396 { "space_to_batch_nchw", "space_to_batch.cl" },
397 { "space_to_batch_static_nchw", "space_to_batch.cl" },
398 { "space_to_batch_nhwc", "space_to_batch.cl" },
399 { "space_to_batch_static_nhwc", "space_to_batch.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700400 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100401 { "strided_slice", "slice_ops.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100402 { "suppress_non_maximum", "canny.cl" },
403 { "tablelookup_U8", "tablelookup.cl" },
404 { "tablelookup_S16", "tablelookup.cl" },
405 { "threshold_binary", "threshold.cl" },
406 { "threshold_range", "threshold.cl" },
407 { "transpose", "transpose.cl" },
408 { "UYVY422_to_IYUV_bt709", "color_convert.cl" },
409 { "UYVY422_to_NV12_bt709", "color_convert.cl" },
410 { "UYVY422_to_RGB888_bt709", "color_convert.cl" },
411 { "UYVY422_to_RGBA8888_bt709", "color_convert.cl" },
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100412 { "upsample_layer_nchw", "upsample_layer.cl" },
413 { "upsample_layer_nhwc", "upsample_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100414 { "warp_affine_nearest_neighbour", "warp_affine.cl" },
415 { "warp_affine_bilinear", "warp_affine.cl" },
416 { "warp_perspective_nearest_neighbour", "warp_perspective.cl" },
417 { "warp_perspective_bilinear", "warp_perspective.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100418 { "winograd_filter_transform_2x2_3x3_nchw", "winograd_filter_transform.cl" },
419 { "winograd_filter_transform_2x1_3x1_nchw", "winograd_filter_transform.cl" },
420 { "winograd_filter_transform_1x2_1x3_nchw", "winograd_filter_transform.cl" },
421 { "winograd_filter_transform_4x4_3x3_nchw", "winograd_filter_transform.cl" },
422 { "winograd_filter_transform_4x1_3x1_nchw", "winograd_filter_transform.cl" },
423 { "winograd_filter_transform_1x4_1x3_nchw", "winograd_filter_transform.cl" },
424 { "winograd_filter_transform_4x4_5x5_nchw", "winograd_filter_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100425 { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
426 { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100427 { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
428 { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100429 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
430 { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100431 { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
432 { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100433 { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd_input_transform.cl" },
434 { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd_input_transform.cl" },
435 { "winograd_input_transform_2x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
436 { "winograd_input_transform_2x1_3x1_stepz2_nchw", "winograd_input_transform.cl" },
437 { "winograd_input_transform_1x2_1x3_stepz1_nchw", "winograd_input_transform.cl" },
438 { "winograd_input_transform_1x2_1x3_stepz2_nchw", "winograd_input_transform.cl" },
439 { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd_input_transform.cl" },
440 { "winograd_input_transform_4x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
441 { "winograd_input_transform_1x4_1x3_stepz1_nchw", "winograd_input_transform.cl" },
442 { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd_input_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100443 { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
444 { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100445 { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
446 { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100447 { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
448 { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100449 { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
450 { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100451 { "winograd_output_transform_2x2_3x3_nchw", "winograd_output_transform.cl" },
452 { "winograd_output_transform_2x1_3x1_nchw", "winograd_output_transform.cl" },
453 { "winograd_output_transform_1x2_1x3_nchw", "winograd_output_transform.cl" },
454 { "winograd_output_transform_4x4_3x3_nchw", "winograd_output_transform.cl" },
455 { "winograd_output_transform_4x1_3x1_nchw", "winograd_output_transform.cl" },
456 { "winograd_output_transform_1x4_1x3_nchw", "winograd_output_transform.cl" },
457 { "winograd_output_transform_4x4_5x5_nchw", "winograd_output_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100458 { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
459 { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100460 { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
461 { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100462 { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
463 { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100464 { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
465 { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
Giorgio Arena73023022018-09-04 14:55:55 +0100466 { "yolo_layer_nchw", "yolo_layer.cl" },
467 { "yolo_layer_nhwc", "yolo_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100468 { "YUYV422_to_IYUV_bt709", "color_convert.cl" },
469 { "YUYV422_to_NV12_bt709", "color_convert.cl" },
470 { "YUYV422_to_RGB888_bt709", "color_convert.cl" },
471 { "YUYV422_to_RGBA8888_bt709", "color_convert.cl" },
472};
473
474const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
475{
476#ifdef EMBEDDED_KERNELS
477 {
478 "absdiff.cl",
479#include "./cl_kernels/absdiff.clembed"
480 },
481 {
482 "accumulate.cl",
483#include "./cl_kernels/accumulate.clembed"
484 },
485 {
486 "activation_layer.cl",
487#include "./cl_kernels/activation_layer.clembed"
488 },
489 {
Michel Iwaniec00633802017-10-12 14:14:15 +0100490 "activation_layer_qa8.cl",
491#include "./cl_kernels/activation_layer_qa8.clembed"
492 },
493 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100494 "arithmetic_op.cl",
495#include "./cl_kernels/arithmetic_op.clembed"
496 },
497 {
Michele Di Giorgio4622ac12018-06-27 16:41:17 +0100498 "arithmetic_op_quantized.cl",
499#include "./cl_kernels/arithmetic_op_quantized.clembed"
500 },
501 {
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100502 "batch_to_space.cl",
503#include "./cl_kernels/batch_to_space.clembed"
504 },
505 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100506 "bitwise_op.cl",
507#include "./cl_kernels/bitwise_op.clembed"
508 },
509 {
giuros01c04a0e82018-10-03 12:44:35 +0100510 "bounding_box_transform.cl",
511#include "./cl_kernels/bounding_box_transform.clembed"
512 },
513 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100514 "canny.cl",
515#include "./cl_kernels/canny.clembed"
516 },
517 {
518 "channel_combine.cl",
519#include "./cl_kernels/channel_combine.clembed"
520 },
521 {
522 "channel_extract.cl",
523#include "./cl_kernels/channel_extract.clembed"
524 },
525 {
Michele Di Giorgio72175632018-05-01 16:52:00 +0100526 "channel_shuffle.cl",
527#include "./cl_kernels/channel_shuffle.clembed"
528 },
529 {
Gian Marco76faef82018-01-29 12:15:32 +0000530 "col2im.cl",
531#include "./cl_kernels/col2im.clembed"
532 },
533 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100534 "concatenate.cl",
535#include "./cl_kernels/concatenate.clembed"
536 },
537 {
538 "color_convert.cl",
539#include "./cl_kernels/color_convert.clembed"
540 },
541 {
Giorgio Arena657bdb32018-04-26 18:52:01 +0100542 "convert_fc_weights.cl",
543#include "./cl_kernels/convert_fc_weights.clembed"
544 },
545 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100546 "convolution3x3.cl",
547#include "./cl_kernels/convolution3x3.clembed"
548 },
549 {
550 "convolution5x5.cl",
551#include "./cl_kernels/convolution5x5.clembed"
552 },
553 {
554 "convolution7x7.cl",
555#include "./cl_kernels/convolution7x7.clembed"
556 },
557 {
558 "convolution9x9.cl",
559#include "./cl_kernels/convolution9x9.clembed"
560 },
561 {
562 "convolution_layer.cl",
563#include "./cl_kernels/convolution_layer.clembed"
564 },
565 {
566 "convolution_rectangle.cl",
567#include "./cl_kernels/convolution_rectangle.clembed"
568 },
569 {
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000570 "copy_tensor.cl",
571#include "./cl_kernels/copy_tensor.clembed"
572 },
573 {
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100574 "upsample_layer.cl",
575#include "./cl_kernels/upsample_layer.clembed"
576 },
577 {
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000578 "deconvolution_layer.cl",
579#include "./cl_kernels/deconvolution_layer.clembed"
580 },
581 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100582 "depth_convert.cl",
583#include "./cl_kernels/depth_convert.clembed"
584 },
585 {
Giorgio Arena93a690e2017-08-01 16:09:33 +0100586 "depthwise_convolution.cl",
587#include "./cl_kernels/depthwise_convolution.clembed"
588 },
589 {
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700590 "depthwise_convolution_quantized.cl",
591#include "./cl_kernels/depthwise_convolution_quantized.clembed"
592 },
593 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100594 "dequantization_layer.cl",
595#include "./cl_kernels/dequantization_layer.clembed"
596 },
597 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100598 "derivative.cl",
599#include "./cl_kernels/derivative.clembed"
600 },
601 {
602 "dilate.cl",
603#include "./cl_kernels/dilate.clembed"
604 },
605 {
SiCong Lic51b72f2017-07-28 14:46:20 +0100606 "direct_convolution1x1.cl",
607#include "./cl_kernels/direct_convolution1x1.clembed"
608 },
609 {
610 "direct_convolution3x3.cl",
611#include "./cl_kernels/direct_convolution3x3.clembed"
steniu0127b386c2017-07-18 17:37:43 +0100612 },
613 {
steniu01db006682017-08-09 16:26:22 +0100614 "direct_convolution5x5.cl",
615#include "./cl_kernels/direct_convolution5x5.clembed"
616 },
617 {
Chunosovd621bca2017-11-03 17:33:15 +0700618 "direct_convolution_1x1_3x3_5x5_quantized.cl",
619#include "./cl_kernels/direct_convolution_1x1_3x3_5x5_quantized.clembed"
620 },
621 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100622 "erode.cl",
623#include "./cl_kernels/erode.clembed"
624 },
625 {
626 "fast_corners.cl",
627#include "./cl_kernels/fast_corners.clembed"
628 },
629 {
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100630 "flatten.cl",
631#include "./cl_kernels/flatten.clembed"
632 },
633 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100634 "fill_border.cl",
635#include "./cl_kernels/fill_border.clembed"
636 },
637 {
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100638 "floor.cl",
639#include "./cl_kernels/floor.clembed"
640 },
641 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100642 "gaussian_pyramid.cl",
643#include "./cl_kernels/gaussian_pyramid.clembed"
644 },
645 {
646 "gemm.cl",
647#include "./cl_kernels/gemm.clembed"
648 },
649 {
Gian Marco05288a22017-11-21 10:57:50 +0000650 "gemmlowp.cl",
651#include "./cl_kernels/gemmlowp.clembed"
652 },
653 {
Giorgio Arena9fe41442017-08-23 16:36:24 +0100654 "gemv.cl",
655#include "./cl_kernels/gemv.clembed"
656 },
657 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100658 "harris_corners.cl",
659#include "./cl_kernels/harris_corners.clembed"
660 },
661 {
662 "helpers.h",
663#include "./cl_kernels/helpers.hembed"
664 },
665 {
Chunosovd621bca2017-11-03 17:33:15 +0700666 "helpers_asymm.h",
667#include "./cl_kernels/helpers_asymm.hembed"
668 },
669 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100670 "histogram.cl",
671#include "./cl_kernels/histogram.clembed"
672 },
673 {
674 "hog.cl",
675#include "./cl_kernels/hog.clembed"
676 },
677 {
Gian Marco76faef82018-01-29 12:15:32 +0000678 "im2col.cl",
679#include "./cl_kernels/im2col.clembed"
680 },
681 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100682 "integral_image.cl",
683#include "./cl_kernels/integral_image.clembed"
684 },
685 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100686 "l2_normalize.cl",
687#include "./cl_kernels/l2_normalize.clembed"
688 },
689 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100690 "magnitude_phase.cl",
691#include "./cl_kernels/magnitude_phase.clembed"
692 },
693 {
694 "mean_stddev.cl",
695#include "./cl_kernels/mean_stddev.clembed"
696 },
697 {
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100698 "memset.cl",
699#include "./cl_kernels/memset.clembed"
700 },
701 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100702 "minmaxloc.cl",
703#include "./cl_kernels/minmaxloc.clembed"
704 },
705 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100706 "minmax_layer.cl",
707#include "./cl_kernels/minmax_layer.clembed"
708 },
709 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100710 "non_linear_filter3x3.cl",
711#include "./cl_kernels/non_linear_filter3x3.clembed"
712 },
713 {
714 "non_linear_filter5x5.cl",
715#include "./cl_kernels/non_linear_filter5x5.clembed"
716 },
717 {
718 "non_linear_filter_helpers.h",
719#include "./cl_kernels/non_linear_filter_helpers.hembed"
720 },
721 {
722 "nonmax.cl",
723#include "./cl_kernels/nonmax.clembed"
724 },
725 {
726 "normalization_layer.cl",
727#include "./cl_kernels/normalization_layer.clembed"
728 },
729 {
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100730 "normalize_planar_yuv_layer.cl",
731#include "./cl_kernels/normalize_planar_yuv_layer.clembed"
732 },
733 {
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100734 "normalize_planar_yuv_layer_quantized.cl",
735#include "./cl_kernels/normalize_planar_yuv_layer_quantized.clembed"
736 },
737 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100738 "batchnormalization_layer.cl",
739#include "./cl_kernels/batchnormalization_layer.clembed"
740 },
741 {
742 "optical_flow_pyramid_lk.cl",
743#include "./cl_kernels/optical_flow_pyramid_lk.clembed"
744 },
745 {
Michalis Spyrou5237e012018-01-17 09:40:27 +0000746 "permute.cl",
747#include "./cl_kernels/permute.clembed"
748 },
749 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100750 "pixelwise_mul_float.cl",
751#include "./cl_kernels/pixelwise_mul_float.clembed"
752 },
753 {
754 "pixelwise_mul_int.cl",
755#include "./cl_kernels/pixelwise_mul_int.clembed"
756 },
757 {
758 "pooling_layer.cl",
759#include "./cl_kernels/pooling_layer.clembed"
760 },
761 {
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000762 "pooling_layer_quantized.cl",
763#include "./cl_kernels/pooling_layer_quantized.clembed"
764 },
765 {
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100766 "prior_box_layer.cl",
767#include "./cl_kernels/prior_box_layer.clembed"
768 },
769 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100770 "quantization_layer.cl",
771#include "./cl_kernels/quantization_layer.clembed"
772 },
773 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100774 "reduction_operation.cl",
775#include "./cl_kernels/reduction_operation.clembed"
776 },
777 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100778 "remap.cl",
779#include "./cl_kernels/remap.clembed"
780 },
781 {
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100782 "reorg_layer.cl",
783#include "./cl_kernels/reorg_layer.clembed"
784 },
785 {
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100786 "reshape_layer.cl",
787#include "./cl_kernels/reshape_layer.clembed"
788 },
789 {
giuros0118870812018-09-13 09:31:40 +0100790 "roi_align_layer.cl",
791#include "./cl_kernels/roi_align_layer.clembed"
792 },
793 {
SiCong Li3e363692017-07-04 15:02:10 +0100794 "roi_pooling_layer.cl",
795#include "./cl_kernels/roi_pooling_layer.clembed"
796 },
797 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100798 "scale.cl",
799#include "./cl_kernels/scale.clembed"
800 },
801 {
Michalis Spyrou17220e22018-09-12 13:35:38 +0100802 "scale_quantized.cl",
803#include "./cl_kernels/scale_quantized.clembed"
804 },
805 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100806 "scharr_filter.cl",
807#include "./cl_kernels/scharr_filter.clembed"
808 },
809 {
810 "sobel_filter.cl",
811#include "./cl_kernels/sobel_filter.clembed"
812 },
813 {
814 "softmax_layer.cl",
815#include "./cl_kernels/softmax_layer.clembed"
816 },
817 {
Chunosovf450caa2017-11-08 16:09:35 +0700818 "softmax_layer_quantized.cl",
819#include "./cl_kernels/softmax_layer_quantized.clembed"
820 },
821 {
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100822 "slice_ops.cl",
823#include "./cl_kernels/slice_ops.clembed"
Georgios Pinitas77589b52018-08-21 14:41:35 +0100824 },
825 {
Michalis Spyrou16934a52018-08-21 18:03:58 +0100826 "space_to_batch.cl",
827#include "./cl_kernels/space_to_batch.clembed"
828 },
829 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100830 "tablelookup.cl",
831#include "./cl_kernels/tablelookup.clembed"
832 },
833 {
834 "threshold.cl",
835#include "./cl_kernels/threshold.clembed"
836 },
837 {
838 "transpose.cl",
839#include "./cl_kernels/transpose.clembed"
840 },
841 {
842 "types.h",
843#include "./cl_kernels/types.hembed"
844 },
845 {
846 "warp_affine.cl",
847#include "./cl_kernels/warp_affine.clembed"
848 },
849 {
850 "warp_helpers.h",
851#include "./cl_kernels/warp_helpers.hembed"
852 },
853 {
854 "warp_perspective.cl",
855#include "./cl_kernels/warp_perspective.clembed"
Michalis Spyroud7e82812017-06-20 15:00:14 +0100856 },
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000857 {
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100858 "winograd_filter_transform.cl",
859#include "./cl_kernels/winograd_filter_transform.clembed"
860 },
861 {
862 "winograd_input_transform.cl",
863#include "./cl_kernels/winograd_input_transform.clembed"
864 },
865 {
866 "winograd_output_transform.cl",
867#include "./cl_kernels/winograd_output_transform.clembed"
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000868 },
Giorgio Arena73023022018-09-04 14:55:55 +0100869 {
870 "yolo_layer.cl",
871#include "./cl_kernels/yolo_layer.clembed"
872 },
Anthony Barbierac69aa12017-07-03 17:39:37 +0100873#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100874};
875
876CLKernelLibrary::CLKernelLibrary()
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100877 : _context(), _device(), _kernel_path("."), _programs_map(), _built_programs_map()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100878{
Anthony Barbierecb1c622018-04-17 11:45:10 +0100879 opencl_is_available(); // Make sure the OpenCL symbols are initialised *before* the CLKernelLibrary is built
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100880}
881
882CLKernelLibrary &CLKernelLibrary::get()
883{
884 static CLKernelLibrary _kernel_library;
885 return _kernel_library;
886}
887
888Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const StringSet &build_options_set) const
889{
890 // Find which program contains the kernel
891 auto kernel_program_it = _kernel_program_map.find(kernel_name);
892
893 if(_kernel_program_map.end() == kernel_program_it)
894 {
895 ARM_COMPUTE_ERROR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
896 }
steniu0134702472017-07-11 09:22:58 +0100897 std::string concat_str;
898
Georgios Pinitasdf473ea2018-05-31 18:53:52 +0100899#if defined(ARM_COMPUTE_DEBUG_ENABLED)
900 // Enable debug properties in CL kernels
901 concat_str += " -DARM_COMPUTE_DEBUG_ENABLED";
902#endif // defined(ARM_COMPUTE_DEBUG_ENABLED)
903
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100904 if(fp16_supported())
Matthew Bentham6f31f8c2017-10-27 11:50:06 +0100905 {
906 concat_str += " -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 ";
907 }
908
Michalis Spyroue03342e2018-01-15 14:39:13 +0000909 if(dot8_supported(_device))
910 {
911 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ENABLED=1 ";
912 }
913
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100914 if(dot8_acc_supported(_device))
915 {
916 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED=1 ";
917 }
918
Pablo Telloe86a09f2018-01-11 15:44:48 +0000919 if(get_cl_version(_device) == CLVersion::CL20)
steniu0134702472017-07-11 09:22:58 +0100920 {
921 concat_str += " -cl-std=CL2.0 ";
922 }
Anthony Barbierd727e852018-04-20 11:05:29 +0100923 else if(arm_non_uniform_workgroup_supported(_device))
Pablo Telloe86a09f2018-01-11 15:44:48 +0000924 {
925 concat_str += " -cl-arm-non-uniform-work-group-size ";
926 }
steniu0134702472017-07-11 09:22:58 +0100927 else
928 {
929 ARM_COMPUTE_ERROR("Non uniform workgroup size is not supported!!");
930 }
931
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100932 // Check if the program has been built before with same build options.
steniu0134702472017-07-11 09:22:58 +0100933 const std::string program_name = kernel_program_it->second;
934 const std::string build_options = stringify_set(build_options_set) + concat_str;
935
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100936 const std::string built_program_name = program_name + "_" + build_options;
937 auto built_program_it = _built_programs_map.find(built_program_name);
938
939 cl::Program cl_program;
940
941 if(_built_programs_map.end() != built_program_it)
942 {
943 // If program has been built, retrieve to create kernel from it
944 cl_program = built_program_it->second;
945 }
946 else
947 {
948 // Get program
949 Program program = load_program(program_name);
950
951 // Build program
952 cl_program = program.build(build_options);
953
954 // Add built program to internal map
955 _built_programs_map.emplace(built_program_name, cl_program);
956 }
957
958 // Create and return kernel
959 return Kernel(kernel_name, cl_program);
960}
961
Anthony Barbier7da55aa2018-04-13 16:58:43 +0100962void CLKernelLibrary::add_built_program(const std::string &built_program_name, cl::Program program)
963{
964 _built_programs_map.emplace(built_program_name, program);
965}
966
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100967bool CLKernelLibrary::fp16_supported() const
968{
969 return ::fp16_supported(_device);
970}
971
Vidhya Sudhan Loganathan76c85642018-05-25 13:53:02 +0100972bool CLKernelLibrary::int64_base_atomics_supported() const
973{
974 return device_supports_extension(_device, "cl_khr_int64_base_atomics");
975}
976
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100977const Program &CLKernelLibrary::load_program(const std::string &program_name) const
978{
979 const auto program_it = _programs_map.find(program_name);
980
981 if(program_it != _programs_map.end())
982 {
983 return program_it->second;
984 }
985
986 Program program;
987
988#ifdef EMBEDDED_KERNELS
989 const auto program_source_it = _program_source_map.find(program_name);
990
991 if(_program_source_map.end() == program_source_it)
992 {
993 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
994 }
995
996 program = Program(_context, program_name, program_source_it->second);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100997#else /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100998 // Check for binary
999 std::string source_name = _kernel_path + program_name;
1000 std::string binary_name = source_name + "bin";
1001
1002 if(std::ifstream(binary_name).is_open())
1003 {
1004 const std::string program_binary = read_file(binary_name, true);
1005 program = Program(_context, _device, program_name, std::vector<unsigned char>(program_binary.begin(), program_binary.end()));
1006 }
1007 else if(std::ifstream(source_name).is_open())
1008 {
1009 program = Program(_context, program_name, read_file(source_name, false));
1010 }
1011 else
1012 {
1013 ARM_COMPUTE_ERROR("Kernel file %s does not exist.", source_name.c_str());
1014 }
Anthony Barbierac69aa12017-07-03 17:39:37 +01001015#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001016
1017 // Insert program to program map
1018 const auto new_program = _programs_map.emplace(program_name, std::move(program));
1019
1020 return new_program.first->second;
1021}
1022
1023std::string CLKernelLibrary::stringify_set(const StringSet &s) const
1024{
steniu0134702472017-07-11 09:22:58 +01001025 std::string concat_set;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001026
1027#ifndef EMBEDDED_KERNELS
1028 concat_set += "-I" + _kernel_path + " ";
1029#endif /* EMBEDDED_KERNELS */
1030
1031 // Concatenate set
1032 for(const auto &el : s)
1033 {
1034 concat_set += " " + el;
1035 }
1036
1037 return concat_set;
1038}
Michalis Spyroud7e82812017-06-20 15:00:14 +01001039
1040std::string CLKernelLibrary::get_program_source(const std::string &program_name)
1041{
1042 const auto program_source_it = _program_source_map.find(program_name);
1043
1044 if(program_source_it == _program_source_map.end())
1045 {
1046 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
1047 }
1048
1049 return program_source_it->second;
1050}
steniu015f910722017-08-23 10:15:22 +01001051
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001052size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const
steniu015f910722017-08-23 10:15:22 +01001053{
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001054 size_t result;
steniu015f910722017-08-23 10:15:22 +01001055
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001056 size_t err = kernel.getWorkGroupInfo(_device, CL_KERNEL_WORK_GROUP_SIZE, &result);
1057 ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel");
1058 ARM_COMPUTE_UNUSED(err);
1059
1060 return result;
steniu015f910722017-08-23 10:15:22 +01001061}
1062
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001063cl::NDRange CLKernelLibrary::default_ndrange() const
steniu015f910722017-08-23 10:15:22 +01001064{
Anthony Barbierb6eb3532018-08-08 13:20:04 +01001065 GPUTarget _target = get_target_from_device(_device);
Michalis Spyroua9676112018-02-22 18:07:43 +00001066 cl::NDRange default_range;
1067
1068 switch(_target)
1069 {
1070 case GPUTarget::MIDGARD:
1071 case GPUTarget::T600:
1072 case GPUTarget::T700:
1073 case GPUTarget::T800:
1074 default_range = cl::NDRange(128u, 1);
1075 break;
1076 default:
1077 default_range = cl::NullRange;
1078 }
1079
1080 return default_range;
steniu015f910722017-08-23 10:15:22 +01001081}
Anthony Barbier847864d2018-03-07 11:35:53 +00001082
1083std::string CLKernelLibrary::get_device_version()
1084{
1085 return _device.getInfo<CL_DEVICE_VERSION>();
1086}