Compute Library
 19.11
CLKernelLibrary.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019 ARM Limited.
3  *
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  */
25 
27 #include "arm_compute/core/Error.h"
28 #include "arm_compute/core/Utils.h"
29 
30 #include <algorithm>
31 #include <fstream>
32 #include <iostream>
33 #include <utility>
34 #include <vector>
35 
36 using namespace arm_compute;
37 
39  : _build_opts()
40 {
41 }
42 
43 void CLBuildOptions::add_option(std::string option)
44 {
45  _build_opts.emplace(std::move(option));
46 }
47 
48 void CLBuildOptions::add_option_if(bool cond, std::string option)
49 {
50  if(cond)
51  {
52  add_option(std::move(option));
53  }
54 }
55 
56 void 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 
61 void CLBuildOptions::add_options(const StringSet &options)
62 {
63  _build_opts.insert(options.begin(), options.end());
64 }
65 
66 void CLBuildOptions::add_options_if(bool cond, const StringSet &options)
67 {
68  if(cond)
69  {
71  }
72 }
73 
74 const CLBuildOptions::StringSet &CLBuildOptions::options() const
75 {
76  return _build_opts;
77 }
78 
80  : _context(), _device(), _is_binary(false), _name(), _source(), _binary()
81 {
82 }
83 
84 Program::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 
89 Program::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 
94 Program::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 
106 bool 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 
126 cl::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 
134  : _name(), _kernel()
135 {
136 }
137 
138 Kernel::Kernel(std::string name, const cl::Program &program)
139  : _name(std::move(name)),
140  _kernel(cl::Kernel(program, _name.c_str()))
141 {
142 }
143 
144 const 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" },
151  { "activation_layer_quant", "activation_layer_quant.cl" },
152  { "activation_layer_quant_f32", "activation_layer_quant.cl" },
153  { "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" },
157  { "batchnormalization_layer_nchw", "batchnormalization_layer.cl" },
158  { "batchnormalization_layer_nhwc", "batchnormalization_layer.cl" },
159  { "bitwise_or", "bitwise_op.cl" },
160  { "bitwise_and", "bitwise_op.cl" },
161  { "bitwise_xor", "bitwise_op.cl" },
162  { "bitwise_not", "bitwise_op.cl" },
163  { "bounding_box_transform", "bounding_box_transform.cl" },
164  { "bounding_box_transform_quantized", "bounding_box_transform_quantized.cl" },
165  { "channel_combine_NV", "channel_combine.cl" },
166  { "channel_combine_RGB888", "channel_combine.cl" },
167  { "channel_combine_RGBA8888", "channel_combine.cl" },
168  { "channel_combine_UYVY422", "channel_combine.cl" },
169  { "channel_combine_YUYV422", "channel_combine.cl" },
170  { "channel_shuffle_nchw", "channel_shuffle.cl" },
171  { "channel_shuffle_nhwc", "channel_shuffle.cl" },
172  { "channel_extract_NV12", "channel_extract.cl" },
173  { "channel_extract_NV21", "channel_extract.cl" },
174  { "channel_extract_RGB888", "channel_extract.cl" },
175  { "channel_extract_RGBA8888", "channel_extract.cl" },
176  { "channel_extract_UYVY422", "channel_extract.cl" },
177  { "channel_extract_YUYV422", "channel_extract.cl" },
178  { "combine_gradients_L1", "canny.cl" },
179  { "combine_gradients_L2", "canny.cl" },
180  { "compare_equal", "comparisons.cl" },
181  { "compare_equal_quantized", "comparisons.cl" },
182  { "compare_notequal", "comparisons.cl" },
183  { "compare_notequal_quantized", "comparisons.cl" },
184  { "compare_greater", "comparisons.cl" },
185  { "compare_greater_quantized", "comparisons.cl" },
186  { "compare_greaterequal", "comparisons.cl" },
187  { "compare_greaterequal_quantized", "comparisons.cl" },
188  { "compare_less", "comparisons.cl" },
189  { "compare_less_quantized", "comparisons.cl" },
190  { "compare_lessequal", "comparisons.cl" },
191  { "compare_lessequal_quantized", "comparisons.cl" },
192  { "concatenate", "concatenate.cl" },
193  { "concatenate_width", "concatenate.cl" },
194  { "concatenate_height", "concatenate.cl" },
195  { "concatenate_width_x2", "concatenate.cl" },
196  { "concatenate_width_x4", "concatenate.cl" },
197  { "convolution_rectangle", "convolution_rectangle.cl" },
198  { "col2im", "col2im.cl" },
199  { "convert_depth_down", "depth_convert.cl" },
200  { "convert_depth_up", "depth_convert.cl" },
201  { "convert_fc_weights", "convert_fc_weights.cl" },
202  { "convolution3x3_static", "convolution3x3.cl" },
203  { "convolution5x5_static", "convolution5x5.cl" },
204  { "convolution7x7_static", "convolution7x7.cl" },
205  { "convolution9x9_static", "convolution9x9.cl" },
206  { "convolution_separable1x5_static", "convolution5x5.cl" },
207  { "convolution_separable5x1_static", "convolution5x5.cl" },
208  { "convolution_separable1x7_static", "convolution7x7.cl" },
209  { "convolution_separable7x1_static", "convolution7x7.cl" },
210  { "convolution_separable1x9_static", "convolution9x9.cl" },
211  { "convolution_separable9x1_static", "convolution9x9.cl" },
212  { "copy_tensor", "copy_tensor.cl" },
213  { "copy_pad_tensor", "copy_tensor.cl" },
214  { "copy_plane", "channel_extract.cl" },
215  { "copy_planes_3p", "channel_combine.cl" },
216  { "copy_to_keypoint", "fast_corners.cl" },
217  { "crop_tensor", "crop_tensor.cl" },
218  { "deconvolution_reshape", "deconvolution_layer.cl" },
219  { "deconvolution_upsample", "deconvolution_layer.cl" },
220  { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
221  { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
222  { "depthwise_convolution_3x3_nhwc", "depthwise_convolution.cl" },
223  { "depthwise_convolution_3x3_nhwc_stride1", "depthwise_convolution.cl" },
224  { "dwc_MxN_native_fp_nhwc", "depthwise_convolution.cl" },
225  { "dwc_MxN_native_quantized8_nhwc", "depthwise_convolution_quantized.cl" },
226  { "dwc_3x3_native_quantized8_nchw", "depthwise_convolution_quantized.cl" },
227  { "dwc_3x3_native_quantized8_dot8_nchw", "depthwise_convolution_quantized.cl" },
228  { "dwc_3x3_reshaped_quantized8_nhwc", "depthwise_convolution_quantized.cl" },
229  { "dwc_3x3_reshaped_quantized8_stride1_nhwc", "depthwise_convolution_quantized.cl" },
230  { "dwc_3x3_reshaped_quantized8_dot8_stride1_nhwc", "depthwise_convolution_quantized.cl" },
231  { "depth_to_space_nchw", "depth_to_space.cl" },
232  { "depth_to_space_nhwc", "depth_to_space.cl" },
233  { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16", "depthwise_convolution.cl" },
234  { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16", "depthwise_convolution.cl" },
235  { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32", "depthwise_convolution.cl" },
236  { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32", "depthwise_convolution.cl" },
237  { "depthwise_convolution_reshape_weights", "depthwise_convolution.cl" },
238  { "dequantization_layer", "dequantization_layer.cl" },
239  { "dequantization_layer_per_channel_nhwc", "dequantization_layer.cl" },
240  { "dequantization_layer_per_channel_nchw", "dequantization_layer.cl" },
241  { "derivative", "derivative.cl" },
242  { "dilate", "dilate.cl" },
243  { "direct_convolution1x1", "direct_convolution1x1.cl" },
244  { "direct_convolution1x1_nhwc", "direct_convolution1x1.cl" },
245  { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
246  { "direct_convolution3x3", "direct_convolution3x3.cl" },
247  { "direct_convolution3x3_nhwc", "direct_convolution3x3.cl" },
248  { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
249  { "direct_convolution5x5", "direct_convolution5x5.cl" },
250  { "direct_convolution5x5_nhwc", "direct_convolution5x5.cl" },
251  { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
252  { "direct_convolution_quantized", "direct_convolution_quantized.cl" },
253  { "direct_convolution9x9_nhwc", "direct_convolution9x9.cl" },
254  { "elementwise_operation_ADD", "elementwise_operation.cl" },
255  { "elementwise_operation_SUB", "elementwise_operation.cl" },
256  { "elementwise_operation_MAX", "elementwise_operation.cl" },
257  { "elementwise_operation_MIN", "elementwise_operation.cl" },
258  { "elementwise_operation_DIV", "elementwise_operation.cl" },
259  { "elementwise_operation_SQUARED_DIFF", "elementwise_operation.cl" },
260  { "elementwise_operation_POWER", "elementwise_operation.cl" },
261  { "elementwise_operation_PRELU", "elementwise_operation.cl" },
262  { "elementwise_operation_ADD_quantized", "elementwise_operation_quantized.cl" },
263  { "elementwise_operation_SUB_quantized", "elementwise_operation_quantized.cl" },
264  { "elementwise_operation_MAX_quantized", "elementwise_operation_quantized.cl" },
265  { "elementwise_operation_MIN_quantized", "elementwise_operation_quantized.cl" },
266  { "elementwise_operation_DIV_quantized", "elementwise_operation_quantized.cl" },
267  { "elementwise_operation_SQUARED_DIFF_quantized", "elementwise_operation_quantized.cl" },
268  { "elementwise_operation_PRELU_quantized", "elementwise_operation_quantized.cl" },
269  { "elementwise_unary", "elementwise_unary.cl" },
270  { "erode", "erode.cl" },
271  { "fast_corners", "fast_corners.cl" },
272  { "fft_digit_reverse_axis_0", "fft_digit_reverse.cl" },
273  { "fft_digit_reverse_axis_1", "fft_digit_reverse.cl" },
274  { "fft_radix_2_first_stage_axis_0", "fft.cl" },
275  { "fft_radix_2_first_stage_axis_1", "fft.cl" },
276  { "fft_radix_2_axis_0", "fft.cl" },
277  { "fft_radix_2_axis_1", "fft.cl" },
278  { "fft_radix_3_first_stage_axis_0", "fft.cl" },
279  { "fft_radix_3_first_stage_axis_1", "fft.cl" },
280  { "fft_radix_3_axis_0", "fft.cl" },
281  { "fft_radix_3_axis_1", "fft.cl" },
282  { "fft_radix_4_first_stage_axis_0", "fft.cl" },
283  { "fft_radix_4_first_stage_axis_1", "fft.cl" },
284  { "fft_radix_4_axis_0", "fft.cl" },
285  { "fft_radix_4_axis_1", "fft.cl" },
286  { "fft_radix_5_first_stage_axis_0", "fft.cl" },
287  { "fft_radix_5_first_stage_axis_1", "fft.cl" },
288  { "fft_radix_5_axis_0", "fft.cl" },
289  { "fft_radix_5_axis_1", "fft.cl" },
290  { "fft_radix_7_first_stage_axis_0", "fft.cl" },
291  { "fft_radix_7_first_stage_axis_1", "fft.cl" },
292  { "fft_radix_7_axis_0", "fft.cl" },
293  { "fft_radix_7_axis_1", "fft.cl" },
294  { "fft_radix_8_first_stage_axis_0", "fft.cl" },
295  { "fft_radix_8_first_stage_axis_1", "fft.cl" },
296  { "fft_radix_8_axis_0", "fft.cl" },
297  { "fft_radix_8_axis_1", "fft.cl" },
298  { "fft_scale_conj", "fft_scale.cl" },
299  { "fill_image_borders_constant", "fill_border.cl" },
300  { "fill_image_borders_replicate", "fill_border.cl" },
301  { "finalize", "optical_flow_pyramid_lk.cl" },
302  { "flatten", "flatten.cl" },
303  { "floor_layer", "floor.cl" },
304  { "fuse_batchnormalization_layer", "batchnormalization_layer.cl" },
305  { "gather", "gather.cl" },
306  { "gaussian1x5_sub_x", "gaussian_pyramid.cl" },
307  { "gaussian5x1_sub_y", "gaussian_pyramid.cl" },
308  { "gemm_accumulate_biases", "gemm.cl" },
309  { "gemm_ma_f16", "gemm.cl" },
310  { "gemm_ma_f32", "gemm.cl" },
311  { "gemm_mv", "gemv.cl" },
312  { "gemm_mv_quantized", "gemv.cl" },
313  { "gemm_mm_interleaved_transposed_f16", "gemm.cl" },
314  { "gemm_mm_interleaved_transposed_f16_acc32", "gemm.cl" },
315  { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm.cl" },
316  { "gemm_mm_interleaved_transposed_f32", "gemm.cl" },
317  { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm.cl" },
318  { "gemm_mm_floating_point", "gemm.cl" },
319  { "gemm_mm_floating_point_f16_bifrost", "gemm.cl" },
320  { "gemm_mm_floating_point_f16_bifrost_acc32", "gemm.cl" },
321  { "gemm_mm_floating_point_f32_bifrost", "gemm.cl" },
322  { "gemm_mm_floating_point_f32_bifrost_1000", "gemm.cl" },
323  { "gemm_mm_native", "gemm.cl" },
324  { "gemm_mm_reshaped_lhs_nt_rhs_t", "gemm.cl" },
325  { "gemm_mm_reshaped_lhs_t_rhs_nt", "gemm.cl" },
326  { "gemm_mm_reshaped_only_rhs_nt", "gemm.cl" },
327  { "gemm_mm_reshaped_only_rhs_t", "gemm.cl" },
328  { "gemm_lc_vm_f32", "gemm.cl" },
329  { "gemm_reshape_lhs_matrix_nt", "gemm.cl" },
330  { "gemm_reshape_lhs_matrix_t", "gemm.cl" },
331  { "gemm_reshape_rhs_matrix_nt", "gemm.cl" },
332  { "gemm_reshape_rhs_matrix_t", "gemm.cl" },
333  { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
334  { "gemmlowp_matrix_a_reduction_dot8", "gemmlowp.cl" },
335  { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
336  { "gemmlowp_mm_midgard", "gemmlowp.cl" },
337  { "gemmlowp_mm_native", "gemmlowp.cl" },
338  { "gemmlowp_mm_reshaped_lhs_nt_rhs_t", "gemmlowp.cl" },
339  { "gemmlowp_mm_reshaped_only_rhs_t", "gemmlowp.cl" },
340  { "gemmlowp_offset_contribution", "gemmlowp.cl" },
341  { "gemmlowp_offset_contribution_quantize_down", "gemmlowp.cl" },
342  { "gemmlowp_offset_contribution_quantize_down_fixedpoint", "gemmlowp.cl" },
343  { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
344  { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
345  { "gemmlowp_output_stage_quantize_down_fixedpoint_qsymm16", "gemmlowp.cl" },
346  { "gemmlowp_output_stage_quantize_down_float", "gemmlowp.cl" },
347  { "generate_proposals_compute_all_anchors", "generate_proposals.cl" },
348  { "generate_proposals_compute_all_anchors_quantized", "generate_proposals_quantized.cl" },
349  { "harris_score_3x3", "harris_corners.cl" },
350  { "harris_score_5x5", "harris_corners.cl" },
351  { "harris_score_7x7", "harris_corners.cl" },
352  { "hist_border_kernel", "histogram.cl" },
353  { "hist_border_kernel_fixed", "histogram.cl" },
354  { "hist_local_kernel", "histogram.cl" },
355  { "hist_local_kernel_fixed", "histogram.cl" },
356  { "hog_block_normalization", "hog.cl" },
357  { "hog_detector", "hog.cl" },
358  { "hog_orientation_binning", "hog.cl" },
359  { "hysteresis", "canny.cl" },
360  { "im2col1x1_stridex1_nchw", "im2col.cl" },
361  { "im2col3x3_nchw", "im2col.cl" },
362  { "im2col5x5_nchw", "im2col.cl" },
363  { "im2col11x11_padx0_pady0_nchw", "im2col.cl" },
364  { "im2col_generic_nchw", "im2col.cl" },
365  { "im2col_generic_padx0_pady0_nchw", "im2col.cl" },
366  { "im2col3x3_nhwc", "im2col.cl" },
367  { "im2col9x9_nhwc", "im2col.cl" },
368  { "im2col_generic_nhwc", "im2col.cl" },
369  { "init_level", "optical_flow_pyramid_lk.cl" },
370  { "init_level_max", "optical_flow_pyramid_lk.cl" },
371  { "init_level_max_initial_estimate", "optical_flow_pyramid_lk.cl" },
372  { "instance_normalization", "instance_normalization.cl" },
373  { "integral_horizontal", "integral_image.cl" },
374  { "integral_vertical", "integral_image.cl" },
375  { "IYUV_to_NV12_bt709", "color_convert.cl" },
376  { "IYUV_to_RGB888_bt709", "color_convert.cl" },
377  { "IYUV_to_RGBA8888_bt709", "color_convert.cl" },
378  { "IYUV_to_YUV444_bt709", "color_convert.cl" },
379  { "l2_normalize_x", "l2_normalize.cl" },
380  { "l2_normalize_y", "l2_normalize.cl" },
381  { "l2_normalize_z", "l2_normalize.cl" },
382  { "lktracker_stage0", "optical_flow_pyramid_lk.cl" },
383  { "lktracker_stage1", "optical_flow_pyramid_lk.cl" },
384  { "magnitude_phase", "magnitude_phase.cl" },
385  { "mean_stddev_accumulate", "mean_stddev.cl" },
386  { "mean_stddev_normalization", "mean_stddev_normalization.cl" },
387  { "memset", "memset.cl" },
388  { "minmax", "minmaxloc.cl" },
389  { "minmax_border", "minmaxloc.cl" },
390  { "minmax_layer", "minmax_layer.cl" },
391  { "minmaxloc", "minmaxloc.cl" },
392  { "non_linear_filter_box3x3", "non_linear_filter3x3.cl" },
393  { "non_linear_filter_cross3x3", "non_linear_filter3x3.cl" },
394  { "non_linear_filter_disk3x3", "non_linear_filter3x3.cl" },
395  { "non_linear_filter_box5x5", "non_linear_filter5x5.cl" },
396  { "non_linear_filter_cross5x5", "non_linear_filter5x5.cl" },
397  { "non_linear_filter_disk5x5", "non_linear_filter5x5.cl" },
398  { "non_max_suppression", "nonmax.cl" },
399  { "normalization_layer_cross_map", "normalization_layer.cl" },
400  { "normalization_layer_in_map_nchw", "normalization_layer.cl" },
401  { "normalization_layer_in_map_nhwc", "normalization_layer.cl" },
402  { "normalize_planar_yuv_layer_nchw", "normalize_planar_yuv_layer.cl" },
403  { "normalize_planar_yuv_layer_nhwc", "normalize_planar_yuv_layer.cl" },
404  { "normalize_planar_yuv_layer_q8_nchw", "normalize_planar_yuv_layer_quantized.cl" },
405  { "normalize_planar_yuv_layer_q8_nhwc", "normalize_planar_yuv_layer_quantized.cl" },
406  { "NV12_to_IYUV_bt709", "color_convert.cl" },
407  { "NV12_to_RGB888_bt709", "color_convert.cl" },
408  { "NV12_to_RGBA8888_bt709", "color_convert.cl" },
409  { "NV12_to_YUV444_bt709", "color_convert.cl" },
410  { "NV21_to_IYUV_bt709", "color_convert.cl" },
411  { "NV21_to_RGB888_bt709", "color_convert.cl" },
412  { "NV21_to_RGBA8888_bt709", "color_convert.cl" },
413  { "NV21_to_YUV444_bt709", "color_convert.cl" },
414  { "pad_layer_constant", "pad_layer.cl" },
415  { "pad_layer_symmetric_reflect", "pad_layer.cl" },
416  { "permute", "permute.cl" },
417  { "pixelwise_mul_complex", "pixelwise_mul_float.cl" },
418  { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
419  { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
420  { "pixelwise_mul_quantized", "pixelwise_mul_int.cl" },
421  { "pooling_layer_2", "pooling_layer.cl" },
422  { "pooling_layer_3", "pooling_layer.cl" },
423  { "pooling_layer_optimized_3", "pooling_layer.cl" },
424  { "pooling_layer_7", "pooling_layer.cl" },
425  { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
426  { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
427  { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
428  { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
429  { "prior_box_layer_nchw", "prior_box_layer.cl" },
430  { "quantization_layer", "quantization_layer.cl" },
431  { "range", "range.cl" },
432  { "range_quantized", "range.cl" },
433  { "reduction_operation_x", "reduction_operation.cl" },
434  { "reduction_operation_non_parallel_x", "reduction_operation.cl" },
435  { "reduction_operation_y", "reduction_operation.cl" },
436  { "reduction_operation_z", "reduction_operation.cl" },
437  { "reduction_operation_w", "reduction_operation.cl" },
438  { "remap_nearest_neighbour", "remap.cl" },
439  { "remap_bilinear", "remap.cl" },
440  { "reorg_layer_nchw", "reorg_layer.cl" },
441  { "reorg_layer_nhwc", "reorg_layer.cl" },
442  { "reshape_layer", "reshape_layer.cl" },
443  { "reshape_to_columns", "convolution_layer.cl" },
444  { "reverse", "reverse.cl" },
445  { "RGB888_to_IYUV_bt709", "color_convert.cl" },
446  { "RGB888_to_NV12_bt709", "color_convert.cl" },
447  { "RGB888_to_RGBA8888_bt709", "color_convert.cl" },
448  { "RGB888_to_U8_bt709", "color_convert.cl" },
449  { "RGB888_to_YUV444_bt709", "color_convert.cl" },
450  { "RGBA8888_to_IYUV_bt709", "color_convert.cl" },
451  { "RGBA8888_to_NV12_bt709", "color_convert.cl" },
452  { "RGBA8888_to_RGB888_bt709", "color_convert.cl" },
453  { "RGBA8888_to_YUV444_bt709", "color_convert.cl" },
454  { "roi_align_layer", "roi_align_layer.cl" },
455  { "roi_align_layer_quantized", "roi_align_layer_quantized.cl" },
456  { "roi_pooling_layer", "roi_pooling_layer.cl" },
457  { "scale_nearest_neighbour_nchw", "scale.cl" },
458  { "scale_nearest_neighbour_nhwc", "scale.cl" },
459  { "scale_bilinear_nchw", "scale.cl" },
460  { "scale_bilinear_nhwc", "scale.cl" },
461  { "scale_bilinear_quantized_nchw", "scale_quantized.cl" },
462  { "scale_bilinear_quantized_nhwc", "scale_quantized.cl" },
463  { "scharr3x3", "scharr_filter.cl" },
464  { "select_same_rank", "select.cl" },
465  { "select_different_rank_2", "select.cl" },
466  { "select_different_rank_n", "select.cl" },
467  { "sobel3x3", "sobel_filter.cl" },
468  { "sobel_separable5x1", "sobel_filter.cl" },
469  { "sobel_separable1x5", "sobel_filter.cl" },
470  { "sobel_separable7x1", "sobel_filter.cl" },
471  { "sobel_separable1x7", "sobel_filter.cl" },
472  { "softmax_layer_norm", "softmax_layer.cl" },
473  { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
474  { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
475  { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
476  { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
477  { "space_to_batch_nchw", "space_to_batch.cl" },
478  { "space_to_batch_static_nchw", "space_to_batch.cl" },
479  { "space_to_batch_nhwc", "space_to_batch.cl" },
480  { "space_to_batch_static_nhwc", "space_to_batch.cl" },
481  { "space_to_depth_nchw", "space_to_depth.cl" },
482  { "space_to_depth_nhwc", "space_to_depth.cl" },
483  { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
484  { "stack_layer", "stack_layer.cl" },
485  { "strided_slice", "slice_ops.cl" },
486  { "suppress_non_maximum", "canny.cl" },
487  { "tablelookup_U8", "tablelookup.cl" },
488  { "tablelookup_S16", "tablelookup.cl" },
489  { "threshold_binary", "threshold.cl" },
490  { "threshold_range", "threshold.cl" },
491  { "tile", "tile.cl" },
492  { "transpose", "transpose.cl" },
493  { "UYVY422_to_IYUV_bt709", "color_convert.cl" },
494  { "UYVY422_to_NV12_bt709", "color_convert.cl" },
495  { "UYVY422_to_RGB888_bt709", "color_convert.cl" },
496  { "UYVY422_to_RGBA8888_bt709", "color_convert.cl" },
497  { "upsample_layer_nchw", "upsample_layer.cl" },
498  { "upsample_layer_nhwc", "upsample_layer.cl" },
499  { "warp_affine_nearest_neighbour", "warp_affine.cl" },
500  { "warp_affine_bilinear", "warp_affine.cl" },
501  { "warp_perspective_nearest_neighbour", "warp_perspective.cl" },
502  { "warp_perspective_bilinear", "warp_perspective.cl" },
503  { "winograd_filter_transform_2x2_3x3_nchw", "winograd_filter_transform.cl" },
504  { "winograd_filter_transform_2x1_3x1_nchw", "winograd_filter_transform.cl" },
505  { "winograd_filter_transform_1x2_1x3_nchw", "winograd_filter_transform.cl" },
506  { "winograd_filter_transform_4x4_3x3_nchw", "winograd_filter_transform.cl" },
507  { "winograd_filter_transform_4x1_3x1_nchw", "winograd_filter_transform.cl" },
508  { "winograd_filter_transform_1x4_1x3_nchw", "winograd_filter_transform.cl" },
509  { "winograd_filter_transform_4x4_5x5_nchw", "winograd_filter_transform.cl" },
510  { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
511  { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
512  { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
513  { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
514  { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
515  { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
516  { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
517  { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
518  { "winograd_filter_transform_2x2_7x7_nhwc", "winograd_filter_transform.cl" },
519  { "winograd_filter_transform_2x1_7x1_nhwc", "winograd_filter_transform.cl" },
520  { "winograd_filter_transform_1x2_1x7_nhwc", "winograd_filter_transform.cl" },
521  { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd_input_transform.cl" },
522  { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd_input_transform.cl" },
523  { "winograd_input_transform_2x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
524  { "winograd_input_transform_2x1_3x1_stepz2_nchw", "winograd_input_transform.cl" },
525  { "winograd_input_transform_1x2_1x3_stepz1_nchw", "winograd_input_transform.cl" },
526  { "winograd_input_transform_1x2_1x3_stepz2_nchw", "winograd_input_transform.cl" },
527  { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd_input_transform.cl" },
528  { "winograd_input_transform_4x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
529  { "winograd_input_transform_1x4_1x3_stepz1_nchw", "winograd_input_transform.cl" },
530  { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd_input_transform.cl" },
531  { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
532  { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
533  { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
534  { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
535  { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
536  { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
537  { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
538  { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
539  { "winograd_input_transform_2x2_7x7_stepz1_nhwc", "winograd_input_transform.cl" },
540  { "winograd_input_transform_2x1_7x1_stepz1_nhwc", "winograd_input_transform.cl" },
541  { "winograd_input_transform_1x2_1x7_stepz1_nhwc", "winograd_input_transform.cl" },
542  { "winograd_output_transform_2x2_3x3_nchw", "winograd_output_transform.cl" },
543  { "winograd_output_transform_2x1_3x1_nchw", "winograd_output_transform.cl" },
544  { "winograd_output_transform_1x2_1x3_nchw", "winograd_output_transform.cl" },
545  { "winograd_output_transform_4x4_3x3_nchw", "winograd_output_transform.cl" },
546  { "winograd_output_transform_4x1_3x1_nchw", "winograd_output_transform.cl" },
547  { "winograd_output_transform_1x4_1x3_nchw", "winograd_output_transform.cl" },
548  { "winograd_output_transform_4x4_5x5_nchw", "winograd_output_transform.cl" },
549  { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
550  { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
551  { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
552  { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
553  { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
554  { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
555  { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
556  { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
557  { "winograd_output_transform_2x2_7x7_nhwc", "winograd_output_transform.cl" },
558  { "winograd_output_transform_2x1_7x1_nhwc", "winograd_output_transform.cl" },
559  { "winograd_output_transform_1x2_1x7_nhwc", "winograd_output_transform.cl" },
560  { "yolo_layer_nchw", "yolo_layer.cl" },
561  { "yolo_layer_nhwc", "yolo_layer.cl" },
562  { "YUYV422_to_IYUV_bt709", "color_convert.cl" },
563  { "YUYV422_to_NV12_bt709", "color_convert.cl" },
564  { "YUYV422_to_RGB888_bt709", "color_convert.cl" },
565  { "YUYV422_to_RGBA8888_bt709", "color_convert.cl" },
566 };
567 
568 const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
569 {
570 #ifdef EMBEDDED_KERNELS
571  {
572  "absdiff.cl",
573 #include "./cl_kernels/absdiff.clembed"
574  },
575  {
576  "accumulate.cl",
577 #include "./cl_kernels/accumulate.clembed"
578  },
579  {
580  "activation_layer.cl",
581 #include "./cl_kernels/activation_layer.clembed"
582  },
583  {
584  "activation_layer_quant.cl",
585 #include "./cl_kernels/activation_layer_quant.clembed"
586  },
587  {
588  "batch_to_space.cl",
589 #include "./cl_kernels/batch_to_space.clembed"
590  },
591  {
592  "bitwise_op.cl",
593 #include "./cl_kernels/bitwise_op.clembed"
594  },
595  {
596  "bounding_box_transform.cl",
597 #include "./cl_kernels/bounding_box_transform.clembed"
598  },
599  {
600  "bounding_box_transform_quantized.cl",
601 #include "./cl_kernels/bounding_box_transform_quantized.clembed"
602  },
603  {
604  "canny.cl",
605 #include "./cl_kernels/canny.clembed"
606  },
607  {
608  "channel_combine.cl",
609 #include "./cl_kernels/channel_combine.clembed"
610  },
611  {
612  "channel_extract.cl",
613 #include "./cl_kernels/channel_extract.clembed"
614  },
615  {
616  "channel_shuffle.cl",
617 #include "./cl_kernels/channel_shuffle.clembed"
618  },
619  {
620  "col2im.cl",
621 #include "./cl_kernels/col2im.clembed"
622  },
623  {
624  "comparisons.cl",
625 #include "./cl_kernels/comparisons.clembed"
626  },
627  {
628  "concatenate.cl",
629 #include "./cl_kernels/concatenate.clembed"
630  },
631  {
632  "color_convert.cl",
633 #include "./cl_kernels/color_convert.clembed"
634  },
635  {
636  "convert_fc_weights.cl",
637 #include "./cl_kernels/convert_fc_weights.clembed"
638  },
639  {
640  "convolution3x3.cl",
641 #include "./cl_kernels/convolution3x3.clembed"
642  },
643  {
644  "convolution5x5.cl",
645 #include "./cl_kernels/convolution5x5.clembed"
646  },
647  {
648  "convolution7x7.cl",
649 #include "./cl_kernels/convolution7x7.clembed"
650  },
651  {
652  "convolution9x9.cl",
653 #include "./cl_kernels/convolution9x9.clembed"
654  },
655  {
656  "convolution_layer.cl",
657 #include "./cl_kernels/convolution_layer.clembed"
658  },
659  {
660  "convolution_rectangle.cl",
661 #include "./cl_kernels/convolution_rectangle.clembed"
662  },
663  {
664  "copy_tensor.cl",
665 #include "./cl_kernels/copy_tensor.clembed"
666  },
667  {
668  "crop_tensor.cl",
669 #include "./cl_kernels/crop_tensor.clembed"
670  },
671  {
672  "upsample_layer.cl",
673 #include "./cl_kernels/upsample_layer.clembed"
674  },
675  {
676  "deconvolution_layer.cl",
677 #include "./cl_kernels/deconvolution_layer.clembed"
678  },
679  {
680  "depth_convert.cl",
681 #include "./cl_kernels/depth_convert.clembed"
682  },
683  {
684  "depth_to_space.cl",
685 #include "./cl_kernels/depth_to_space.clembed"
686  },
687  {
688  "depthwise_convolution.cl",
689 #include "./cl_kernels/depthwise_convolution.clembed"
690  },
691  {
692  "depthwise_convolution_quantized.cl",
693 #include "./cl_kernels/depthwise_convolution_quantized.clembed"
694  },
695  {
696  "dequantization_layer.cl",
697 #include "./cl_kernels/dequantization_layer.clembed"
698  },
699  {
700  "derivative.cl",
701 #include "./cl_kernels/derivative.clembed"
702  },
703  {
704  "dilate.cl",
705 #include "./cl_kernels/dilate.clembed"
706  },
707  {
708  "direct_convolution1x1.cl",
709 #include "./cl_kernels/direct_convolution1x1.clembed"
710  },
711  {
712  "direct_convolution3x3.cl",
713 #include "./cl_kernels/direct_convolution3x3.clembed"
714  },
715  {
716  "direct_convolution5x5.cl",
717 #include "./cl_kernels/direct_convolution5x5.clembed"
718  },
719  {
720  "direct_convolution_quantized.cl",
721 #include "./cl_kernels/direct_convolution_quantized.clembed"
722  },
723  {
724  "direct_convolution9x9.cl",
725 #include "./cl_kernels/direct_convolution9x9.clembed"
726  },
727  {
728  "elementwise_operation.cl",
729 #include "./cl_kernels/elementwise_operation.clembed"
730  },
731  {
732  "elementwise_operation_quantized.cl",
733 #include "./cl_kernels/elementwise_operation_quantized.clembed"
734  },
735  {
736  "elementwise_unary.cl",
737 #include "./cl_kernels/elementwise_unary.clembed"
738  },
739  {
740  "erode.cl",
741 #include "./cl_kernels/erode.clembed"
742  },
743  {
744  "fast_corners.cl",
745 #include "./cl_kernels/fast_corners.clembed"
746  },
747  {
748  "fft.cl",
749 #include "./cl_kernels/fft.clembed"
750  },
751  {
752  "fft_digit_reverse.cl",
753 #include "./cl_kernels/fft_digit_reverse.clembed"
754  },
755  {
756  "fft_scale.cl",
757 #include "./cl_kernels/fft_scale.clembed"
758  },
759  {
760  "fill_border.cl",
761 #include "./cl_kernels/fill_border.clembed"
762  },
763  {
764  "flatten.cl",
765 #include "./cl_kernels/flatten.clembed"
766  },
767  {
768  "floor.cl",
769 #include "./cl_kernels/floor.clembed"
770  },
771  {
772  "gather.cl",
773 #include "./cl_kernels/gather.clembed"
774  },
775  {
776  "gaussian_pyramid.cl",
777 #include "./cl_kernels/gaussian_pyramid.clembed"
778  },
779  {
780  "gemm.cl",
781 #include "./cl_kernels/gemm.clembed"
782  },
783  {
784  "gemmlowp.cl",
785 #include "./cl_kernels/gemmlowp.clembed"
786  },
787  {
788  "gemv.cl",
789 #include "./cl_kernels/gemv.clembed"
790  },
791  {
792  "generate_proposals.cl",
793 #include "./cl_kernels/generate_proposals.clembed"
794  },
795  {
796  "generate_proposals_quantized.cl",
797 #include "./cl_kernels/generate_proposals_quantized.clembed"
798  },
799  {
800  "harris_corners.cl",
801 #include "./cl_kernels/harris_corners.clembed"
802  },
803  {
804  "helpers.h",
805 #include "./cl_kernels/helpers.hembed"
806  },
807  {
808  "helpers_asymm.h",
809 #include "./cl_kernels/helpers_asymm.hembed"
810  },
811  {
812  "histogram.cl",
813 #include "./cl_kernels/histogram.clembed"
814  },
815  {
816  "hog.cl",
817 #include "./cl_kernels/hog.clembed"
818  },
819  {
820  "im2col.cl",
821 #include "./cl_kernels/im2col.clembed"
822  },
823  {
824  "instance_normalization.cl",
825 #include "./cl_kernels/instance_normalization.clembed"
826  },
827  {
828  "integral_image.cl",
829 #include "./cl_kernels/integral_image.clembed"
830  },
831  {
832  "l2_normalize.cl",
833 #include "./cl_kernels/l2_normalize.clembed"
834  },
835  {
836  "magnitude_phase.cl",
837 #include "./cl_kernels/magnitude_phase.clembed"
838  },
839  {
840  "mean_stddev.cl",
841 #include "./cl_kernels/mean_stddev.clembed"
842  },
843  {
844  "mean_stddev_normalization.cl",
845 #include "./cl_kernels/mean_stddev_normalization.clembed"
846  },
847  {
848  "memset.cl",
849 #include "./cl_kernels/memset.clembed"
850  },
851  {
852  "minmaxloc.cl",
853 #include "./cl_kernels/minmaxloc.clembed"
854  },
855  {
856  "minmax_layer.cl",
857 #include "./cl_kernels/minmax_layer.clembed"
858  },
859  {
860  "non_linear_filter3x3.cl",
861 #include "./cl_kernels/non_linear_filter3x3.clembed"
862  },
863  {
864  "non_linear_filter5x5.cl",
865 #include "./cl_kernels/non_linear_filter5x5.clembed"
866  },
867  {
868  "non_linear_filter_helpers.h",
869 #include "./cl_kernels/non_linear_filter_helpers.hembed"
870  },
871  {
872  "nonmax.cl",
873 #include "./cl_kernels/nonmax.clembed"
874  },
875  {
876  "normalization_layer.cl",
877 #include "./cl_kernels/normalization_layer.clembed"
878  },
879  {
880  "normalize_planar_yuv_layer.cl",
881 #include "./cl_kernels/normalize_planar_yuv_layer.clembed"
882  },
883  {
884  "normalize_planar_yuv_layer_quantized.cl",
885 #include "./cl_kernels/normalize_planar_yuv_layer_quantized.clembed"
886  },
887  {
888  "batchnormalization_layer.cl",
889 #include "./cl_kernels/batchnormalization_layer.clembed"
890  },
891  {
892  "optical_flow_pyramid_lk.cl",
893 #include "./cl_kernels/optical_flow_pyramid_lk.clembed"
894  },
895  {
896  "pad_layer.cl",
897 #include "./cl_kernels/pad_layer.clembed"
898  },
899  {
900  "permute.cl",
901 #include "./cl_kernels/permute.clembed"
902  },
903  {
904  "pixelwise_mul_float.cl",
905 #include "./cl_kernels/pixelwise_mul_float.clembed"
906  },
907  {
908  "pixelwise_mul_int.cl",
909 #include "./cl_kernels/pixelwise_mul_int.clembed"
910  },
911  {
912  "pooling_layer.cl",
913 #include "./cl_kernels/pooling_layer.clembed"
914  },
915  {
916  "pooling_layer_quantized.cl",
917 #include "./cl_kernels/pooling_layer_quantized.clembed"
918  },
919  {
920  "prior_box_layer.cl",
921 #include "./cl_kernels/prior_box_layer.clembed"
922  },
923  {
924  "quantization_layer.cl",
925 #include "./cl_kernels/quantization_layer.clembed"
926  },
927  {
928  "range.cl",
929 #include "./cl_kernels/range.clembed"
930  },
931  {
932  "reduction_operation.cl",
933 #include "./cl_kernels/reduction_operation.clembed"
934  },
935  {
936  "remap.cl",
937 #include "./cl_kernels/remap.clembed"
938  },
939  {
940  "reorg_layer.cl",
941 #include "./cl_kernels/reorg_layer.clembed"
942  },
943  {
944  "reshape_layer.cl",
945 #include "./cl_kernels/reshape_layer.clembed"
946  },
947  {
948  "reverse.cl",
949 #include "./cl_kernels/reverse.clembed"
950  },
951  {
952  "roi_align_layer.cl",
953 #include "./cl_kernels/roi_align_layer.clembed"
954  },
955  {
956  "roi_align_layer_quantized.cl",
957 #include "./cl_kernels/roi_align_layer_quantized.clembed"
958  },
959  {
960  "roi_pooling_layer.cl",
961 #include "./cl_kernels/roi_pooling_layer.clembed"
962  },
963  {
964  "scale.cl",
965 #include "./cl_kernels/scale.clembed"
966  },
967  {
968  "scale_quantized.cl",
969 #include "./cl_kernels/scale_quantized.clembed"
970  },
971  {
972  "scharr_filter.cl",
973 #include "./cl_kernels/scharr_filter.clembed"
974  },
975  {
976  "select.cl",
977 #include "./cl_kernels/select.clembed"
978  },
979  {
980  "sobel_filter.cl",
981 #include "./cl_kernels/sobel_filter.clembed"
982  },
983  {
984  "softmax_layer.cl",
985 #include "./cl_kernels/softmax_layer.clembed"
986  },
987  {
988  "softmax_layer_quantized.cl",
989 #include "./cl_kernels/softmax_layer_quantized.clembed"
990  },
991  {
992  "slice_ops.cl",
993 #include "./cl_kernels/slice_ops.clembed"
994  },
995  {
996  "space_to_batch.cl",
997 #include "./cl_kernels/space_to_batch.clembed"
998  },
999  {
1000  "space_to_depth.cl",
1001 #include "./cl_kernels/space_to_depth.clembed"
1002  },
1003  {
1004  "stack_layer.cl",
1005 #include "./cl_kernels/stack_layer.clembed"
1006  },
1007  {
1008  "tablelookup.cl",
1009 #include "./cl_kernels/tablelookup.clembed"
1010  },
1011  {
1012  "threshold.cl",
1013 #include "./cl_kernels/threshold.clembed"
1014  },
1015  {
1016  "tile.cl",
1017 #include "./cl_kernels/tile.clembed"
1018  },
1019  {
1020  "transpose.cl",
1021 #include "./cl_kernels/transpose.clembed"
1022  },
1023  {
1024  "types.h",
1025 #include "./cl_kernels/types.hembed"
1026  },
1027  {
1028  "warp_affine.cl",
1029 #include "./cl_kernels/warp_affine.clembed"
1030  },
1031  {
1032  "warp_helpers.h",
1033 #include "./cl_kernels/warp_helpers.hembed"
1034  },
1035  {
1036  "warp_perspective.cl",
1037 #include "./cl_kernels/warp_perspective.clembed"
1038  },
1039  {
1040  "winograd_filter_transform.cl",
1041 #include "./cl_kernels/winograd_filter_transform.clembed"
1042  },
1043  {
1044  "winograd_input_transform.cl",
1045 #include "./cl_kernels/winograd_input_transform.clembed"
1046  },
1047  {
1048  "winograd_output_transform.cl",
1049 #include "./cl_kernels/winograd_output_transform.clembed"
1050  },
1051  {
1052  "yolo_layer.cl",
1053 #include "./cl_kernels/yolo_layer.clembed"
1054  },
1055 #endif /* EMBEDDED_KERNELS */
1056 };
1057 
1059  : _context(), _device(), _kernel_path("."), _programs_map(), _built_programs_map()
1060 {
1061  opencl_is_available(); // Make sure the OpenCL symbols are initialised *before* the CLKernelLibrary is built
1062 }
1063 
1065 {
1066  static CLKernelLibrary _kernel_library;
1067  return _kernel_library;
1068 }
1069 
1070 Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const StringSet &build_options_set) const
1071 {
1072  // Find which program contains the kernel
1073  auto kernel_program_it = _kernel_program_map.find(kernel_name);
1074 
1075  if(_kernel_program_map.end() == kernel_program_it)
1076  {
1077  ARM_COMPUTE_ERROR_VAR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
1078  }
1079  std::string concat_str;
1080 
1081 #if defined(ARM_COMPUTE_DEBUG_ENABLED)
1082  // Enable debug properties in CL kernels
1083  concat_str += " -DARM_COMPUTE_DEBUG_ENABLED";
1084 #endif // defined(ARM_COMPUTE_DEBUG_ENABLED)
1085 
1087  concat_str += " -DGPU_ARCH=" + support::cpp11::to_string(
1088  static_cast<std::underlying_type<GPUTarget>::type>(gpu_arch));
1089  if(fp16_supported())
1090  {
1091  concat_str += " -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 ";
1092  }
1093 
1094  if(dot8_supported(_device))
1095  {
1096  concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ENABLED=1 ";
1097  }
1098 
1099  if(dot8_acc_supported(_device))
1100  {
1101  concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED=1 ";
1102  }
1103 
1104  if(get_cl_version(_device) == CLVersion::CL20)
1105  {
1106  concat_str += " -cl-std=CL2.0 ";
1107  }
1108  else if(arm_non_uniform_workgroup_supported(_device))
1109  {
1110  concat_str += " -cl-arm-non-uniform-work-group-size ";
1111  }
1112  else
1113  {
1114  ARM_COMPUTE_ERROR("Non uniform workgroup size is not supported!!");
1115  }
1116 
1117  // Check if the program has been built before with same build options.
1118  const std::string program_name = kernel_program_it->second;
1119  const std::string build_options = stringify_set(build_options_set) + concat_str;
1120 
1121  const std::string built_program_name = program_name + "_" + build_options;
1122  auto built_program_it = _built_programs_map.find(built_program_name);
1123 
1124  cl::Program cl_program;
1125 
1126  if(_built_programs_map.end() != built_program_it)
1127  {
1128  // If program has been built, retrieve to create kernel from it
1129  cl_program = built_program_it->second;
1130  }
1131  else
1132  {
1133  // Get program
1134  Program program = load_program(program_name);
1135 
1136  // Build program
1137  cl_program = program.build(build_options);
1138 
1139  // Add built program to internal map
1140  _built_programs_map.emplace(built_program_name, cl_program);
1141  }
1142 
1143  // Create and return kernel
1144  return Kernel(kernel_name, cl_program);
1145 }
1146 
1147 void CLKernelLibrary::init(std::string kernel_path, cl::Context context, cl::Device device)
1148 {
1149  _kernel_path = std::move(kernel_path);
1150  _context = std::move(context);
1151  _device = std::move(device);
1152 }
1153 
1154 void CLKernelLibrary::set_kernel_path(const std::string &kernel_path)
1155 {
1156  _kernel_path = kernel_path;
1157 }
1158 
1160 {
1161  return _context;
1162 }
1163 
1165 {
1166  return _device;
1167 }
1168 
1169 void CLKernelLibrary::set_device(cl::Device device)
1170 {
1171  _device = std::move(device);
1172 }
1173 
1175 {
1176  return _kernel_path;
1177 }
1178 
1180 {
1181  _programs_map.clear();
1182  _built_programs_map.clear();
1183 }
1184 
1185 const std::map<std::string, cl::Program> &CLKernelLibrary::get_built_programs() const
1186 {
1187  return _built_programs_map;
1188 }
1189 
1190 void CLKernelLibrary::add_built_program(const std::string &built_program_name, const cl::Program &program)
1191 {
1192  _built_programs_map.emplace(built_program_name, program);
1193 }
1194 
1196 {
1197  return ::fp16_supported(_device);
1198 }
1199 
1201 {
1202  return device_supports_extension(_device, "cl_khr_int64_base_atomics");
1203 }
1204 
1205 const Program &CLKernelLibrary::load_program(const std::string &program_name) const
1206 {
1207  const auto program_it = _programs_map.find(program_name);
1208 
1209  if(program_it != _programs_map.end())
1210  {
1211  return program_it->second;
1212  }
1213 
1214  Program program;
1215 
1216 #ifdef EMBEDDED_KERNELS
1217  const auto program_source_it = _program_source_map.find(program_name);
1218 
1219  if(_program_source_map.end() == program_source_it)
1220  {
1221  ARM_COMPUTE_ERROR_VAR("Embedded program for %s does not exist.", program_name.c_str());
1222  }
1223 
1224  program = Program(_context, program_name, program_source_it->second);
1225 #else /* EMBEDDED_KERNELS */
1226  // Check for binary
1227  std::string source_name = _kernel_path + program_name;
1228  std::string binary_name = source_name + "bin";
1229 
1230  if(std::ifstream(binary_name).is_open())
1231  {
1232  const std::string program_binary = read_file(binary_name, true);
1233  program = Program(_context, _device, program_name, std::vector<unsigned char>(program_binary.begin(), program_binary.end()));
1234  }
1235  else if(std::ifstream(source_name).is_open())
1236  {
1237  program = Program(_context, program_name, read_file(source_name, false));
1238  }
1239  else
1240  {
1241  ARM_COMPUTE_ERROR_VAR("Kernel file %s does not exist.", source_name.c_str());
1242  }
1243 #endif /* EMBEDDED_KERNELS */
1244 
1245  // Insert program to program map
1246  const auto new_program = _programs_map.emplace(program_name, std::move(program));
1247 
1248  return new_program.first->second;
1249 }
1250 
1251 void CLKernelLibrary::set_context(cl::Context context)
1252 {
1253  _context = std::move(context);
1254  if(_context.get() == nullptr)
1255  {
1256  _device = cl::Device();
1257  }
1258  else
1259  {
1260  const auto cl_devices = _context.getInfo<CL_CONTEXT_DEVICES>();
1261 
1262  if(cl_devices.empty())
1263  {
1264  _device = cl::Device();
1265  }
1266  else
1267  {
1268  _device = cl_devices[0];
1269  }
1270  }
1271 }
1272 
1273 std::string CLKernelLibrary::stringify_set(const StringSet &s) const
1274 {
1275  std::string concat_set;
1276 
1277 #ifndef EMBEDDED_KERNELS
1278  concat_set += "-I" + _kernel_path + " ";
1279 #endif /* EMBEDDED_KERNELS */
1280 
1281  // Concatenate set
1282  for(const auto &el : s)
1283  {
1284  concat_set += " " + el;
1285  }
1286 
1287  return concat_set;
1288 }
1289 
1290 std::string CLKernelLibrary::get_program_source(const std::string &program_name)
1291 {
1292  const auto program_source_it = _program_source_map.find(program_name);
1293 
1294  if(program_source_it == _program_source_map.end())
1295  {
1296  ARM_COMPUTE_ERROR_VAR("Embedded program for %s does not exist.", program_name.c_str());
1297  }
1298 
1299  return program_source_it->second;
1300 }
1301 
1302 size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const
1303 {
1304  size_t result;
1305 
1306  size_t err = kernel.getWorkGroupInfo(_device, CL_KERNEL_WORK_GROUP_SIZE, &result);
1307  ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel");
1308  ARM_COMPUTE_UNUSED(err);
1309 
1310  return result;
1311 }
1312 
1314 {
1315  GPUTarget _target = get_target_from_device(_device);
1316  cl::NDRange default_range;
1317 
1318  switch(_target)
1319  {
1320  case GPUTarget::MIDGARD:
1321  case GPUTarget::T600:
1322  case GPUTarget::T700:
1323  case GPUTarget::T800:
1324  default_range = cl::NDRange(128u, 1);
1325  break;
1326  default:
1327  default_range = cl::NullRange;
1328  }
1329 
1330  return default_range;
1331 }
1332 
1334 {
1335  return _device.getInfo<CL_DEVICE_VERSION>();
1336 }
1337 
1339 {
1340  return _device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>();
1341 }
bool dot8_acc_supported(const cl::Device &device)
Helper function to check whether the cl_arm_integer_dot_product_accumulate_int8 extension is supporte...
Definition: CLHelpers.cpp:214
void set_kernel_path(const std::string &kernel_path)
Sets the path that the kernels reside in.
cl::Device & get_device()
Gets the CL device for which the programs are created.
bool dot8_supported(const cl::Device &device)
Helper function to check whether the cl_arm_integer_dot_product_int8 extension is supported.
Definition: CLHelpers.cpp:204
Kernel()
Default Constructor.
bool fp16_supported(const cl::Device &device)
Helper function to check whether the cl_khr_fp16 extension is supported.
Definition: CLHelpers.cpp:199
void add_built_program(const std::string &built_program_name, const cl::Program &program)
Add a new built program to the cache.
std::string get_device_version()
Return the device version.
const StringSet & options() const
Gets the current options list set.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
std::string to_string(T &&value)
Convert integer and float values to string.
#define ARM_COMPUTE_ERROR_VAR(msg,...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:346
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
CLBuildOptions()
Default constructor.
GPUTarget get_arch_from_target(GPUTarget target)
Helper function to get the GPU arch.
Definition: GPUTarget.cpp:189
void set_context(cl::Context context)
Sets the CL context used to create programs.
Copyright (c) 2017-2019 ARM Limited.
cl_uint get_num_compute_units()
Return the maximum number of compute units in the device.
size_t max_local_workgroup_size(const cl::Kernel &kernel) const
Find the maximum number of local work items in a workgroup can be supported for the kernel.
void add_option(std::string option)
Adds option to the existing build option list.
void add_options(const StringSet &options)
Appends given build options to the current's objects options.
cl::NDRange default_ndrange() const
Return the default NDRange for the device.
void clear_programs_cache()
Clear the library's cache of binary programs.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
std::string read_file(const std::string &filename, bool binary)
Load an entire file in memory.
Definition: Utils.cpp:47
void set_device(cl::Device device)
Sets the CL device for which the programs are created.
CLKernelLibrary()
Default Constructor.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
std::string get_program_source(const std::string &program_name)
Gets the source of the selected program.
static bool build(const cl::Program &program, const std::string &build_options="")
Build the given CL program.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
GPUTarget get_target_from_device(const cl::Device &device)
Helper function to get the GPU target from CL device.
Definition: CLHelpers.cpp:186
void init(std::string kernel_path, cl::Context context, cl::Device device)
Initialises the kernel library.
Program()
Default constructor.
CLVersion get_cl_version(const cl::Device &device)
Helper function to get the highest OpenCL version supported.
Definition: CLHelpers.cpp:219
bool int64_base_atomics_supported() const
Returns true if int64_base_atomics extension is supported by the CL device.
bool device_supports_extension(const cl::Device &device, const char *extension_name)
Helper function to check whether a given extension is supported.
Definition: CLHelpers.cpp:242
GPUTarget
Available GPU Targets.
Definition: GPUTarget.h:34
bool fp16_supported() const
Returns true if FP16 is supported by the CL device.
Kernel create_kernel(const std::string &kernel_name, const StringSet &build_options_set={}) const
Creates a kernel from the kernel library.
CLKernelLibrary class.
std::string get_kernel_path()
Gets the path that the kernels reside in.
bool arm_non_uniform_workgroup_supported(const cl::Device &device)
Helper function to check whether the arm_non_uniform_work_group_size extension is supported.
Definition: CLHelpers.cpp:194
const std::map< std::string, cl::Program > & get_built_programs() const
Access the cache of built OpenCL programs.
void add_options_if(bool cond, const StringSet &options)
Appends given build options to the current's objects options if a given condition is true.
bool opencl_is_available()
Check if OpenCL is available.
Definition: OpenCL.cpp:142
cl::Context & context()
Accessor for the associated CL context.
void add_option_if_else(bool cond, std::string option_true, std::string option_false)
Adds first option if condition is true else the second one.