blob: a86d8d0414195399fec22be4d8f578436573fe6a [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" },
Michele Di Giorgioe5bf4c52019-02-14 17:47:33 +0000152 { "activation_layer_logistic_qa8", "activation_layer_qa8.cl" },
Michalis Spyrouf1addb62018-09-11 11:16:47 +0100153 { "batch_to_space_nchw", "batch_to_space.cl" },
154 { "batch_to_space_static_nchw", "batch_to_space.cl" },
155 { "batch_to_space_nhwc", "batch_to_space.cl" },
156 { "batch_to_space_static_nhwc", "batch_to_space.cl" },
Michele Di Giorgiobf3c6622018-03-08 11:52:27 +0000157 { "batchnormalization_layer_nchw", "batchnormalization_layer.cl" },
158 { "batchnormalization_layer_nhwc", "batchnormalization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100159 { "bitwise_or", "bitwise_op.cl" },
160 { "bitwise_and", "bitwise_op.cl" },
161 { "bitwise_xor", "bitwise_op.cl" },
162 { "bitwise_not", "bitwise_op.cl" },
giuros01c04a0e82018-10-03 12:44:35 +0100163 { "bounding_box_transform", "bounding_box_transform.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100164 { "channel_combine_NV", "channel_combine.cl" },
165 { "channel_combine_RGB888", "channel_combine.cl" },
166 { "channel_combine_RGBA8888", "channel_combine.cl" },
167 { "channel_combine_UYVY422", "channel_combine.cl" },
168 { "channel_combine_YUYV422", "channel_combine.cl" },
Michele Di Giorgio72175632018-05-01 16:52:00 +0100169 { "channel_shuffle_nchw", "channel_shuffle.cl" },
Gian Marco Iodice8bab0ee2018-09-13 11:51:56 +0100170 { "channel_shuffle_nhwc", "channel_shuffle.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100171 { "channel_extract_NV12", "channel_extract.cl" },
172 { "channel_extract_NV21", "channel_extract.cl" },
173 { "channel_extract_RGB888", "channel_extract.cl" },
174 { "channel_extract_RGBA8888", "channel_extract.cl" },
175 { "channel_extract_UYVY422", "channel_extract.cl" },
176 { "channel_extract_YUYV422", "channel_extract.cl" },
177 { "combine_gradients_L1", "canny.cl" },
178 { "combine_gradients_L2", "canny.cl" },
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000179 { "compare_equal", "comparisons.cl" },
180 { "compare_equal_quantized", "comparisons.cl" },
181 { "compare_notequal", "comparisons.cl" },
182 { "compare_notequal_quantized", "comparisons.cl" },
183 { "compare_greater", "comparisons.cl" },
184 { "compare_greater_quantized", "comparisons.cl" },
185 { "compare_greaterequal", "comparisons.cl" },
186 { "compare_greaterequal_quantized", "comparisons.cl" },
187 { "compare_less", "comparisons.cl" },
188 { "compare_less_quantized", "comparisons.cl" },
189 { "compare_lessequal", "comparisons.cl" },
190 { "compare_lessequal_quantized", "comparisons.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100191 { "concatenate_depth", "concatenate.cl" },
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100192 { "concatenate_width", "concatenate.cl" },
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000193 { "concatenate_width_x2", "concatenate.cl" },
194 { "concatenate_width_x4", "concatenate.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100195 { "convolution_rectangle", "convolution_rectangle.cl" },
Gian Marco76faef82018-01-29 12:15:32 +0000196 { "col2im", "col2im.cl" },
Giorgio Arena657bdb32018-04-26 18:52:01 +0100197 { "convert_depth_down", "depth_convert.cl" },
198 { "convert_depth_up", "depth_convert.cl" },
199 { "convert_fc_weights", "convert_fc_weights.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100200 { "convolution3x3_static", "convolution3x3.cl" },
201 { "convolution5x5_static", "convolution5x5.cl" },
202 { "convolution7x7_static", "convolution7x7.cl" },
203 { "convolution9x9_static", "convolution9x9.cl" },
204 { "convolution_separable1x5_static", "convolution5x5.cl" },
205 { "convolution_separable5x1_static", "convolution5x5.cl" },
206 { "convolution_separable1x7_static", "convolution7x7.cl" },
207 { "convolution_separable7x1_static", "convolution7x7.cl" },
208 { "convolution_separable1x9_static", "convolution9x9.cl" },
209 { "convolution_separable9x1_static", "convolution9x9.cl" },
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000210 { "copy_tensor", "copy_tensor.cl" },
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100211 { "copy_pad_tensor", "copy_tensor.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100212 { "copy_plane", "channel_extract.cl" },
213 { "copy_planes_3p", "channel_combine.cl" },
214 { "copy_to_keypoint", "fast_corners.cl" },
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000215 { "deconvolution_upsample", "deconvolution_layer.cl" },
Giorgio Arena93a690e2017-08-01 16:09:33 +0100216 { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
Michele Di Giorgio933fe862018-02-19 15:42:12 +0000217 { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
Giorgio Arenad051e972018-06-20 11:46:42 +0100218 { "depthwise_convolution_3x3_nhwc", "depthwise_convolution.cl" },
219 { "depthwise_convolution_3x3_nhwc_stride1", "depthwise_convolution.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000220 { "depthwise_convolution_3x3_quantized_nchw", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100221 { "depthwise_convolution_3x3_quantized_nhwc", "depthwise_convolution_quantized.cl" },
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000222 { "depthwise_convolution_3x3_quantized_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100223 { "depthwise_convolution_3x3_quantized_dot8_nchw", "depthwise_convolution_quantized.cl" },
224 { "depthwise_convolution_3x3_quantized_dot8_nhwc_stride1", "depthwise_convolution_quantized.cl" },
Michele Di Giorgio3ebef322018-02-21 10:02:58 +0000225 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16", "depthwise_convolution.cl" },
226 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16", "depthwise_convolution.cl" },
227 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32", "depthwise_convolution.cl" },
228 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32", "depthwise_convolution.cl" },
giuros016d109962019-01-07 17:47:19 +0000229 { "depthwise_convolution_reshape_weights", "depthwise_convolution.cl" },
230 { "depthwise_convolution_reshape_weights_generic", "depthwise_convolution.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100231 { "depthwise_im2col", "depthwise_convolution.cl" },
232 { "depthwise_vector_to_tensor", "depthwise_convolution.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100233 { "dequantization_layer", "dequantization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100234 { "derivative", "derivative.cl" },
235 { "dilate", "dilate.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100236 { "direct_convolution1x1", "direct_convolution1x1.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100237 { "direct_convolution1x1_nhwc", "direct_convolution1x1.cl" },
Gian Marco Iodice1c8409d2017-09-06 17:24:25 +0100238 { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100239 { "direct_convolution3x3", "direct_convolution3x3.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100240 { "direct_convolution3x3_nhwc", "direct_convolution3x3.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100241 { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
steniu01db006682017-08-09 16:26:22 +0100242 { "direct_convolution5x5", "direct_convolution5x5.cl" },
Pablo Tello3d319462018-06-21 15:13:17 +0100243 { "direct_convolution5x5_nhwc", "direct_convolution5x5.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100244 { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
Chunosovd621bca2017-11-03 17:33:15 +0700245 { "direct_convolution_1x1_3x3_5x5_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
giuros01164a2722018-11-20 18:34:46 +0000246 { "elementwise_operation_ADD", "elementwise_operation.cl" },
247 { "elementwise_operation_SUB", "elementwise_operation.cl" },
248 { "elementwise_operation_MAX", "elementwise_operation.cl" },
249 { "elementwise_operation_MIN", "elementwise_operation.cl" },
250 { "elementwise_operation_DIV", "elementwise_operation.cl" },
251 { "elementwise_operation_SQUARED_DIFF", "elementwise_operation.cl" },
252 { "elementwise_operation_ADD_quantized", "elementwise_operation_quantized.cl" },
253 { "elementwise_operation_SUB_quantized", "elementwise_operation_quantized.cl" },
254 { "elementwise_operation_MAX_quantized", "elementwise_operation_quantized.cl" },
255 { "elementwise_operation_MIN_quantized", "elementwise_operation_quantized.cl" },
256 { "elementwise_operation_DIV_quantized", "elementwise_operation_quantized.cl" },
257 { "elementwise_operation_SQUARED_DIFF_quantized", "elementwise_operation_quantized.cl" },
Michalis Spyroue9362622018-11-23 17:41:37 +0000258 { "elementwise_unary", "elementwise_unary.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100259 { "erode", "erode.cl" },
260 { "fast_corners", "fast_corners.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100261 { "flatten", "flatten.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100262 { "fill_image_borders_constant", "fill_border.cl" },
263 { "fill_image_borders_replicate", "fill_border.cl" },
264 { "finalize", "optical_flow_pyramid_lk.cl" },
Georgios Pinitasc9369172018-09-26 11:25:40 +0100265 { "fuse_batchnormalization_layer", "batchnormalization_layer.cl" },
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100266 { "floor_layer", "floor.cl" },
Manuel Bottini8529bd62018-11-21 11:53:04 +0000267 { "gather", "gather.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100268 { "gaussian1x5_sub_x", "gaussian_pyramid.cl" },
269 { "gaussian5x1_sub_y", "gaussian_pyramid.cl" },
Gian Marco Iodice578ab612017-06-23 09:34:33 +0100270 { "gemm_accumulate_biases", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000271 { "gemm_interleave4x4", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100272 { "gemm_ma_f16", "gemm.cl" },
273 { "gemm_ma_f32", "gemm.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100274 { "gemm_mv", "gemv.cl" },
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +0000275 { "gemm_mv_quantized", "gemv.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100276 { "gemm_mm_interleaved_transposed_f16", "gemm.cl" },
Vidhya Sudhan Loganathan38d93bd2018-11-20 15:38:13 +0000277 { "gemm_mm_interleaved_transposed_f16_acc32", "gemm.cl" },
Gian Marco Iodicebb36a8e2018-04-19 12:05:08 +0100278 { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm.cl" },
279 { "gemm_mm_interleaved_transposed_f32", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100280 { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm.cl" },
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100281 { "gemm_mm_floating_point", "gemm.cl" },
Gian Marco Iodicefd683112018-04-17 09:52:44 +0100282 { "gemm_mm_floating_point_f16_bifrost", "gemm.cl" },
Vidhya Sudhan Loganathana25d16c2018-11-16 11:33:12 +0000283 { "gemm_mm_floating_point_f16_bifrost_acc32", "gemm.cl" },
Anton Lokhmotov3e80c7f2017-11-20 11:02:10 +0000284 { "gemm_mm_floating_point_f32_bifrost", "gemm.cl" },
285 { "gemm_mm_floating_point_f32_bifrost_1000", "gemm.cl" },
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000286 { "gemm_mm_reshaped_lhs_nt_rhs_t", "gemm.cl" },
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000287 { "gemm_mm_reshaped_only_rhs_t", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100288 { "gemm_lc_vm_f32", "gemm.cl" },
Gian Marco36a0a462018-01-12 10:21:40 +0000289 { "gemm_transpose1xW", "gemm.cl" },
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000290 { "gemm_reshape_lhs_matrix_nt", "gemm.cl" },
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000291 { "gemm_reshape_lhs_matrix_t", "gemm.cl" },
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000292 { "gemm_reshape_rhs_matrix_nt", "gemm.cl" },
293 { "gemm_reshape_rhs_matrix_t", "gemm.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000294 { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100295 { "gemmlowp_matrix_a_reduction_dot8", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000296 { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000297 { "gemmlowp_mm_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100298 { "gemmlowp_mm_bifrost_dot8", "gemmlowp.cl" },
Gian Marco7b4d5472018-01-10 15:56:30 +0000299 { "gemmlowp_mm_midgard", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000300 { "gemmlowp_mm_interleaved_transposed_bifrost", "gemmlowp.cl" },
Giorgio Arena6200fa42018-07-06 17:06:36 +0100301 { "gemmlowp_mm_interleaved_transposed_bifrost_dot8", "gemmlowp.cl" },
Gian Marco19835e52018-01-30 13:35:54 +0000302 { "gemmlowp_mm_interleaved_transposed_midgard", "gemmlowp.cl" },
Gian Marco Iodicedb63b9c2019-01-17 09:47:04 +0000303 { "gemmlowp_mm_reshaped_lhs_nt_rhs_t", "gemmlowp.cl" },
304 { "gemmlowp_mm_reshaped_lhs_nt_rhs_t_dot8", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000305 { "gemmlowp_offset_contribution", "gemmlowp.cl" },
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100306 { "gemmlowp_offset_contribution_quantize_down", "gemmlowp.cl" },
307 { "gemmlowp_offset_contribution_quantize_down_fixedpoint", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000308 { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
Gian Marco58c57942017-11-28 09:10:03 +0000309 { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
Georgios Pinitas51e53a32018-10-22 13:49:08 +0100310 { "gemmlowp_output_stage_quantize_down_float", "gemmlowp.cl" },
Manuel Bottini5209be52019-02-13 16:34:56 +0000311 { "generate_proposals_compute_all_anchors", "generate_proposals.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100312 { "harris_score_3x3", "harris_corners.cl" },
313 { "harris_score_5x5", "harris_corners.cl" },
314 { "harris_score_7x7", "harris_corners.cl" },
315 { "hist_border_kernel", "histogram.cl" },
316 { "hist_border_kernel_fixed", "histogram.cl" },
317 { "hist_local_kernel", "histogram.cl" },
318 { "hist_local_kernel_fixed", "histogram.cl" },
319 { "hog_block_normalization", "hog.cl" },
320 { "hog_detector", "hog.cl" },
321 { "hog_orientation_binning", "hog.cl" },
322 { "hysteresis", "canny.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100323 { "im2col1x1_stridex1_nchw", "im2col.cl" },
324 { "im2col3x3_nchw", "im2col.cl" },
325 { "im2col5x5_nchw", "im2col.cl" },
326 { "im2col11x11_padx0_pady0_nchw", "im2col.cl" },
327 { "im2col_generic_nchw", "im2col.cl" },
328 { "im2col_generic_padx0_pady0_nchw", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100329 { "im2col3x3_nhwc", "im2col.cl" },
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000330 { "im2col9x9_nhwc", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100331 { "im2col_generic_nhwc", "im2col.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100332 { "init_level", "optical_flow_pyramid_lk.cl" },
333 { "init_level_max", "optical_flow_pyramid_lk.cl" },
334 { "init_level_max_initial_estimate", "optical_flow_pyramid_lk.cl" },
335 { "integral_horizontal", "integral_image.cl" },
336 { "integral_vertical", "integral_image.cl" },
337 { "IYUV_to_NV12_bt709", "color_convert.cl" },
338 { "IYUV_to_RGB888_bt709", "color_convert.cl" },
339 { "IYUV_to_RGBA8888_bt709", "color_convert.cl" },
340 { "IYUV_to_YUV444_bt709", "color_convert.cl" },
Michalis Spyrou5538d342018-11-14 08:10:13 +0000341 { "l2_normalize_x", "l2_normalize.cl" },
342 { "l2_normalize_y", "l2_normalize.cl" },
343 { "l2_normalize_z", "l2_normalize.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100344 { "lktracker_stage0", "optical_flow_pyramid_lk.cl" },
345 { "lktracker_stage1", "optical_flow_pyramid_lk.cl" },
346 { "magnitude_phase", "magnitude_phase.cl" },
347 { "mean_stddev_accumulate", "mean_stddev.cl" },
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100348 { "memset", "memset.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100349 { "minmax", "minmaxloc.cl" },
350 { "minmax_border", "minmaxloc.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100351 { "minmax_layer", "minmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100352 { "minmaxloc", "minmaxloc.cl" },
353 { "non_linear_filter_box3x3", "non_linear_filter3x3.cl" },
354 { "non_linear_filter_cross3x3", "non_linear_filter3x3.cl" },
355 { "non_linear_filter_disk3x3", "non_linear_filter3x3.cl" },
356 { "non_linear_filter_box5x5", "non_linear_filter5x5.cl" },
357 { "non_linear_filter_cross5x5", "non_linear_filter5x5.cl" },
358 { "non_linear_filter_disk5x5", "non_linear_filter5x5.cl" },
359 { "non_max_suppression", "nonmax.cl" },
360 { "normalization_layer_cross_map", "normalization_layer.cl" },
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +0000361 { "normalization_layer_in_map_nchw", "normalization_layer.cl" },
362 { "normalization_layer_in_map_nhwc", "normalization_layer.cl" },
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100363 { "normalize_planar_yuv_layer_nchw", "normalize_planar_yuv_layer.cl" },
364 { "normalize_planar_yuv_layer_nhwc", "normalize_planar_yuv_layer.cl" },
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100365 { "normalize_planar_yuv_layer_q8_nchw", "normalize_planar_yuv_layer_quantized.cl" },
366 { "normalize_planar_yuv_layer_q8_nhwc", "normalize_planar_yuv_layer_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100367 { "NV12_to_IYUV_bt709", "color_convert.cl" },
368 { "NV12_to_RGB888_bt709", "color_convert.cl" },
369 { "NV12_to_RGBA8888_bt709", "color_convert.cl" },
370 { "NV12_to_YUV444_bt709", "color_convert.cl" },
371 { "NV21_to_IYUV_bt709", "color_convert.cl" },
372 { "NV21_to_RGB888_bt709", "color_convert.cl" },
373 { "NV21_to_RGBA8888_bt709", "color_convert.cl" },
374 { "NV21_to_YUV444_bt709", "color_convert.cl" },
Giorgio Arenaa086a0a2018-02-16 12:42:16 +0000375 { "output_stage_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" },
shubhame1a4e372019-01-07 21:37:55 +0530376 { "permute", "permute.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100377 { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
378 { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100379 { "pixelwise_mul_quantized", "pixelwise_mul_int.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100380 { "pooling_layer_2", "pooling_layer.cl" },
381 { "pooling_layer_3", "pooling_layer.cl" },
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000382 { "pooling_layer_optimized_3", "pooling_layer.cl" },
Georgios Pinitasce093142017-06-19 16:11:53 +0100383 { "pooling_layer_7", "pooling_layer.cl" },
Michalis Spyroue74b2012018-04-18 09:49:16 +0100384 { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
385 { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
386 { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
387 { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100388 { "prior_box_layer_nchw", "prior_box_layer.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100389 { "quantization_layer", "quantization_layer.cl" },
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +0000390 { "range", "range.cl" },
391 { "range_quantized", "range.cl" },
Michalis Spyrou7e9391b2018-10-05 14:49:28 +0100392 { "reduction_operation_x", "reduction_operation.cl" },
Michalis Spyrou7930db42018-11-22 17:36:28 +0000393 { "reduction_operation_non_parallel_x", "reduction_operation.cl" },
Michalis Spyrou7e9391b2018-10-05 14:49:28 +0100394 { "reduction_operation_y", "reduction_operation.cl" },
395 { "reduction_operation_z", "reduction_operation.cl" },
396 { "reduction_operation_w", "reduction_operation.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100397 { "remap_nearest_neighbour", "remap.cl" },
398 { "remap_bilinear", "remap.cl" },
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100399 { "reorg_layer_nchw", "reorg_layer.cl" },
400 { "reorg_layer_nhwc", "reorg_layer.cl" },
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100401 { "reshape_layer", "reshape_layer.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100402 { "reshape_to_columns", "convolution_layer.cl" },
Michele Di Giorgio5daeffd2018-11-26 10:01:15 +0000403 { "reverse", "reverse.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100404 { "RGB888_to_IYUV_bt709", "color_convert.cl" },
405 { "RGB888_to_NV12_bt709", "color_convert.cl" },
406 { "RGB888_to_RGBA8888_bt709", "color_convert.cl" },
Manuel Bottiniacaf21d2018-09-26 17:38:19 +0100407 { "RGB888_to_U8_bt709", "color_convert.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100408 { "RGB888_to_YUV444_bt709", "color_convert.cl" },
409 { "RGBA8888_to_IYUV_bt709", "color_convert.cl" },
410 { "RGBA8888_to_NV12_bt709", "color_convert.cl" },
411 { "RGBA8888_to_RGB888_bt709", "color_convert.cl" },
412 { "RGBA8888_to_YUV444_bt709", "color_convert.cl" },
giuros0118870812018-09-13 09:31:40 +0100413 { "roi_align_layer", "roi_align_layer.cl" },
SiCong Li3e363692017-07-04 15:02:10 +0100414 { "roi_pooling_layer", "roi_pooling_layer.cl" },
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100415 { "scale_nearest_neighbour_nchw", "scale.cl" },
416 { "scale_nearest_neighbour_nhwc", "scale.cl" },
417 { "scale_bilinear_nchw", "scale.cl" },
418 { "scale_bilinear_nhwc", "scale.cl" },
Michalis Spyrou17220e22018-09-12 13:35:38 +0100419 { "scale_bilinear_quantized_nchw", "scale_quantized.cl" },
420 { "scale_bilinear_quantized_nhwc", "scale_quantized.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100421 { "scharr3x3", "scharr_filter.cl" },
Georgios Pinitasaaa27182018-11-21 16:32:15 +0000422 { "select_same_rank", "select.cl" },
423 { "select_different_rank_2", "select.cl" },
424 { "select_different_rank_n", "select.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100425 { "sobel3x3", "sobel_filter.cl" },
426 { "sobel_separable5x1", "sobel_filter.cl" },
427 { "sobel_separable1x5", "sobel_filter.cl" },
428 { "sobel_separable7x1", "sobel_filter.cl" },
429 { "sobel_separable1x7", "sobel_filter.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100430 { "softmax_layer_norm", "softmax_layer.cl" },
Chunosovf450caa2017-11-08 16:09:35 +0700431 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
Giorgio Arena4402cb92018-02-15 13:37:40 +0000432 { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
433 { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700434 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100435 { "space_to_batch_nchw", "space_to_batch.cl" },
436 { "space_to_batch_static_nchw", "space_to_batch.cl" },
437 { "space_to_batch_nhwc", "space_to_batch.cl" },
438 { "space_to_batch_static_nhwc", "space_to_batch.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700439 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000440 { "stack_layer", "stack_layer.cl" },
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100441 { "strided_slice", "slice_ops.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100442 { "suppress_non_maximum", "canny.cl" },
443 { "tablelookup_U8", "tablelookup.cl" },
444 { "tablelookup_S16", "tablelookup.cl" },
445 { "threshold_binary", "threshold.cl" },
446 { "threshold_range", "threshold.cl" },
giuros013175fcf2018-11-21 09:59:17 +0000447 { "tile", "tile.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100448 { "transpose", "transpose.cl" },
449 { "UYVY422_to_IYUV_bt709", "color_convert.cl" },
450 { "UYVY422_to_NV12_bt709", "color_convert.cl" },
451 { "UYVY422_to_RGB888_bt709", "color_convert.cl" },
452 { "UYVY422_to_RGBA8888_bt709", "color_convert.cl" },
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100453 { "upsample_layer_nchw", "upsample_layer.cl" },
454 { "upsample_layer_nhwc", "upsample_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100455 { "warp_affine_nearest_neighbour", "warp_affine.cl" },
456 { "warp_affine_bilinear", "warp_affine.cl" },
457 { "warp_perspective_nearest_neighbour", "warp_perspective.cl" },
458 { "warp_perspective_bilinear", "warp_perspective.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100459 { "winograd_filter_transform_2x2_3x3_nchw", "winograd_filter_transform.cl" },
460 { "winograd_filter_transform_2x1_3x1_nchw", "winograd_filter_transform.cl" },
461 { "winograd_filter_transform_1x2_1x3_nchw", "winograd_filter_transform.cl" },
462 { "winograd_filter_transform_4x4_3x3_nchw", "winograd_filter_transform.cl" },
463 { "winograd_filter_transform_4x1_3x1_nchw", "winograd_filter_transform.cl" },
464 { "winograd_filter_transform_1x4_1x3_nchw", "winograd_filter_transform.cl" },
465 { "winograd_filter_transform_4x4_5x5_nchw", "winograd_filter_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100466 { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
467 { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100468 { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
469 { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100470 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
471 { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100472 { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
473 { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100474 { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd_input_transform.cl" },
475 { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd_input_transform.cl" },
476 { "winograd_input_transform_2x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
477 { "winograd_input_transform_2x1_3x1_stepz2_nchw", "winograd_input_transform.cl" },
478 { "winograd_input_transform_1x2_1x3_stepz1_nchw", "winograd_input_transform.cl" },
479 { "winograd_input_transform_1x2_1x3_stepz2_nchw", "winograd_input_transform.cl" },
480 { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd_input_transform.cl" },
481 { "winograd_input_transform_4x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
482 { "winograd_input_transform_1x4_1x3_stepz1_nchw", "winograd_input_transform.cl" },
483 { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd_input_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100484 { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
485 { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100486 { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
487 { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100488 { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
489 { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100490 { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
491 { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100492 { "winograd_output_transform_2x2_3x3_nchw", "winograd_output_transform.cl" },
493 { "winograd_output_transform_2x1_3x1_nchw", "winograd_output_transform.cl" },
494 { "winograd_output_transform_1x2_1x3_nchw", "winograd_output_transform.cl" },
495 { "winograd_output_transform_4x4_3x3_nchw", "winograd_output_transform.cl" },
496 { "winograd_output_transform_4x1_3x1_nchw", "winograd_output_transform.cl" },
497 { "winograd_output_transform_1x4_1x3_nchw", "winograd_output_transform.cl" },
498 { "winograd_output_transform_4x4_5x5_nchw", "winograd_output_transform.cl" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100499 { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
500 { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100501 { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
502 { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100503 { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
504 { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100505 { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
506 { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
Giorgio Arena73023022018-09-04 14:55:55 +0100507 { "yolo_layer_nchw", "yolo_layer.cl" },
508 { "yolo_layer_nhwc", "yolo_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100509 { "YUYV422_to_IYUV_bt709", "color_convert.cl" },
510 { "YUYV422_to_NV12_bt709", "color_convert.cl" },
511 { "YUYV422_to_RGB888_bt709", "color_convert.cl" },
512 { "YUYV422_to_RGBA8888_bt709", "color_convert.cl" },
513};
514
515const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
516{
517#ifdef EMBEDDED_KERNELS
518 {
519 "absdiff.cl",
520#include "./cl_kernels/absdiff.clembed"
521 },
522 {
523 "accumulate.cl",
524#include "./cl_kernels/accumulate.clembed"
525 },
526 {
527 "activation_layer.cl",
528#include "./cl_kernels/activation_layer.clembed"
529 },
530 {
Michel Iwaniec00633802017-10-12 14:14:15 +0100531 "activation_layer_qa8.cl",
532#include "./cl_kernels/activation_layer_qa8.clembed"
533 },
534 {
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100535 "batch_to_space.cl",
536#include "./cl_kernels/batch_to_space.clembed"
537 },
538 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100539 "bitwise_op.cl",
540#include "./cl_kernels/bitwise_op.clembed"
541 },
542 {
giuros01c04a0e82018-10-03 12:44:35 +0100543 "bounding_box_transform.cl",
544#include "./cl_kernels/bounding_box_transform.clembed"
545 },
546 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100547 "canny.cl",
548#include "./cl_kernels/canny.clembed"
549 },
550 {
551 "channel_combine.cl",
552#include "./cl_kernels/channel_combine.clembed"
553 },
554 {
555 "channel_extract.cl",
556#include "./cl_kernels/channel_extract.clembed"
557 },
558 {
Michele Di Giorgio72175632018-05-01 16:52:00 +0100559 "channel_shuffle.cl",
560#include "./cl_kernels/channel_shuffle.clembed"
561 },
562 {
Gian Marco76faef82018-01-29 12:15:32 +0000563 "col2im.cl",
564#include "./cl_kernels/col2im.clembed"
565 },
566 {
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000567 "comparisons.cl",
568#include "./cl_kernels/comparisons.clembed"
569 },
570 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100571 "concatenate.cl",
572#include "./cl_kernels/concatenate.clembed"
573 },
574 {
575 "color_convert.cl",
576#include "./cl_kernels/color_convert.clembed"
577 },
578 {
Giorgio Arena657bdb32018-04-26 18:52:01 +0100579 "convert_fc_weights.cl",
580#include "./cl_kernels/convert_fc_weights.clembed"
581 },
582 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100583 "convolution3x3.cl",
584#include "./cl_kernels/convolution3x3.clembed"
585 },
586 {
587 "convolution5x5.cl",
588#include "./cl_kernels/convolution5x5.clembed"
589 },
590 {
591 "convolution7x7.cl",
592#include "./cl_kernels/convolution7x7.clembed"
593 },
594 {
595 "convolution9x9.cl",
596#include "./cl_kernels/convolution9x9.clembed"
597 },
598 {
599 "convolution_layer.cl",
600#include "./cl_kernels/convolution_layer.clembed"
601 },
602 {
603 "convolution_rectangle.cl",
604#include "./cl_kernels/convolution_rectangle.clembed"
605 },
606 {
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000607 "copy_tensor.cl",
608#include "./cl_kernels/copy_tensor.clembed"
609 },
610 {
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100611 "upsample_layer.cl",
612#include "./cl_kernels/upsample_layer.clembed"
613 },
614 {
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000615 "deconvolution_layer.cl",
616#include "./cl_kernels/deconvolution_layer.clembed"
617 },
618 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100619 "depth_convert.cl",
620#include "./cl_kernels/depth_convert.clembed"
621 },
622 {
Giorgio Arena93a690e2017-08-01 16:09:33 +0100623 "depthwise_convolution.cl",
624#include "./cl_kernels/depthwise_convolution.clembed"
625 },
626 {
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700627 "depthwise_convolution_quantized.cl",
628#include "./cl_kernels/depthwise_convolution_quantized.clembed"
629 },
630 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100631 "dequantization_layer.cl",
632#include "./cl_kernels/dequantization_layer.clembed"
633 },
634 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100635 "derivative.cl",
636#include "./cl_kernels/derivative.clembed"
637 },
638 {
639 "dilate.cl",
640#include "./cl_kernels/dilate.clembed"
641 },
642 {
SiCong Lic51b72f2017-07-28 14:46:20 +0100643 "direct_convolution1x1.cl",
644#include "./cl_kernels/direct_convolution1x1.clembed"
645 },
646 {
647 "direct_convolution3x3.cl",
648#include "./cl_kernels/direct_convolution3x3.clembed"
steniu0127b386c2017-07-18 17:37:43 +0100649 },
650 {
steniu01db006682017-08-09 16:26:22 +0100651 "direct_convolution5x5.cl",
652#include "./cl_kernels/direct_convolution5x5.clembed"
653 },
654 {
Chunosovd621bca2017-11-03 17:33:15 +0700655 "direct_convolution_1x1_3x3_5x5_quantized.cl",
656#include "./cl_kernels/direct_convolution_1x1_3x3_5x5_quantized.clembed"
657 },
658 {
giuros01164a2722018-11-20 18:34:46 +0000659 "elementwise_operation.cl",
660#include "./cl_kernels/elementwise_operation.clembed"
661 },
662 {
663 "elementwise_operation_quantized.cl",
664#include "./cl_kernels/elementwise_operation_quantized.clembed"
665 },
666 {
Michalis Spyroue9362622018-11-23 17:41:37 +0000667 "elementwise_unary.cl",
668#include "./cl_kernels/elementwise_unary.clembed"
669 },
670 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100671 "erode.cl",
672#include "./cl_kernels/erode.clembed"
673 },
674 {
675 "fast_corners.cl",
676#include "./cl_kernels/fast_corners.clembed"
677 },
678 {
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100679 "flatten.cl",
680#include "./cl_kernels/flatten.clembed"
681 },
682 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100683 "fill_border.cl",
684#include "./cl_kernels/fill_border.clembed"
685 },
686 {
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100687 "floor.cl",
688#include "./cl_kernels/floor.clembed"
689 },
690 {
Manuel Bottini8529bd62018-11-21 11:53:04 +0000691 "gather.cl",
692#include "./cl_kernels/gather.clembed"
693 },
694 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100695 "gaussian_pyramid.cl",
696#include "./cl_kernels/gaussian_pyramid.clembed"
697 },
698 {
699 "gemm.cl",
700#include "./cl_kernels/gemm.clembed"
701 },
702 {
Gian Marco05288a22017-11-21 10:57:50 +0000703 "gemmlowp.cl",
704#include "./cl_kernels/gemmlowp.clembed"
705 },
706 {
Giorgio Arena9fe41442017-08-23 16:36:24 +0100707 "gemv.cl",
708#include "./cl_kernels/gemv.clembed"
709 },
710 {
Manuel Bottini5209be52019-02-13 16:34:56 +0000711 "generate_proposals.cl",
712#include "./cl_kernels/generate_proposals.clembed"
713 },
714 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100715 "harris_corners.cl",
716#include "./cl_kernels/harris_corners.clembed"
717 },
718 {
719 "helpers.h",
720#include "./cl_kernels/helpers.hembed"
721 },
722 {
Chunosovd621bca2017-11-03 17:33:15 +0700723 "helpers_asymm.h",
724#include "./cl_kernels/helpers_asymm.hembed"
725 },
726 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100727 "histogram.cl",
728#include "./cl_kernels/histogram.clembed"
729 },
730 {
731 "hog.cl",
732#include "./cl_kernels/hog.clembed"
733 },
734 {
Gian Marco76faef82018-01-29 12:15:32 +0000735 "im2col.cl",
736#include "./cl_kernels/im2col.clembed"
737 },
738 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100739 "integral_image.cl",
740#include "./cl_kernels/integral_image.clembed"
741 },
742 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100743 "l2_normalize.cl",
744#include "./cl_kernels/l2_normalize.clembed"
745 },
746 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100747 "magnitude_phase.cl",
748#include "./cl_kernels/magnitude_phase.clembed"
749 },
750 {
751 "mean_stddev.cl",
752#include "./cl_kernels/mean_stddev.clembed"
753 },
754 {
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100755 "memset.cl",
756#include "./cl_kernels/memset.clembed"
757 },
758 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100759 "minmaxloc.cl",
760#include "./cl_kernels/minmaxloc.clembed"
761 },
762 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100763 "minmax_layer.cl",
764#include "./cl_kernels/minmax_layer.clembed"
765 },
766 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100767 "non_linear_filter3x3.cl",
768#include "./cl_kernels/non_linear_filter3x3.clembed"
769 },
770 {
771 "non_linear_filter5x5.cl",
772#include "./cl_kernels/non_linear_filter5x5.clembed"
773 },
774 {
775 "non_linear_filter_helpers.h",
776#include "./cl_kernels/non_linear_filter_helpers.hembed"
777 },
778 {
779 "nonmax.cl",
780#include "./cl_kernels/nonmax.clembed"
781 },
782 {
783 "normalization_layer.cl",
784#include "./cl_kernels/normalization_layer.clembed"
785 },
786 {
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100787 "normalize_planar_yuv_layer.cl",
788#include "./cl_kernels/normalize_planar_yuv_layer.clembed"
789 },
790 {
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100791 "normalize_planar_yuv_layer_quantized.cl",
792#include "./cl_kernels/normalize_planar_yuv_layer_quantized.clembed"
793 },
794 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100795 "batchnormalization_layer.cl",
796#include "./cl_kernels/batchnormalization_layer.clembed"
797 },
798 {
799 "optical_flow_pyramid_lk.cl",
800#include "./cl_kernels/optical_flow_pyramid_lk.clembed"
801 },
802 {
Michalis Spyrou5237e012018-01-17 09:40:27 +0000803 "permute.cl",
804#include "./cl_kernels/permute.clembed"
805 },
806 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100807 "pixelwise_mul_float.cl",
808#include "./cl_kernels/pixelwise_mul_float.clembed"
809 },
810 {
811 "pixelwise_mul_int.cl",
812#include "./cl_kernels/pixelwise_mul_int.clembed"
813 },
814 {
815 "pooling_layer.cl",
816#include "./cl_kernels/pooling_layer.clembed"
817 },
818 {
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000819 "pooling_layer_quantized.cl",
820#include "./cl_kernels/pooling_layer_quantized.clembed"
821 },
822 {
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100823 "prior_box_layer.cl",
824#include "./cl_kernels/prior_box_layer.clembed"
825 },
826 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100827 "quantization_layer.cl",
828#include "./cl_kernels/quantization_layer.clembed"
829 },
830 {
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +0000831 "range.cl",
832#include "./cl_kernels/range.clembed"
833 },
834 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100835 "reduction_operation.cl",
836#include "./cl_kernels/reduction_operation.clembed"
837 },
838 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100839 "remap.cl",
840#include "./cl_kernels/remap.clembed"
841 },
842 {
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100843 "reorg_layer.cl",
844#include "./cl_kernels/reorg_layer.clembed"
845 },
846 {
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100847 "reshape_layer.cl",
848#include "./cl_kernels/reshape_layer.clembed"
849 },
850 {
Michele Di Giorgio5daeffd2018-11-26 10:01:15 +0000851 "reverse.cl",
852#include "./cl_kernels/reverse.clembed"
853 },
854 {
giuros0118870812018-09-13 09:31:40 +0100855 "roi_align_layer.cl",
856#include "./cl_kernels/roi_align_layer.clembed"
857 },
858 {
SiCong Li3e363692017-07-04 15:02:10 +0100859 "roi_pooling_layer.cl",
860#include "./cl_kernels/roi_pooling_layer.clembed"
861 },
862 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100863 "scale.cl",
864#include "./cl_kernels/scale.clembed"
865 },
866 {
Michalis Spyrou17220e22018-09-12 13:35:38 +0100867 "scale_quantized.cl",
868#include "./cl_kernels/scale_quantized.clembed"
869 },
870 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100871 "scharr_filter.cl",
872#include "./cl_kernels/scharr_filter.clembed"
873 },
874 {
Georgios Pinitasaaa27182018-11-21 16:32:15 +0000875 "select.cl",
876#include "./cl_kernels/select.clembed"
877 },
878 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100879 "sobel_filter.cl",
880#include "./cl_kernels/sobel_filter.clembed"
881 },
882 {
883 "softmax_layer.cl",
884#include "./cl_kernels/softmax_layer.clembed"
885 },
886 {
Chunosovf450caa2017-11-08 16:09:35 +0700887 "softmax_layer_quantized.cl",
888#include "./cl_kernels/softmax_layer_quantized.clembed"
889 },
890 {
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100891 "slice_ops.cl",
892#include "./cl_kernels/slice_ops.clembed"
Georgios Pinitas77589b52018-08-21 14:41:35 +0100893 },
894 {
Michalis Spyrou16934a52018-08-21 18:03:58 +0100895 "space_to_batch.cl",
896#include "./cl_kernels/space_to_batch.clembed"
897 },
898 {
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000899 "stack_layer.cl",
900#include "./cl_kernels/stack_layer.clembed"
901 },
902 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100903 "tablelookup.cl",
904#include "./cl_kernels/tablelookup.clembed"
905 },
906 {
907 "threshold.cl",
908#include "./cl_kernels/threshold.clembed"
909 },
910 {
giuros013175fcf2018-11-21 09:59:17 +0000911 "tile.cl",
912#include "./cl_kernels/tile.clembed"
913 },
914 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100915 "transpose.cl",
916#include "./cl_kernels/transpose.clembed"
917 },
918 {
919 "types.h",
920#include "./cl_kernels/types.hembed"
921 },
922 {
923 "warp_affine.cl",
924#include "./cl_kernels/warp_affine.clembed"
925 },
926 {
927 "warp_helpers.h",
928#include "./cl_kernels/warp_helpers.hembed"
929 },
930 {
931 "warp_perspective.cl",
932#include "./cl_kernels/warp_perspective.clembed"
Michalis Spyroud7e82812017-06-20 15:00:14 +0100933 },
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000934 {
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100935 "winograd_filter_transform.cl",
936#include "./cl_kernels/winograd_filter_transform.clembed"
937 },
938 {
939 "winograd_input_transform.cl",
940#include "./cl_kernels/winograd_input_transform.clembed"
941 },
942 {
943 "winograd_output_transform.cl",
944#include "./cl_kernels/winograd_output_transform.clembed"
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000945 },
Giorgio Arena73023022018-09-04 14:55:55 +0100946 {
947 "yolo_layer.cl",
948#include "./cl_kernels/yolo_layer.clembed"
949 },
Anthony Barbierac69aa12017-07-03 17:39:37 +0100950#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100951};
952
953CLKernelLibrary::CLKernelLibrary()
Abel Bernabeu5a6e0532017-09-28 09:53:45 +0100954 : _context(), _device(), _kernel_path("."), _programs_map(), _built_programs_map()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100955{
Anthony Barbierecb1c622018-04-17 11:45:10 +0100956 opencl_is_available(); // Make sure the OpenCL symbols are initialised *before* the CLKernelLibrary is built
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100957}
958
959CLKernelLibrary &CLKernelLibrary::get()
960{
961 static CLKernelLibrary _kernel_library;
962 return _kernel_library;
963}
964
965Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const StringSet &build_options_set) const
966{
967 // Find which program contains the kernel
968 auto kernel_program_it = _kernel_program_map.find(kernel_name);
969
970 if(_kernel_program_map.end() == kernel_program_it)
971 {
972 ARM_COMPUTE_ERROR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
973 }
steniu0134702472017-07-11 09:22:58 +0100974 std::string concat_str;
975
Georgios Pinitasdf473ea2018-05-31 18:53:52 +0100976#if defined(ARM_COMPUTE_DEBUG_ENABLED)
977 // Enable debug properties in CL kernels
978 concat_str += " -DARM_COMPUTE_DEBUG_ENABLED";
979#endif // defined(ARM_COMPUTE_DEBUG_ENABLED)
980
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100981 if(fp16_supported())
Matthew Bentham6f31f8c2017-10-27 11:50:06 +0100982 {
983 concat_str += " -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 ";
984 }
985
Michalis Spyroue03342e2018-01-15 14:39:13 +0000986 if(dot8_supported(_device))
987 {
988 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ENABLED=1 ";
989 }
990
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100991 if(dot8_acc_supported(_device))
992 {
993 concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED=1 ";
994 }
995
Pablo Telloe86a09f2018-01-11 15:44:48 +0000996 if(get_cl_version(_device) == CLVersion::CL20)
steniu0134702472017-07-11 09:22:58 +0100997 {
998 concat_str += " -cl-std=CL2.0 ";
999 }
Anthony Barbierd727e852018-04-20 11:05:29 +01001000 else if(arm_non_uniform_workgroup_supported(_device))
Pablo Telloe86a09f2018-01-11 15:44:48 +00001001 {
1002 concat_str += " -cl-arm-non-uniform-work-group-size ";
1003 }
steniu0134702472017-07-11 09:22:58 +01001004 else
1005 {
1006 ARM_COMPUTE_ERROR("Non uniform workgroup size is not supported!!");
1007 }
1008
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001009 // Check if the program has been built before with same build options.
steniu0134702472017-07-11 09:22:58 +01001010 const std::string program_name = kernel_program_it->second;
1011 const std::string build_options = stringify_set(build_options_set) + concat_str;
1012
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001013 const std::string built_program_name = program_name + "_" + build_options;
1014 auto built_program_it = _built_programs_map.find(built_program_name);
1015
1016 cl::Program cl_program;
1017
1018 if(_built_programs_map.end() != built_program_it)
1019 {
1020 // If program has been built, retrieve to create kernel from it
1021 cl_program = built_program_it->second;
1022 }
1023 else
1024 {
1025 // Get program
1026 Program program = load_program(program_name);
1027
1028 // Build program
1029 cl_program = program.build(build_options);
1030
1031 // Add built program to internal map
1032 _built_programs_map.emplace(built_program_name, cl_program);
1033 }
1034
1035 // Create and return kernel
1036 return Kernel(kernel_name, cl_program);
1037}
1038
Anthony Barbier7da55aa2018-04-13 16:58:43 +01001039void CLKernelLibrary::add_built_program(const std::string &built_program_name, cl::Program program)
1040{
1041 _built_programs_map.emplace(built_program_name, program);
1042}
1043
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +01001044bool CLKernelLibrary::fp16_supported() const
1045{
1046 return ::fp16_supported(_device);
1047}
1048
Vidhya Sudhan Loganathan76c85642018-05-25 13:53:02 +01001049bool CLKernelLibrary::int64_base_atomics_supported() const
1050{
1051 return device_supports_extension(_device, "cl_khr_int64_base_atomics");
1052}
1053
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001054const Program &CLKernelLibrary::load_program(const std::string &program_name) const
1055{
1056 const auto program_it = _programs_map.find(program_name);
1057
1058 if(program_it != _programs_map.end())
1059 {
1060 return program_it->second;
1061 }
1062
1063 Program program;
1064
1065#ifdef EMBEDDED_KERNELS
1066 const auto program_source_it = _program_source_map.find(program_name);
1067
1068 if(_program_source_map.end() == program_source_it)
1069 {
1070 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
1071 }
1072
1073 program = Program(_context, program_name, program_source_it->second);
Anthony Barbierac69aa12017-07-03 17:39:37 +01001074#else /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001075 // Check for binary
1076 std::string source_name = _kernel_path + program_name;
1077 std::string binary_name = source_name + "bin";
1078
1079 if(std::ifstream(binary_name).is_open())
1080 {
1081 const std::string program_binary = read_file(binary_name, true);
1082 program = Program(_context, _device, program_name, std::vector<unsigned char>(program_binary.begin(), program_binary.end()));
1083 }
1084 else if(std::ifstream(source_name).is_open())
1085 {
1086 program = Program(_context, program_name, read_file(source_name, false));
1087 }
1088 else
1089 {
1090 ARM_COMPUTE_ERROR("Kernel file %s does not exist.", source_name.c_str());
1091 }
Anthony Barbierac69aa12017-07-03 17:39:37 +01001092#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001093
1094 // Insert program to program map
1095 const auto new_program = _programs_map.emplace(program_name, std::move(program));
1096
1097 return new_program.first->second;
1098}
1099
1100std::string CLKernelLibrary::stringify_set(const StringSet &s) const
1101{
steniu0134702472017-07-11 09:22:58 +01001102 std::string concat_set;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001103
1104#ifndef EMBEDDED_KERNELS
1105 concat_set += "-I" + _kernel_path + " ";
1106#endif /* EMBEDDED_KERNELS */
1107
1108 // Concatenate set
1109 for(const auto &el : s)
1110 {
1111 concat_set += " " + el;
1112 }
1113
1114 return concat_set;
1115}
Michalis Spyroud7e82812017-06-20 15:00:14 +01001116
1117std::string CLKernelLibrary::get_program_source(const std::string &program_name)
1118{
1119 const auto program_source_it = _program_source_map.find(program_name);
1120
1121 if(program_source_it == _program_source_map.end())
1122 {
1123 ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str());
1124 }
1125
1126 return program_source_it->second;
1127}
steniu015f910722017-08-23 10:15:22 +01001128
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001129size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const
steniu015f910722017-08-23 10:15:22 +01001130{
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001131 size_t result;
steniu015f910722017-08-23 10:15:22 +01001132
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001133 size_t err = kernel.getWorkGroupInfo(_device, CL_KERNEL_WORK_GROUP_SIZE, &result);
1134 ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel");
1135 ARM_COMPUTE_UNUSED(err);
1136
1137 return result;
steniu015f910722017-08-23 10:15:22 +01001138}
1139
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001140cl::NDRange CLKernelLibrary::default_ndrange() const
steniu015f910722017-08-23 10:15:22 +01001141{
Anthony Barbierb6eb3532018-08-08 13:20:04 +01001142 GPUTarget _target = get_target_from_device(_device);
Michalis Spyroua9676112018-02-22 18:07:43 +00001143 cl::NDRange default_range;
1144
1145 switch(_target)
1146 {
1147 case GPUTarget::MIDGARD:
1148 case GPUTarget::T600:
1149 case GPUTarget::T700:
1150 case GPUTarget::T800:
1151 default_range = cl::NDRange(128u, 1);
1152 break;
1153 default:
1154 default_range = cl::NullRange;
1155 }
1156
1157 return default_range;
steniu015f910722017-08-23 10:15:22 +01001158}
Anthony Barbier847864d2018-03-07 11:35:53 +00001159
1160std::string CLKernelLibrary::get_device_version()
1161{
1162 return _device.getInfo<CL_DEVICE_VERSION>();
1163}