Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 5237e01 | 2018-01-17 09:40:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | */ |
| 24 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
| 25 | |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CL/CLHelpers.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/Utils.h" |
| 29 | |
steniu01 | 5f91072 | 2017-08-23 10:15:22 +0100 | [diff] [blame] | 30 | #include <algorithm> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | #include <fstream> |
| 32 | #include <iostream> |
| 33 | #include <utility> |
| 34 | #include <vector> |
| 35 | |
| 36 | using namespace arm_compute; |
| 37 | |
Georgios Pinitas | 388d3ec | 2017-11-02 12:17:56 +0000 | [diff] [blame] | 38 | CLBuildOptions::CLBuildOptions() |
| 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 | |
Chunosov | f450caa | 2017-11-08 16:09:35 +0700 | [diff] [blame] | 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 | { |
| 70 | add_options(options); |
| 71 | } |
| 72 | } |
| 73 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 74 | const CLBuildOptions::StringSet &CLBuildOptions::options() const |
Georgios Pinitas | 388d3ec | 2017-11-02 12:17:56 +0000 | [diff] [blame] | 75 | { |
| 76 | return _build_opts; |
| 77 | } |
| 78 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 79 | Program::Program() |
| 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 | |
| 133 | Kernel::Kernel() |
| 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" }, |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 151 | { "activation_layer_qa8", "activation_layer_qa8.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 152 | { "arithmetic_add", "arithmetic_op.cl" }, |
| 153 | { "arithmetic_sub", "arithmetic_op.cl" }, |
Georgios Pinitas | de5a1cc | 2018-02-02 12:52:07 +0000 | [diff] [blame] | 154 | { "batchnormalization_layer", "batchnormalization_layer.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 155 | { "bitwise_or", "bitwise_op.cl" }, |
| 156 | { "bitwise_and", "bitwise_op.cl" }, |
| 157 | { "bitwise_xor", "bitwise_op.cl" }, |
| 158 | { "bitwise_not", "bitwise_op.cl" }, |
| 159 | { "channel_combine_NV", "channel_combine.cl" }, |
| 160 | { "channel_combine_RGB888", "channel_combine.cl" }, |
| 161 | { "channel_combine_RGBA8888", "channel_combine.cl" }, |
| 162 | { "channel_combine_UYVY422", "channel_combine.cl" }, |
| 163 | { "channel_combine_YUYV422", "channel_combine.cl" }, |
| 164 | { "channel_extract_NV12", "channel_extract.cl" }, |
| 165 | { "channel_extract_NV21", "channel_extract.cl" }, |
| 166 | { "channel_extract_RGB888", "channel_extract.cl" }, |
| 167 | { "channel_extract_RGBA8888", "channel_extract.cl" }, |
| 168 | { "channel_extract_UYVY422", "channel_extract.cl" }, |
| 169 | { "channel_extract_YUYV422", "channel_extract.cl" }, |
| 170 | { "combine_gradients_L1", "canny.cl" }, |
| 171 | { "combine_gradients_L2", "canny.cl" }, |
| 172 | { "concatenate_depth", "concatenate.cl" }, |
| 173 | { "convolution_rectangle", "convolution_rectangle.cl" }, |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 174 | { "col2im", "col2im.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 175 | { "convolution3x3_static", "convolution3x3.cl" }, |
| 176 | { "convolution5x5_static", "convolution5x5.cl" }, |
| 177 | { "convolution7x7_static", "convolution7x7.cl" }, |
| 178 | { "convolution9x9_static", "convolution9x9.cl" }, |
| 179 | { "convolution_separable1x5_static", "convolution5x5.cl" }, |
| 180 | { "convolution_separable5x1_static", "convolution5x5.cl" }, |
| 181 | { "convolution_separable1x7_static", "convolution7x7.cl" }, |
| 182 | { "convolution_separable7x1_static", "convolution7x7.cl" }, |
| 183 | { "convolution_separable1x9_static", "convolution9x9.cl" }, |
| 184 | { "convolution_separable9x1_static", "convolution9x9.cl" }, |
| 185 | { "convert_depth_down", "depth_convert.cl" }, |
| 186 | { "convert_depth_up", "depth_convert.cl" }, |
| 187 | { "copy_plane", "channel_extract.cl" }, |
| 188 | { "copy_planes_3p", "channel_combine.cl" }, |
| 189 | { "copy_to_keypoint", "fast_corners.cl" }, |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 190 | { "deconvolution_upsample", "deconvolution_layer.cl" }, |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 191 | { "depthwise_convolution_3x3", "depthwise_convolution.cl" }, |
Michele Di Giorgio | 933fe86 | 2018-02-19 15:42:12 +0000 | [diff] [blame] | 192 | { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" }, |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 193 | { "depthwise_convolution_3x3_quantized", "depthwise_convolution_quantized.cl" }, |
Gian Marco | c799ed8 | 2018-02-01 16:57:48 +0000 | [diff] [blame] | 194 | { "depthwise_convolution_3x3_stridex1_stridey1_bifrost", "depthwise_convolution.cl" }, |
| 195 | { "depthwise_convolution_3x3_stridex2_stridey2_bifrost", "depthwise_convolution.cl" }, |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 196 | { "depthwise_im2col", "depthwise_convolution.cl" }, |
| 197 | { "depthwise_vector_to_tensor", "depthwise_convolution.cl" }, |
| 198 | { "depthwise_weights_reshape", "depthwise_convolution.cl" }, |
Michele Di Giorgio | 56dd726 | 2017-07-27 09:53:49 +0100 | [diff] [blame] | 199 | { "dequantization_layer", "dequantization_layer.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 200 | { "derivative", "derivative.cl" }, |
| 201 | { "dilate", "dilate.cl" }, |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 202 | { "direct_convolution1x1", "direct_convolution1x1.cl" }, |
Gian Marco Iodice | 1c8409d | 2017-09-06 17:24:25 +0100 | [diff] [blame] | 203 | { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" }, |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 204 | { "direct_convolution3x3", "direct_convolution3x3.cl" }, |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 205 | { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" }, |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 206 | { "direct_convolution5x5", "direct_convolution5x5.cl" }, |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 207 | { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" }, |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 208 | { "direct_convolution_1x1_3x3_5x5_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 209 | { "erode", "erode.cl" }, |
| 210 | { "fast_corners", "fast_corners.cl" }, |
| 211 | { "fill_image_borders_constant", "fill_border.cl" }, |
| 212 | { "fill_image_borders_replicate", "fill_border.cl" }, |
| 213 | { "finalize", "optical_flow_pyramid_lk.cl" }, |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 214 | { "floor_layer", "floor.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 215 | { "gaussian1x5_sub_x", "gaussian_pyramid.cl" }, |
| 216 | { "gaussian5x1_sub_y", "gaussian_pyramid.cl" }, |
Gian Marco Iodice | 578ab61 | 2017-06-23 09:34:33 +0100 | [diff] [blame] | 217 | { "gemm_accumulate_biases", "gemm.cl" }, |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 218 | { "gemm_interleave4x4", "gemm.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 219 | { "gemm_ma_f16", "gemm.cl" }, |
| 220 | { "gemm_ma_f32", "gemm.cl" }, |
Gian Marco Iodice | 3a3066b | 2017-06-23 13:38:14 +0100 | [diff] [blame] | 221 | { "gemm_ma_qs8", "gemm.cl" }, |
Gian Marco Iodice | 8a38369 | 2017-07-03 17:41:47 +0100 | [diff] [blame] | 222 | { "gemm_ma_qs16", "gemm.cl" }, |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 223 | { "gemm_mv", "gemv.cl" }, |
Georgios Pinitas | de5a1cc | 2018-02-02 12:52:07 +0000 | [diff] [blame] | 224 | { "gemm_mv_quantized", "gemv.cl" }, |
Gian Marco Iodice | edfa9f4 | 2017-08-15 11:45:22 +0100 | [diff] [blame] | 225 | { "gemm_mm_interleaved_transposed_f16", "gemm.cl" }, |
| 226 | { "gemm_mm_interleaved_transposed_f32_midgard", "gemm.cl" }, |
| 227 | { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm.cl" }, |
| 228 | { "gemm_mm_interleaved_transposed_qs8", "gemm.cl" }, |
| 229 | { "gemm_mm_interleaved_transposed_qs16", "gemm.cl" }, |
| 230 | { "gemm_mm_floating_point", "gemm.cl" }, |
Anton Lokhmotov | 3e80c7f | 2017-11-20 11:02:10 +0000 | [diff] [blame] | 231 | { "gemm_mm_floating_point_f32_bifrost", "gemm.cl" }, |
| 232 | { "gemm_mm_floating_point_f32_bifrost_1000", "gemm.cl" }, |
Gian Marco Iodice | 3a3066b | 2017-06-23 13:38:14 +0100 | [diff] [blame] | 233 | { "gemm_mm_qs8", "gemm.cl" }, |
Gian Marco Iodice | 8a38369 | 2017-07-03 17:41:47 +0100 | [diff] [blame] | 234 | { "gemm_mm_qs16", "gemm.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 235 | { "gemm_lc_vm_f32", "gemm.cl" }, |
Gian Marco | 36a0a46 | 2018-01-12 10:21:40 +0000 | [diff] [blame] | 236 | { "gemm_transpose1xW", "gemm.cl" }, |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 237 | { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" }, |
| 238 | { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" }, |
Gian Marco | 7b4d547 | 2018-01-10 15:56:30 +0000 | [diff] [blame] | 239 | { "gemmlowp_mm_bifrost", "gemmlowp.cl" }, |
| 240 | { "gemmlowp_mm_midgard", "gemmlowp.cl" }, |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 241 | { "gemmlowp_mm_interleaved_transposed_bifrost", "gemmlowp.cl" }, |
| 242 | { "gemmlowp_mm_interleaved_transposed_midgard", "gemmlowp.cl" }, |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 243 | { "gemmlowp_offset_contribution", "gemmlowp.cl" }, |
| 244 | { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" }, |
Gian Marco | 58c5794 | 2017-11-28 09:10:03 +0000 | [diff] [blame] | 245 | { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 246 | { "harris_score_3x3", "harris_corners.cl" }, |
| 247 | { "harris_score_5x5", "harris_corners.cl" }, |
| 248 | { "harris_score_7x7", "harris_corners.cl" }, |
| 249 | { "hist_border_kernel", "histogram.cl" }, |
| 250 | { "hist_border_kernel_fixed", "histogram.cl" }, |
| 251 | { "hist_local_kernel", "histogram.cl" }, |
| 252 | { "hist_local_kernel_fixed", "histogram.cl" }, |
| 253 | { "hog_block_normalization", "hog.cl" }, |
| 254 | { "hog_detector", "hog.cl" }, |
| 255 | { "hog_orientation_binning", "hog.cl" }, |
| 256 | { "hysteresis", "canny.cl" }, |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 257 | { "im2col1x1_stridex1_dchw", "im2col.cl" }, |
| 258 | { "im2col3x3_dchw", "im2col.cl" }, |
| 259 | { "im2col5x5_dchw", "im2col.cl" }, |
| 260 | { "im2col11x11_padx0_pady0_dchw", "im2col.cl" }, |
| 261 | { "im2col_generic_dchw", "im2col.cl" }, |
| 262 | { "im2col_generic_padx0_pady0_dchw", "im2col.cl" }, |
| 263 | { "im2col_reduced_dchw", "im2col.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 264 | { "init_level", "optical_flow_pyramid_lk.cl" }, |
| 265 | { "init_level_max", "optical_flow_pyramid_lk.cl" }, |
| 266 | { "init_level_max_initial_estimate", "optical_flow_pyramid_lk.cl" }, |
| 267 | { "integral_horizontal", "integral_image.cl" }, |
| 268 | { "integral_vertical", "integral_image.cl" }, |
| 269 | { "IYUV_to_NV12_bt709", "color_convert.cl" }, |
| 270 | { "IYUV_to_RGB888_bt709", "color_convert.cl" }, |
| 271 | { "IYUV_to_RGBA8888_bt709", "color_convert.cl" }, |
| 272 | { "IYUV_to_YUV444_bt709", "color_convert.cl" }, |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 273 | { "l2_normalize", "l2_normalize.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 274 | { "lktracker_stage0", "optical_flow_pyramid_lk.cl" }, |
| 275 | { "lktracker_stage1", "optical_flow_pyramid_lk.cl" }, |
| 276 | { "magnitude_phase", "magnitude_phase.cl" }, |
| 277 | { "mean_stddev_accumulate", "mean_stddev.cl" }, |
| 278 | { "minmax", "minmaxloc.cl" }, |
| 279 | { "minmax_border", "minmaxloc.cl" }, |
Michele Di Giorgio | 56dd726 | 2017-07-27 09:53:49 +0100 | [diff] [blame] | 280 | { "minmax_layer", "minmax_layer.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 281 | { "minmaxloc", "minmaxloc.cl" }, |
| 282 | { "non_linear_filter_box3x3", "non_linear_filter3x3.cl" }, |
| 283 | { "non_linear_filter_cross3x3", "non_linear_filter3x3.cl" }, |
| 284 | { "non_linear_filter_disk3x3", "non_linear_filter3x3.cl" }, |
| 285 | { "non_linear_filter_box5x5", "non_linear_filter5x5.cl" }, |
| 286 | { "non_linear_filter_cross5x5", "non_linear_filter5x5.cl" }, |
| 287 | { "non_linear_filter_disk5x5", "non_linear_filter5x5.cl" }, |
| 288 | { "non_max_suppression", "nonmax.cl" }, |
| 289 | { "normalization_layer_cross_map", "normalization_layer.cl" }, |
Georgios Pinitas | 0162436 | 2017-11-30 10:53:31 +0000 | [diff] [blame] | 290 | { "normalization_layer_in_map", "normalization_layer.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 291 | { "NV12_to_IYUV_bt709", "color_convert.cl" }, |
| 292 | { "NV12_to_RGB888_bt709", "color_convert.cl" }, |
| 293 | { "NV12_to_RGBA8888_bt709", "color_convert.cl" }, |
| 294 | { "NV12_to_YUV444_bt709", "color_convert.cl" }, |
| 295 | { "NV21_to_IYUV_bt709", "color_convert.cl" }, |
| 296 | { "NV21_to_RGB888_bt709", "color_convert.cl" }, |
| 297 | { "NV21_to_RGBA8888_bt709", "color_convert.cl" }, |
| 298 | { "NV21_to_YUV444_bt709", "color_convert.cl" }, |
Giorgio Arena | a086a0a | 2018-02-16 12:42:16 +0000 | [diff] [blame] | 299 | { "output_stage_quantized", "direct_convolution_1x1_3x3_5x5_quantized.cl" }, |
Michalis Spyrou | 5237e01 | 2018-01-17 09:40:27 +0000 | [diff] [blame] | 300 | { "permute_201", "permute.cl" }, |
| 301 | { "permute_120", "permute.cl" }, |
| 302 | { "permute_3201", "permute.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 303 | { "pixelwise_mul_float", "pixelwise_mul_float.cl" }, |
| 304 | { "pixelwise_mul_int", "pixelwise_mul_int.cl" }, |
| 305 | { "pooling_layer_2", "pooling_layer.cl" }, |
| 306 | { "pooling_layer_3", "pooling_layer.cl" }, |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 307 | { "pooling_layer_optimized_3", "pooling_layer.cl" }, |
Georgios Pinitas | ce09314 | 2017-06-19 16:11:53 +0100 | [diff] [blame] | 308 | { "pooling_layer_7", "pooling_layer.cl" }, |
Isabella Gottardi | a527e8c | 2018-01-31 17:49:25 +0000 | [diff] [blame] | 309 | { "pooling_layer_MxN", "pooling_layer.cl" }, |
| 310 | { "pooling_layer_MxN_quantized", "pooling_layer_quantized.cl" }, |
Michele Di Giorgio | 56dd726 | 2017-07-27 09:53:49 +0100 | [diff] [blame] | 311 | { "quantization_layer", "quantization_layer.cl" }, |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 312 | { "reduction_operation", "reduction_operation.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 313 | { "remap_nearest_neighbour", "remap.cl" }, |
| 314 | { "remap_bilinear", "remap.cl" }, |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 315 | { "reshape_layer", "reshape_layer.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 316 | { "reshape_to_columns", "convolution_layer.cl" }, |
| 317 | { "RGB888_to_IYUV_bt709", "color_convert.cl" }, |
| 318 | { "RGB888_to_NV12_bt709", "color_convert.cl" }, |
| 319 | { "RGB888_to_RGBA8888_bt709", "color_convert.cl" }, |
| 320 | { "RGB888_to_YUV444_bt709", "color_convert.cl" }, |
| 321 | { "RGBA8888_to_IYUV_bt709", "color_convert.cl" }, |
| 322 | { "RGBA8888_to_NV12_bt709", "color_convert.cl" }, |
| 323 | { "RGBA8888_to_RGB888_bt709", "color_convert.cl" }, |
| 324 | { "RGBA8888_to_YUV444_bt709", "color_convert.cl" }, |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 325 | { "roi_pooling_layer", "roi_pooling_layer.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 326 | { "scale_nearest_neighbour", "scale.cl" }, |
| 327 | { "scale_bilinear", "scale.cl" }, |
| 328 | { "scharr3x3", "scharr_filter.cl" }, |
| 329 | { "sobel3x3", "sobel_filter.cl" }, |
| 330 | { "sobel_separable5x1", "sobel_filter.cl" }, |
| 331 | { "sobel_separable1x5", "sobel_filter.cl" }, |
| 332 | { "sobel_separable7x1", "sobel_filter.cl" }, |
| 333 | { "sobel_separable1x7", "sobel_filter.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 334 | { "softmax_layer_norm", "softmax_layer.cl" }, |
Chunosov | f450caa | 2017-11-08 16:09:35 +0700 | [diff] [blame] | 335 | { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" }, |
Giorgio Arena | 4402cb9 | 2018-02-15 13:37:40 +0000 | [diff] [blame] | 336 | { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" }, |
| 337 | { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" }, |
Chunosov | d6afedc | 2017-11-06 22:09:45 +0700 | [diff] [blame] | 338 | { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" }, |
| 339 | { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 340 | { "suppress_non_maximum", "canny.cl" }, |
| 341 | { "tablelookup_U8", "tablelookup.cl" }, |
| 342 | { "tablelookup_S16", "tablelookup.cl" }, |
| 343 | { "threshold_binary", "threshold.cl" }, |
| 344 | { "threshold_range", "threshold.cl" }, |
| 345 | { "transpose", "transpose.cl" }, |
| 346 | { "UYVY422_to_IYUV_bt709", "color_convert.cl" }, |
| 347 | { "UYVY422_to_NV12_bt709", "color_convert.cl" }, |
| 348 | { "UYVY422_to_RGB888_bt709", "color_convert.cl" }, |
| 349 | { "UYVY422_to_RGBA8888_bt709", "color_convert.cl" }, |
| 350 | { "warp_affine_nearest_neighbour", "warp_affine.cl" }, |
| 351 | { "warp_affine_bilinear", "warp_affine.cl" }, |
| 352 | { "warp_perspective_nearest_neighbour", "warp_perspective.cl" }, |
| 353 | { "warp_perspective_bilinear", "warp_perspective.cl" }, |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 354 | { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd.cl" }, |
| 355 | { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd.cl" }, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 356 | { "YUYV422_to_IYUV_bt709", "color_convert.cl" }, |
| 357 | { "YUYV422_to_NV12_bt709", "color_convert.cl" }, |
| 358 | { "YUYV422_to_RGB888_bt709", "color_convert.cl" }, |
| 359 | { "YUYV422_to_RGBA8888_bt709", "color_convert.cl" }, |
| 360 | }; |
| 361 | |
| 362 | const std::map<std::string, std::string> CLKernelLibrary::_program_source_map = |
| 363 | { |
| 364 | #ifdef EMBEDDED_KERNELS |
| 365 | { |
| 366 | "absdiff.cl", |
| 367 | #include "./cl_kernels/absdiff.clembed" |
| 368 | }, |
| 369 | { |
| 370 | "accumulate.cl", |
| 371 | #include "./cl_kernels/accumulate.clembed" |
| 372 | }, |
| 373 | { |
| 374 | "activation_layer.cl", |
| 375 | #include "./cl_kernels/activation_layer.clembed" |
| 376 | }, |
| 377 | { |
Michel Iwaniec | 0063380 | 2017-10-12 14:14:15 +0100 | [diff] [blame] | 378 | "activation_layer_qa8.cl", |
| 379 | #include "./cl_kernels/activation_layer_qa8.clembed" |
| 380 | }, |
| 381 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 382 | "arithmetic_op.cl", |
| 383 | #include "./cl_kernels/arithmetic_op.clembed" |
| 384 | }, |
| 385 | { |
| 386 | "bitwise_op.cl", |
| 387 | #include "./cl_kernels/bitwise_op.clembed" |
| 388 | }, |
| 389 | { |
| 390 | "canny.cl", |
| 391 | #include "./cl_kernels/canny.clembed" |
| 392 | }, |
| 393 | { |
| 394 | "channel_combine.cl", |
| 395 | #include "./cl_kernels/channel_combine.clembed" |
| 396 | }, |
| 397 | { |
| 398 | "channel_extract.cl", |
| 399 | #include "./cl_kernels/channel_extract.clembed" |
| 400 | }, |
| 401 | { |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 402 | "col2im.cl", |
| 403 | #include "./cl_kernels/col2im.clembed" |
| 404 | }, |
| 405 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 406 | "concatenate.cl", |
| 407 | #include "./cl_kernels/concatenate.clembed" |
| 408 | }, |
| 409 | { |
| 410 | "color_convert.cl", |
| 411 | #include "./cl_kernels/color_convert.clembed" |
| 412 | }, |
| 413 | { |
| 414 | "convolution3x3.cl", |
| 415 | #include "./cl_kernels/convolution3x3.clembed" |
| 416 | }, |
| 417 | { |
| 418 | "convolution5x5.cl", |
| 419 | #include "./cl_kernels/convolution5x5.clembed" |
| 420 | }, |
| 421 | { |
| 422 | "convolution7x7.cl", |
| 423 | #include "./cl_kernels/convolution7x7.clembed" |
| 424 | }, |
| 425 | { |
| 426 | "convolution9x9.cl", |
| 427 | #include "./cl_kernels/convolution9x9.clembed" |
| 428 | }, |
| 429 | { |
| 430 | "convolution_layer.cl", |
| 431 | #include "./cl_kernels/convolution_layer.clembed" |
| 432 | }, |
| 433 | { |
| 434 | "convolution_rectangle.cl", |
| 435 | #include "./cl_kernels/convolution_rectangle.clembed" |
| 436 | }, |
| 437 | { |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 438 | "deconvolution_layer.cl", |
| 439 | #include "./cl_kernels/deconvolution_layer.clembed" |
| 440 | }, |
| 441 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 442 | "depth_convert.cl", |
| 443 | #include "./cl_kernels/depth_convert.clembed" |
| 444 | }, |
| 445 | { |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 446 | "depthwise_convolution.cl", |
| 447 | #include "./cl_kernels/depthwise_convolution.clembed" |
| 448 | }, |
| 449 | { |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 450 | "depthwise_convolution_quantized.cl", |
| 451 | #include "./cl_kernels/depthwise_convolution_quantized.clembed" |
| 452 | }, |
| 453 | { |
Michele Di Giorgio | 56dd726 | 2017-07-27 09:53:49 +0100 | [diff] [blame] | 454 | "dequantization_layer.cl", |
| 455 | #include "./cl_kernels/dequantization_layer.clembed" |
| 456 | }, |
| 457 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 458 | "derivative.cl", |
| 459 | #include "./cl_kernels/derivative.clembed" |
| 460 | }, |
| 461 | { |
| 462 | "dilate.cl", |
| 463 | #include "./cl_kernels/dilate.clembed" |
| 464 | }, |
| 465 | { |
SiCong Li | c51b72f | 2017-07-28 14:46:20 +0100 | [diff] [blame] | 466 | "direct_convolution1x1.cl", |
| 467 | #include "./cl_kernels/direct_convolution1x1.clembed" |
| 468 | }, |
| 469 | { |
| 470 | "direct_convolution3x3.cl", |
| 471 | #include "./cl_kernels/direct_convolution3x3.clembed" |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 472 | }, |
| 473 | { |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 474 | "direct_convolution5x5.cl", |
| 475 | #include "./cl_kernels/direct_convolution5x5.clembed" |
| 476 | }, |
| 477 | { |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 478 | "direct_convolution_1x1_3x3_5x5_quantized.cl", |
| 479 | #include "./cl_kernels/direct_convolution_1x1_3x3_5x5_quantized.clembed" |
| 480 | }, |
| 481 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 482 | "erode.cl", |
| 483 | #include "./cl_kernels/erode.clembed" |
| 484 | }, |
| 485 | { |
| 486 | "fast_corners.cl", |
| 487 | #include "./cl_kernels/fast_corners.clembed" |
| 488 | }, |
| 489 | { |
| 490 | "fill_border.cl", |
| 491 | #include "./cl_kernels/fill_border.clembed" |
| 492 | }, |
| 493 | { |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 494 | "fixed_point.h", |
| 495 | #include "./cl_kernels/fixed_point.hembed" |
| 496 | }, |
| 497 | { |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 498 | "floor.cl", |
| 499 | #include "./cl_kernels/floor.clembed" |
| 500 | }, |
| 501 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 502 | "gaussian_pyramid.cl", |
| 503 | #include "./cl_kernels/gaussian_pyramid.clembed" |
| 504 | }, |
| 505 | { |
| 506 | "gemm.cl", |
| 507 | #include "./cl_kernels/gemm.clembed" |
| 508 | }, |
| 509 | { |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 510 | "gemmlowp.cl", |
| 511 | #include "./cl_kernels/gemmlowp.clembed" |
| 512 | }, |
| 513 | { |
Giorgio Arena | 9fe4144 | 2017-08-23 16:36:24 +0100 | [diff] [blame] | 514 | "gemv.cl", |
| 515 | #include "./cl_kernels/gemv.clembed" |
| 516 | }, |
| 517 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 518 | "harris_corners.cl", |
| 519 | #include "./cl_kernels/harris_corners.clembed" |
| 520 | }, |
| 521 | { |
| 522 | "helpers.h", |
| 523 | #include "./cl_kernels/helpers.hembed" |
| 524 | }, |
| 525 | { |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 526 | "helpers_asymm.h", |
| 527 | #include "./cl_kernels/helpers_asymm.hembed" |
| 528 | }, |
| 529 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 530 | "histogram.cl", |
| 531 | #include "./cl_kernels/histogram.clembed" |
| 532 | }, |
| 533 | { |
| 534 | "hog.cl", |
| 535 | #include "./cl_kernels/hog.clembed" |
| 536 | }, |
| 537 | { |
Gian Marco | 76faef8 | 2018-01-29 12:15:32 +0000 | [diff] [blame] | 538 | "im2col.cl", |
| 539 | #include "./cl_kernels/im2col.clembed" |
| 540 | }, |
| 541 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 542 | "integral_image.cl", |
| 543 | #include "./cl_kernels/integral_image.clembed" |
| 544 | }, |
| 545 | { |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 546 | "l2_normalize.cl", |
| 547 | #include "./cl_kernels/l2_normalize.clembed" |
| 548 | }, |
| 549 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 550 | "magnitude_phase.cl", |
| 551 | #include "./cl_kernels/magnitude_phase.clembed" |
| 552 | }, |
| 553 | { |
| 554 | "mean_stddev.cl", |
| 555 | #include "./cl_kernels/mean_stddev.clembed" |
| 556 | }, |
| 557 | { |
| 558 | "minmaxloc.cl", |
| 559 | #include "./cl_kernels/minmaxloc.clembed" |
| 560 | }, |
| 561 | { |
Michele Di Giorgio | 56dd726 | 2017-07-27 09:53:49 +0100 | [diff] [blame] | 562 | "minmax_layer.cl", |
| 563 | #include "./cl_kernels/minmax_layer.clembed" |
| 564 | }, |
| 565 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 566 | "non_linear_filter3x3.cl", |
| 567 | #include "./cl_kernels/non_linear_filter3x3.clembed" |
| 568 | }, |
| 569 | { |
| 570 | "non_linear_filter5x5.cl", |
| 571 | #include "./cl_kernels/non_linear_filter5x5.clembed" |
| 572 | }, |
| 573 | { |
| 574 | "non_linear_filter_helpers.h", |
| 575 | #include "./cl_kernels/non_linear_filter_helpers.hembed" |
| 576 | }, |
| 577 | { |
| 578 | "nonmax.cl", |
| 579 | #include "./cl_kernels/nonmax.clembed" |
| 580 | }, |
| 581 | { |
| 582 | "normalization_layer.cl", |
| 583 | #include "./cl_kernels/normalization_layer.clembed" |
| 584 | }, |
| 585 | { |
| 586 | "batchnormalization_layer.cl", |
| 587 | #include "./cl_kernels/batchnormalization_layer.clembed" |
| 588 | }, |
| 589 | { |
| 590 | "optical_flow_pyramid_lk.cl", |
| 591 | #include "./cl_kernels/optical_flow_pyramid_lk.clembed" |
| 592 | }, |
| 593 | { |
Michalis Spyrou | 5237e01 | 2018-01-17 09:40:27 +0000 | [diff] [blame] | 594 | "permute.cl", |
| 595 | #include "./cl_kernels/permute.clembed" |
| 596 | }, |
| 597 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 598 | "pixelwise_mul_float.cl", |
| 599 | #include "./cl_kernels/pixelwise_mul_float.clembed" |
| 600 | }, |
| 601 | { |
| 602 | "pixelwise_mul_int.cl", |
| 603 | #include "./cl_kernels/pixelwise_mul_int.clembed" |
| 604 | }, |
| 605 | { |
| 606 | "pooling_layer.cl", |
| 607 | #include "./cl_kernels/pooling_layer.clembed" |
| 608 | }, |
| 609 | { |
Anton Lokhmotov | af6204c | 2017-11-08 09:34:19 +0000 | [diff] [blame] | 610 | "pooling_layer_quantized.cl", |
| 611 | #include "./cl_kernels/pooling_layer_quantized.clembed" |
| 612 | }, |
| 613 | { |
Michele Di Giorgio | 56dd726 | 2017-07-27 09:53:49 +0100 | [diff] [blame] | 614 | "quantization_layer.cl", |
| 615 | #include "./cl_kernels/quantization_layer.clembed" |
| 616 | }, |
| 617 | { |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 618 | "reduction_operation.cl", |
| 619 | #include "./cl_kernels/reduction_operation.clembed" |
| 620 | }, |
| 621 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 622 | "remap.cl", |
| 623 | #include "./cl_kernels/remap.clembed" |
| 624 | }, |
| 625 | { |
Georgios Pinitas | 5ee66ea | 2017-09-07 17:29:16 +0100 | [diff] [blame] | 626 | "reshape_layer.cl", |
| 627 | #include "./cl_kernels/reshape_layer.clembed" |
| 628 | }, |
| 629 | { |
SiCong Li | 3e36369 | 2017-07-04 15:02:10 +0100 | [diff] [blame] | 630 | "roi_pooling_layer.cl", |
| 631 | #include "./cl_kernels/roi_pooling_layer.clembed" |
| 632 | }, |
| 633 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 634 | "scale.cl", |
| 635 | #include "./cl_kernels/scale.clembed" |
| 636 | }, |
| 637 | { |
| 638 | "scharr_filter.cl", |
| 639 | #include "./cl_kernels/scharr_filter.clembed" |
| 640 | }, |
| 641 | { |
| 642 | "sobel_filter.cl", |
| 643 | #include "./cl_kernels/sobel_filter.clembed" |
| 644 | }, |
| 645 | { |
| 646 | "softmax_layer.cl", |
| 647 | #include "./cl_kernels/softmax_layer.clembed" |
| 648 | }, |
| 649 | { |
Chunosov | f450caa | 2017-11-08 16:09:35 +0700 | [diff] [blame] | 650 | "softmax_layer_quantized.cl", |
| 651 | #include "./cl_kernels/softmax_layer_quantized.clembed" |
| 652 | }, |
| 653 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 654 | "tablelookup.cl", |
| 655 | #include "./cl_kernels/tablelookup.clembed" |
| 656 | }, |
| 657 | { |
| 658 | "threshold.cl", |
| 659 | #include "./cl_kernels/threshold.clembed" |
| 660 | }, |
| 661 | { |
| 662 | "transpose.cl", |
| 663 | #include "./cl_kernels/transpose.clembed" |
| 664 | }, |
| 665 | { |
| 666 | "types.h", |
| 667 | #include "./cl_kernels/types.hembed" |
| 668 | }, |
| 669 | { |
| 670 | "warp_affine.cl", |
| 671 | #include "./cl_kernels/warp_affine.clembed" |
| 672 | }, |
| 673 | { |
| 674 | "warp_helpers.h", |
| 675 | #include "./cl_kernels/warp_helpers.hembed" |
| 676 | }, |
| 677 | { |
| 678 | "warp_perspective.cl", |
| 679 | #include "./cl_kernels/warp_perspective.clembed" |
Michalis Spyrou | d7e8281 | 2017-06-20 15:00:14 +0100 | [diff] [blame] | 680 | }, |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 681 | { |
| 682 | "winograd.cl", |
| 683 | #include "./cl_kernels/winograd.clembed" |
| 684 | }, |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 685 | #endif /* EMBEDDED_KERNELS */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 686 | }; |
| 687 | |
| 688 | CLKernelLibrary::CLKernelLibrary() |
Abel Bernabeu | 5a6e053 | 2017-09-28 09:53:45 +0100 | [diff] [blame] | 689 | : _context(), _device(), _kernel_path("."), _programs_map(), _built_programs_map() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 690 | { |
| 691 | } |
| 692 | |
| 693 | CLKernelLibrary &CLKernelLibrary::get() |
| 694 | { |
| 695 | static CLKernelLibrary _kernel_library; |
| 696 | return _kernel_library; |
| 697 | } |
| 698 | |
| 699 | Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const StringSet &build_options_set) const |
| 700 | { |
| 701 | // Find which program contains the kernel |
| 702 | auto kernel_program_it = _kernel_program_map.find(kernel_name); |
| 703 | |
| 704 | if(_kernel_program_map.end() == kernel_program_it) |
| 705 | { |
| 706 | ARM_COMPUTE_ERROR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str()); |
| 707 | } |
| 708 | |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 709 | std::string concat_str; |
| 710 | |
Matthew Bentham | 6f31f8c | 2017-10-27 11:50:06 +0100 | [diff] [blame] | 711 | if(fp16_support(_device)) |
| 712 | { |
| 713 | concat_str += " -DARM_COMPUTE_OPENCL_FP16_ENABLED=1 "; |
| 714 | } |
| 715 | |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 716 | if(non_uniform_workgroup_support(_device)) |
| 717 | { |
| 718 | concat_str += " -cl-arm-non-uniform-work-group-size "; |
| 719 | } |
| 720 | else if(get_cl_version(_device) == CLVersion::CL20) |
| 721 | { |
| 722 | concat_str += " -cl-std=CL2.0 "; |
| 723 | } |
| 724 | else |
| 725 | { |
| 726 | ARM_COMPUTE_ERROR("Non uniform workgroup size is not supported!!"); |
| 727 | } |
| 728 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 729 | // Check if the program has been built before with same build options. |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 730 | const std::string program_name = kernel_program_it->second; |
| 731 | const std::string build_options = stringify_set(build_options_set) + concat_str; |
| 732 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 733 | const std::string built_program_name = program_name + "_" + build_options; |
| 734 | auto built_program_it = _built_programs_map.find(built_program_name); |
| 735 | |
| 736 | cl::Program cl_program; |
| 737 | |
| 738 | if(_built_programs_map.end() != built_program_it) |
| 739 | { |
| 740 | // If program has been built, retrieve to create kernel from it |
| 741 | cl_program = built_program_it->second; |
| 742 | } |
| 743 | else |
| 744 | { |
| 745 | // Get program |
| 746 | Program program = load_program(program_name); |
| 747 | |
| 748 | // Build program |
| 749 | cl_program = program.build(build_options); |
| 750 | |
| 751 | // Add built program to internal map |
| 752 | _built_programs_map.emplace(built_program_name, cl_program); |
| 753 | } |
| 754 | |
| 755 | // Create and return kernel |
| 756 | return Kernel(kernel_name, cl_program); |
| 757 | } |
| 758 | |
| 759 | const Program &CLKernelLibrary::load_program(const std::string &program_name) const |
| 760 | { |
| 761 | const auto program_it = _programs_map.find(program_name); |
| 762 | |
| 763 | if(program_it != _programs_map.end()) |
| 764 | { |
| 765 | return program_it->second; |
| 766 | } |
| 767 | |
| 768 | Program program; |
| 769 | |
| 770 | #ifdef EMBEDDED_KERNELS |
| 771 | const auto program_source_it = _program_source_map.find(program_name); |
| 772 | |
| 773 | if(_program_source_map.end() == program_source_it) |
| 774 | { |
| 775 | ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str()); |
| 776 | } |
| 777 | |
| 778 | program = Program(_context, program_name, program_source_it->second); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 779 | #else /* EMBEDDED_KERNELS */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 780 | // Check for binary |
| 781 | std::string source_name = _kernel_path + program_name; |
| 782 | std::string binary_name = source_name + "bin"; |
| 783 | |
| 784 | if(std::ifstream(binary_name).is_open()) |
| 785 | { |
| 786 | const std::string program_binary = read_file(binary_name, true); |
| 787 | program = Program(_context, _device, program_name, std::vector<unsigned char>(program_binary.begin(), program_binary.end())); |
| 788 | } |
| 789 | else if(std::ifstream(source_name).is_open()) |
| 790 | { |
| 791 | program = Program(_context, program_name, read_file(source_name, false)); |
| 792 | } |
| 793 | else |
| 794 | { |
| 795 | ARM_COMPUTE_ERROR("Kernel file %s does not exist.", source_name.c_str()); |
| 796 | } |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 797 | #endif /* EMBEDDED_KERNELS */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 798 | |
| 799 | // Insert program to program map |
| 800 | const auto new_program = _programs_map.emplace(program_name, std::move(program)); |
| 801 | |
| 802 | return new_program.first->second; |
| 803 | } |
| 804 | |
| 805 | std::string CLKernelLibrary::stringify_set(const StringSet &s) const |
| 806 | { |
steniu01 | 3470247 | 2017-07-11 09:22:58 +0100 | [diff] [blame] | 807 | std::string concat_set; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 808 | |
| 809 | #ifndef EMBEDDED_KERNELS |
| 810 | concat_set += "-I" + _kernel_path + " "; |
| 811 | #endif /* EMBEDDED_KERNELS */ |
| 812 | |
| 813 | // Concatenate set |
| 814 | for(const auto &el : s) |
| 815 | { |
| 816 | concat_set += " " + el; |
| 817 | } |
| 818 | |
| 819 | return concat_set; |
| 820 | } |
Michalis Spyrou | d7e8281 | 2017-06-20 15:00:14 +0100 | [diff] [blame] | 821 | |
| 822 | std::string CLKernelLibrary::get_program_source(const std::string &program_name) |
| 823 | { |
| 824 | const auto program_source_it = _program_source_map.find(program_name); |
| 825 | |
| 826 | if(program_source_it == _program_source_map.end()) |
| 827 | { |
| 828 | ARM_COMPUTE_ERROR("Embedded program for %s does not exist.", program_name.c_str()); |
| 829 | } |
| 830 | |
| 831 | return program_source_it->second; |
| 832 | } |
steniu01 | 5f91072 | 2017-08-23 10:15:22 +0100 | [diff] [blame] | 833 | |
Abel Bernabeu | 5a6e053 | 2017-09-28 09:53:45 +0100 | [diff] [blame] | 834 | size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const |
steniu01 | 5f91072 | 2017-08-23 10:15:22 +0100 | [diff] [blame] | 835 | { |
Abel Bernabeu | 5a6e053 | 2017-09-28 09:53:45 +0100 | [diff] [blame] | 836 | size_t result; |
steniu01 | 5f91072 | 2017-08-23 10:15:22 +0100 | [diff] [blame] | 837 | |
Abel Bernabeu | 5a6e053 | 2017-09-28 09:53:45 +0100 | [diff] [blame] | 838 | size_t err = kernel.getWorkGroupInfo(_device, CL_KERNEL_WORK_GROUP_SIZE, &result); |
| 839 | ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetKernelWorkGroupInfo failed to return the maximum workgroup size for the kernel"); |
| 840 | ARM_COMPUTE_UNUSED(err); |
| 841 | |
| 842 | return result; |
steniu01 | 5f91072 | 2017-08-23 10:15:22 +0100 | [diff] [blame] | 843 | } |
| 844 | |
Abel Bernabeu | 5a6e053 | 2017-09-28 09:53:45 +0100 | [diff] [blame] | 845 | cl::NDRange CLKernelLibrary::default_ndrange() const |
steniu01 | 5f91072 | 2017-08-23 10:15:22 +0100 | [diff] [blame] | 846 | { |
Michalis Spyrou | a967611 | 2018-02-22 18:07:43 +0000 | [diff] [blame] | 847 | cl::Device device = cl::Device::getDefault(); |
| 848 | GPUTarget _target = get_target_from_device(device); |
| 849 | cl::NDRange default_range; |
| 850 | |
| 851 | switch(_target) |
| 852 | { |
| 853 | case GPUTarget::MIDGARD: |
| 854 | case GPUTarget::T600: |
| 855 | case GPUTarget::T700: |
| 856 | case GPUTarget::T800: |
| 857 | default_range = cl::NDRange(128u, 1); |
| 858 | break; |
| 859 | default: |
| 860 | default_range = cl::NullRange; |
| 861 | } |
| 862 | |
| 863 | return default_range; |
steniu01 | 5f91072 | 2017-08-23 10:15:22 +0100 | [diff] [blame] | 864 | } |
Anthony Barbier | 847864d | 2018-03-07 11:35:53 +0000 | [diff] [blame] | 865 | |
| 866 | std::string CLKernelLibrary::get_device_version() |
| 867 | { |
| 868 | return _device.getInfo<CL_DEVICE_VERSION>(); |
| 869 | } |