blob: 9d516e54a772a7a60688d1d52b864564e3f9117f [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" },
Georgios Pinitas11d84152021-04-28 10:20:18 +0100219 { "cast_down", "cast.cl" },
220 { "cast_up", "cast.cl" },
Georgios Pinitas908f6162021-05-04 10:11:09 +0100221 { "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" },
Frederick Liardet36dff9f2021-04-22 21:13:21 +0100400 { "remap_nearest_neighbour_nchw", "remap.cl" },
401 { "remap_bilinear_nchw", "remap.cl" },
402 { "remap_nearest_neighbour_nhwc", "remap.cl" },
403 { "remap_bilinear_nhwc", "remap.cl" },
Georgios Pinitas908f6162021-05-04 10:11:09 +0100404 { "reorg_layer_nchw", "reorg_layer.cl" },
405 { "reorg_layer_nhwc", "reorg_layer.cl" },
406 { "reshape_layer", "reshape_layer.cl" },
407 { "reshape_to_columns", "convolution_layer.cl" },
408 { "reverse", "reverse.cl" },
409 { "roi_align_layer", "roi_align_layer.cl" },
410 { "roi_align_layer_quantized", "roi_align_layer_quantized.cl" },
411 { "roi_pooling_layer", "roi_pooling_layer.cl" },
412 { "scale_nearest_neighbour_nchw", "scale.cl" },
413 { "scale_nearest_neighbour_nhwc", "scale.cl" },
414 { "scale_bilinear_nchw", "scale.cl" },
415 { "scale_bilinear_nhwc", "scale.cl" },
416 { "scale_bilinear_quantized_nchw", "scale_quantized.cl" },
417 { "scale_bilinear_quantized_nhwc", "scale_quantized.cl" },
418 { "select_same_rank", "select.cl" },
419 { "select_different_rank_2", "select.cl" },
420 { "select_different_rank_n", "select.cl" },
421 { "softmax_layer_norm", "softmax_layer.cl" },
422 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
423 { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
424 { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
425 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
426 { "space_to_batch_nchw", "space_to_batch.cl" },
427 { "space_to_batch_static_nchw", "space_to_batch.cl" },
428 { "space_to_batch_nhwc", "space_to_batch.cl" },
429 { "space_to_batch_static_nhwc", "space_to_batch.cl" },
430 { "space_to_depth_nchw", "space_to_depth.cl" },
431 { "space_to_depth_nhwc", "space_to_depth.cl" },
432 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
433 { "stack_layer", "stack_layer.cl" },
434 { "strided_slice", "slice_ops.cl" },
435 { "tile", "tile.cl" },
436 { "transpose", "transpose.cl" },
437 { "upsample_layer_nchw", "upsample_layer.cl" },
438 { "upsample_layer_nhwc", "upsample_layer.cl" },
439 { "winograd_filter_transform_2x2_3x3_nchw", "winograd_filter_transform.cl" },
440 { "winograd_filter_transform_2x1_3x1_nchw", "winograd_filter_transform.cl" },
441 { "winograd_filter_transform_1x2_1x3_nchw", "winograd_filter_transform.cl" },
442 { "winograd_filter_transform_4x4_3x3_nchw", "winograd_filter_transform.cl" },
443 { "winograd_filter_transform_4x1_3x1_nchw", "winograd_filter_transform.cl" },
444 { "winograd_filter_transform_1x4_1x3_nchw", "winograd_filter_transform.cl" },
445 { "winograd_filter_transform_4x4_5x5_nchw", "winograd_filter_transform.cl" },
446 { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
447 { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
448 { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
449 { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
450 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
451 { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
452 { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
453 { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
454 { "winograd_filter_transform_2x2_7x7_nhwc", "winograd_filter_transform.cl" },
455 { "winograd_filter_transform_2x1_7x1_nhwc", "winograd_filter_transform.cl" },
456 { "winograd_filter_transform_1x2_1x7_nhwc", "winograd_filter_transform.cl" },
457 { "winograd_input_transform_2x2_3x3_stepz1_nchw", "winograd_input_transform.cl" },
458 { "winograd_input_transform_2x2_3x3_stepz2_nchw", "winograd_input_transform.cl" },
459 { "winograd_input_transform_2x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
460 { "winograd_input_transform_2x1_3x1_stepz2_nchw", "winograd_input_transform.cl" },
461 { "winograd_input_transform_1x2_1x3_stepz1_nchw", "winograd_input_transform.cl" },
462 { "winograd_input_transform_1x2_1x3_stepz2_nchw", "winograd_input_transform.cl" },
463 { "winograd_input_transform_4x4_3x3_stepz1_nchw", "winograd_input_transform.cl" },
464 { "winograd_input_transform_4x1_3x1_stepz1_nchw", "winograd_input_transform.cl" },
465 { "winograd_input_transform_1x4_1x3_stepz1_nchw", "winograd_input_transform.cl" },
466 { "winograd_input_transform_4x4_5x5_stepz1_nchw", "winograd_input_transform.cl" },
467 { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
468 { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
469 { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
470 { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
471 { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
472 { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
473 { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
474 { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
475 { "winograd_input_transform_2x2_7x7_stepz1_nhwc", "winograd_input_transform.cl" },
476 { "winograd_input_transform_2x1_7x1_stepz1_nhwc", "winograd_input_transform.cl" },
477 { "winograd_input_transform_1x2_1x7_stepz1_nhwc", "winograd_input_transform.cl" },
478 { "winograd_output_transform_2x2_3x3_nchw", "winograd_output_transform.cl" },
479 { "winograd_output_transform_2x1_3x1_nchw", "winograd_output_transform.cl" },
480 { "winograd_output_transform_1x2_1x3_nchw", "winograd_output_transform.cl" },
481 { "winograd_output_transform_4x4_3x3_nchw", "winograd_output_transform.cl" },
482 { "winograd_output_transform_4x1_3x1_nchw", "winograd_output_transform.cl" },
483 { "winograd_output_transform_1x4_1x3_nchw", "winograd_output_transform.cl" },
484 { "winograd_output_transform_4x4_5x5_nchw", "winograd_output_transform.cl" },
485 { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
486 { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
487 { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
488 { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
489 { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
490 { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
491 { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
492 { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
493 { "winograd_output_transform_2x2_7x7_nhwc", "winograd_output_transform.cl" },
494 { "winograd_output_transform_2x1_7x1_nhwc", "winograd_output_transform.cl" },
495 { "winograd_output_transform_1x2_1x7_nhwc", "winograd_output_transform.cl" },
496};
497
498const std::map<std::string, std::string> ClKernelLibrary::_program_source_map =
499{
500#ifdef EMBEDDED_KERNELS
501 {
502 "activation_layer.cl",
503#include "./cl_kernels/activation_layer.clembed"
504 },
505 {
506 "activation_layer_quant.cl",
507#include "./cl_kernels/activation_layer_quant.clembed"
508 },
509 {
510 "arg_min_max.cl",
511#include "./cl_kernels/arg_min_max.clembed"
512 },
513 {
514 "batch_to_space.cl",
515#include "./cl_kernels/batch_to_space.clembed"
516 },
517 {
518 "bitwise_op.cl",
519#include "./cl_kernels/bitwise_op.clembed"
520 },
521 {
522 "bounding_box_transform.cl",
523#include "./cl_kernels/bounding_box_transform.clembed"
524 },
525 {
526 "bounding_box_transform_quantized.cl",
527#include "./cl_kernels/bounding_box_transform_quantized.clembed"
528 },
529 {
530 "channel_shuffle.cl",
531#include "./cl_kernels/channel_shuffle.clembed"
532 },
533 {
534 "col2im.cl",
535#include "./cl_kernels/col2im.clembed"
536 },
537 {
538 "comparisons.cl",
539#include "./cl_kernels/comparisons.clembed"
540 },
541 {
542 "concatenate.cl",
543#include "./cl_kernels/concatenate.clembed"
544 },
545 {
546 "convert_fc_weights.cl",
547#include "./cl_kernels/convert_fc_weights.clembed"
548 },
549 {
550 "convolution_layer.cl",
551#include "./cl_kernels/convolution_layer.clembed"
552 },
553 {
554 "copy_tensor.cl",
555#include "./cl_kernels/copy_tensor.clembed"
556 },
557 {
558 "crop_tensor.cl",
559#include "./cl_kernels/crop_tensor.clembed"
560 },
561 {
562 "upsample_layer.cl",
563#include "./cl_kernels/upsample_layer.clembed"
564 },
565 {
566 "deconvolution_layer.cl",
567#include "./cl_kernels/deconvolution_layer.clembed"
568 },
569 {
Georgios Pinitas11d84152021-04-28 10:20:18 +0100570 "cast.cl",
571#include "./cl_kernels/cast.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100572 },
573 {
574 "depth_to_space.cl",
575#include "./cl_kernels/depth_to_space.clembed"
576 },
577 {
578 "depthwise_convolution.cl",
579#include "./cl_kernels/depthwise_convolution.clembed"
580 },
581 {
582 "depthwise_convolution_quantized.cl",
583#include "./cl_kernels/depthwise_convolution_quantized.clembed"
584 },
585 {
586 "dequantization_layer.cl",
587#include "./cl_kernels/dequantization_layer.clembed"
588 },
589 {
590 "direct_convolution1x1.cl",
591#include "./cl_kernels/direct_convolution1x1.clembed"
592 },
593 {
594 "direct_convolution3x3.cl",
595#include "./cl_kernels/direct_convolution3x3.clembed"
596 },
597 {
598 "direct_convolution5x5.cl",
599#include "./cl_kernels/direct_convolution5x5.clembed"
600 },
601 {
602 "direct_convolution_quantized.cl",
603#include "./cl_kernels/direct_convolution_quantized.clembed"
604 },
605 {
606 "direct_convolution.cl",
607#include "./cl_kernels/direct_convolution.clembed"
608 },
609 {
610 "elementwise_operation.cl",
611#include "./cl_kernels/elementwise_operation.clembed"
612 },
613 {
614 "elementwise_operation_quantized.cl",
615#include "./cl_kernels/elementwise_operation_quantized.clembed"
616 },
617 {
618 "elementwise_unary.cl",
619#include "./cl_kernels/elementwise_unary.clembed"
620 },
621 {
622 "fft.cl",
623#include "./cl_kernels/fft.clembed"
624 },
625 {
626 "fft_digit_reverse.cl",
627#include "./cl_kernels/fft_digit_reverse.clembed"
628 },
629 {
630 "fft_scale.cl",
631#include "./cl_kernels/fft_scale.clembed"
632 },
633 {
634 "fill_border.cl",
635#include "./cl_kernels/fill_border.clembed"
636 },
637 {
638 "floor.cl",
639#include "./cl_kernels/floor.clembed"
640 },
641 {
642 "gather.cl",
643#include "./cl_kernels/gather.clembed"
644 },
645 {
646 "gemm.cl",
647#include "./cl_kernels/gemm.clembed"
648 },
649 {
650 "gemm_v1.cl",
651#include "./cl_kernels/gemm_v1.clembed"
652 },
653 {
654 "gemmlowp.cl",
655#include "./cl_kernels/gemmlowp.clembed"
656 },
657 {
658 "gemv.cl",
659#include "./cl_kernels/gemv.clembed"
660 },
661 {
662 "generate_proposals.cl",
663#include "./cl_kernels/generate_proposals.clembed"
664 },
665 {
666 "generate_proposals_quantized.cl",
667#include "./cl_kernels/generate_proposals_quantized.clembed"
668 },
669 {
670 "helpers.h",
671#include "./cl_kernels/helpers.hembed"
672 },
673 {
674 "helpers_asymm.h",
675#include "./cl_kernels/helpers_asymm.hembed"
676 },
677 {
678 "im2col.cl",
679#include "./cl_kernels/im2col.clembed"
680 },
681 {
682 "instance_normalization.cl",
683#include "./cl_kernels/instance_normalization.clembed"
684 },
685 {
686 "l2_normalize.cl",
687#include "./cl_kernels/l2_normalize.clembed"
688 },
689 {
690 "mean_stddev_normalization.cl",
691#include "./cl_kernels/mean_stddev_normalization.clembed"
692 },
693 {
694 "memset.cl",
695#include "./cl_kernels/memset.clembed"
696 },
697 {
698 "minmax_layer.cl",
699#include "./cl_kernels/minmax_layer.clembed"
700 },
701 {
702 "nonmax.cl",
703#include "./cl_kernels/nonmax.clembed"
704 },
705 {
706 "normalization_layer.cl",
707#include "./cl_kernels/normalization_layer.clembed"
708 },
709 {
710 "normalize_planar_yuv_layer.cl",
711#include "./cl_kernels/normalize_planar_yuv_layer.clembed"
712 },
713 {
714 "normalize_planar_yuv_layer_quantized.cl",
715#include "./cl_kernels/normalize_planar_yuv_layer_quantized.clembed"
716 },
717 {
718 "batchnormalization_layer.cl",
719#include "./cl_kernels/batchnormalization_layer.clembed"
720 },
721 {
722 "pad_layer.cl",
723#include "./cl_kernels/pad_layer.clembed"
724 },
725 {
726 "permute.cl",
727#include "./cl_kernels/permute.clembed"
728 },
729 {
730 "pixelwise_mul_float.cl",
731#include "./cl_kernels/pixelwise_mul_float.clembed"
732 },
733 {
734 "pixelwise_mul_int.cl",
735#include "./cl_kernels/pixelwise_mul_int.clembed"
736 },
737 {
738 "pooling_layer.cl",
739#include "./cl_kernels/pooling_layer.clembed"
740 },
741 {
742 "pooling_layer_quantized.cl",
743#include "./cl_kernels/pooling_layer_quantized.clembed"
744 },
745 {
746 "prior_box_layer.cl",
747#include "./cl_kernels/prior_box_layer.clembed"
748 },
749 {
750 "qlstm_layer_normalization.cl",
751#include "./cl_kernels/qlstm_layer_normalization.clembed"
752 },
753 {
754 "quantization_layer.cl",
755#include "./cl_kernels/quantization_layer.clembed"
756 },
757 {
758 "range.cl",
759#include "./cl_kernels/range.clembed"
760 },
761 {
762 "reduction_operation.cl",
763#include "./cl_kernels/reduction_operation.clembed"
764 },
765 {
766 "remap.cl",
767#include "./cl_kernels/remap.clembed"
768 },
769 {
770 "reorg_layer.cl",
771#include "./cl_kernels/reorg_layer.clembed"
772 },
773 {
774 "reshape_layer.cl",
775#include "./cl_kernels/reshape_layer.clembed"
776 },
777 {
778 "reverse.cl",
779#include "./cl_kernels/reverse.clembed"
780 },
781 {
782 "roi_align_layer.cl",
783#include "./cl_kernels/roi_align_layer.clembed"
784 },
785 {
786 "roi_align_layer_quantized.cl",
787#include "./cl_kernels/roi_align_layer_quantized.clembed"
788 },
789 {
790 "roi_pooling_layer.cl",
791#include "./cl_kernels/roi_pooling_layer.clembed"
792 },
793 {
794 "scale.cl",
795#include "./cl_kernels/scale.clembed"
796 },
797 {
798 "scale_quantized.cl",
799#include "./cl_kernels/scale_quantized.clembed"
800 },
801 {
802 "select.cl",
803#include "./cl_kernels/select.clembed"
804 },
805 {
806 "softmax_layer.cl",
807#include "./cl_kernels/softmax_layer.clembed"
808 },
809 {
810 "softmax_layer_quantized.cl",
811#include "./cl_kernels/softmax_layer_quantized.clembed"
812 },
813 {
814 "slice_ops.cl",
815#include "./cl_kernels/slice_ops.clembed"
816 },
817 {
818 "space_to_batch.cl",
819#include "./cl_kernels/space_to_batch.clembed"
820 },
821 {
822 "space_to_depth.cl",
823#include "./cl_kernels/space_to_depth.clembed"
824 },
825 {
826 "stack_layer.cl",
827#include "./cl_kernels/stack_layer.clembed"
828 },
829 {
830 "tile.cl",
831#include "./cl_kernels/tile.clembed"
832 },
833 {
834 "transpose.cl",
835#include "./cl_kernels/transpose.clembed"
836 },
837 {
838 "types.h",
839#include "./cl_kernels/types.hembed"
840 },
841 {
842 "unpooling_layer.cl",
843#include "./cl_kernels/unpooling_layer.clembed"
844 },
845 {
846 "winograd_filter_transform.cl",
847#include "./cl_kernels/winograd_filter_transform.clembed"
848 },
849 {
850 "winograd_input_transform.cl",
851#include "./cl_kernels/winograd_input_transform.clembed"
852 },
853 {
854 "winograd_output_transform.cl",
855#include "./cl_kernels/winograd_output_transform.clembed"
856 },
857#endif /* EMBEDDED_KERNELS */
858};
859
860ClKernelLibrary &ClKernelLibrary::get()
861{
862 static ClKernelLibrary _kernel_library;
863 return _kernel_library;
864}
865
866std::string ClKernelLibrary::program_name(const std::string &kernel_name) const
867{
868 // Find which program contains the kernel
869 auto kernel_program_it = _kernel_program_map.find(kernel_name);
870
871 if(_kernel_program_map.end() == kernel_program_it)
872 {
873 ARM_COMPUTE_ERROR_VAR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
874 }
875
876 const std::string program_name = kernel_program_it->second;
877
878 return program_name;
879}
880
881void ClKernelLibrary::set_kernel_path(std::string kernel_path)
882{
883 _kernel_path = std::move(kernel_path);
884 _kernel_path += "/";
885}
886
887const std::string &ClKernelLibrary::kernel_path() const
888{
889 return _kernel_path;
890}
891
892ClKernelLibrary::ClProgramInfo ClKernelLibrary::program(const std::string &program_name) const
893{
894#ifdef EMBEDDED_KERNELS
895#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
896 const auto inflatted_program_source_it = _decompressed_source_map.find(program_name);
897 if(inflatted_program_source_it != _decompressed_source_map.end())
898 {
899 return ClProgramInfo{ inflatted_program_source_it->second, false };
900 }
901#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
902
903 const auto program_source_it = _program_source_map.find(program_name);
904 if(program_source_it == _program_source_map.end())
905 {
906 ARM_COMPUTE_ERROR_VAR("Embedded program for %s does not exist.", program_name.c_str());
907 }
908 std::string program_source = program_source_it->second;
909
910#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
911 std::string decompressed_program_source = decompress_zlib(decode_base64(program_source_it->second));
912 ARM_COMPUTE_ERROR_ON_MSG(decompressed_program_source.empty(), "Cannot de-compress requested program");
913 _decompressed_source_map.insert(std::make_pair(program_name, decompressed_program_source));
914 program_source = std::move(decompressed_program_source);
915#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
916
917 return ClProgramInfo{ program_source, false };
918#else /* EMBEDDED_KERNELS */
919 // Check for binary
920 std::string source_name = _kernel_path + program_name;
921 std::string binary_name = source_name + "bin";
922 std::string program_source{};
923 bool is_binary = false;
924
925 if(std::ifstream(binary_name).is_open())
926 {
927 program_source = read_file(binary_name, true);
928 is_binary = true;
929 }
930 else if(std::ifstream(source_name).is_open())
931 {
932 program_source = read_file(source_name, false);
933 }
934 else
935 {
936 ARM_COMPUTE_ERROR_VAR("Kernel file %s does not exist.", source_name.c_str());
937 }
938
939 return ClProgramInfo{ program_source, is_binary };
940#endif /* EMBEDDED_KERNELS */
941}
942} // namespace opencl
943} // namespace arm_compute