blob: 286ed4c02175d37f809925c2d16afdf7f5bb8aea [file] [log] [blame]
Georgios Pinitas908f6162021-05-04 10:11:09 +01001/*
2 * Copyright (c) 2016-2021 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 */
24#include "src/core/gpu/cl/ClKernelLibrary.h"
25
26#include "arm_compute/core/Error.h"
27#include "arm_compute/core/Utils.h"
28
29#include <algorithm>
30#include <array>
31#include <fstream>
32#include <utility>
33
34#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
35#include <zlib.h>
36
37namespace
38{
39/* Decoding table */
40constexpr std::array<uint8_t, 256> b64_invtab =
41{
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
45 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0,
46 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
47 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
48 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
49 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0,
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58};
59
60/** Decode a base64 encoded string
61 *
62 * @param[in] str Base64 encoded string to decode
63 *
64 * @return The decode string in case of a valid, non-empty string otherwise an empty string
65 */
66std::string decode_base64(const std::string &str)
67{
68 constexpr const char pad_char = '=';
69
70 // Handle empty string
71 if(str.empty())
72 {
73 return {};
74 }
75
76 // Base64 encoded string has size multiple of 4
77 if(str.length() % 4)
78 {
79 return {};
80 }
81
82 //
83 // Check encoded string padding
84 std::size_t padding = (str.rbegin()[0] == pad_char) + (str.rbegin()[1] == pad_char);
85 const int str_len = str.size();
86
87 // Reserve memory for the decoded string
88 // Note each 4 consecutive elements of 6-bit encode 3 bytes
89 std::string dec_b64;
90 dec_b64.reserve(((str_len / 4) * 3));
91
92 // Block decoding function (exclude padding)
93 int c = 0;
94 const int end = str_len - 4 - padding;
95 for(; c <= end; c += 4)
96 {
97 const int byte0 = b64_invtab[str[c]];
98 const int byte1 = b64_invtab[str[c + 1]];
99 const int byte2 = b64_invtab[str[c + 2]];
100 const int byte3 = b64_invtab[str[c + 3]];
101
102 dec_b64.push_back((byte0 << 2) | (byte1 >> 4));
103 dec_b64.push_back((byte1 << 4) | (byte2 >> 2));
104 dec_b64.push_back((byte2 << 6) | (byte3));
105 }
106
107 // Last step that might contain padding symbols
108 if(padding == 1)
109 {
110 const int byte0 = b64_invtab[str[c]];
111 const int byte1 = b64_invtab[str[c + 1]];
112 const int byte2 = b64_invtab[str[c + 2]];
113
114 dec_b64.push_back((byte0 << 2) | (byte1 >> 4));
115 dec_b64.push_back((byte1 << 4) | (byte2 >> 2));
116 }
117 else if(padding == 2)
118 {
119 const int byte0 = b64_invtab[str[c]];
120 const int byte1 = b64_invtab[str[c + 1]];
121
122 dec_b64.push_back((byte0 << 2) | (byte1 >> 4));
123 }
124
125 return dec_b64;
126}
127
128/** Decompress a zlib compressed string
129 *
130 * @param[in] str ZLib compressed string
131 *
132 * @return The decompressed string if successful, otherwise false.
133 */
134std::string decompress_zlib(const std::string &str)
135{
136 // Create and initialize decompression stream
137 z_stream ds{};
138 if(inflateInit(&ds) != Z_OK)
139 {
140 return std::string();
141 }
142 ds.avail_in = str.size();
143 ds.next_in = (Bytef *)str.data();
144
145 // Roll-over the string using a buffer and decompress
146 int status = Z_OK;
147 char roll_buff[16384];
148 std::string inflated_str;
149 do
150 {
151 ds.avail_out = sizeof(roll_buff);
152 ds.next_out = reinterpret_cast<Bytef *>(roll_buff);
153
154 status = inflate(&ds, 0);
155 if(inflated_str.size() < ds.total_out)
156 {
157 inflated_str.append(roll_buff, ds.total_out - inflated_str.size());
158 }
159 }
160 while(status == Z_OK);
161
162 // Finalize decompression stream
163 inflateEnd(&ds);
164 if(status != Z_STREAM_END)
165 {
166 return std::string();
167 }
168
169 return inflated_str;
170}
171} // namespace
172#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
173
174namespace arm_compute
175{
176namespace opencl
177{
178const std::map<std::string, std::string> ClKernelLibrary::_kernel_program_map =
179{
180 { "activation_layer", "activation_layer.cl" },
181 { "activation_layer_quant", "activation_layer_quant.cl" },
182 { "activation_layer_quant_f32", "activation_layer_quant.cl" },
183 { "arg_min_max_x", "arg_min_max.cl" },
184 { "arg_min_max_y", "arg_min_max.cl" },
185 { "arg_min_max_z", "arg_min_max.cl" },
186 { "arg_min_max_w", "arg_min_max.cl" },
187 { "batch_to_space_nchw", "batch_to_space.cl" },
188 { "batch_to_space_static_nchw", "batch_to_space.cl" },
189 { "batch_to_space_nhwc", "batch_to_space.cl" },
190 { "batch_to_space_static_nhwc", "batch_to_space.cl" },
191 { "batchnormalization_layer_nchw", "batchnormalization_layer.cl" },
192 { "batchnormalization_layer_nhwc", "batchnormalization_layer.cl" },
193 { "bitwise_or", "bitwise_op.cl" },
194 { "bitwise_and", "bitwise_op.cl" },
195 { "bitwise_xor", "bitwise_op.cl" },
196 { "bitwise_not", "bitwise_op.cl" },
197 { "bounding_box_transform", "bounding_box_transform.cl" },
198 { "bounding_box_transform_quantized", "bounding_box_transform_quantized.cl" },
199 { "channel_shuffle_nchw", "channel_shuffle.cl" },
200 { "channel_shuffle_nhwc", "channel_shuffle.cl" },
201 { "compare_equal", "comparisons.cl" },
202 { "compare_equal_quantized", "comparisons.cl" },
203 { "compare_notequal", "comparisons.cl" },
204 { "compare_notequal_quantized", "comparisons.cl" },
205 { "compare_greater", "comparisons.cl" },
206 { "compare_greater_quantized", "comparisons.cl" },
207 { "compare_greaterequal", "comparisons.cl" },
208 { "compare_greaterequal_quantized", "comparisons.cl" },
209 { "compare_less", "comparisons.cl" },
210 { "compare_less_quantized", "comparisons.cl" },
211 { "compare_lessequal", "comparisons.cl" },
212 { "compare_lessequal_quantized", "comparisons.cl" },
213 { "concatenate", "concatenate.cl" },
214 { "concatenate_width", "concatenate.cl" },
215 { "concatenate_height", "concatenate.cl" },
216 { "concatenate_width_x2", "concatenate.cl" },
217 { "concatenate_width_x4", "concatenate.cl" },
218 { "col2im", "col2im.cl" },
219 { "convert_depth_down", "depth_convert.cl" },
220 { "convert_depth_up", "depth_convert.cl" },
221 { "convert_fc_weights", "convert_fc_weights.cl" },
222 { "copy_tensor", "copy_tensor.cl" },
223 { "crop_tensor", "crop_tensor.cl" },
224 { "deconvolution_reshape", "deconvolution_layer.cl" },
225 { "deconvolution_upsample", "deconvolution_layer.cl" },
226 { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
227 { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
228 { "depthwise_convolution_3x3_nhwc", "depthwise_convolution.cl" },
229 { "depthwise_convolution_3x3_nhwc_stride1", "depthwise_convolution.cl" },
230 { "dwc_MxN_native_fp_nhwc", "depthwise_convolution.cl" },
231 { "dwc_MxN_native_quantized8_nhwc", "depthwise_convolution_quantized.cl" },
232 { "dwc_3x3_native_quantized8_nchw", "depthwise_convolution_quantized.cl" },
233 { "dwc_3x3_native_quantized8_dot8_nchw", "depthwise_convolution_quantized.cl" },
234 { "depth_to_space_nchw", "depth_to_space.cl" },
235 { "depth_to_space_nhwc", "depth_to_space.cl" },
236 { "depthwise_convolution_3x3_stridex1_stridey1_f16", "depthwise_convolution.cl" },
237 { "depthwise_convolution_3x3_stridex2_stridey2_f16", "depthwise_convolution.cl" },
238 { "depthwise_convolution_3x3_stridex1_stridey1_f32", "depthwise_convolution.cl" },
239 { "depthwise_convolution_3x3_stridex2_stridey2_f32", "depthwise_convolution.cl" },
240 { "dequantization_layer", "dequantization_layer.cl" },
241 { "dequantization_layer_per_channel_nhwc", "dequantization_layer.cl" },
242 { "dequantization_layer_per_channel_nchw", "dequantization_layer.cl" },
243 { "direct_convolution_nhwc", "direct_convolution.cl" },
244 { "direct_convolution1x1", "direct_convolution1x1.cl" },
245 { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
246 { "direct_convolution3x3", "direct_convolution3x3.cl" },
247 { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
248 { "direct_convolution5x5", "direct_convolution5x5.cl" },
249 { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
250 { "direct_convolution_quantized", "direct_convolution_quantized.cl" },
251 { "elementwise_operation_ADD", "elementwise_operation.cl" },
252 { "elementwise_operation_SUB", "elementwise_operation.cl" },
253 { "elementwise_operation_MAX", "elementwise_operation.cl" },
254 { "elementwise_operation_MIN", "elementwise_operation.cl" },
255 { "elementwise_operation_DIV", "elementwise_operation.cl" },
256 { "elementwise_operation_SQUARED_DIFF", "elementwise_operation.cl" },
257 { "elementwise_operation_POWER", "elementwise_operation.cl" },
258 { "elementwise_operation_PRELU", "elementwise_operation.cl" },
259 { "elementwise_operation_AND", "elementwise_operation.cl" },
260 { "elementwise_operation_OR", "elementwise_operation.cl" },
261 { "elementwise_operation_ADD_quantized", "elementwise_operation_quantized.cl" },
262 { "elementwise_operation_SUB_quantized", "elementwise_operation_quantized.cl" },
263 { "elementwise_operation_MAX_quantized", "elementwise_operation_quantized.cl" },
264 { "elementwise_operation_MIN_quantized", "elementwise_operation_quantized.cl" },
265 { "elementwise_operation_DIV_quantized", "elementwise_operation_quantized.cl" },
266 { "elementwise_operation_SQUARED_DIFF_quantized", "elementwise_operation_quantized.cl" },
267 { "elementwise_operation_PRELU_quantized", "elementwise_operation_quantized.cl" },
268 { "elementwise_unary", "elementwise_unary.cl" },
269 { "fft_digit_reverse_axis_0", "fft_digit_reverse.cl" },
270 { "fft_digit_reverse_axis_1", "fft_digit_reverse.cl" },
271 { "fft_radix_2_first_stage_axis_0", "fft.cl" },
272 { "fft_radix_2_first_stage_axis_1", "fft.cl" },
273 { "fft_radix_2_axis_0", "fft.cl" },
274 { "fft_radix_2_axis_1", "fft.cl" },
275 { "fft_radix_3_first_stage_axis_0", "fft.cl" },
276 { "fft_radix_3_first_stage_axis_1", "fft.cl" },
277 { "fft_radix_3_axis_0", "fft.cl" },
278 { "fft_radix_3_axis_1", "fft.cl" },
279 { "fft_radix_4_first_stage_axis_0", "fft.cl" },
280 { "fft_radix_4_first_stage_axis_1", "fft.cl" },
281 { "fft_radix_4_axis_0", "fft.cl" },
282 { "fft_radix_4_axis_1", "fft.cl" },
283 { "fft_radix_5_first_stage_axis_0", "fft.cl" },
284 { "fft_radix_5_first_stage_axis_1", "fft.cl" },
285 { "fft_radix_5_axis_0", "fft.cl" },
286 { "fft_radix_5_axis_1", "fft.cl" },
287 { "fft_radix_7_first_stage_axis_0", "fft.cl" },
288 { "fft_radix_7_first_stage_axis_1", "fft.cl" },
289 { "fft_radix_7_axis_0", "fft.cl" },
290 { "fft_radix_7_axis_1", "fft.cl" },
291 { "fft_radix_8_first_stage_axis_0", "fft.cl" },
292 { "fft_radix_8_first_stage_axis_1", "fft.cl" },
293 { "fft_radix_8_axis_0", "fft.cl" },
294 { "fft_radix_8_axis_1", "fft.cl" },
295 { "fft_scale_conj", "fft_scale.cl" },
296 { "fill_image_borders_constant", "fill_border.cl" },
297 { "fill_image_borders_replicate", "fill_border.cl" },
298 { "floor_layer", "floor.cl" },
299 { "fuse_batchnormalization_layer", "batchnormalization_layer.cl" },
300 { "gather", "gather.cl" },
301 { "gemm_ma_f16", "gemm.cl" },
302 { "gemm_ma_f32", "gemm.cl" },
303 { "gemm_mv", "gemv.cl" },
304 { "gemm_mv_quantized", "gemv.cl" },
305 { "gemm_mm_interleaved_transposed_f16", "gemm_v1.cl" },
306 { "gemm_mm_interleaved_transposed_f16_acc32", "gemm_v1.cl" },
307 { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm_v1.cl" },
308 { "gemm_mm_interleaved_transposed_f32", "gemm_v1.cl" },
309 { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm_v1.cl" },
310 { "gemm_mm_floating_point", "gemm_v1.cl" },
311 { "gemm_mm_floating_point_f16_bifrost", "gemm_v1.cl" },
312 { "gemm_mm_floating_point_f16_bifrost_acc32", "gemm_v1.cl" },
313 { "gemm_mm_floating_point_f32_bifrost", "gemm_v1.cl" },
314 { "gemm_mm_floating_point_f32_bifrost_1000", "gemm_v1.cl" },
315 { "gemm_mm_native", "gemm.cl" },
316 { "gemm_mm_reshaped_lhs_nt_rhs_t", "gemm.cl" },
317 { "gemm_mm_reshaped_lhs_nt_rhs_t_texture", "gemm.cl" },
318 { "gemm_mm_reshaped_lhs_t_rhs_nt", "gemm.cl" },
319 { "gemm_mm_reshaped_lhs_t_rhs_nt_texture", "gemm.cl" },
320 { "gemm_mm_reshaped_only_rhs_nt", "gemm.cl" },
321 { "gemm_mm_reshaped_only_rhs_nt_texture", "gemm.cl" },
322 { "gemm_mm_reshaped_only_rhs_t", "gemm.cl" },
323 { "gemm_mm_reshaped_only_rhs_t_texture", "gemm.cl" },
324 { "gemm_lc_vm_f32", "gemm.cl" },
325 { "gemm_reshape_lhs_matrix_nt", "gemm.cl" },
326 { "gemm_reshape_lhs_matrix_t", "gemm.cl" },
327 { "gemm_reshape_rhs_matrix_nt", "gemm.cl" },
328 { "gemm_reshape_rhs_matrix_t", "gemm.cl" },
329 { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
330 { "gemmlowp_matrix_a_reduction_dot8", "gemmlowp.cl" },
331 { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
332 { "gemmlowp_mm_native", "gemmlowp.cl" },
333 { "gemmlowp_mm_reshaped_lhs_nt_rhs_t", "gemmlowp.cl" },
334 { "gemmlowp_mm_reshaped_only_rhs_t", "gemmlowp.cl" },
335 { "gemmlowp_mm_reshaped_only_rhs_t_fused_output_stage_fixedpoint", "gemmlowp.cl" },
336 { "gemmlowp_offset_contribution", "gemmlowp.cl" },
337 { "gemmlowp_offset_contribution_quantize_down", "gemmlowp.cl" },
338 { "gemmlowp_offset_contribution_quantize_down_fixedpoint", "gemmlowp.cl" },
339 { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
340 { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
341 { "gemmlowp_output_stage_quantize_down_fixedpoint_qsymm16", "gemmlowp.cl" },
342 { "gemmlowp_output_stage_quantize_down_float", "gemmlowp.cl" },
343 { "generate_proposals_compute_all_anchors", "generate_proposals.cl" },
344 { "generate_proposals_compute_all_anchors_quantized", "generate_proposals_quantized.cl" },
345 { "im2col1x1_stridex1_nchw", "im2col.cl" },
346 { "im2col3x3_nchw", "im2col.cl" },
347 { "im2col5x5_nchw", "im2col.cl" },
348 { "im2col11x11_padx0_pady0_nchw", "im2col.cl" },
349 { "im2col_generic_nchw", "im2col.cl" },
350 { "im2col_generic_padx0_pady0_nchw", "im2col.cl" },
351 { "im2col3x3_nhwc", "im2col.cl" },
352 { "im2col9x9_nhwc", "im2col.cl" },
353 { "im2col_generic_nhwc", "im2col.cl" },
354 { "instance_normalization", "instance_normalization.cl" },
355 { "compute_mean_var", "instance_normalization.cl" },
356 { "l2_normalize_x", "l2_normalize.cl" },
357 { "l2_normalize_y", "l2_normalize.cl" },
358 { "l2_normalize_z", "l2_normalize.cl" },
359 { "max_unpooling_layer_2", "unpooling_layer.cl" },
360 { "mean_stddev_normalization", "mean_stddev_normalization.cl" },
361 { "memset", "memset.cl" },
362 { "minmax_layer", "minmax_layer.cl" },
363 { "non_max_suppression", "nonmax.cl" },
364 { "normalization_layer_cross_map_nchw", "normalization_layer.cl" },
365 { "normalization_layer_cross_map_nhwc", "normalization_layer.cl" },
366 { "normalization_layer_in_map_nchw", "normalization_layer.cl" },
367 { "normalization_layer_in_map_nhwc", "normalization_layer.cl" },
368 { "normalize_planar_yuv_layer_nchw", "normalize_planar_yuv_layer.cl" },
369 { "normalize_planar_yuv_layer_nhwc", "normalize_planar_yuv_layer.cl" },
370 { "normalize_planar_yuv_layer_q8_nchw", "normalize_planar_yuv_layer_quantized.cl" },
371 { "normalize_planar_yuv_layer_q8_nhwc", "normalize_planar_yuv_layer_quantized.cl" },
372 { "pad_layer_constant", "pad_layer.cl" },
373 { "pad_layer_symmetric_reflect", "pad_layer.cl" },
374 { "permute", "permute.cl" },
375 { "pixelwise_mul_complex", "pixelwise_mul_float.cl" },
376 { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
377 { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
378 { "pixelwise_mul_quantized", "pixelwise_mul_int.cl" },
379 { "pooling_layer_2", "pooling_layer.cl" },
380 { "pooling_layer_3", "pooling_layer.cl" },
381 { "pooling_layer_optimized_3", "pooling_layer.cl" },
382 { "pooling_layer_7", "pooling_layer.cl" },
383 { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
384 { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
385 { "pooling_layer_2x2_nhwc", "pooling_layer.cl" },
386 { "pooling_layer_2_nchw_indices_fp32", "pooling_layer.cl" },
387 { "pooling_layer_2_nchw_indices_fp16", "pooling_layer.cl" },
388 { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
389 { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
390 { "prior_box_layer_nchw", "prior_box_layer.cl" },
391 { "qlstm_layer_normalization", "qlstm_layer_normalization.cl" },
392 { "quantization_layer", "quantization_layer.cl" },
393 { "range", "range.cl" },
394 { "range_quantized", "range.cl" },
395 { "reduction_operation_x", "reduction_operation.cl" },
396 { "reduction_operation_non_parallel_x", "reduction_operation.cl" },
397 { "reduction_operation_y", "reduction_operation.cl" },
398 { "reduction_operation_z", "reduction_operation.cl" },
399 { "reduction_operation_w", "reduction_operation.cl" },
400 { "remap_nearest_neighbour", "remap.cl" },
401 { "remap_bilinear", "remap.cl" },
402 { "reorg_layer_nchw", "reorg_layer.cl" },
403 { "reorg_layer_nhwc", "reorg_layer.cl" },
404 { "reshape_layer", "reshape_layer.cl" },
405 { "reshape_to_columns", "convolution_layer.cl" },
406 { "reverse", "reverse.cl" },
407 { "roi_align_layer", "roi_align_layer.cl" },
408 { "roi_align_layer_quantized", "roi_align_layer_quantized.cl" },
409 { "roi_pooling_layer", "roi_pooling_layer.cl" },
410 { "scale_nearest_neighbour_nchw", "scale.cl" },
411 { "scale_nearest_neighbour_nhwc", "scale.cl" },
412 { "scale_bilinear_nchw", "scale.cl" },
413 { "scale_bilinear_nhwc", "scale.cl" },
414 { "scale_bilinear_quantized_nchw", "scale_quantized.cl" },
415 { "scale_bilinear_quantized_nhwc", "scale_quantized.cl" },
416 { "select_same_rank", "select.cl" },
417 { "select_different_rank_2", "select.cl" },
418 { "select_different_rank_n", "select.cl" },
419 { "softmax_layer_norm", "softmax_layer.cl" },
420 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
421 { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
422 { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
423 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
424 { "space_to_batch_nchw", "space_to_batch.cl" },
425 { "space_to_batch_static_nchw", "space_to_batch.cl" },
426 { "space_to_batch_nhwc", "space_to_batch.cl" },
427 { "space_to_batch_static_nhwc", "space_to_batch.cl" },
428 { "space_to_depth_nchw", "space_to_depth.cl" },
429 { "space_to_depth_nhwc", "space_to_depth.cl" },
430 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
431 { "stack_layer", "stack_layer.cl" },
432 { "strided_slice", "slice_ops.cl" },
433 { "tile", "tile.cl" },
434 { "transpose", "transpose.cl" },
435 { "upsample_layer_nchw", "upsample_layer.cl" },
436 { "upsample_layer_nhwc", "upsample_layer.cl" },
437 { "winograd_filter_transform_2x2_3x3_nchw", "winograd_filter_transform.cl" },
438 { "winograd_filter_transform_2x1_3x1_nchw", "winograd_filter_transform.cl" },
439 { "winograd_filter_transform_1x2_1x3_nchw", "winograd_filter_transform.cl" },
440 { "winograd_filter_transform_4x4_3x3_nchw", "winograd_filter_transform.cl" },
441 { "winograd_filter_transform_4x1_3x1_nchw", "winograd_filter_transform.cl" },
442 { "winograd_filter_transform_1x4_1x3_nchw", "winograd_filter_transform.cl" },
443 { "winograd_filter_transform_4x4_5x5_nchw", "winograd_filter_transform.cl" },
444 { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
445 { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
446 { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
447 { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
448 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
449 { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
450 { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
451 { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
452 { "winograd_filter_transform_2x2_7x7_nhwc", "winograd_filter_transform.cl" },
453 { "winograd_filter_transform_2x1_7x1_nhwc", "winograd_filter_transform.cl" },
454 { "winograd_filter_transform_1x2_1x7_nhwc", "winograd_filter_transform.cl" },
455 { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd_input_transform.cl" },
456 { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd_input_transform.cl" },
457 { "winograd_input_transform_2x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
458 { "winograd_input_transform_2x1_3x1_stepz2_nchw", "winograd_input_transform.cl" },
459 { "winograd_input_transform_1x2_1x3_stepz1_nchw", "winograd_input_transform.cl" },
460 { "winograd_input_transform_1x2_1x3_stepz2_nchw", "winograd_input_transform.cl" },
461 { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd_input_transform.cl" },
462 { "winograd_input_transform_4x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
463 { "winograd_input_transform_1x4_1x3_stepz1_nchw", "winograd_input_transform.cl" },
464 { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd_input_transform.cl" },
465 { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
466 { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
467 { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
468 { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
469 { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
470 { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
471 { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
472 { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
473 { "winograd_input_transform_2x2_7x7_stepz1_nhwc", "winograd_input_transform.cl" },
474 { "winograd_input_transform_2x1_7x1_stepz1_nhwc", "winograd_input_transform.cl" },
475 { "winograd_input_transform_1x2_1x7_stepz1_nhwc", "winograd_input_transform.cl" },
476 { "winograd_output_transform_2x2_3x3_nchw", "winograd_output_transform.cl" },
477 { "winograd_output_transform_2x1_3x1_nchw", "winograd_output_transform.cl" },
478 { "winograd_output_transform_1x2_1x3_nchw", "winograd_output_transform.cl" },
479 { "winograd_output_transform_4x4_3x3_nchw", "winograd_output_transform.cl" },
480 { "winograd_output_transform_4x1_3x1_nchw", "winograd_output_transform.cl" },
481 { "winograd_output_transform_1x4_1x3_nchw", "winograd_output_transform.cl" },
482 { "winograd_output_transform_4x4_5x5_nchw", "winograd_output_transform.cl" },
483 { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
484 { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
485 { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
486 { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
487 { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
488 { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
489 { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
490 { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
491 { "winograd_output_transform_2x2_7x7_nhwc", "winograd_output_transform.cl" },
492 { "winograd_output_transform_2x1_7x1_nhwc", "winograd_output_transform.cl" },
493 { "winograd_output_transform_1x2_1x7_nhwc", "winograd_output_transform.cl" },
494};
495
496const std::map<std::string, std::string> ClKernelLibrary::_program_source_map =
497{
498#ifdef EMBEDDED_KERNELS
499 {
500 "activation_layer.cl",
501#include "./cl_kernels/activation_layer.clembed"
502 },
503 {
504 "activation_layer_quant.cl",
505#include "./cl_kernels/activation_layer_quant.clembed"
506 },
507 {
508 "arg_min_max.cl",
509#include "./cl_kernels/arg_min_max.clembed"
510 },
511 {
512 "batch_to_space.cl",
513#include "./cl_kernels/batch_to_space.clembed"
514 },
515 {
516 "bitwise_op.cl",
517#include "./cl_kernels/bitwise_op.clembed"
518 },
519 {
520 "bounding_box_transform.cl",
521#include "./cl_kernels/bounding_box_transform.clembed"
522 },
523 {
524 "bounding_box_transform_quantized.cl",
525#include "./cl_kernels/bounding_box_transform_quantized.clembed"
526 },
527 {
528 "channel_shuffle.cl",
529#include "./cl_kernels/channel_shuffle.clembed"
530 },
531 {
532 "col2im.cl",
533#include "./cl_kernels/col2im.clembed"
534 },
535 {
536 "comparisons.cl",
537#include "./cl_kernels/comparisons.clembed"
538 },
539 {
540 "concatenate.cl",
541#include "./cl_kernels/concatenate.clembed"
542 },
543 {
544 "convert_fc_weights.cl",
545#include "./cl_kernels/convert_fc_weights.clembed"
546 },
547 {
548 "convolution_layer.cl",
549#include "./cl_kernels/convolution_layer.clembed"
550 },
551 {
552 "copy_tensor.cl",
553#include "./cl_kernels/copy_tensor.clembed"
554 },
555 {
556 "crop_tensor.cl",
557#include "./cl_kernels/crop_tensor.clembed"
558 },
559 {
560 "upsample_layer.cl",
561#include "./cl_kernels/upsample_layer.clembed"
562 },
563 {
564 "deconvolution_layer.cl",
565#include "./cl_kernels/deconvolution_layer.clembed"
566 },
567 {
568 "depth_convert.cl",
569#include "./cl_kernels/depth_convert.clembed"
570 },
571 {
572 "depth_to_space.cl",
573#include "./cl_kernels/depth_to_space.clembed"
574 },
575 {
576 "depthwise_convolution.cl",
577#include "./cl_kernels/depthwise_convolution.clembed"
578 },
579 {
580 "depthwise_convolution_quantized.cl",
581#include "./cl_kernels/depthwise_convolution_quantized.clembed"
582 },
583 {
584 "dequantization_layer.cl",
585#include "./cl_kernels/dequantization_layer.clembed"
586 },
587 {
588 "direct_convolution1x1.cl",
589#include "./cl_kernels/direct_convolution1x1.clembed"
590 },
591 {
592 "direct_convolution3x3.cl",
593#include "./cl_kernels/direct_convolution3x3.clembed"
594 },
595 {
596 "direct_convolution5x5.cl",
597#include "./cl_kernels/direct_convolution5x5.clembed"
598 },
599 {
600 "direct_convolution_quantized.cl",
601#include "./cl_kernels/direct_convolution_quantized.clembed"
602 },
603 {
604 "direct_convolution.cl",
605#include "./cl_kernels/direct_convolution.clembed"
606 },
607 {
608 "elementwise_operation.cl",
609#include "./cl_kernels/elementwise_operation.clembed"
610 },
611 {
612 "elementwise_operation_quantized.cl",
613#include "./cl_kernels/elementwise_operation_quantized.clembed"
614 },
615 {
616 "elementwise_unary.cl",
617#include "./cl_kernels/elementwise_unary.clembed"
618 },
619 {
620 "fft.cl",
621#include "./cl_kernels/fft.clembed"
622 },
623 {
624 "fft_digit_reverse.cl",
625#include "./cl_kernels/fft_digit_reverse.clembed"
626 },
627 {
628 "fft_scale.cl",
629#include "./cl_kernels/fft_scale.clembed"
630 },
631 {
632 "fill_border.cl",
633#include "./cl_kernels/fill_border.clembed"
634 },
635 {
636 "floor.cl",
637#include "./cl_kernels/floor.clembed"
638 },
639 {
640 "gather.cl",
641#include "./cl_kernels/gather.clembed"
642 },
643 {
644 "gemm.cl",
645#include "./cl_kernels/gemm.clembed"
646 },
647 {
648 "gemm_v1.cl",
649#include "./cl_kernels/gemm_v1.clembed"
650 },
651 {
652 "gemmlowp.cl",
653#include "./cl_kernels/gemmlowp.clembed"
654 },
655 {
656 "gemv.cl",
657#include "./cl_kernels/gemv.clembed"
658 },
659 {
660 "generate_proposals.cl",
661#include "./cl_kernels/generate_proposals.clembed"
662 },
663 {
664 "generate_proposals_quantized.cl",
665#include "./cl_kernels/generate_proposals_quantized.clembed"
666 },
667 {
668 "helpers.h",
669#include "./cl_kernels/helpers.hembed"
670 },
671 {
672 "helpers_asymm.h",
673#include "./cl_kernels/helpers_asymm.hembed"
674 },
675 {
676 "im2col.cl",
677#include "./cl_kernels/im2col.clembed"
678 },
679 {
680 "instance_normalization.cl",
681#include "./cl_kernels/instance_normalization.clembed"
682 },
683 {
684 "l2_normalize.cl",
685#include "./cl_kernels/l2_normalize.clembed"
686 },
687 {
688 "mean_stddev_normalization.cl",
689#include "./cl_kernels/mean_stddev_normalization.clembed"
690 },
691 {
692 "memset.cl",
693#include "./cl_kernels/memset.clembed"
694 },
695 {
696 "minmax_layer.cl",
697#include "./cl_kernels/minmax_layer.clembed"
698 },
699 {
700 "nonmax.cl",
701#include "./cl_kernels/nonmax.clembed"
702 },
703 {
704 "normalization_layer.cl",
705#include "./cl_kernels/normalization_layer.clembed"
706 },
707 {
708 "normalize_planar_yuv_layer.cl",
709#include "./cl_kernels/normalize_planar_yuv_layer.clembed"
710 },
711 {
712 "normalize_planar_yuv_layer_quantized.cl",
713#include "./cl_kernels/normalize_planar_yuv_layer_quantized.clembed"
714 },
715 {
716 "batchnormalization_layer.cl",
717#include "./cl_kernels/batchnormalization_layer.clembed"
718 },
719 {
720 "pad_layer.cl",
721#include "./cl_kernels/pad_layer.clembed"
722 },
723 {
724 "permute.cl",
725#include "./cl_kernels/permute.clembed"
726 },
727 {
728 "pixelwise_mul_float.cl",
729#include "./cl_kernels/pixelwise_mul_float.clembed"
730 },
731 {
732 "pixelwise_mul_int.cl",
733#include "./cl_kernels/pixelwise_mul_int.clembed"
734 },
735 {
736 "pooling_layer.cl",
737#include "./cl_kernels/pooling_layer.clembed"
738 },
739 {
740 "pooling_layer_quantized.cl",
741#include "./cl_kernels/pooling_layer_quantized.clembed"
742 },
743 {
744 "prior_box_layer.cl",
745#include "./cl_kernels/prior_box_layer.clembed"
746 },
747 {
748 "qlstm_layer_normalization.cl",
749#include "./cl_kernels/qlstm_layer_normalization.clembed"
750 },
751 {
752 "quantization_layer.cl",
753#include "./cl_kernels/quantization_layer.clembed"
754 },
755 {
756 "range.cl",
757#include "./cl_kernels/range.clembed"
758 },
759 {
760 "reduction_operation.cl",
761#include "./cl_kernels/reduction_operation.clembed"
762 },
763 {
764 "remap.cl",
765#include "./cl_kernels/remap.clembed"
766 },
767 {
768 "reorg_layer.cl",
769#include "./cl_kernels/reorg_layer.clembed"
770 },
771 {
772 "reshape_layer.cl",
773#include "./cl_kernels/reshape_layer.clembed"
774 },
775 {
776 "reverse.cl",
777#include "./cl_kernels/reverse.clembed"
778 },
779 {
780 "roi_align_layer.cl",
781#include "./cl_kernels/roi_align_layer.clembed"
782 },
783 {
784 "roi_align_layer_quantized.cl",
785#include "./cl_kernels/roi_align_layer_quantized.clembed"
786 },
787 {
788 "roi_pooling_layer.cl",
789#include "./cl_kernels/roi_pooling_layer.clembed"
790 },
791 {
792 "scale.cl",
793#include "./cl_kernels/scale.clembed"
794 },
795 {
796 "scale_quantized.cl",
797#include "./cl_kernels/scale_quantized.clembed"
798 },
799 {
800 "select.cl",
801#include "./cl_kernels/select.clembed"
802 },
803 {
804 "softmax_layer.cl",
805#include "./cl_kernels/softmax_layer.clembed"
806 },
807 {
808 "softmax_layer_quantized.cl",
809#include "./cl_kernels/softmax_layer_quantized.clembed"
810 },
811 {
812 "slice_ops.cl",
813#include "./cl_kernels/slice_ops.clembed"
814 },
815 {
816 "space_to_batch.cl",
817#include "./cl_kernels/space_to_batch.clembed"
818 },
819 {
820 "space_to_depth.cl",
821#include "./cl_kernels/space_to_depth.clembed"
822 },
823 {
824 "stack_layer.cl",
825#include "./cl_kernels/stack_layer.clembed"
826 },
827 {
828 "tile.cl",
829#include "./cl_kernels/tile.clembed"
830 },
831 {
832 "transpose.cl",
833#include "./cl_kernels/transpose.clembed"
834 },
835 {
836 "types.h",
837#include "./cl_kernels/types.hembed"
838 },
839 {
840 "unpooling_layer.cl",
841#include "./cl_kernels/unpooling_layer.clembed"
842 },
843 {
844 "winograd_filter_transform.cl",
845#include "./cl_kernels/winograd_filter_transform.clembed"
846 },
847 {
848 "winograd_input_transform.cl",
849#include "./cl_kernels/winograd_input_transform.clembed"
850 },
851 {
852 "winograd_output_transform.cl",
853#include "./cl_kernels/winograd_output_transform.clembed"
854 },
855#endif /* EMBEDDED_KERNELS */
856};
857
858ClKernelLibrary &ClKernelLibrary::get()
859{
860 static ClKernelLibrary _kernel_library;
861 return _kernel_library;
862}
863
864std::string ClKernelLibrary::program_name(const std::string &kernel_name) const
865{
866 // Find which program contains the kernel
867 auto kernel_program_it = _kernel_program_map.find(kernel_name);
868
869 if(_kernel_program_map.end() == kernel_program_it)
870 {
871 ARM_COMPUTE_ERROR_VAR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
872 }
873
874 const std::string program_name = kernel_program_it->second;
875
876 return program_name;
877}
878
879void ClKernelLibrary::set_kernel_path(std::string kernel_path)
880{
881 _kernel_path = std::move(kernel_path);
882 _kernel_path += "/";
883}
884
885const std::string &ClKernelLibrary::kernel_path() const
886{
887 return _kernel_path;
888}
889
890ClKernelLibrary::ClProgramInfo ClKernelLibrary::program(const std::string &program_name) const
891{
892#ifdef EMBEDDED_KERNELS
893#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
894 const auto inflatted_program_source_it = _decompressed_source_map.find(program_name);
895 if(inflatted_program_source_it != _decompressed_source_map.end())
896 {
897 return ClProgramInfo{ inflatted_program_source_it->second, false };
898 }
899#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
900
901 const auto program_source_it = _program_source_map.find(program_name);
902 if(program_source_it == _program_source_map.end())
903 {
904 ARM_COMPUTE_ERROR_VAR("Embedded program for %s does not exist.", program_name.c_str());
905 }
906 std::string program_source = program_source_it->second;
907
908#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
909 std::string decompressed_program_source = decompress_zlib(decode_base64(program_source_it->second));
910 ARM_COMPUTE_ERROR_ON_MSG(decompressed_program_source.empty(), "Cannot de-compress requested program");
911 _decompressed_source_map.insert(std::make_pair(program_name, decompressed_program_source));
912 program_source = std::move(decompressed_program_source);
913#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
914
915 return ClProgramInfo{ program_source, false };
916#else /* EMBEDDED_KERNELS */
917 // Check for binary
918 std::string source_name = _kernel_path + program_name;
919 std::string binary_name = source_name + "bin";
920 std::string program_source{};
921 bool is_binary = false;
922
923 if(std::ifstream(binary_name).is_open())
924 {
925 program_source = read_file(binary_name, true);
926 is_binary = true;
927 }
928 else if(std::ifstream(source_name).is_open())
929 {
930 program_source = read_file(source_name, false);
931 }
932 else
933 {
934 ARM_COMPUTE_ERROR_VAR("Kernel file %s does not exist.", source_name.c_str());
935 }
936
937 return ClProgramInfo{ program_source, is_binary };
938#endif /* EMBEDDED_KERNELS */
939}
940} // namespace opencl
941} // namespace arm_compute