blob: ce846d1dc5bc4d04e1c5b2887179e4a0027f142c [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Manuel Bottini8529bd62018-11-21 11:53:04 +00002 * Copyright (c) 2016-2019 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" },
Michalis Spyrouf1addb62018-09-11 11:16:47 +0100152 { "batch_to_space_nchw", "batch_to_space.cl" },
153 { "batch_to_space_static_nchw", "batch_to_space.cl" },
154 { "batch_to_space_nhwc", "batch_to_space.cl" },
155 { "batch_to_space_static_nhwc", "batch_to_space.cl" },
Michele Di Giorgiobf3c6622018-03-08 11:52:27 +0000156 { "batchnormalization_layer_nchw", "batchnormalization_layer.cl" },
157 { "batchnormalization_layer_nhwc", "batchnormalization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100158 { "bitwise_or", "bitwise_op.cl" },
159 { "bitwise_and", "bitwise_op.cl" },
160 { "bitwise_xor", "bitwise_op.cl" },
161 { "bitwise_not", "bitwise_op.cl" },
giuros01c04a0e82018-10-03 12:44:35 +0100162 { "bounding_box_transform", "bounding_box_transform.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100163 { "channel_combine_NV", "channel_combine.cl" },
164 { "channel_combine_RGB888", "channel_combine.cl" },
165 { "channel_combine_RGBA8888", "channel_combine.cl" },
166 { "channel_combine_UYVY422", "channel_combine.cl" },
167 { "channel_combine_YUYV422", "channel_combine.cl" },
Michele Di Giorgio72175632018-05-01 16:52:00 +0100168 { "channel_shuffle_nchw", "channel_shuffle.cl" },
Gian Marco Iodice8bab0ee2018-09-13 11:51:56 +0100169 { "channel_shuffle_nhwc", "channel_shuffle.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100170 { "channel_extract_NV12", "channel_extract.cl" },
171 { "channel_extract_NV21", "channel_extract.cl" },
172 { "channel_extract_RGB888", "channel_extract.cl" },
173 { "channel_extract_RGBA8888", "channel_extract.cl" },
174 { "channel_extract_UYVY422", "channel_extract.cl" },
175 { "channel_extract_YUYV422", "channel_extract.cl" },
176 { "combine_gradients_L1", "canny.cl" },
177 { "combine_gradients_L2", "canny.cl" },
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000178 { "compare_equal", "comparisons.cl" },
179 { "compare_equal_quantized", "comparisons.cl" },
180 { "compare_notequal", "comparisons.cl" },
181 { "compare_notequal_quantized", "comparisons.cl" },
182 { "compare_greater", "comparisons.cl" },
183 { "compare_greater_quantized", "comparisons.cl" },
184 { "compare_greaterequal", "comparisons.cl" },
185 { "compare_greaterequal_quantized", "comparisons.cl" },
186 { "compare_less", "comparisons.cl" },
187 { "compare_less_quantized", "comparisons.cl" },
188 { "compare_lessequal", "comparisons.cl" },
189 { "compare_lessequal_quantized", "comparisons.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100190 { "concatenate_depth", "concatenate.cl" },
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100191 { "concatenate_width", "concatenate.cl" },
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000192 { "concatenate_width_x2", "concatenate.cl" },
193 { "concatenate_width_x4", "concatenate.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100194 { "convolution_rectangle", "convolution_rectangle.cl" },
Gian Marco76faef82018-01-29 12:15:32 +0000195 { "col2im", "col2im.cl" },
Giorgio Arena657bdb32018-04-26 18:52:01 +0100196 { "convert_depth_down", "depth_convert.cl" },
197 { "convert_depth_up", "depth_convert.cl" },
198 { "convert_fc_weights", "convert_fc_weights.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100199 { "convolution3x3_static", "convolution3x3.cl" },
200 { "convolution5x5_static", "convolution5x5.cl" },
201 { "convolution7x7_static", "convolution7x7.cl" },
202 { "convolution9x9_static", "convolution9x9.cl" },
203 { "convolution_separable1x5_static", "convolution5x5.cl" },
204 { "convolution_separable5x1_static", "convolution5x5.cl" },
205 { "convolution_separable1x7_static", "convolution7x7.cl" },
206 { "convolution_separable7x1_static", "convolution7x7.cl" },
207 { "convolution_separable1x9_static", "convolution9x9.cl" },
208 { "convolution_separable9x1_static", "convolution9x9.cl" },
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000209 { "copy_tensor", "copy_tensor.cl" },
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100210 { "copy_pad_tensor", "copy_tensor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100211 { "copy_plane", "channel_extract.cl" },
212 { "copy_planes_3p", "channel_combine.cl" },
213 { "copy_to_keypoint", "fast_corners.cl" },
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000214 { "deconvolution_upsample", "deconvolution_layer.cl" },
Giorgio Arena93a690e2017-08-01 16:09:33 +0100215 { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
Michele Di Giorgio933fe862018-02-19 15:42:12 +0000216 { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
Giorgio Arenad051e972018-06-20 11:46:42 +0100217 { "depthwise_convolution_3x3_nhwc", "depthwise_convolution.cl" },
218 { "depthwise_convolution_3x3_nhwc_stride1", "depthwise_convolution.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000219 { "depthwise_convolution_3x3_quantized_nchw", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100220 { "depthwise_convolution_3x3_quantized_nhwc", "depthwise_convolution_quantized.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000221 { "depthwise_convolution_3x3_quantized_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100222 { "depthwise_convolution_3x3_quantized_dot8_nchw", "depthwise_convolution_quantized.cl" },
223 { "depthwise_convolution_3x3_quantized_dot8_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Michele Di Giorgio3ebef322018-02-21 10:02:58 +0000224 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16", "depthwise_convolution.cl" },
225 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16", "depthwise_convolution.cl" },
226 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32", "depthwise_convolution.cl" },
227 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32", "depthwise_convolution.cl" },
giuros016d109962019-01-07 17:47:19 +0000228 { "depthwise_convolution_reshape_weights", "depthwise_convolution.cl" },
229 { "depthwise_convolution_reshape_weights_generic", "depthwise_convolution.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100230 { "depthwise_im2col", "depthwise_convolution.cl" },
231 { "depthwise_vector_to_tensor", "depthwise_convolution.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100232 { "dequantization_layer", "dequantization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100233 { "derivative", "derivative.cl" },
234 { "dilate", "dilate.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100235 { "direct_convolution1x1", "direct_convolution1x1.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100236 { "direct_convolution1x1_nhwc", "direct_convolution1x1.cl" },
Gian Marco Iodice1c8409d2017-09-06 17:24:25 +0100237 { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100238 { "direct_convolution3x3", "direct_convolution3x3.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100239 { "direct_convolution3x3_nhwc", "direct_convolution3x3.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100240 { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
steniu01db006682017-08-09 16:26:22 +0100241 { "direct_convolution5x5", "direct_convolution5x5.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100242 { "direct_convolution5x5_nhwc", "direct_convolution5x5.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100243 { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
Chunosovd621bca2017-11-03 17:33:15 +0700244 { "direct_convolution_1x1_3x3_5x5_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
giuros01164a2722018-11-20 18:34:46 +0000245 { "elementwise_operation_ADD", "elementwise_operation.cl" },
246 { "elementwise_operation_SUB", "elementwise_operation.cl" },
247 { "elementwise_operation_MAX", "elementwise_operation.cl" },
248 { "elementwise_operation_MIN", "elementwise_operation.cl" },
249 { "elementwise_operation_DIV", "elementwise_operation.cl" },
250 { "elementwise_operation_SQUARED_DIFF", "elementwise_operation.cl" },
251 { "elementwise_operation_ADD_quantized", "elementwise_operation_quantized.cl" },
252 { "elementwise_operation_SUB_quantized", "elementwise_operation_quantized.cl" },
253 { "elementwise_operation_MAX_quantized", "elementwise_operation_quantized.cl" },
254 { "elementwise_operation_MIN_quantized", "elementwise_operation_quantized.cl" },
255 { "elementwise_operation_DIV_quantized", "elementwise_operation_quantized.cl" },
256 { "elementwise_operation_SQUARED_DIFF_quantized", "elementwise_operation_quantized.cl" },
Michalis Spyroue9362622018-11-23 17:41:37 +0000257 { "elementwise_unary", "elementwise_unary.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258 { "erode", "erode.cl" },
259 { "fast_corners", "fast_corners.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100260 { "flatten", "flatten.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100261 { "fill_image_borders_constant", "fill_border.cl" },
262 { "fill_image_borders_replicate", "fill_border.cl" },
263 { "finalize", "optical_flow_pyramid_lk.cl" },
Georgios Pinitasc9369172018-09-26 11:25:40 +0100264 { "fuse_batchnormalization_layer", "batchnormalization_layer.cl" },
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100265 { "floor_layer", "floor.cl" },
Manuel Bottini8529bd62018-11-21 11:53:04 +0000266 { "gather", "gather.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100267 { "gaussian1x5_sub_x", "gaussian_pyramid.cl" },
268 { "gaussian5x1_sub_y", "gaussian_pyramid.cl" },
Gian Marco Iodice578ab612017-06-23 09:34:33 +0100269 { "gemm_accumulate_biases", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000270 { "gemm_interleave4x4", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100271 { "gemm_ma_f16", "gemm.cl" },
272 { "gemm_ma_f32", "gemm.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100273 { "gemm_mv", "gemv.cl" },
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +0000274 { "gemm_mv_quantized", "gemv.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100275 { "gemm_mm_interleaved_transposed_f16", "gemm.cl" },
Vidhya Sudhan Loganathan38d93bd2018-11-20 15:38:13 +0000276 { "gemm_mm_interleaved_transposed_f16_acc32", "gemm.cl" },
Gian Marco Iodicebb36a8e2018-04-19 12:05:08 +0100277 { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm.cl" },
278 { "gemm_mm_interleaved_transposed_f32", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100279 { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100280 { "gemm_mm_floating_point", "gemm.cl" },
Gian Marco Iodicefd683112018-04-17 09:52:44 +0100281 { "gemm_mm_floating_point_f16_bifrost", "gemm.cl" },
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +0000282 { "gemm_mm_floating_point_f16_bifrost_acc32", "gemm.cl" },
Anton Lokhmotov3e80c7f2017-11-20 11:02:10 +0000283 { "gemm_mm_floating_point_f32_bifrost", "gemm.cl" },
284 { "gemm_mm_floating_point_f32_bifrost_1000", "gemm.cl" },
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000285 { "gemm_mm_reshaped_lhs_nt_rhs_t", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100286 { "gemm_lc_vm_f32", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000287 { "gemm_transpose1xW", "gemm.cl" },
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000288 { "gemm_reshape_lhs_matrix_nt", "gemm.cl" },
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000289 { "gemm_reshape_lhs_matrix_t", "gemm.cl" },
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000290 { "gemm_reshape_rhs_matrix_nt", "gemm.cl" },
291 { "gemm_reshape_rhs_matrix_t", "gemm.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000292 { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100293 { "gemmlowp_matrix_a_reduction_dot8", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000294 { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000295 { "gemmlowp_mm_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100296 { "gemmlowp_mm_bifrost_dot8", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000297 { "gemmlowp_mm_midgard", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000298 { "gemmlowp_mm_interleaved_transposed_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100299 { "gemmlowp_mm_interleaved_transposed_bifrost_dot8", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000300 { "gemmlowp_mm_interleaved_transposed_midgard", "gemmlowp.cl" },
Gian Marco Iodicedb63b9c2019-01-17 09:47:04 +0000301 { "gemmlowp_mm_reshaped_lhs_nt_rhs_t", "gemmlowp.cl" },
302 { "gemmlowp_mm_reshaped_lhs_nt_rhs_t_dot8", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000303 { "gemmlowp_offset_contribution", "gemmlowp.cl" },
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100304 { "gemmlowp_offset_contribution_quantize_down", "gemmlowp.cl" },
305 { "gemmlowp_offset_contribution_quantize_down_fixedpoint", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000306 { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
Gian Marco58c57942017-11-28 09:10:03 +0000307 { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
Georgios Pinitas51e53a32018-10-22 13:49:08 +0100308 { "gemmlowp_output_stage_quantize_down_float", "gemmlowp.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100309 { "harris_score_3x3", "harris_corners.cl" },
310 { "harris_score_5x5", "harris_corners.cl" },
311 { "harris_score_7x7", "harris_corners.cl" },
312 { "hist_border_kernel", "histogram.cl" },
313 { "hist_border_kernel_fixed", "histogram.cl" },
314 { "hist_local_kernel", "histogram.cl" },
315 { "hist_local_kernel_fixed", "histogram.cl" },
316 { "hog_block_normalization", "hog.cl" },
317 { "hog_detector", "hog.cl" },
318 { "hog_orientation_binning", "hog.cl" },
319 { "hysteresis", "canny.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100320 { "im2col1x1_stridex1_nchw", "im2col.cl" },
321 { "im2col3x3_nchw", "im2col.cl" },
322 { "im2col5x5_nchw", "im2col.cl" },
323 { "im2col11x11_padx0_pady0_nchw", "im2col.cl" },
324 { "im2col_generic_nchw", "im2col.cl" },
325 { "im2col_generic_padx0_pady0_nchw", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100326 { "im2col3x3_nhwc", "im2col.cl" },
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000327 { "im2col9x9_nhwc", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100328 { "im2col_generic_nhwc", "im2col.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100329 { "init_level", "optical_flow_pyramid_lk.cl" },
330 { "init_level_max", "optical_flow_pyramid_lk.cl" },
331 { "init_level_max_initial_estimate", "optical_flow_pyramid_lk.cl" },
332 { "integral_horizontal", "integral_image.cl" },
333 { "integral_vertical", "integral_image.cl" },
334 { "IYUV_to_NV12_bt709", "color_convert.cl" },
335 { "IYUV_to_RGB888_bt709", "color_convert.cl" },
336 { "IYUV_to_RGBA8888_bt709", "color_convert.cl" },
337 { "IYUV_to_YUV444_bt709", "color_convert.cl" },
Michalis Spyrou5538d342018-11-14 08:10:13 +0000338 { "l2_normalize_x", "l2_normalize.cl" },
339 { "l2_normalize_y", "l2_normalize.cl" },
340 { "l2_normalize_z", "l2_normalize.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100341 { "lktracker_stage0", "optical_flow_pyramid_lk.cl" },
342 { "lktracker_stage1", "optical_flow_pyramid_lk.cl" },
343 { "magnitude_phase", "magnitude_phase.cl" },
344 { "mean_stddev_accumulate", "mean_stddev.cl" },
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100345 { "memset", "memset.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100346 { "minmax", "minmaxloc.cl" },
347 { "minmax_border", "minmaxloc.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100348 { "minmax_layer", "minmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100349 { "minmaxloc", "minmaxloc.cl" },
350 { "non_linear_filter_box3x3", "non_linear_filter3x3.cl" },
351 { "non_linear_filter_cross3x3", "non_linear_filter3x3.cl" },
352 { "non_linear_filter_disk3x3", "non_linear_filter3x3.cl" },
353 { "non_linear_filter_box5x5", "non_linear_filter5x5.cl" },
354 { "non_linear_filter_cross5x5", "non_linear_filter5x5.cl" },
355 { "non_linear_filter_disk5x5", "non_linear_filter5x5.cl" },
356 { "non_max_suppression", "nonmax.cl" },
357 { "normalization_layer_cross_map", "normalization_layer.cl" },
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +0000358 { "normalization_layer_in_map_nchw", "normalization_layer.cl" },
359 { "normalization_layer_in_map_nhwc", "normalization_layer.cl" },
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100360 { "normalize_planar_yuv_layer_nchw", "normalize_planar_yuv_layer.cl" },
361 { "normalize_planar_yuv_layer_nhwc", "normalize_planar_yuv_layer.cl" },
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100362 { "normalize_planar_yuv_layer_q8_nchw", "normalize_planar_yuv_layer_quantized.cl" },
363 { "normalize_planar_yuv_layer_q8_nhwc", "normalize_planar_yuv_layer_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100364 { "NV12_to_IYUV_bt709", "color_convert.cl" },
365 { "NV12_to_RGB888_bt709", "color_convert.cl" },
366 { "NV12_to_RGBA8888_bt709", "color_convert.cl" },
367 { "NV12_to_YUV444_bt709", "color_convert.cl" },
368 { "NV21_to_IYUV_bt709", "color_convert.cl" },
369 { "NV21_to_RGB888_bt709", "color_convert.cl" },
370 { "NV21_to_RGBA8888_bt709", "color_convert.cl" },
371 { "NV21_to_YUV444_bt709", "color_convert.cl" },
Giorgio Arenaa086a0a2018-02-16 12:42:16 +0000372 { "output_stage_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
shubhame1a4e372019-01-07 21:37:55 +0530373 { "permute", "permute.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100374 { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
375 { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100376 { "pixelwise_mul_quantized", "pixelwise_mul_int.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100377 { "pooling_layer_2", "pooling_layer.cl" },
378 { "pooling_layer_3", "pooling_layer.cl" },
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000379 { "pooling_layer_optimized_3", "pooling_layer.cl" },
Georgios Pinitasce093142017-06-19 16:11:53 +0100380 { "pooling_layer_7", "pooling_layer.cl" },
Michalis Spyroue74b2012018-04-18 09:49:16 +0100381 { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
382 { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
383 { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
384 { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100385 { "prior_box_layer_nchw", "prior_box_layer.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100386 { "quantization_layer", "quantization_layer.cl" },
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +0000387 { "range", "range.cl" },
388 { "range_quantized", "range.cl" },
Michalis Spyrou7e9391b2018-10-05 14:49:28 +0100389 { "reduction_operation_x", "reduction_operation.cl" },
Michalis Spyrou7930db42018-11-22 17:36:28 +0000390 { "reduction_operation_non_parallel_x", "reduction_operation.cl" },
Michalis Spyrou7e9391b2018-10-05 14:49:28 +0100391 { "reduction_operation_y", "reduction_operation.cl" },
392 { "reduction_operation_z", "reduction_operation.cl" },
393 { "reduction_operation_w", "reduction_operation.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100394 { "remap_nearest_neighbour", "remap.cl" },
395 { "remap_bilinear", "remap.cl" },
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100396 { "reorg_layer_nchw", "reorg_layer.cl" },
397 { "reorg_layer_nhwc", "reorg_layer.cl" },
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100398 { "reshape_layer", "reshape_layer.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100399 { "reshape_to_columns", "convolution_layer.cl" },
Michele Di Giorgio5daeffd2018-11-26 10:01:15 +0000400 { "reverse", "reverse.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100401 { "RGB888_to_IYUV_bt709", "color_convert.cl" },
402 { "RGB888_to_NV12_bt709", "color_convert.cl" },
403 { "RGB888_to_RGBA8888_bt709", "color_convert.cl" },
Manuel Bottiniacaf21d2018-09-26 17:38:19 +0100404 { "RGB888_to_U8_bt709", "color_convert.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100405 { "RGB888_to_YUV444_bt709", "color_convert.cl" },
406 { "RGBA8888_to_IYUV_bt709", "color_convert.cl" },
407 { "RGBA8888_to_NV12_bt709", "color_convert.cl" },
408 { "RGBA8888_to_RGB888_bt709", "color_convert.cl" },
409 { "RGBA8888_to_YUV444_bt709", "color_convert.cl" },
giuros0118870812018-09-13 09:31:40 +0100410 { "roi_align_layer", "roi_align_layer.cl" },
SiCong Li3e363692017-07-04 15:02:10 +0100411 { "roi_pooling_layer", "roi_pooling_layer.cl" },
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100412 { "scale_nearest_neighbour_nchw", "scale.cl" },
413 { "scale_nearest_neighbour_nhwc", "scale.cl" },
414 { "scale_bilinear_nchw", "scale.cl" },
415 { "scale_bilinear_nhwc", "scale.cl" },
Michalis Spyrou17220e22018-09-12 13:35:38 +0100416 { "scale_bilinear_quantized_nchw", "scale_quantized.cl" },
417 { "scale_bilinear_quantized_nhwc", "scale_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100418 { "scharr3x3", "scharr_filter.cl" },
Georgios Pinitasaaa27182018-11-21 16:32:15 +0000419 { "select_same_rank", "select.cl" },
420 { "select_different_rank_2", "select.cl" },
421 { "select_different_rank_n", "select.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100422 { "sobel3x3", "sobel_filter.cl" },
423 { "sobel_separable5x1", "sobel_filter.cl" },
424 { "sobel_separable1x5", "sobel_filter.cl" },
425 { "sobel_separable7x1", "sobel_filter.cl" },
426 { "sobel_separable1x7", "sobel_filter.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100427 { "softmax_layer_norm", "softmax_layer.cl" },
Chunosovf450caa2017-11-08 16:09:35 +0700428 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
Giorgio Arena4402cb92018-02-15 13:37:40 +0000429 { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
430 { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700431 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100432 { "space_to_batch_nchw", "space_to_batch.cl" },
433 { "space_to_batch_static_nchw", "space_to_batch.cl" },
434 { "space_to_batch_nhwc", "space_to_batch.cl" },
435 { "space_to_batch_static_nhwc", "space_to_batch.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700436 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000437 { "stack_layer", "stack_layer.cl" },
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100438 { "strided_slice", "slice_ops.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100439 { "suppress_non_maximum", "canny.cl" },
440 { "tablelookup_U8", "tablelookup.cl" },
441 { "tablelookup_S16", "tablelookup.cl" },
442 { "threshold_binary", "threshold.cl" },
443 { "threshold_range", "threshold.cl" },
giuros013175fcf2018-11-21 09:59:17 +0000444 { "tile", "tile.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100445 { "transpose", "transpose.cl" },
446 { "UYVY422_to_IYUV_bt709", "color_convert.cl" },
447 { "UYVY422_to_NV12_bt709", "color_convert.cl" },
448 { "UYVY422_to_RGB888_bt709", "color_convert.cl" },
449 { "UYVY422_to_RGBA8888_bt709", "color_convert.cl" },
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100450 { "upsample_layer_nchw", "upsample_layer.cl" },
451 { "upsample_layer_nhwc", "upsample_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100452 { "warp_affine_nearest_neighbour", "warp_affine.cl" },
453 { "warp_affine_bilinear", "warp_affine.cl" },
454 { "warp_perspective_nearest_neighbour", "warp_perspective.cl" },
455 { "warp_perspective_bilinear", "warp_perspective.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100456 { "winograd_filter_transform_2x2_3x3_nchw", "winograd_filter_transform.cl" },
457 { "winograd_filter_transform_2x1_3x1_nchw", "winograd_filter_transform.cl" },
458 { "winograd_filter_transform_1x2_1x3_nchw", "winograd_filter_transform.cl" },
459 { "winograd_filter_transform_4x4_3x3_nchw", "winograd_filter_transform.cl" },
460 { "winograd_filter_transform_4x1_3x1_nchw", "winograd_filter_transform.cl" },
461 { "winograd_filter_transform_1x4_1x3_nchw", "winograd_filter_transform.cl" },
462 { "winograd_filter_transform_4x4_5x5_nchw", "winograd_filter_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100463 { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
464 { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100465 { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
466 { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100467 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
468 { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100469 { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
470 { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100471 { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd_input_transform.cl" },
472 { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd_input_transform.cl" },
473 { "winograd_input_transform_2x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
474 { "winograd_input_transform_2x1_3x1_stepz2_nchw", "winograd_input_transform.cl" },
475 { "winograd_input_transform_1x2_1x3_stepz1_nchw", "winograd_input_transform.cl" },
476 { "winograd_input_transform_1x2_1x3_stepz2_nchw", "winograd_input_transform.cl" },
477 { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd_input_transform.cl" },
478 { "winograd_input_transform_4x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
479 { "winograd_input_transform_1x4_1x3_stepz1_nchw", "winograd_input_transform.cl" },
480 { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd_input_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100481 { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
482 { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100483 { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
484 { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100485 { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
486 { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100487 { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
488 { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100489 { "winograd_output_transform_2x2_3x3_nchw", "winograd_output_transform.cl" },
490 { "winograd_output_transform_2x1_3x1_nchw", "winograd_output_transform.cl" },
491 { "winograd_output_transform_1x2_1x3_nchw", "winograd_output_transform.cl" },
492 { "winograd_output_transform_4x4_3x3_nchw", "winograd_output_transform.cl" },
493 { "winograd_output_transform_4x1_3x1_nchw", "winograd_output_transform.cl" },
494 { "winograd_output_transform_1x4_1x3_nchw", "winograd_output_transform.cl" },
495 { "winograd_output_transform_4x4_5x5_nchw", "winograd_output_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100496 { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
497 { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100498 { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
499 { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100500 { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
501 { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100502 { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
503 { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
Giorgio Arena73023022018-09-04 14:55:55 +0100504 { "yolo_layer_nchw", "yolo_layer.cl" },
505 { "yolo_layer_nhwc", "yolo_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100506 { "YUYV422_to_IYUV_bt709", "color_convert.cl" },
507 { "YUYV422_to_NV12_bt709", "color_convert.cl" },
508 { "YUYV422_to_RGB888_bt709", "color_convert.cl" },
509 { "YUYV422_to_RGBA8888_bt709", "color_convert.cl" },
510};
511
512const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
513{
514#ifdef EMBEDDED_KERNELS
515 {
516 "absdiff.cl",
517#include "./cl_kernels/absdiff.clembed"
518 },
519 {
520 "accumulate.cl",
521#include "./cl_kernels/accumulate.clembed"
522 },
523 {
524 "activation_layer.cl",
525#include "./cl_kernels/activation_layer.clembed"
526 },
527 {
Michel Iwaniec00633802017-10-12 14:14:15 +0100528 "activation_layer_qa8.cl",
529#include "./cl_kernels/activation_layer_qa8.clembed"
530 },
531 {
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100532 "batch_to_space.cl",
533#include "./cl_kernels/batch_to_space.clembed"
534 },
535 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100536 "bitwise_op.cl",
537#include "./cl_kernels/bitwise_op.clembed"
538 },
539 {
giuros01c04a0e82018-10-03 12:44:35 +0100540 "bounding_box_transform.cl",
541#include "./cl_kernels/bounding_box_transform.clembed"
542 },
543 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100544 "canny.cl",
545#include "./cl_kernels/canny.clembed"
546 },
547 {
548 "channel_combine.cl",
549#include "./cl_kernels/channel_combine.clembed"
550 },
551 {
552 "channel_extract.cl",
553#include "./cl_kernels/channel_extract.clembed"
554 },
555 {
Michele Di Giorgio72175632018-05-01 16:52:00 +0100556 "channel_shuffle.cl",
557#include "./cl_kernels/channel_shuffle.clembed"
558 },
559 {
Gian Marco76faef82018-01-29 12:15:32 +0000560 "col2im.cl",
561#include "./cl_kernels/col2im.clembed"
562 },
563 {
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000564 "comparisons.cl",
565#include "./cl_kernels/comparisons.clembed"
566 },
567 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100568 "concatenate.cl",
569#include "./cl_kernels/concatenate.clembed"
570 },
571 {
572 "color_convert.cl",
573#include "./cl_kernels/color_convert.clembed"
574 },
575 {
Giorgio Arena657bdb32018-04-26 18:52:01 +0100576 "convert_fc_weights.cl",
577#include "./cl_kernels/convert_fc_weights.clembed"
578 },
579 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100580 "convolution3x3.cl",
581#include "./cl_kernels/convolution3x3.clembed"
582 },
583 {
584 "convolution5x5.cl",
585#include "./cl_kernels/convolution5x5.clembed"
586 },
587 {
588 "convolution7x7.cl",
589#include "./cl_kernels/convolution7x7.clembed"
590 },
591 {
592 "convolution9x9.cl",
593#include "./cl_kernels/convolution9x9.clembed"
594 },
595 {
596 "convolution_layer.cl",
597#include "./cl_kernels/convolution_layer.clembed"
598 },
599 {
600 "convolution_rectangle.cl",
601#include "./cl_kernels/convolution_rectangle.clembed"
602 },
603 {
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000604 "copy_tensor.cl",
605#include "./cl_kernels/copy_tensor.clembed"
606 },
607 {
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100608 "upsample_layer.cl",
609#include "./cl_kernels/upsample_layer.clembed"
610 },
611 {
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000612 "deconvolution_layer.cl",
613#include "./cl_kernels/deconvolution_layer.clembed"
614 },
615 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100616 "depth_convert.cl",
617#include "./cl_kernels/depth_convert.clembed"
618 },
619 {
Giorgio Arena93a690e2017-08-01 16:09:33 +0100620 "depthwise_convolution.cl",
621#include "./cl_kernels/depthwise_convolution.clembed"
622 },
623 {
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700624 "depthwise_convolution_quantized.cl",
625#include "./cl_kernels/depthwise_convolution_quantized.clembed"
626 },
627 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100628 "dequantization_layer.cl",
629#include "./cl_kernels/dequantization_layer.clembed"
630 },
631 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100632 "derivative.cl",
633#include "./cl_kernels/derivative.clembed"
634 },
635 {
636 "dilate.cl",
637#include "./cl_kernels/dilate.clembed"
638 },
639 {
SiCong Lic51b72f2017-07-28 14:46:20 +0100640 "direct_convolution1x1.cl",
641#include "./cl_kernels/direct_convolution1x1.clembed"
642 },
643 {
644 "direct_convolution3x3.cl",
645#include "./cl_kernels/direct_convolution3x3.clembed"
steniu0127b386c2017-07-18 17:37:43 +0100646 },
647 {
steniu01db006682017-08-09 16:26:22 +0100648 "direct_convolution5x5.cl",
649#include "./cl_kernels/direct_convolution5x5.clembed"
650 },
651 {
Chunosovd621bca2017-11-03 17:33:15 +0700652 "direct_convolution_1x1_3x3_5x5_quantized.cl",
653#include "./cl_kernels/direct_convolution_1x1_3x3_5x5_quantized.clembed"
654 },
655 {
giuros01164a2722018-11-20 18:34:46 +0000656 "elementwise_operation.cl",
657#include "./cl_kernels/elementwise_operation.clembed"
658 },
659 {
660 "elementwise_operation_quantized.cl",
661#include "./cl_kernels/elementwise_operation_quantized.clembed"
662 },
663 {
Michalis Spyroue9362622018-11-23 17:41:37 +0000664 "elementwise_unary.cl",
665#include "./cl_kernels/elementwise_unary.clembed"
666 },
667 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100668 "erode.cl",
669#include "./cl_kernels/erode.clembed"
670 },
671 {
672 "fast_corners.cl",
673#include "./cl_kernels/fast_corners.clembed"
674 },
675 {
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100676 "flatten.cl",
677#include "./cl_kernels/flatten.clembed"
678 },
679 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100680 "fill_border.cl",
681#include "./cl_kernels/fill_border.clembed"
682 },
683 {
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100684 "floor.cl",
685#include "./cl_kernels/floor.clembed"
686 },
687 {
Manuel Bottini8529bd62018-11-21 11:53:04 +0000688 "gather.cl",
689#include "./cl_kernels/gather.clembed"
690 },
691 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100692 "gaussian_pyramid.cl",
693#include "./cl_kernels/gaussian_pyramid.clembed"
694 },
695 {
696 "gemm.cl",
697#include "./cl_kernels/gemm.clembed"
698 },
699 {
Gian Marco05288a22017-11-21 10:57:50 +0000700 "gemmlowp.cl",
701#include "./cl_kernels/gemmlowp.clembed"
702 },
703 {
Giorgio Arena9fe41442017-08-23 16:36:24 +0100704 "gemv.cl",
705#include "./cl_kernels/gemv.clembed"
706 },
707 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100708 "harris_corners.cl",
709#include "./cl_kernels/harris_corners.clembed"
710 },
711 {
712 "helpers.h",
713#include "./cl_kernels/helpers.hembed"
714 },
715 {
Chunosovd621bca2017-11-03 17:33:15 +0700716 "helpers_asymm.h",
717#include "./cl_kernels/helpers_asymm.hembed"
718 },
719 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100720 "histogram.cl",
721#include "./cl_kernels/histogram.clembed"
722 },
723 {
724 "hog.cl",
725#include "./cl_kernels/hog.clembed"
726 },
727 {
Gian Marco76faef82018-01-29 12:15:32 +0000728 "im2col.cl",
729#include "./cl_kernels/im2col.clembed"
730 },
731 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100732 "integral_image.cl",
733#include "./cl_kernels/integral_image.clembed"
734 },
735 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100736 "l2_normalize.cl",
737#include "./cl_kernels/l2_normalize.clembed"
738 },
739 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100740 "magnitude_phase.cl",
741#include "./cl_kernels/magnitude_phase.clembed"
742 },
743 {
744 "mean_stddev.cl",
745#include "./cl_kernels/mean_stddev.clembed"
746 },
747 {
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100748 "memset.cl",
749#include "./cl_kernels/memset.clembed"
750 },
751 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100752 "minmaxloc.cl",
753#include "./cl_kernels/minmaxloc.clembed"
754 },
755 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100756 "minmax_layer.cl",
757#include "./cl_kernels/minmax_layer.clembed"
758 },
759 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100760 "non_linear_filter3x3.cl",
761#include "./cl_kernels/non_linear_filter3x3.clembed"
762 },
763 {
764 "non_linear_filter5x5.cl",
765#include "./cl_kernels/non_linear_filter5x5.clembed"
766 },
767 {
768 "non_linear_filter_helpers.h",
769#include "./cl_kernels/non_linear_filter_helpers.hembed"
770 },
771 {
772 "nonmax.cl",
773#include "./cl_kernels/nonmax.clembed"
774 },
775 {
776 "normalization_layer.cl",
777#include "./cl_kernels/normalization_layer.clembed"
778 },
779 {
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100780 "normalize_planar_yuv_layer.cl",
781#include "./cl_kernels/normalize_planar_yuv_layer.clembed"
782 },
783 {
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100784 "normalize_planar_yuv_layer_quantized.cl",
785#include "./cl_kernels/normalize_planar_yuv_layer_quantized.clembed"
786 },
787 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100788 "batchnormalization_layer.cl",
789#include "./cl_kernels/batchnormalization_layer.clembed"
790 },
791 {
792 "optical_flow_pyramid_lk.cl",
793#include "./cl_kernels/optical_flow_pyramid_lk.clembed"
794 },
795 {
Michalis Spyrou5237e012018-01-17 09:40:27 +0000796 "permute.cl",
797#include "./cl_kernels/permute.clembed"
798 },
799 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100800 "pixelwise_mul_float.cl",
801#include "./cl_kernels/pixelwise_mul_float.clembed"
802 },
803 {
804 "pixelwise_mul_int.cl",
805#include "./cl_kernels/pixelwise_mul_int.clembed"
806 },
807 {
808 "pooling_layer.cl",
809#include "./cl_kernels/pooling_layer.clembed"
810 },
811 {
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000812 "pooling_layer_quantized.cl",
813#include "./cl_kernels/pooling_layer_quantized.clembed"
814 },
815 {
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100816 "prior_box_layer.cl",
817#include "./cl_kernels/prior_box_layer.clembed"
818 },
819 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100820 "quantization_layer.cl",
821#include "./cl_kernels/quantization_layer.clembed"
822 },
823 {
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +0000824 "range.cl",
825#include "./cl_kernels/range.clembed"
826 },
827 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100828 "reduction_operation.cl",
829#include "./cl_kernels/reduction_operation.clembed"
830 },
831 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100832 "remap.cl",
833#include "./cl_kernels/remap.clembed"
834 },
835 {
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100836 "reorg_layer.cl",
837#include "./cl_kernels/reorg_layer.clembed"
838 },
839 {
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100840 "reshape_layer.cl",
841#include "./cl_kernels/reshape_layer.clembed"
842 },
843 {
Michele Di Giorgio5daeffd2018-11-26 10:01:15 +0000844 "reverse.cl",
845#include "./cl_kernels/reverse.clembed"
846 },
847 {
giuros0118870812018-09-13 09:31:40 +0100848 "roi_align_layer.cl",
849#include "./cl_kernels/roi_align_layer.clembed"
850 },
851 {
SiCong Li3e363692017-07-04 15:02:10 +0100852 "roi_pooling_layer.cl",
853#include "./cl_kernels/roi_pooling_layer.clembed"
854 },
855 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100856 "scale.cl",
857#include "./cl_kernels/scale.clembed"
858 },
859 {
Michalis Spyrou17220e22018-09-12 13:35:38 +0100860 "scale_quantized.cl",
861#include "./cl_kernels/scale_quantized.clembed"
862 },
863 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100864 "scharr_filter.cl",
865#include "./cl_kernels/scharr_filter.clembed"
866 },
867 {
Georgios Pinitasaaa27182018-11-21 16:32:15 +0000868 "select.cl",
869#include "./cl_kernels/select.clembed"
870 },
871 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100872 "sobel_filter.cl",
873#include "./cl_kernels/sobel_filter.clembed"
874 },
875 {
876 "softmax_layer.cl",
877#include "./cl_kernels/softmax_layer.clembed"
878 },
879 {
Chunosovf450caa2017-11-08 16:09:35 +0700880 "softmax_layer_quantized.cl",
881#include "./cl_kernels/softmax_layer_quantized.clembed"
882 },
883 {
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100884 "slice_ops.cl",
885#include "./cl_kernels/slice_ops.clembed"
Georgios Pinitas77589b52018-08-21 14:41:35 +0100886 },
887 {
Michalis Spyrou16934a52018-08-21 18:03:58 +0100888 "space_to_batch.cl",
889#include "./cl_kernels/space_to_batch.clembed"
890 },
891 {
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000892 "stack_layer.cl",
893#include "./cl_kernels/stack_layer.clembed"
894 },
895 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100896 "tablelookup.cl",
897#include "./cl_kernels/tablelookup.clembed"
898 },
899 {
900 "threshold.cl",
901#include "./cl_kernels/threshold.clembed"
902 },
903 {
giuros013175fcf2018-11-21 09:59:17 +0000904 "tile.cl",
905#include "./cl_kernels/tile.clembed"
906 },
907 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100908 "transpose.cl",
909#include "./cl_kernels/transpose.clembed"
910 },
911 {
912 "types.h",
913#include "./cl_kernels/types.hembed"
914 },
915 {
916 "warp_affine.cl",
917#include "./cl_kernels/warp_affine.clembed"
918 },
919 {
920 "warp_helpers.h",
921#include "./cl_kernels/warp_helpers.hembed"
922 },
923 {
924 "warp_perspective.cl",
925#include "./cl_kernels/warp_perspective.clembed"
Michalis Spyroud7e82812017-06-20 15:00:14 +0100926 },
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000927 {
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100928 "winograd_filter_transform.cl",
929#include "./cl_kernels/winograd_filter_transform.clembed"
930 },
931 {
932 "winograd_input_transform.cl",
933#include "./cl_kernels/winograd_input_transform.clembed"
934 },
935 {
936 "winograd_output_transform.cl",
937#include "./cl_kernels/winograd_output_transform.clembed"
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000938 },
Giorgio Arena73023022018-09-04 14:55:55 +0100939 {
940 "yolo_layer.cl",
941#include "./cl_kernels/yolo_layer.clembed"
942 },
Anthony Barbierac69aa12017-07-03 17:39:37 +0100943#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100944};
945
946CLKernelLibrary::CLKernelLibrary()
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100947 : _context(), _device(), _kernel_path("."), _programs_map(), _built_programs_map()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100948{
Anthony Barbierecb1c622018-04-17 11:45:10 +0100949 opencl_is_available(); // Make sure the OpenCL symbols are initialised *before* the CLKernelLibrary is built
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100950}
951
952CLKernelLibrary &CLKernelLibrary::get()
953{
954 static CLKernelLibrary _kernel_library;
955 return _kernel_library;
956}
957
958Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const StringSet &build_options_set) const
959{
960 // Find which program contains the kernel
961 auto kernel_program_it = _kernel_program_map.find(kernel_name);
962
963 if(_kernel_program_map.end() == kernel_program_it)
964 {
965 ARM_COMPUTE_ERROR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
966 }
steniu0134702472017-07-11 09:22:58 +0100967 std::string concat_str;
968
Georgios Pinitasdf473ea2018-05-31 18:53:52 +0100969#if defined(ARM_COMPUTE_DEBUG_ENABLED)
970 // Enable debug properties in CL kernels
971 concat_str += " -DARM_COMPUTE_DEBUG_ENABLED";
972#endif // defined(ARM_COMPUTE_DEBUG_ENABLED)
973
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100974 if(fp16_supported())
Matthew Bentham6f31f8c2017-10-27 11:50:06 +0100975 {
976 concat_str += " -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 ";
977 }
978
Michalis Spyroue03342e2018-01-15 14:39:13 +0000979 if(dot8_supported(_device))
980 {
981 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ENABLED=1 ";
982 }
983
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100984 if(dot8_acc_supported(_device))
985 {
986 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED=1 ";
987 }
988
Pablo Telloe86a09f2018-01-11 15:44:48 +0000989 if(get_cl_version(_device) == CLVersion::CL20)
steniu0134702472017-07-11 09:22:58 +0100990 {
991 concat_str += " -cl-std=CL2.0 ";
992 }
Anthony Barbierd727e852018-04-20 11:05:29 +0100993 else if(arm_non_uniform_workgroup_supported(_device))
Pablo Telloe86a09f2018-01-11 15:44:48 +0000994 {
995 concat_str += " -cl-arm-non-uniform-work-group-size ";
996 }
steniu0134702472017-07-11 09:22:58 +0100997 else
998 {
999 ARM_COMPUTE_ERROR("Non uniform workgroup size is not supported!!");
1000 }
1001
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001002 // Check if the program has been built before with same build options.
steniu0134702472017-07-11 09:22:58 +01001003 const std::string program_name = kernel_program_it->second;
1004 const std::string build_options = stringify_set(build_options_set) + concat_str;
1005
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001006 const std::string built_program_name = program_name + "_" + build_options;
1007 auto built_program_it = _built_programs_map.find(built_program_name);
1008
1009 cl::Program cl_program;
1010
1011 if(_built_programs_map.end() != built_program_it)
1012 {
1013 // If program has been built, retrieve to create kernel from it
1014 cl_program = built_program_it->second;
1015 }
1016 else
1017 {
1018 // Get program
1019 Program program = load_program(program_name);
1020
1021 // Build program
1022 cl_program = program.build(build_options);
1023
1024 // Add built program to internal map
1025 _built_programs_map.emplace(built_program_name, cl_program);
1026 }
1027
1028 // Create and return kernel
1029 return Kernel(kernel_name, cl_program);
1030}
1031
Anthony Barbier7da55aa2018-04-13 16:58:43 +01001032void CLKernelLibrary::add_built_program(const std::string &built_program_name, cl::Program program)
1033{
1034 _built_programs_map.emplace(built_program_name, program);
1035}
1036
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +01001037bool CLKernelLibrary::fp16_supported() const
1038{
1039 return ::fp16_supported(_device);
1040}
1041
Vidhya Sudhan Loganathan76c85642018-05-25 13:53:02 +01001042bool CLKernelLibrary::int64_base_atomics_supported() const
1043{
1044 return device_supports_extension(_device, "cl_khr_int64_base_atomics");
1045}
1046
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001047const Program &CLKernelLibrary::load_program(const std::string &program_name) const
1048{
1049 const auto program_it = _programs_map.find(program_name);
1050
1051 if(program_it != _programs_map.end())
1052 {
1053 return program_it->second;
1054 }
1055
1056 Program program;
1057
1058#ifdef EMBEDDED_KERNELS
1059 const auto program_source_it = _program_source_map.find(program_name);
1060
1061 if(_program_source_map.end() == program_source_it)
1062 {
1063 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
1064 }
1065
1066 program = Program(_context, program_name, program_source_it->second);
Anthony Barbierac69aa12017-07-03 17:39:37 +01001067#else /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001068 // Check for binary
1069 std::string source_name = _kernel_path + program_name;
1070 std::string binary_name = source_name + "bin";
1071
1072 if(std::ifstream(binary_name).is_open())
1073 {
1074 const std::string program_binary = read_file(binary_name, true);
1075 program = Program(_context, _device, program_name, std::vector<unsigned char>(program_binary.begin(), program_binary.end()));
1076 }
1077 else if(std::ifstream(source_name).is_open())
1078 {
1079 program = Program(_context, program_name, read_file(source_name, false));
1080 }
1081 else
1082 {
1083 ARM_COMPUTE_ERROR("Kernel file %s does not exist.", source_name.c_str());
1084 }
Anthony Barbierac69aa12017-07-03 17:39:37 +01001085#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001086
1087 // Insert program to program map
1088 const auto new_program = _programs_map.emplace(program_name, std::move(program));
1089
1090 return new_program.first->second;
1091}
1092
1093std::string CLKernelLibrary::stringify_set(const StringSet &s) const
1094{
steniu0134702472017-07-11 09:22:58 +01001095 std::string concat_set;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001096
1097#ifndef EMBEDDED_KERNELS
1098 concat_set += "-I" + _kernel_path + " ";
1099#endif /* EMBEDDED_KERNELS */
1100
1101 // Concatenate set
1102 for(const auto &el : s)
1103 {
1104 concat_set += " " + el;
1105 }
1106
1107 return concat_set;
1108}
Michalis Spyroud7e82812017-06-20 15:00:14 +01001109
1110std::string CLKernelLibrary::get_program_source(const std::string &program_name)
1111{
1112 const auto program_source_it = _program_source_map.find(program_name);
1113
1114 if(program_source_it == _program_source_map.end())
1115 {
1116 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
1117 }
1118
1119 return program_source_it->second;
1120}
steniu015f910722017-08-23 10:15:22 +01001121
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001122size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const
steniu015f910722017-08-23 10:15:22 +01001123{
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001124 size_t result;
steniu015f910722017-08-23 10:15:22 +01001125
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001126 size_t err = kernel.getWorkGroupInfo(_device, CL_KERNEL_WORK_GROUP_SIZE, &result);
1127 ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel");
1128 ARM_COMPUTE_UNUSED(err);
1129
1130 return result;
steniu015f910722017-08-23 10:15:22 +01001131}
1132
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001133cl::NDRange CLKernelLibrary::default_ndrange() const
steniu015f910722017-08-23 10:15:22 +01001134{
Anthony Barbierb6eb3532018-08-08 13:20:04 +01001135 GPUTarget _target = get_target_from_device(_device);
Michalis Spyroua9676112018-02-22 18:07:43 +00001136 cl::NDRange default_range;
1137
1138 switch(_target)
1139 {
1140 case GPUTarget::MIDGARD:
1141 case GPUTarget::T600:
1142 case GPUTarget::T700:
1143 case GPUTarget::T800:
1144 default_range = cl::NDRange(128u, 1);
1145 break;
1146 default:
1147 default_range = cl::NullRange;
1148 }
1149
1150 return default_range;
steniu015f910722017-08-23 10:15:22 +01001151}
Anthony Barbier847864d2018-03-07 11:35:53 +00001152
1153std::string CLKernelLibrary::get_device_version()
1154{
1155 return _device.getInfo<CL_DEVICE_VERSION>();
1156}