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