blob: bcade9452294775691fa30909546fcb80f9aaf18 [file] [log] [blame]
Georgios Pinitas908f6162021-05-04 10:11:09 +01001/*
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +00002 * Copyright (c) 2016-2023 Arm Limited.
Georgios Pinitas908f6162021-05-04 10:11:09 +01003 *
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 */
Georgios Pinitas7891a732021-08-20 21:39:25 +010024#include "src/gpu/cl/ClKernelLibrary.h"
Georgios Pinitas908f6162021-05-04 10:11:09 +010025
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 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010040constexpr std::array<uint8_t, 256> b64_invtab = {
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
43 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
44 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Georgios Pinitas908f6162021-05-04 10:11:09 +010050};
51
52/** Decode a base64 encoded string
53 *
54 * @param[in] str Base64 encoded string to decode
55 *
56 * @return The decode string in case of a valid, non-empty string otherwise an empty string
57 */
58std::string decode_base64(const std::string &str)
59{
60 constexpr const char pad_char = '=';
61
62 // Handle empty string
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063 if (str.empty())
Georgios Pinitas908f6162021-05-04 10:11:09 +010064 {
65 return {};
66 }
67
68 // Base64 encoded string has size multiple of 4
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010069 if (str.length() % 4)
Georgios Pinitas908f6162021-05-04 10:11:09 +010070 {
71 return {};
72 }
73
74 //
75 // Check encoded string padding
76 std::size_t padding = (str.rbegin()[0] == pad_char) + (str.rbegin()[1] == pad_char);
77 const int str_len = str.size();
78
79 // Reserve memory for the decoded string
80 // Note each 4 consecutive elements of 6-bit encode 3 bytes
81 std::string dec_b64;
82 dec_b64.reserve(((str_len / 4) * 3));
83
84 // Block decoding function (exclude padding)
85 int c = 0;
86 const int end = str_len - 4 - padding;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010087 for (; c <= end; c += 4)
Georgios Pinitas908f6162021-05-04 10:11:09 +010088 {
89 const int byte0 = b64_invtab[str[c]];
90 const int byte1 = b64_invtab[str[c + 1]];
91 const int byte2 = b64_invtab[str[c + 2]];
92 const int byte3 = b64_invtab[str[c + 3]];
93
94 dec_b64.push_back((byte0 << 2) | (byte1 >> 4));
95 dec_b64.push_back((byte1 << 4) | (byte2 >> 2));
96 dec_b64.push_back((byte2 << 6) | (byte3));
97 }
98
99 // Last step that might contain padding symbols
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100100 if (padding == 1)
Georgios Pinitas908f6162021-05-04 10:11:09 +0100101 {
102 const int byte0 = b64_invtab[str[c]];
103 const int byte1 = b64_invtab[str[c + 1]];
104 const int byte2 = b64_invtab[str[c + 2]];
105
106 dec_b64.push_back((byte0 << 2) | (byte1 >> 4));
107 dec_b64.push_back((byte1 << 4) | (byte2 >> 2));
108 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100109 else if (padding == 2)
Georgios Pinitas908f6162021-05-04 10:11:09 +0100110 {
111 const int byte0 = b64_invtab[str[c]];
112 const int byte1 = b64_invtab[str[c + 1]];
113
114 dec_b64.push_back((byte0 << 2) | (byte1 >> 4));
115 }
116
117 return dec_b64;
118}
119
120/** Decompress a zlib compressed string
121 *
122 * @param[in] str ZLib compressed string
123 *
124 * @return The decompressed string if successful, otherwise false.
125 */
126std::string decompress_zlib(const std::string &str)
127{
128 // Create and initialize decompression stream
129 z_stream ds{};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100130 if (inflateInit(&ds) != Z_OK)
Georgios Pinitas908f6162021-05-04 10:11:09 +0100131 {
132 return std::string();
133 }
134 ds.avail_in = str.size();
135 ds.next_in = (Bytef *)str.data();
136
137 // Roll-over the string using a buffer and decompress
138 int status = Z_OK;
139 char roll_buff[16384];
140 std::string inflated_str;
141 do
142 {
143 ds.avail_out = sizeof(roll_buff);
144 ds.next_out = reinterpret_cast<Bytef *>(roll_buff);
145
146 status = inflate(&ds, 0);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100147 if (inflated_str.size() < ds.total_out)
Georgios Pinitas908f6162021-05-04 10:11:09 +0100148 {
149 inflated_str.append(roll_buff, ds.total_out - inflated_str.size());
150 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100151 } while (status == Z_OK);
Georgios Pinitas908f6162021-05-04 10:11:09 +0100152
153 // Finalize decompression stream
154 inflateEnd(&ds);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100155 if (status != Z_STREAM_END)
Georgios Pinitas908f6162021-05-04 10:11:09 +0100156 {
157 return std::string();
158 }
159
160 return inflated_str;
161}
162} // namespace
163#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
164
165namespace arm_compute
166{
167namespace opencl
168{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100169const std::map<std::string, std::string> ClKernelLibrary::_kernel_program_map = {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100170 // Common Kernels
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100171 {"activation_layer", "common/activation_layer.cl"},
172 {"activation_layer_quant", "common/activation_layer_quant.cl"},
173 {"activation_layer_quant_f32", "common/activation_layer_quant.cl"},
174 {"arg_min_max_x", "common/arg_min_max.cl"},
175 {"arg_min_max_y", "common/arg_min_max.cl"},
176 {"arg_min_max_z", "common/arg_min_max.cl"},
177 {"arg_min_max_w", "common/arg_min_max.cl"},
178 {"bitwise_or", "common/bitwise_op.cl"},
179 {"bitwise_and", "common/bitwise_op.cl"},
180 {"bitwise_xor", "common/bitwise_op.cl"},
181 {"bitwise_not", "common/bitwise_op.cl"},
182 {"bounding_box_transform", "common/bounding_box_transform.cl"},
183 {"bounding_box_transform_quantized", "common/bounding_box_transform_quantized.cl"},
184 {"compare_equal", "common/comparisons.cl"},
185 {"compare_equal_quantized", "common/comparisons.cl"},
186 {"compare_notequal", "common/comparisons.cl"},
187 {"compare_notequal_quantized", "common/comparisons.cl"},
188 {"compare_greater", "common/comparisons.cl"},
189 {"compare_greater_quantized", "common/comparisons.cl"},
190 {"compare_greaterequal", "common/comparisons.cl"},
191 {"compare_greaterequal_quantized", "common/comparisons.cl"},
192 {"compare_less", "common/comparisons.cl"},
193 {"compare_less_quantized", "common/comparisons.cl"},
194 {"compare_lessequal", "common/comparisons.cl"},
195 {"compare_lessequal_quantized", "common/comparisons.cl"},
196 {"concatenate", "common/concatenate.cl"},
197 {"concatenate_width", "common/concatenate.cl"},
198 {"concatenate_height", "common/concatenate.cl"},
199 {"concatenate_width_x2", "common/concatenate.cl"},
200 {"concatenate_width_x4", "common/concatenate.cl"},
201 {"col2im", "common/col2im.cl"},
202 {"cast_down", "common/cast.cl"},
203 {"cast_up", "common/cast.cl"},
204 {"convert_fc_weights", "common/convert_fc_weights.cl"},
205 {"copy_tensor", "common/copy_tensor.cl"},
206 {"crop_tensor", "common/crop_tensor.cl"},
207 {"deconvolution_reshape", "common/deconvolution_layer.cl"},
208 {"deconvolution_upsample", "common/deconvolution_layer.cl"},
209 {"dequantization_layer", "common/dequantization_layer.cl"},
210 {"elementwise_operation_ADD", "common/elementwise_operation.cl"},
211 {"elementwise_operation_SUB", "common/elementwise_operation.cl"},
212 {"elementwise_operation_MAX", "common/elementwise_operation.cl"},
213 {"elementwise_operation_MIN", "common/elementwise_operation.cl"},
214 {"elementwise_operation_DIV", "common/elementwise_operation.cl"},
215 {"elementwise_operation_SQUARED_DIFF", "common/elementwise_operation.cl"},
216 {"elementwise_operation_POWER", "common/elementwise_operation.cl"},
217 {"elementwise_operation_PRELU", "common/elementwise_operation.cl"},
218 {"elementwise_operation_AND", "common/elementwise_operation.cl"},
219 {"elementwise_operation_OR", "common/elementwise_operation.cl"},
220 {"elementwise_operation_ADD_quantized", "common/elementwise_operation_quantized.cl"},
221 {"elementwise_operation_SUB_quantized", "common/elementwise_operation_quantized.cl"},
222 {"elementwise_operation_MAX_quantized", "common/elementwise_operation_quantized.cl"},
223 {"elementwise_operation_MIN_quantized", "common/elementwise_operation_quantized.cl"},
224 {"elementwise_operation_DIV_quantized", "common/elementwise_operation_quantized.cl"},
225 {"elementwise_operation_SQUARED_DIFF_quantized", "common/elementwise_operation_quantized.cl"},
226 {"elementwise_operation_PRELU_quantized", "common/elementwise_operation_quantized.cl"},
227 {"elementwise_unary", "common/elementwise_unary.cl"},
228 {"elementwise_unary_quantized", "common/elementwise_unary_quantized.cl"},
229 {"fft_digit_reverse_axis_0", "common/fft_digit_reverse.cl"},
230 {"fft_digit_reverse_axis_1", "common/fft_digit_reverse.cl"},
231 {"fft_radix_2_first_stage_axis_0", "common/fft.cl"},
232 {"fft_radix_2_first_stage_axis_1", "common/fft.cl"},
233 {"fft_radix_2_axis_0", "common/fft.cl"},
234 {"fft_radix_2_axis_1", "common/fft.cl"},
235 {"fft_radix_3_first_stage_axis_0", "common/fft.cl"},
236 {"fft_radix_3_first_stage_axis_1", "common/fft.cl"},
237 {"fft_radix_3_axis_0", "common/fft.cl"},
238 {"fft_radix_3_axis_1", "common/fft.cl"},
239 {"fft_radix_4_first_stage_axis_0", "common/fft.cl"},
240 {"fft_radix_4_first_stage_axis_1", "common/fft.cl"},
241 {"fft_radix_4_axis_0", "common/fft.cl"},
242 {"fft_radix_4_axis_1", "common/fft.cl"},
243 {"fft_radix_5_first_stage_axis_0", "common/fft.cl"},
244 {"fft_radix_5_first_stage_axis_1", "common/fft.cl"},
245 {"fft_radix_5_axis_0", "common/fft.cl"},
246 {"fft_radix_5_axis_1", "common/fft.cl"},
247 {"fft_radix_7_first_stage_axis_0", "common/fft.cl"},
248 {"fft_radix_7_first_stage_axis_1", "common/fft.cl"},
249 {"fft_radix_7_axis_0", "common/fft.cl"},
250 {"fft_radix_7_axis_1", "common/fft.cl"},
251 {"fft_radix_8_first_stage_axis_0", "common/fft.cl"},
252 {"fft_radix_8_first_stage_axis_1", "common/fft.cl"},
253 {"fft_radix_8_axis_0", "common/fft.cl"},
254 {"fft_radix_8_axis_1", "common/fft.cl"},
255 {"fft_scale_conj", "common/fft_scale.cl"},
256 {"fill_image_borders_constant", "common/fill_border.cl"},
257 {"fill_image_borders_replicate", "common/fill_border.cl"},
258 {"floor_layer", "common/floor.cl"},
259 {"fuse_batchnormalization_layer", "common/batchnormalization_layer.cl"},
260 {"gather", "common/gather.cl"},
261 {"gemm_ma_f16", "common/gemm.cl"},
262 {"gemm_ma_f32", "common/gemm.cl"},
263 {"gemm_mv", "common/gemv.cl"},
264 {"gemm_mv_quantized", "common/gemv.cl"},
265 {"gemm_mm_native", "common/gemm.cl"},
266 {"gemm_mm_reshaped_only_rhs_nt_mmul", "common/gemm_reshaped_only_rhs_mmul.cl"},
267 {"gemm_mm_reshaped_only_rhs_nt_mmul_texture", "common/gemm_reshaped_only_rhs_mmul.cl"},
268 {"gemm_mm_reshaped_lhs_nt_rhs_t", "common/gemm.cl"},
269 {"gemm_mm_reshaped_lhs_nt_rhs_t_texture", "common/gemm.cl"},
270 {"gemm_mm_reshaped_lhs_t_rhs_nt", "common/gemm.cl"},
271 {"gemm_mm_reshaped_lhs_t_rhs_nt_texture", "common/gemm.cl"},
272 {"gemm_mm_reshaped_only_rhs_nt", "common/gemm.cl"},
273 {"gemm_mm_reshaped_only_rhs_nt_texture", "common/gemm.cl"},
274 {"gemm_mm_reshaped_only_rhs_t", "common/gemm.cl"},
275 {"gemm_mm_reshaped_only_rhs_t_texture", "common/gemm.cl"},
276 {"gemm_lc_vm_f32", "common/gemm.cl"},
277 {"gemm_reshape_lhs_matrix_nt", "common/gemm_utils.cl"},
278 {"gemm_reshape_lhs_matrix_t", "common/gemm_utils.cl"},
279 {"gemm_reshape_rhs_matrix_nt", "common/gemm_utils.cl"},
280 {"gemm_reshape_rhs_matrix_t", "common/gemm_utils.cl"},
281 {"gemmlowp_matrix_a_reduction", "common/gemmlowp.cl"},
282 {"gemmlowp_matrix_a_reduction_dot8", "common/gemmlowp.cl"},
283 {"gemmlowp_matrix_b_reduction", "common/gemmlowp.cl"},
284 {"gemmlowp_mm_native", "common/gemmlowp.cl"},
285 {"gemmlowp_mm_reshaped_lhs_nt_rhs_t", "common/gemmlowp.cl"},
286 {"gemmlowp_mm_reshaped_only_rhs_t", "common/gemmlowp.cl"},
287 {"gemmlowp_mm_reshaped_only_rhs_t_fused_output_stage_fixedpoint", "common/gemmlowp.cl"},
288 {"gemmlowp_mm_reshaped_only_rhs_mmul", "common/gemmlowp_reshaped_only_rhs_mmul.cl"},
289 {"gemmlowp_offset_contribution", "common/gemmlowp.cl"},
290 {"gemmlowp_offset_contribution_quantize_down", "common/gemmlowp.cl"},
291 {"gemmlowp_offset_contribution_quantize_down_fixedpoint", "common/gemmlowp.cl"},
292 {"gemmlowp_output_stage_quantize_down", "common/gemmlowp.cl"},
293 {"gemmlowp_output_stage_quantize_down_fixedpoint", "common/gemmlowp.cl"},
294 {"gemmlowp_output_stage_quantize_down_fixedpoint_qsymm16", "common/gemmlowp.cl"},
295 {"gemmlowp_output_stage_quantize_down_float", "common/gemmlowp.cl"},
296 {"generate_proposals_compute_all_anchors", "common/generate_proposals.cl"},
297 {"generate_proposals_compute_all_anchors_quantized", "common/generate_proposals_quantized.cl"},
298 {"instance_normalization", "common/instance_normalization.cl"},
299 {"compute_mean_var", "common/instance_normalization.cl"},
300 {"l2_normalize_x", "common/l2_normalize.cl"},
301 {"l2_normalize_y", "common/l2_normalize.cl"},
302 {"l2_normalize_z", "common/l2_normalize.cl"},
303 {"mat_mul_native_mmul_nt_nt", "common/mat_mul_mmul.cl"},
304 {"mat_mul_native_mmul_t_nt", "common/mat_mul_mmul.cl"},
305 {"mat_mul_native_mmul_nt_t", "common/mat_mul_mmul.cl"},
306 {"mat_mul_native_mmul_t_t", "common/mat_mul_mmul.cl"},
307 {"mat_mul_native_nt_nt", "common/mat_mul.cl"},
308 {"mat_mul_native_nt_t", "common/mat_mul.cl"},
309 {"mat_mul_native_t_nt", "common/mat_mul.cl"},
310 {"mat_mul_native_t_t", "common/mat_mul.cl"},
311 {"mat_mul_native_quantized_nt_nt", "common/mat_mul_quantized.cl"},
312 {"mat_mul_native_quantized_nt_t", "common/mat_mul_quantized.cl"},
313 {"mat_mul_native_quantized_t_nt", "common/mat_mul_quantized.cl"},
314 {"mat_mul_native_quantized_t_t", "common/mat_mul_quantized.cl"},
315 {"mat_mul_native_quantized_mmul_nt_nt", "common/mat_mul_quantized_mmul.cl"},
316 {"mat_mul_native_quantized_mmul_nt_t", "common/mat_mul_quantized_mmul.cl"},
317 {"mat_mul_native_quantized_mmul_t_nt", "common/mat_mul_quantized_mmul.cl"},
318 {"mat_mul_native_quantized_mmul_t_t", "common/mat_mul_quantized_mmul.cl"},
319 {"max_unpooling_layer_2", "common/unpooling_layer.cl"},
320 {"mean_stddev_normalization", "common/mean_stddev_normalization.cl"},
321 {"memset", "common/memset.cl"},
322 {"minmax_layer", "common/minmax_layer.cl"},
323 {"non_max_suppression", "common/nonmax.cl"},
324 {"pad_layer_constant", "common/pad_layer.cl"},
325 {"pad_layer_symmetric_reflect", "common/pad_layer.cl"},
326 {"permute", "common/permute.cl"},
327 {"pixelwise_mul_complex", "common/pixelwise_mul_float.cl"},
328 {"pixelwise_mul_float", "common/pixelwise_mul_float.cl"},
329 {"pixelwise_mul_int", "common/pixelwise_mul_int.cl"},
330 {"pixelwise_mul_quantized", "common/pixelwise_mul_int.cl"},
331 {"qlstm_layer_normalization", "common/qlstm_layer_normalization.cl"},
332 {"quantization_layer", "common/quantization_layer.cl"},
333 {"range", "common/range.cl"},
334 {"range_quantized", "common/range.cl"},
335 {"reduction_operation_x", "common/reduction_operation.cl"},
336 {"reduction_operation_non_parallel_x", "common/reduction_operation.cl"},
337 {"reduction_operation_y", "common/reduction_operation.cl"},
338 {"reduction_operation_z", "common/reduction_operation.cl"},
339 {"reduction_operation_w", "common/reduction_operation.cl"},
340 {"reshape_layer", "common/reshape_layer.cl"},
341 {"reshape_to_columns", "common/convolution_layer.cl"},
342 {"reverse", "common/reverse.cl"},
343 {"roi_align_layer", "common/roi_align_layer.cl"},
344 {"roi_align_layer_quantized", "common/roi_align_layer_quantized.cl"},
345 {"roi_pooling_layer", "common/roi_pooling_layer.cl"},
346 {"select_same_rank", "common/select.cl"},
347 {"select_different_rank_2", "common/select.cl"},
348 {"select_different_rank_n", "common/select.cl"},
349 {"softmax_layer_norm", "common/softmax_layer.cl"},
350 {"softmax_layer_norm_quantized", "common/softmax_layer_quantized.cl"},
351 {"softmax_layer_max_shift_exp_sum_quantized_serial", "common/softmax_layer_quantized.cl"},
352 {"softmax_layer_max_shift_exp_sum_quantized_parallel", "common/softmax_layer_quantized.cl"},
353 {"softmax_layer_max_shift_exp_sum_serial", "common/softmax_layer.cl"},
354 {"softmax_layer_max_shift_exp_sum_parallel", "common/softmax_layer.cl"},
355 {"stack_layer", "common/stack_layer.cl"},
356 {"strided_slice", "common/slice_ops.cl"},
357 {"tile", "common/tile.cl"},
358 {"transpose", "common/transpose.cl"},
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100359#ifdef ENABLE_NCHW_KERNELS
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100360 {"batch_to_space_nchw", "nchw/batch_to_space.cl"},
361 {"batch_to_space_static_nchw", "nchw/batch_to_space.cl"},
362 {"batchnormalization_layer_nchw", "nchw/batchnormalization_layer.cl"},
363 {"channel_shuffle_nchw", "nchw/channel_shuffle.cl"},
364 {"depth_to_space_nchw", "nchw/depth_to_space.cl"},
365 {"dequantization_layer_per_channel_nchw", "nchw/dequantization_layer.cl"},
366 {"direct_convolution1x1", "nchw/direct_convolution1x1.cl"},
367 {"direct_convolution_nchw", "nchw/direct_convolution.cl"},
Adnan AlSinan30124352021-12-02 19:12:20 +0000368
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100369 {"im2col1x1_stridex1_nchw", "nchw/im2col.cl"},
370 {"im2col3x3_nchw", "nchw/im2col.cl"},
371 {"im2col5x5_nchw", "nchw/im2col.cl"},
372 {"im2col11x11_padx0_pady0_nchw", "nchw/im2col.cl"},
373 {"im2col_generic_nchw", "nchw/im2col.cl"},
374 {"im2col_generic_padx0_pady0_nchw", "nchw/im2col.cl"},
375 {"normalization_layer_cross_map_nchw", "nchw/normalization_layer.cl"},
376 {"normalization_layer_in_map_nchw", "nchw/normalization_layer.cl"},
377 {"normalize_planar_yuv_layer_nchw", "nchw/normalize_planar_yuv_layer.cl"},
378 {"normalize_planar_yuv_layer_q8_nchw", "nchw/normalize_planar_yuv_layer_quantized.cl"},
379 {"pooling_layer_MxN_nchw", "nchw/pooling_layer.cl"},
380 {"pooling_layer_2_nchw_indices", "nchw/pooling_layer.cl"},
381 {"prior_box_layer_nchw", "nchw/prior_box_layer.cl"},
382 {"reorg_layer_nchw", "nchw/reorg_layer.cl"},
383 {"scale_nearest_neighbour_nchw", "nchw/scale.cl"},
384 {"scale_bilinear_nchw", "nchw/scale.cl"},
385 {"space_to_batch_nchw", "nchw/space_to_batch.cl"},
386 {"space_to_batch_static_nchw", "nchw/space_to_batch.cl"},
387 {"space_to_depth_nchw", "nchw/space_to_depth.cl"},
388 {"upsample_layer_nchw", "nchw/upsample_layer.cl"},
389 {"winograd_filter_transform_2x2_3x3_nchw", "nchw/winograd_filter_transform.cl"},
390 {"winograd_filter_transform_2x1_3x1_nchw", "nchw/winograd_filter_transform.cl"},
391 {"winograd_filter_transform_1x2_1x3_nchw", "nchw/winograd_filter_transform.cl"},
392 {"winograd_filter_transform_4x4_3x3_nchw", "nchw/winograd_filter_transform.cl"},
393 {"winograd_filter_transform_4x1_3x1_nchw", "nchw/winograd_filter_transform.cl"},
394 {"winograd_filter_transform_1x4_1x3_nchw", "nchw/winograd_filter_transform.cl"},
395 {"winograd_filter_transform_4x4_5x5_nchw", "nchw/winograd_filter_transform.cl"},
396 {"winograd_filter_transform_4x1_5x1_nchw", "nchw/winograd_filter_transform.cl"},
397 {"winograd_filter_transform_1x4_1x5_nchw", "nchw/winograd_filter_transform.cl"},
398 {"winograd_input_transform_2x2_3x3_stepz1_nchw", "nchw/winograd_input_transform.cl"},
399 {"winograd_input_transform_2x2_3x3_stepz2_nchw", "nchw/winograd_input_transform.cl"},
400 {"winograd_input_transform_2x1_3x1_stepz1_nchw", "nchw/winograd_input_transform.cl"},
401 {"winograd_input_transform_2x1_3x1_stepz2_nchw", "nchw/winograd_input_transform.cl"},
402 {"winograd_input_transform_1x2_1x3_stepz1_nchw", "nchw/winograd_input_transform.cl"},
403 {"winograd_input_transform_1x2_1x3_stepz2_nchw", "nchw/winograd_input_transform.cl"},
404 {"winograd_input_transform_4x4_3x3_stepz1_nchw", "nchw/winograd_input_transform.cl"},
405 {"winograd_input_transform_4x1_3x1_stepz1_nchw", "nchw/winograd_input_transform.cl"},
406 {"winograd_input_transform_1x4_1x3_stepz1_nchw", "nchw/winograd_input_transform.cl"},
407 {"winograd_input_transform_4x4_5x5_stepz1_nchw", "nchw/winograd_input_transform.cl"},
408 {"winograd_input_transform_4x1_5x1_stepz1_nchw", "nchw/winograd_input_transform.cl"},
409 {"winograd_input_transform_1x4_1x5_stepz1_nchw", "nchw/winograd_input_transform.cl"},
410 {"winograd_output_transform_2x2_3x3_nchw", "nchw/winograd_output_transform.cl"},
411 {"winograd_output_transform_2x1_3x1_nchw", "nchw/winograd_output_transform.cl"},
412 {"winograd_output_transform_1x2_1x3_nchw", "nchw/winograd_output_transform.cl"},
413 {"winograd_output_transform_4x4_3x3_nchw", "nchw/winograd_output_transform.cl"},
414 {"winograd_output_transform_4x1_3x1_nchw", "nchw/winograd_output_transform.cl"},
415 {"winograd_output_transform_1x4_1x3_nchw", "nchw/winograd_output_transform.cl"},
416 {"winograd_output_transform_4x4_5x5_nchw", "nchw/winograd_output_transform.cl"},
417 {"winograd_output_transform_4x1_5x1_nchw", "nchw/winograd_output_transform.cl"},
418 {"winograd_output_transform_1x4_1x5_nchw", "nchw/winograd_output_transform.cl"},
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100419#endif /* ENABLE_NCHW_KERNELS */
420#ifdef ENABLE_NHWC_KERNELS
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100421 {"batch_to_space_nhwc", "nhwc/batch_to_space.cl"},
422 {"batch_to_space_static_nhwc", "nhwc/batch_to_space.cl"},
423 {"batchnormalization_layer_nhwc", "nhwc/batchnormalization_layer.cl"},
424 {"channel_shuffle_nhwc", "nhwc/channel_shuffle.cl"},
425 {"depth_to_space_nhwc", "nhwc/depth_to_space.cl"},
426 {"dequantization_layer_per_channel_nhwc", "nhwc/dequantization_layer.cl"},
427 {"dwc_native_fp_nhwc", "nhwc/dwc_native_fp_nhwc.cl"},
428 {"dwc_native_quantized_nhwc", "nhwc/dwc_native_quantized_nhwc.cl"},
429 {"direct_convolution_nhwc", "nhwc/direct_convolution.cl"},
430 {"direct_convolution3d_ndhwc", "nhwc/direct_convolution3d.cl"},
431 {"im2col3x3_nhwc", "nhwc/im2col.cl"},
432 {"im2col9x9_nhwc", "nhwc/im2col.cl"},
433 {"im2col_generic_nhwc", "nhwc/im2col.cl"},
434 {"indirect_convolution_nhwc", "nhwc/indirect_convolution.cl"},
435 {"indirect_convolution_address_precalculation", "nhwc/indirect_convolution.cl"},
436 {"normalization_layer_cross_map_nhwc", "nhwc/normalization_layer.cl"},
437 {"normalization_layer_in_map_nhwc", "nhwc/normalization_layer.cl"},
438 {"normalize_planar_yuv_layer_nhwc", "nhwc/normalize_planar_yuv_layer.cl"},
439 {"normalize_planar_yuv_layer_q8_nhwc", "nhwc/normalize_planar_yuv_layer_quantized.cl"},
440 {"pooling_layer_MxN_nhwc", "nhwc/pooling_layer.cl"},
441 {"pooling_layer_2x2_nhwc", "nhwc/pooling_layer.cl"},
442 {"pooling_layer_MxN_quantized_nhwc", "nhwc/pooling_layer_quantized.cl"},
443 {"pooling_3d_layer_MxN_ndhwc", "nhwc/pooling_3d_layer.cl"},
444 {"pooling_3d_layer_MxN_ndhwc_quantized", "nhwc/pooling_3d_layer_quantized.cl"},
445 {"reorg_layer_nhwc", "nhwc/reorg_layer.cl"},
446 {"scale_nearest_neighbour_nhwc", "nhwc/scale.cl"},
447 {"scale_bilinear_nhwc", "nhwc/scale.cl"},
448 {"space_to_batch_nhwc", "nhwc/space_to_batch.cl"},
449 {"space_to_batch_static_nhwc", "nhwc/space_to_batch.cl"},
450 {"space_to_depth_nhwc", "nhwc/space_to_depth.cl"},
451 {"transposed_convolution_nhwc", "nhwc/transposed_convolution.cl"},
452 {"upsample_layer_nhwc", "nhwc/upsample_layer.cl"},
453 {"winograd_filter_transform_4x1_3x1_nhwc", "nhwc/winograd_filter_transform.cl"},
454 {"winograd_filter_transform_1x4_1x3_nhwc", "nhwc/winograd_filter_transform.cl"},
455 {"winograd_filter_transform_4x4_3x3_nhwc", "nhwc/winograd_filter_transform.cl"},
456 {"winograd_filter_transform_4x4_5x5_nhwc", "nhwc/winograd_filter_transform.cl"},
457 {"winograd_filter_transform_4x1_5x1_nhwc", "nhwc/winograd_filter_transform.cl"},
458 {"winograd_filter_transform_1x4_1x5_nhwc", "nhwc/winograd_filter_transform.cl"},
459 {"winograd_filter_transform_2x2_7x7_nhwc", "nhwc/winograd_filter_transform.cl"},
460 {"winograd_filter_transform_2x1_7x1_nhwc", "nhwc/winograd_filter_transform.cl"},
461 {"winograd_filter_transform_1x2_1x7_nhwc", "nhwc/winograd_filter_transform.cl"},
462 {"winograd_input_transform_4x1_3x1_stepz1_nhwc", "nhwc/winograd_input_transform.cl"},
463 {"winograd_input_transform_1x4_1x3_stepz1_nhwc", "nhwc/winograd_input_transform.cl"},
464 {"winograd_input_transform_4x4_3x3_stepz1_nhwc", "nhwc/winograd_input_transform.cl"},
465 {"winograd_input_transform_4x4_5x5_stepz1_nhwc", "nhwc/winograd_input_transform.cl"},
466 {"winograd_input_transform_4x1_5x1_stepz1_nhwc", "nhwc/winograd_input_transform.cl"},
467 {"winograd_input_transform_1x4_1x5_stepz1_nhwc", "nhwc/winograd_input_transform.cl"},
468 {"winograd_input_transform_2x2_7x7_stepz1_nhwc", "nhwc/winograd_input_transform.cl"},
469 {"winograd_input_transform_2x1_7x1_stepz1_nhwc", "nhwc/winograd_input_transform.cl"},
470 {"winograd_input_transform_1x2_1x7_stepz1_nhwc", "nhwc/winograd_input_transform.cl"},
471 {"winograd_output_transform_4x1_3x1_nhwc", "nhwc/winograd_output_transform.cl"},
472 {"winograd_output_transform_1x4_1x3_nhwc", "nhwc/winograd_output_transform.cl"},
473 {"winograd_output_transform_4x4_3x3_nhwc", "nhwc/winograd_output_transform.cl"},
474 {"winograd_output_transform_4x4_5x5_nhwc", "nhwc/winograd_output_transform.cl"},
475 {"winograd_output_transform_4x1_5x1_nhwc", "nhwc/winograd_output_transform.cl"},
476 {"winograd_output_transform_1x4_1x5_nhwc", "nhwc/winograd_output_transform.cl"},
477 {"winograd_output_transform_2x2_7x7_nhwc", "nhwc/winograd_output_transform.cl"},
478 {"winograd_output_transform_2x1_7x1_nhwc", "nhwc/winograd_output_transform.cl"},
479 {"winograd_output_transform_1x2_1x7_nhwc", "nhwc/winograd_output_transform.cl"},
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100480#endif /* ENABLE_NHWC_KERNELS */
Georgios Pinitas908f6162021-05-04 10:11:09 +0100481};
482
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100483const std::map<std::string, std::string> ClKernelLibrary::_program_source_map = {
Georgios Pinitas908f6162021-05-04 10:11:09 +0100484#ifdef EMBEDDED_KERNELS
485 {
Jakub Sujak32741722022-11-25 16:43:18 +0000486 "activation_float_helpers.h",
487#include "./cl_kernels/activation_float_helpers.hembed"
488 },
489 {
490 "activation_quant_helpers.h",
491#include "./cl_kernels/activation_quant_helpers.hembed"
492 },
493 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100494 "common/activation_layer.cl",
495#include "./cl_kernels/common/activation_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100496 },
497 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100498 "common/activation_layer_quant.cl",
499#include "./cl_kernels/common/activation_layer_quant.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100500 },
501 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100502 "common/arg_min_max.cl",
503#include "./cl_kernels/common/arg_min_max.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100504 },
505 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100506 "common/bitwise_op.cl",
507#include "./cl_kernels/common/bitwise_op.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100508 },
509 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100510 "common/bounding_box_transform.cl",
511#include "./cl_kernels/common/bounding_box_transform.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100512 },
513 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100514 "common/bounding_box_transform_quantized.cl",
515#include "./cl_kernels/common/bounding_box_transform_quantized.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100516 },
517 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100518 "common/col2im.cl",
519#include "./cl_kernels/common/col2im.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100520 },
521 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100522 "common/comparisons.cl",
523#include "./cl_kernels/common/comparisons.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100524 },
525 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100526 "common/concatenate.cl",
527#include "./cl_kernels/common/concatenate.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100528 },
529 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100530 "common/convert_fc_weights.cl",
531#include "./cl_kernels/common/convert_fc_weights.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100532 },
533 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100534 "common/convolution_layer.cl",
535#include "./cl_kernels/common/convolution_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100536 },
537 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100538 "common/copy_tensor.cl",
539#include "./cl_kernels/common/copy_tensor.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100540 },
541 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100542 "common/crop_tensor.cl",
543#include "./cl_kernels/common/crop_tensor.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100544 },
545 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100546 "common/deconvolution_layer.cl",
547#include "./cl_kernels/common/deconvolution_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100548 },
549 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100550 "common/cast.cl",
551#include "./cl_kernels/common/cast.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100552 },
553 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100554 "common/dequantization_layer.cl",
555#include "./cl_kernels/common/dequantization_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100556 },
557 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100558 "common/elementwise_operation.cl",
559#include "./cl_kernels/common/elementwise_operation.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100560 },
561 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100562 "common/elementwise_operation_quantized.cl",
563#include "./cl_kernels/common/elementwise_operation_quantized.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100564 },
565 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100566 "common/elementwise_unary.cl",
567#include "./cl_kernels/common/elementwise_unary.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100568 },
569 {
Ramy Elgammal14d7b532023-01-30 04:56:47 +0000570 "common/elementwise_unary_quantized.cl",
571#include "./cl_kernels/common/elementwise_unary_quantized.clembed"
572 },
573 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100574 "common/fft.cl",
575#include "./cl_kernels/common/fft.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100576 },
577 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100578 "common/fft_digit_reverse.cl",
579#include "./cl_kernels/common/fft_digit_reverse.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100580 },
581 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100582 "common/fft_scale.cl",
583#include "./cl_kernels/common/fft_scale.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100584 },
585 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100586 "common/fill_border.cl",
587#include "./cl_kernels/common/fill_border.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100588 },
589 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100590 "common/floor.cl",
591#include "./cl_kernels/common/floor.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100592 },
593 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100594 "common/gather.cl",
595#include "./cl_kernels/common/gather.clembed"
596 },
597 {
598 "common/gemm.cl",
599#include "./cl_kernels/common/gemm.clembed"
600 },
601 {
Gunes Bayir4bfc70e2021-12-10 16:17:56 +0000602 "common/gemm_reshaped_only_rhs_mmul.cl",
603#include "./cl_kernels/common/gemm_reshaped_only_rhs_mmul.clembed"
604 },
605 {
ramelg019cca5922021-11-11 10:05:00 +0000606 "common/gemm_utils.cl",
607#include "./cl_kernels/common/gemm_utils.clembed"
608 },
609 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100610 "common/gemmlowp.cl",
611#include "./cl_kernels/common/gemmlowp.clembed"
612 },
613 {
Freddie Liardete572dff2022-05-16 14:09:10 +0100614 "common/gemmlowp_reshaped_only_rhs_mmul.cl",
615#include "./cl_kernels/common/gemmlowp_reshaped_only_rhs_mmul.clembed"
616 },
617 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100618 "common/gemv.cl",
619#include "./cl_kernels/common/gemv.clembed"
620 },
621 {
622 "common/generate_proposals.cl",
623#include "./cl_kernels/common/generate_proposals.clembed"
624 },
625 {
626 "common/generate_proposals_quantized.cl",
627#include "./cl_kernels/common/generate_proposals_quantized.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100628 },
629 {
Giorgio Arena892b70a2022-03-30 12:23:10 +0100630 "gemm_helpers.h",
631#include "./cl_kernels/gemm_helpers.hembed"
632 },
633 {
Georgios Pinitas908f6162021-05-04 10:11:09 +0100634 "helpers.h",
635#include "./cl_kernels/helpers.hembed"
636 },
637 {
638 "helpers_asymm.h",
639#include "./cl_kernels/helpers_asymm.hembed"
640 },
641 {
Giorgio Arena892b70a2022-03-30 12:23:10 +0100642 "repeat.h",
643#include "./cl_kernels/repeat.hembed"
644 },
645 {
SiCong Lica364df2022-04-13 15:48:19 +0100646 "tile_helpers.h",
647#include "./cl_kernels/tile_helpers.hembed"
648 },
649 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100650 "common/instance_normalization.cl",
651#include "./cl_kernels/common/instance_normalization.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100652 },
653 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100654 "common/l2_normalize.cl",
655#include "./cl_kernels/common/l2_normalize.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100656 },
657 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100658 "common/mean_stddev_normalization.cl",
659#include "./cl_kernels/common/mean_stddev_normalization.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100660 },
661 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100662 "common/memset.cl",
663#include "./cl_kernels/common/memset.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100664 },
665 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100666 "common/minmax_layer.cl",
667#include "./cl_kernels/common/minmax_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100668 },
669 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100670 "common/nonmax.cl",
671#include "./cl_kernels/common/nonmax.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100672 },
673 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100674 "common/batchnormalization_layer.cl",
675#include "./cl_kernels/common/batchnormalization_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100676 },
677 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100678 "common/pad_layer.cl",
679#include "./cl_kernels/common/pad_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100680 },
681 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100682 "common/permute.cl",
683#include "./cl_kernels/common/permute.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100684 },
685 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100686 "common/pixelwise_mul_float.cl",
687#include "./cl_kernels/common/pixelwise_mul_float.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100688 },
689 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100690 "common/pixelwise_mul_int.cl",
691#include "./cl_kernels/common/pixelwise_mul_int.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100692 },
693 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100694 "common/qlstm_layer_normalization.cl",
695#include "./cl_kernels/common/qlstm_layer_normalization.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100696 },
697 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100698 "common/quantization_layer.cl",
699#include "./cl_kernels/common/quantization_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100700 },
701 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100702 "common/range.cl",
703#include "./cl_kernels/common/range.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100704 },
705 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100706 "common/reduction_operation.cl",
707#include "./cl_kernels/common/reduction_operation.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100708 },
709 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100710 "common/reshape_layer.cl",
711#include "./cl_kernels/common/reshape_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100712 },
713 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100714 "common/reverse.cl",
715#include "./cl_kernels/common/reverse.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100716 },
717 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100718 "common/roi_align_layer.cl",
719#include "./cl_kernels/common/roi_align_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100720 },
721 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100722 "common/roi_align_layer_quantized.cl",
723#include "./cl_kernels/common/roi_align_layer_quantized.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100724 },
725 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100726 "common/roi_pooling_layer.cl",
727#include "./cl_kernels/common/roi_pooling_layer.clembed"
728 },
729 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100730 "common/select.cl",
731#include "./cl_kernels/common/select.clembed"
732 },
733 {
734 "common/softmax_layer.cl",
735#include "./cl_kernels/common/softmax_layer.clembed"
736 },
737 {
738 "common/softmax_layer_quantized.cl",
739#include "./cl_kernels/common/softmax_layer_quantized.clembed"
740 },
741 {
742 "common/slice_ops.cl",
743#include "./cl_kernels/common/slice_ops.clembed"
744 },
745 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100746 "common/stack_layer.cl",
747#include "./cl_kernels/common/stack_layer.clembed"
748 },
749 {
750 "common/tile.cl",
751#include "./cl_kernels/common/tile.clembed"
752 },
753 {
754 "common/transpose.cl",
755#include "./cl_kernels/common/transpose.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100756 },
757 {
758 "types.h",
759#include "./cl_kernels/types.hembed"
760 },
761 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100762 "common/unpooling_layer.cl",
763#include "./cl_kernels/common/unpooling_layer.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100764 },
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000765 {
766 "common/mat_mul.cl",
767#include "./cl_kernels/common/mat_mul.clembed"
768 },
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100769 {
SiCong Lia8d80582023-05-19 14:23:37 +0100770 "common/mat_mul_mmul.cl",
771#include "./cl_kernels/common/mat_mul_mmul.clembed"
772 },
773 {
Gunes Bayir9d0c4de2023-04-13 18:22:58 +0100774 "common/mat_mul_quantized.cl",
775#include "./cl_kernels/common/mat_mul_quantized.clembed"
776 },
Gunes Bayire87fa662023-09-07 12:20:33 +0100777 {
778 "common/mat_mul_quantized_mmul.cl",
779#include "./cl_kernels/common/mat_mul_quantized_mmul.clembed"
780 },
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100781#ifdef ENABLE_NCHW_KERNELS
782 {
783 "nchw/batch_to_space.cl",
784#include "./cl_kernels/nchw/batch_to_space.clembed"
785 },
786 {
787 "nchw/channel_shuffle.cl",
788#include "./cl_kernels/nchw/channel_shuffle.clembed"
789 },
790 {
791 "nchw/upsample_layer.cl",
792#include "./cl_kernels/nchw/upsample_layer.clembed"
793 },
794 {
795 "nchw/depth_to_space.cl",
796#include "./cl_kernels/nchw/depth_to_space.clembed"
797 },
798 {
799 "nchw/dequantization_layer.cl",
800#include "./cl_kernels/nchw/dequantization_layer.clembed"
801 },
802 {
Adnan AlSinan30124352021-12-02 19:12:20 +0000803 "nchw/direct_convolution.cl",
804#include "./cl_kernels/nchw/direct_convolution.clembed"
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100805 },
806 {
807 "nchw/im2col.cl",
808#include "./cl_kernels/nchw/im2col.clembed"
809 },
810 {
811 "nchw/normalization_layer.cl",
812#include "./cl_kernels/nchw/normalization_layer.clembed"
813 },
814 {
815 "nchw/normalize_planar_yuv_layer.cl",
816#include "./cl_kernels/nchw/normalize_planar_yuv_layer.clembed"
817 },
818 {
819 "nchw/normalize_planar_yuv_layer_quantized.cl",
820#include "./cl_kernels/nchw/normalize_planar_yuv_layer_quantized.clembed"
821 },
822 {
823 "nchw/batchnormalization_layer.cl",
824#include "./cl_kernels/nchw/batchnormalization_layer.clembed"
825 },
826 {
827 "nchw/pooling_layer.cl",
828#include "./cl_kernels/nchw/pooling_layer.clembed"
829 },
830 {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100831 "nchw/prior_box_layer.cl",
832#include "./cl_kernels/nchw/prior_box_layer.clembed"
833 },
834 {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100835 "nchw/reorg_layer.cl",
836#include "./cl_kernels/nchw/reorg_layer.clembed"
837 },
838 {
839 "nchw/scale.cl",
840#include "./cl_kernels/nchw/scale.clembed"
841 },
842 {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100843 "nchw/space_to_batch.cl",
844#include "./cl_kernels/nchw/space_to_batch.clembed"
845 },
846 {
847 "nchw/space_to_depth.cl",
848#include "./cl_kernels/nchw/space_to_depth.clembed"
849 },
Georgios Pinitas908f6162021-05-04 10:11:09 +0100850 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100851 "nchw/winograd_filter_transform.cl",
852#include "./cl_kernels/nchw/winograd_filter_transform.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100853 },
854 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100855 "nchw/winograd_input_transform.cl",
856#include "./cl_kernels/nchw/winograd_input_transform.clembed"
857 },
858 {
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100859 "nchw/winograd_output_transform.cl",
860#include "./cl_kernels/nchw/winograd_output_transform.clembed"
861 },
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100862#endif /* ENABLE_NCHW_KERNELS */
863
864#ifdef ENABLE_NHWC_KERNELS
865 {
866 "nhwc/batch_to_space.cl",
867#include "./cl_kernels/nhwc/batch_to_space.clembed"
868 },
869 {
870 "nhwc/channel_shuffle.cl",
871#include "./cl_kernels/nhwc/channel_shuffle.clembed"
872 },
873 {
874 "nhwc/upsample_layer.cl",
875#include "./cl_kernels/nhwc/upsample_layer.clembed"
876 },
877 {
878 "nhwc/depth_to_space.cl",
879#include "./cl_kernels/nhwc/depth_to_space.clembed"
880 },
881 {
882 "nhwc/dequantization_layer.cl",
883#include "./cl_kernels/nhwc/dequantization_layer.clembed"
884 },
885 {
886 "nhwc/direct_convolution.cl",
887#include "./cl_kernels/nhwc/direct_convolution.clembed"
888 },
889 {
Giorgio Arena945ae9e2021-10-13 11:13:04 +0100890 "nhwc/direct_convolution3d.cl",
891#include "./cl_kernels/nhwc/direct_convolution3d.clembed"
892 },
893 {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100894 "nhwc/dwc_native_fp_nhwc.cl",
895#include "./cl_kernels/nhwc/dwc_native_fp_nhwc.clembed"
896 },
897 {
898 "nhwc/dwc_native_quantized_nhwc.cl",
899#include "./cl_kernels/nhwc/dwc_native_quantized_nhwc.clembed"
900 },
901 {
902 "nhwc/normalization_layer.cl",
903#include "./cl_kernels/nhwc/normalization_layer.clembed"
904 },
905 {
906 "nhwc/normalize_planar_yuv_layer.cl",
907#include "./cl_kernels/nhwc/normalize_planar_yuv_layer.clembed"
908 },
909 {
910 "nhwc/normalize_planar_yuv_layer_quantized.cl",
911#include "./cl_kernels/nhwc/normalize_planar_yuv_layer_quantized.clembed"
912 },
913 {
914 "nhwc/im2col.cl",
915#include "./cl_kernels/nhwc/im2col.clembed"
916 },
917 {
Gian Marco Iodice5d016812022-11-17 11:03:39 +0000918 "nhwc/indirect_convolution.cl",
919#include "./cl_kernels/nhwc/indirect_convolution.clembed"
920 },
921 {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100922 "nhwc/batchnormalization_layer.cl",
923#include "./cl_kernels/nhwc/batchnormalization_layer.clembed"
924 },
925 {
926 "nhwc/pooling_layer.cl",
927#include "./cl_kernels/nhwc/pooling_layer.clembed"
928 },
929 {
ramelg0137515692022-02-26 22:06:20 +0000930 "nhwc/pooling_3d_layer.cl",
931#include "./cl_kernels/nhwc/pooling_3d_layer.clembed"
932 },
933 {
Mohammed Suhail Munshi5e549fa2022-03-16 11:14:06 +0000934 "nhwc/pooling_3d_layer_quantized.cl",
935#include "./cl_kernels/nhwc/pooling_3d_layer_quantized.clembed"
936 },
937 {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100938 "nhwc/pooling_layer_quantized.cl",
939#include "./cl_kernels/nhwc/pooling_layer_quantized.clembed"
940 },
941 {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100942 "nhwc/reorg_layer.cl",
943#include "./cl_kernels/nhwc/reorg_layer.clembed"
944 },
945 {
946 "nhwc/scale.cl",
947#include "./cl_kernels/nhwc/scale.clembed"
948 },
949 {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100950 "nhwc/space_to_batch.cl",
951#include "./cl_kernels/nhwc/space_to_batch.clembed"
952 },
953 {
954 "nhwc/space_to_depth.cl",
955#include "./cl_kernels/nhwc/space_to_depth.clembed"
956 },
957 {
Gunes Bayirec0113d2022-11-09 09:26:27 +0000958 "nhwc/transposed_convolution.cl",
959#include "./cl_kernels/nhwc/transposed_convolution.clembed"
960 },
961 {
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100962 "nhwc/winograd_filter_transform.cl",
963#include "./cl_kernels/nhwc/winograd_filter_transform.clembed"
964 },
965 {
966 "nhwc/winograd_input_transform.cl",
967#include "./cl_kernels/nhwc/winograd_input_transform.clembed"
968 },
Adnan AlSinan7075fe22021-07-05 13:12:52 +0100969 {
970 "nhwc/winograd_output_transform.cl",
971#include "./cl_kernels/nhwc/winograd_output_transform.clembed"
Georgios Pinitas908f6162021-05-04 10:11:09 +0100972 },
Adnan AlSinanf81f51c2021-07-26 18:18:37 +0100973#endif /* ENABLE_NHWC_KERNELS */
Georgios Pinitas908f6162021-05-04 10:11:09 +0100974#endif /* EMBEDDED_KERNELS */
975};
976
977ClKernelLibrary &ClKernelLibrary::get()
978{
979 static ClKernelLibrary _kernel_library;
980 return _kernel_library;
981}
982
983std::string ClKernelLibrary::program_name(const std::string &kernel_name) const
984{
985 // Find which program contains the kernel
986 auto kernel_program_it = _kernel_program_map.find(kernel_name);
987
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100988 if (_kernel_program_map.end() == kernel_program_it)
Georgios Pinitas908f6162021-05-04 10:11:09 +0100989 {
990 ARM_COMPUTE_ERROR_VAR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
991 }
992
993 const std::string program_name = kernel_program_it->second;
994
995 return program_name;
996}
997
998void ClKernelLibrary::set_kernel_path(std::string kernel_path)
999{
1000 _kernel_path = std::move(kernel_path);
1001 _kernel_path += "/";
1002}
1003
1004const std::string &ClKernelLibrary::kernel_path() const
1005{
1006 return _kernel_path;
1007}
1008
1009ClKernelLibrary::ClProgramInfo ClKernelLibrary::program(const std::string &program_name) const
1010{
1011#ifdef EMBEDDED_KERNELS
1012#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
1013 const auto inflatted_program_source_it = _decompressed_source_map.find(program_name);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001014 if (inflatted_program_source_it != _decompressed_source_map.end())
Georgios Pinitas908f6162021-05-04 10:11:09 +01001015 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001016 return ClProgramInfo{inflatted_program_source_it->second, false};
Georgios Pinitas908f6162021-05-04 10:11:09 +01001017 }
1018#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
1019
1020 const auto program_source_it = _program_source_map.find(program_name);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001021 if (program_source_it == _program_source_map.end())
Georgios Pinitas908f6162021-05-04 10:11:09 +01001022 {
1023 ARM_COMPUTE_ERROR_VAR("Embedded program for %s does not exist.", program_name.c_str());
1024 }
1025 std::string program_source = program_source_it->second;
1026
1027#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
1028 std::string decompressed_program_source = decompress_zlib(decode_base64(program_source_it->second));
1029 ARM_COMPUTE_ERROR_ON_MSG(decompressed_program_source.empty(), "Cannot de-compress requested program");
1030 _decompressed_source_map.insert(std::make_pair(program_name, decompressed_program_source));
1031 program_source = std::move(decompressed_program_source);
1032#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
1033
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001034 return ClProgramInfo{program_source, false};
Georgios Pinitas908f6162021-05-04 10:11:09 +01001035#else /* EMBEDDED_KERNELS */
1036 // Check for binary
1037 std::string source_name = _kernel_path + program_name;
1038 std::string binary_name = source_name + "bin";
1039 std::string program_source{};
1040 bool is_binary = false;
1041
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001042 if (std::ifstream(binary_name).is_open())
Georgios Pinitas908f6162021-05-04 10:11:09 +01001043 {
1044 program_source = read_file(binary_name, true);
1045 is_binary = true;
1046 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001047 else if (std::ifstream(source_name).is_open())
Georgios Pinitas908f6162021-05-04 10:11:09 +01001048 {
1049 program_source = read_file(source_name, false);
1050 }
1051 else
1052 {
1053 ARM_COMPUTE_ERROR_VAR("Kernel file %s does not exist.", source_name.c_str());
1054 }
1055
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +01001056 return ClProgramInfo{program_source, is_binary};
Georgios Pinitas908f6162021-05-04 10:11:09 +01001057#endif /* EMBEDDED_KERNELS */
1058}
1059} // namespace opencl
1060} // namespace arm_compute