blob: 14d3a2cad5b28a87537db03fc85a5134ff0db4f1 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +00002 * Copyright (c) 2016-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 */
24#include "arm_compute/core/CL/CLKernelLibrary.h"
25
steniu0134702472017-07-11 09:22:58 +010026#include "arm_compute/core/CL/CLHelpers.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Error.h"
28#include "arm_compute/core/Utils.h"
Matthew Bentham758b5ba2020-03-05 23:37:48 +000029#include "support/StringSupport.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
steniu015f910722017-08-23 10:15:22 +010031#include <algorithm>
Georgios Pinitasea857272021-01-22 05:47:37 +000032#include <array>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033#include <fstream>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034#include <utility>
35#include <vector>
36
Georgios Pinitasea857272021-01-22 05:47:37 +000037#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
38#include <zlib.h>
39
40namespace
41{
42/* Decoding table */
43constexpr std::array<uint8_t, 256> b64_invtab =
44{
45 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,
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
48 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0,
49 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
50 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
51 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
52 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61};
62
63/** Decode a base64 encoded string
64 *
65 * @param[in] str Base64 encoded string to decode
66 *
67 * @return The decode string in case of a valid, non-empty string otherwise an empty string
68 */
69std::string decode_base64(const std::string &str)
70{
71 constexpr const char pad_char = '=';
72
73 // Handle empty string
74 if(str.empty())
75 {
76 return {};
77 }
78
79 // Base64 encoded string has size multiple of 4
80 if(str.length() % 4)
81 {
82 return {};
83 }
84
85 //
86 // Check encoded string padding
87 std::size_t padding = (str.rbegin()[0] == pad_char) + (str.rbegin()[1] == pad_char);
88 const int str_len = str.size();
89
90 // Reserve memory for the decoded string
91 // Note each 4 consecutive elements of 6-bit encode 3 bytes
92 std::string dec_b64;
93 dec_b64.reserve(((str_len / 4) * 3));
94
95 // Block decoding function (exclude padding)
96 int c = 0;
97 const int end = str_len - 4 - padding;
98 for(; c <= end; c += 4)
99 {
100 const int byte0 = b64_invtab[str[c]];
101 const int byte1 = b64_invtab[str[c + 1]];
102 const int byte2 = b64_invtab[str[c + 2]];
103 const int byte3 = b64_invtab[str[c + 3]];
104
105 dec_b64.push_back((byte0 << 2) | (byte1 >> 4));
106 dec_b64.push_back((byte1 << 4) | (byte2 >> 2));
107 dec_b64.push_back((byte2 << 6) | (byte3));
108 }
109
110 // Last step that might contain padding symbols
111 if(padding == 1)
112 {
113 const int byte0 = b64_invtab[str[c]];
114 const int byte1 = b64_invtab[str[c + 1]];
115 const int byte2 = b64_invtab[str[c + 2]];
116
117 dec_b64.push_back((byte0 << 2) | (byte1 >> 4));
118 dec_b64.push_back((byte1 << 4) | (byte2 >> 2));
119 }
120 else if(padding == 2)
121 {
122 const int byte0 = b64_invtab[str[c]];
123 const int byte1 = b64_invtab[str[c + 1]];
124
125 dec_b64.push_back((byte0 << 2) | (byte1 >> 4));
126 }
127
128 return dec_b64;
129}
130
131/** Decompress a zlib compressed string
132 *
133 * @param[in] str ZLib compressed string
134 *
135 * @return The decompressed string if successful, otherwise false.
136 */
137std::string decompress_zlib(const std::string &str)
138{
139 // Create and initialize decompression stream
140 z_stream ds{};
141 if(inflateInit(&ds) != Z_OK)
142 {
143 return std::string();
144 }
145 ds.avail_in = str.size();
146 ds.next_in = (Bytef *)str.data();
147
148 // Roll-over the string using a buffer and decompress
149 int status = Z_OK;
150 char roll_buff[16384];
151 std::string inflated_str;
152 do
153 {
154 ds.avail_out = sizeof(roll_buff);
155 ds.next_out = reinterpret_cast<Bytef *>(roll_buff);
156
157 status = inflate(&ds, 0);
158 if(inflated_str.size() < ds.total_out)
159 {
160 inflated_str.append(roll_buff, ds.total_out - inflated_str.size());
161 }
162 }
163 while(status == Z_OK);
164
165 // Finalize decompression stream
166 inflateEnd(&ds);
167 if(status != Z_STREAM_END)
168 {
169 return std::string();
170 }
171
172 return inflated_str;
173}
174} // namespace
175#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
176
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100177using namespace arm_compute;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100178const std::map<std::string, std::string> CLKernelLibrary::_kernel_program_map =
179{
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100180 { "activation_layer", "activation_layer.cl" },
Manuel Bottini30dbeef2019-06-26 16:23:03 +0100181 { "activation_layer_quant", "activation_layer_quant.cl" },
182 { "activation_layer_quant_f32", "activation_layer_quant.cl" },
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100183 { "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" },
Michalis Spyrouf1addb62018-09-11 11:16:47 +0100187 { "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" },
Michele Di Giorgiobf3c6622018-03-08 11:52:27 +0000191 { "batchnormalization_layer_nchw", "batchnormalization_layer.cl" },
192 { "batchnormalization_layer_nhwc", "batchnormalization_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100193 { "bitwise_or", "bitwise_op.cl" },
194 { "bitwise_and", "bitwise_op.cl" },
195 { "bitwise_xor", "bitwise_op.cl" },
196 { "bitwise_not", "bitwise_op.cl" },
giuros01c04a0e82018-10-03 12:44:35 +0100197 { "bounding_box_transform", "bounding_box_transform.cl" },
Michele Di Giorgio4aff98f2019-08-28 16:27:26 +0100198 { "bounding_box_transform_quantized", "bounding_box_transform_quantized.cl" },
Michele Di Giorgio72175632018-05-01 16:52:00 +0100199 { "channel_shuffle_nchw", "channel_shuffle.cl" },
Gian Marco Iodice8bab0ee2018-09-13 11:51:56 +0100200 { "channel_shuffle_nhwc", "channel_shuffle.cl" },
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000201 { "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" },
Vidhya Sudhan Loganathan338595b2019-06-28 14:09:53 +0100213 { "concatenate", "concatenate.cl" },
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100214 { "concatenate_width", "concatenate.cl" },
Pablo Tello6a14adb2019-03-05 17:33:08 +0000215 { "concatenate_height", "concatenate.cl" },
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000216 { "concatenate_width_x2", "concatenate.cl" },
217 { "concatenate_width_x4", "concatenate.cl" },
Gian Marco76faef82018-01-29 12:15:32 +0000218 { "col2im", "col2im.cl" },
Giorgio Arena657bdb32018-04-26 18:52:01 +0100219 { "convert_depth_down", "depth_convert.cl" },
220 { "convert_depth_up", "depth_convert.cl" },
221 { "convert_fc_weights", "convert_fc_weights.cl" },
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000222 { "copy_tensor", "copy_tensor.cl" },
George Wort894066d2019-02-15 15:12:52 +0000223 { "crop_tensor", "crop_tensor.cl" },
giuros0146a49a02019-04-01 13:50:22 +0100224 { "deconvolution_reshape", "deconvolution_layer.cl" },
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000225 { "deconvolution_upsample", "deconvolution_layer.cl" },
Giorgio Arena93a690e2017-08-01 16:09:33 +0100226 { "depthwise_convolution_3x3", "depthwise_convolution.cl" },
Michele Di Giorgio933fe862018-02-19 15:42:12 +0000227 { "depthwise_convolution_3x3_f16", "depthwise_convolution.cl" },
Giorgio Arenad051e972018-06-20 11:46:42 +0100228 { "depthwise_convolution_3x3_nhwc", "depthwise_convolution.cl" },
229 { "depthwise_convolution_3x3_nhwc_stride1", "depthwise_convolution.cl" },
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100230 { "dwc_MxN_native_fp_nhwc", "depthwise_convolution.cl" },
Michele Di Giorgioa046e162019-10-08 09:36:26 +0100231 { "dwc_MxN_native_quantized8_nhwc", "depthwise_convolution_quantized.cl" },
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100232 { "dwc_3x3_native_quantized8_nchw", "depthwise_convolution_quantized.cl" },
233 { "dwc_3x3_native_quantized8_dot8_nchw", "depthwise_convolution_quantized.cl" },
234 { "dwc_3x3_reshaped_quantized8_nhwc", "depthwise_convolution_quantized.cl" },
235 { "dwc_3x3_reshaped_quantized8_stride1_nhwc", "depthwise_convolution_quantized.cl" },
236 { "dwc_3x3_reshaped_quantized8_dot8_stride1_nhwc", "depthwise_convolution_quantized.cl" },
Michalis Spyrou649962c2019-05-22 11:11:55 +0100237 { "depth_to_space_nchw", "depth_to_space.cl" },
238 { "depth_to_space_nhwc", "depth_to_space.cl" },
Michele Di Giorgio3ebef322018-02-21 10:02:58 +0000239 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16", "depthwise_convolution.cl" },
240 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16", "depthwise_convolution.cl" },
241 { "depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32", "depthwise_convolution.cl" },
242 { "depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32", "depthwise_convolution.cl" },
giuros016d109962019-01-07 17:47:19 +0000243 { "depthwise_convolution_reshape_weights", "depthwise_convolution.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100244 { "dequantization_layer", "dequantization_layer.cl" },
Michalis Spyrou3f632f32019-08-22 16:52:00 +0100245 { "dequantization_layer_per_channel_nhwc", "dequantization_layer.cl" },
246 { "dequantization_layer_per_channel_nchw", "dequantization_layer.cl" },
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000247 { "direct_convolution_nhwc", "direct_convolution.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100248 { "direct_convolution1x1", "direct_convolution1x1.cl" },
Gian Marco Iodice1c8409d2017-09-06 17:24:25 +0100249 { "direct_convolution1x1_f32_bifrost", "direct_convolution1x1.cl" },
SiCong Lic51b72f2017-07-28 14:46:20 +0100250 { "direct_convolution3x3", "direct_convolution3x3.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100251 { "direct_convolution3x3_f32_bifrost", "direct_convolution3x3.cl" },
steniu01db006682017-08-09 16:26:22 +0100252 { "direct_convolution5x5", "direct_convolution5x5.cl" },
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100253 { "direct_convolution5x5_f32_bifrost", "direct_convolution5x5.cl" },
Sang-Hoon Parkab5b1a22019-10-15 09:29:13 +0100254 { "direct_convolution_quantized", "direct_convolution_quantized.cl" },
giuros01164a2722018-11-20 18:34:46 +0000255 { "elementwise_operation_ADD", "elementwise_operation.cl" },
256 { "elementwise_operation_SUB", "elementwise_operation.cl" },
257 { "elementwise_operation_MAX", "elementwise_operation.cl" },
258 { "elementwise_operation_MIN", "elementwise_operation.cl" },
259 { "elementwise_operation_DIV", "elementwise_operation.cl" },
260 { "elementwise_operation_SQUARED_DIFF", "elementwise_operation.cl" },
Usama Arif52c54f62019-05-14 10:22:36 +0100261 { "elementwise_operation_POWER", "elementwise_operation.cl" },
giuros011e6e1b82019-05-14 16:12:53 +0100262 { "elementwise_operation_PRELU", "elementwise_operation.cl" },
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000263 { "elementwise_operation_AND", "elementwise_operation.cl" },
264 { "elementwise_operation_OR", "elementwise_operation.cl" },
giuros01164a2722018-11-20 18:34:46 +0000265 { "elementwise_operation_ADD_quantized", "elementwise_operation_quantized.cl" },
266 { "elementwise_operation_SUB_quantized", "elementwise_operation_quantized.cl" },
267 { "elementwise_operation_MAX_quantized", "elementwise_operation_quantized.cl" },
268 { "elementwise_operation_MIN_quantized", "elementwise_operation_quantized.cl" },
269 { "elementwise_operation_DIV_quantized", "elementwise_operation_quantized.cl" },
270 { "elementwise_operation_SQUARED_DIFF_quantized", "elementwise_operation_quantized.cl" },
giuros011e6e1b82019-05-14 16:12:53 +0100271 { "elementwise_operation_PRELU_quantized", "elementwise_operation_quantized.cl" },
Michalis Spyroue9362622018-11-23 17:41:37 +0000272 { "elementwise_unary", "elementwise_unary.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000273 { "fft_digit_reverse_axis_0", "fft_digit_reverse.cl" },
274 { "fft_digit_reverse_axis_1", "fft_digit_reverse.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000275 { "fft_radix_2_first_stage_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000276 { "fft_radix_2_first_stage_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000277 { "fft_radix_2_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000278 { "fft_radix_2_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000279 { "fft_radix_3_first_stage_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000280 { "fft_radix_3_first_stage_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000281 { "fft_radix_3_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000282 { "fft_radix_3_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000283 { "fft_radix_4_first_stage_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000284 { "fft_radix_4_first_stage_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000285 { "fft_radix_4_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000286 { "fft_radix_4_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000287 { "fft_radix_5_first_stage_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000288 { "fft_radix_5_first_stage_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000289 { "fft_radix_5_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000290 { "fft_radix_5_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000291 { "fft_radix_7_first_stage_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000292 { "fft_radix_7_first_stage_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000293 { "fft_radix_7_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000294 { "fft_radix_7_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000295 { "fft_radix_8_first_stage_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000296 { "fft_radix_8_first_stage_axis_1", "fft.cl" },
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000297 { "fft_radix_8_axis_0", "fft.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000298 { "fft_radix_8_axis_1", "fft.cl" },
299 { "fft_scale_conj", "fft_scale.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100300 { "fill_image_borders_constant", "fill_border.cl" },
301 { "fill_image_borders_replicate", "fill_border.cl" },
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100302 { "floor_layer", "floor.cl" },
Manuel Bottini2732cca2019-05-28 11:44:41 +0100303 { "fuse_batchnormalization_layer", "batchnormalization_layer.cl" },
Manuel Bottini8529bd62018-11-21 11:53:04 +0000304 { "gather", "gather.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100305 { "gemm_ma_f16", "gemm.cl" },
306 { "gemm_ma_f32", "gemm.cl" },
Giorgio Arena9fe41442017-08-23 16:36:24 +0100307 { "gemm_mv", "gemv.cl" },
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +0000308 { "gemm_mv_quantized", "gemv.cl" },
SiCong Li4abc9d12020-10-28 14:19:28 +0000309 { "gemm_mm_interleaved_transposed_f16", "gemm_v1.cl" },
310 { "gemm_mm_interleaved_transposed_f16_acc32", "gemm_v1.cl" },
311 { "gemm_mm_interleaved_transposed_f16_bifrost", "gemm_v1.cl" },
312 { "gemm_mm_interleaved_transposed_f32", "gemm_v1.cl" },
313 { "gemm_mm_interleaved_transposed_f32_bifrost", "gemm_v1.cl" },
314 { "gemm_mm_floating_point", "gemm_v1.cl" },
315 { "gemm_mm_floating_point_f16_bifrost", "gemm_v1.cl" },
316 { "gemm_mm_floating_point_f16_bifrost_acc32", "gemm_v1.cl" },
317 { "gemm_mm_floating_point_f32_bifrost", "gemm_v1.cl" },
318 { "gemm_mm_floating_point_f32_bifrost_1000", "gemm_v1.cl" },
giuros01b3204e72019-04-01 13:50:22 +0100319 { "gemm_mm_native", "gemm.cl" },
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000320 { "gemm_mm_reshaped_lhs_nt_rhs_t", "gemm.cl" },
Gian Marco Iodicee3a849a2020-06-10 17:59:30 +0100321 { "gemm_mm_reshaped_lhs_nt_rhs_t_texture", "gemm.cl" },
Giorgio Arenaae99b6e2019-08-01 14:22:12 +0100322 { "gemm_mm_reshaped_lhs_t_rhs_nt", "gemm.cl" },
Gian Marco Iodicee3a849a2020-06-10 17:59:30 +0100323 { "gemm_mm_reshaped_lhs_t_rhs_nt_texture", "gemm.cl" },
Gian Marco Iodiceba5e0962019-03-11 12:17:44 +0000324 { "gemm_mm_reshaped_only_rhs_nt", "gemm.cl" },
Gian Marco Iodice781cba72020-06-19 16:56:57 +0100325 { "gemm_mm_reshaped_only_rhs_nt_texture", "gemm.cl" },
Gian Marco Iodiceadc53952019-02-15 11:10:31 +0000326 { "gemm_mm_reshaped_only_rhs_t", "gemm.cl" },
Gian Marco Iodice781cba72020-06-19 16:56:57 +0100327 { "gemm_mm_reshaped_only_rhs_t_texture", "gemm.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100328 { "gemm_lc_vm_f32", "gemm.cl" },
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000329 { "gemm_reshape_lhs_matrix_nt", "gemm.cl" },
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000330 { "gemm_reshape_lhs_matrix_t", "gemm.cl" },
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000331 { "gemm_reshape_rhs_matrix_nt", "gemm.cl" },
332 { "gemm_reshape_rhs_matrix_t", "gemm.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000333 { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" },
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100334 { "gemmlowp_matrix_a_reduction_dot8", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000335 { "gemmlowp_matrix_b_reduction", "gemmlowp.cl" },
Gian Marco Iodicee7510622019-06-03 17:28:17 +0100336 { "gemmlowp_mm_native", "gemmlowp.cl" },
Gian Marco Iodicedb63b9c2019-01-17 09:47:04 +0000337 { "gemmlowp_mm_reshaped_lhs_nt_rhs_t", "gemmlowp.cl" },
Gian Marco Iodice62251f72019-03-11 16:07:12 +0000338 { "gemmlowp_mm_reshaped_only_rhs_t", "gemmlowp.cl" },
Michele Di Giorgiob54ba282020-01-14 15:31:55 +0000339 { "gemmlowp_mm_reshaped_only_rhs_t_fused_output_stage_fixedpoint", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000340 { "gemmlowp_offset_contribution", "gemmlowp.cl" },
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100341 { "gemmlowp_offset_contribution_quantize_down", "gemmlowp.cl" },
342 { "gemmlowp_offset_contribution_quantize_down_fixedpoint", "gemmlowp.cl" },
Gian Marco05288a22017-11-21 10:57:50 +0000343 { "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
Gian Marco58c57942017-11-28 09:10:03 +0000344 { "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
Manuel Bottini9c9b70b2019-07-01 17:35:56 +0100345 { "gemmlowp_output_stage_quantize_down_fixedpoint_qsymm16", "gemmlowp.cl" },
Georgios Pinitas51e53a32018-10-22 13:49:08 +0100346 { "gemmlowp_output_stage_quantize_down_float", "gemmlowp.cl" },
Manuel Bottini5209be52019-02-13 16:34:56 +0000347 { "generate_proposals_compute_all_anchors", "generate_proposals.cl" },
Michele Di Giorgio6b612f52019-09-05 12:30:22 +0100348 { "generate_proposals_compute_all_anchors_quantized", "generate_proposals_quantized.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100349 { "im2col1x1_stridex1_nchw", "im2col.cl" },
350 { "im2col3x3_nchw", "im2col.cl" },
351 { "im2col5x5_nchw", "im2col.cl" },
352 { "im2col11x11_padx0_pady0_nchw", "im2col.cl" },
353 { "im2col_generic_nchw", "im2col.cl" },
354 { "im2col_generic_padx0_pady0_nchw", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100355 { "im2col3x3_nhwc", "im2col.cl" },
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000356 { "im2col9x9_nhwc", "im2col.cl" },
Pablo Tello4a626a72018-04-04 10:01:14 +0100357 { "im2col_generic_nhwc", "im2col.cl" },
Manuel Bottini79f88e62019-09-18 15:02:53 +0100358 { "instance_normalization", "instance_normalization.cl" },
Michalis Spyrou5538d342018-11-14 08:10:13 +0000359 { "l2_normalize_x", "l2_normalize.cl" },
360 { "l2_normalize_y", "l2_normalize.cl" },
361 { "l2_normalize_z", "l2_normalize.cl" },
Gian Marco Iodice4d81d752020-07-14 15:05:31 +0100362 { "max_unpooling_layer_2", "unpooling_layer.cl" },
Michele Di Giorgio5b48ad72019-06-04 18:43:35 +0100363 { "mean_stddev_normalization", "mean_stddev_normalization.cl" },
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100364 { "memset", "memset.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100365 { "minmax_layer", "minmax_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100366 { "non_max_suppression", "nonmax.cl" },
367 { "normalization_layer_cross_map", "normalization_layer.cl" },
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +0000368 { "normalization_layer_in_map_nchw", "normalization_layer.cl" },
369 { "normalization_layer_in_map_nhwc", "normalization_layer.cl" },
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100370 { "normalize_planar_yuv_layer_nchw", "normalize_planar_yuv_layer.cl" },
371 { "normalize_planar_yuv_layer_nhwc", "normalize_planar_yuv_layer.cl" },
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100372 { "normalize_planar_yuv_layer_q8_nchw", "normalize_planar_yuv_layer_quantized.cl" },
373 { "normalize_planar_yuv_layer_q8_nhwc", "normalize_planar_yuv_layer_quantized.cl" },
Giorgio Arena5c4a8e92019-08-28 17:55:07 +0100374 { "pad_layer_constant", "pad_layer.cl" },
375 { "pad_layer_symmetric_reflect", "pad_layer.cl" },
shubhame1a4e372019-01-07 21:37:55 +0530376 { "permute", "permute.cl" },
Georgios Pinitas8be91482019-03-26 17:23:28 +0000377 { "pixelwise_mul_complex", "pixelwise_mul_float.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100378 { "pixelwise_mul_float", "pixelwise_mul_float.cl" },
379 { "pixelwise_mul_int", "pixelwise_mul_int.cl" },
Georgios Pinitasbf28a3c2018-09-18 14:34:48 +0100380 { "pixelwise_mul_quantized", "pixelwise_mul_int.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100381 { "pooling_layer_2", "pooling_layer.cl" },
382 { "pooling_layer_3", "pooling_layer.cl" },
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000383 { "pooling_layer_optimized_3", "pooling_layer.cl" },
Georgios Pinitasce093142017-06-19 16:11:53 +0100384 { "pooling_layer_7", "pooling_layer.cl" },
Michalis Spyroue74b2012018-04-18 09:49:16 +0100385 { "pooling_layer_MxN_nchw", "pooling_layer.cl" },
386 { "pooling_layer_MxN_nhwc", "pooling_layer.cl" },
Gian Marco Iodice7333e1f2020-10-08 10:25:49 +0100387 { "pooling_layer_2x2_nhwc", "pooling_layer.cl" },
Sheri Zhang801bbcb2020-08-03 20:11:56 +0100388 { "pooling_layer_2_nchw_indices_fp32", "pooling_layer.cl" },
389 { "pooling_layer_2_nchw_indices_fp16", "pooling_layer.cl" },
Michalis Spyroue74b2012018-04-18 09:49:16 +0100390 { "pooling_layer_MxN_quantized_nhwc", "pooling_layer_quantized.cl" },
391 { "pooling_layer_MxN_quantized_nchw", "pooling_layer_quantized.cl" },
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100392 { "prior_box_layer_nchw", "prior_box_layer.cl" },
Sheri Zhangb18252d2020-04-07 11:04:57 +0100393 { "qlstm_layer_normalization", "qlstm_layer_normalization.cl" },
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100394 { "quantization_layer", "quantization_layer.cl" },
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +0000395 { "range", "range.cl" },
396 { "range_quantized", "range.cl" },
Michalis Spyrou7e9391b2018-10-05 14:49:28 +0100397 { "reduction_operation_x", "reduction_operation.cl" },
Michalis Spyrou7930db42018-11-22 17:36:28 +0000398 { "reduction_operation_non_parallel_x", "reduction_operation.cl" },
Michalis Spyrou7e9391b2018-10-05 14:49:28 +0100399 { "reduction_operation_y", "reduction_operation.cl" },
400 { "reduction_operation_z", "reduction_operation.cl" },
401 { "reduction_operation_w", "reduction_operation.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100402 { "remap_nearest_neighbour", "remap.cl" },
403 { "remap_bilinear", "remap.cl" },
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100404 { "reorg_layer_nchw", "reorg_layer.cl" },
405 { "reorg_layer_nhwc", "reorg_layer.cl" },
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100406 { "reshape_layer", "reshape_layer.cl" },
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100407 { "reshape_to_columns", "convolution_layer.cl" },
Michele Di Giorgio5daeffd2018-11-26 10:01:15 +0000408 { "reverse", "reverse.cl" },
giuros0118870812018-09-13 09:31:40 +0100409 { "roi_align_layer", "roi_align_layer.cl" },
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100410 { "roi_align_layer_quantized", "roi_align_layer_quantized.cl" },
SiCong Li3e363692017-07-04 15:02:10 +0100411 { "roi_pooling_layer", "roi_pooling_layer.cl" },
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100412 { "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" },
Michalis Spyrou17220e22018-09-12 13:35:38 +0100416 { "scale_bilinear_quantized_nchw", "scale_quantized.cl" },
417 { "scale_bilinear_quantized_nhwc", "scale_quantized.cl" },
Georgios Pinitasaaa27182018-11-21 16:32:15 +0000418 { "select_same_rank", "select.cl" },
419 { "select_different_rank_2", "select.cl" },
420 { "select_different_rank_n", "select.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100421 { "softmax_layer_norm", "softmax_layer.cl" },
Chunosovf450caa2017-11-08 16:09:35 +0700422 { "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
Giorgio Arena4402cb92018-02-15 13:37:40 +0000423 { "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" },
Chunosovd6afedc2017-11-06 22:09:45 +0700425 { "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100426 { "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" },
Michalis Spyroud69b3b22019-05-29 17:03:38 +0100430 { "space_to_depth_nchw", "space_to_depth.cl" },
431 { "space_to_depth_nhwc", "space_to_depth.cl" },
Chunosovd6afedc2017-11-06 22:09:45 +0700432 { "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000433 { "stack_layer", "stack_layer.cl" },
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100434 { "strided_slice", "slice_ops.cl" },
giuros013175fcf2018-11-21 09:59:17 +0000435 { "tile", "tile.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100436 { "transpose", "transpose.cl" },
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100437 { "upsample_layer_nchw", "upsample_layer.cl" },
438 { "upsample_layer_nhwc", "upsample_layer.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100439 { "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" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100446 { "winograd_filter_transform_4x1_5x1_nchw", "winograd_filter_transform.cl" },
447 { "winograd_filter_transform_1x4_1x5_nchw", "winograd_filter_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100448 { "winograd_filter_transform_4x1_3x1_nhwc", "winograd_filter_transform.cl" },
449 { "winograd_filter_transform_1x4_1x3_nhwc", "winograd_filter_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100450 { "winograd_filter_transform_4x4_3x3_nhwc", "winograd_filter_transform.cl" },
451 { "winograd_filter_transform_4x4_5x5_nhwc", "winograd_filter_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100452 { "winograd_filter_transform_4x1_5x1_nhwc", "winograd_filter_transform.cl" },
453 { "winograd_filter_transform_1x4_1x5_nhwc", "winograd_filter_transform.cl" },
Michele Di Giorgio881c6842019-02-27 14:26:51 +0000454 { "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" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100457 { "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" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100467 { "winograd_input_transform_4x1_5x1_stepz1_nchw", "winograd_input_transform.cl" },
468 { "winograd_input_transform_1x4_1x5_stepz1_nchw", "winograd_input_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100469 { "winograd_input_transform_4x1_3x1_stepz1_nhwc", "winograd_input_transform.cl" },
470 { "winograd_input_transform_1x4_1x3_stepz1_nhwc", "winograd_input_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100471 { "winograd_input_transform_4x4_3x3_stepz1_nhwc", "winograd_input_transform.cl" },
472 { "winograd_input_transform_4x4_5x5_stepz1_nhwc", "winograd_input_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100473 { "winograd_input_transform_4x1_5x1_stepz1_nhwc", "winograd_input_transform.cl" },
474 { "winograd_input_transform_1x4_1x5_stepz1_nhwc", "winograd_input_transform.cl" },
Michele Di Giorgiof955d512019-02-27 14:26:51 +0000475 { "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" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100478 { "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" },
Gian Marco Iodice876be2a2018-07-03 12:22:09 +0100485 { "winograd_output_transform_4x1_5x1_nchw", "winograd_output_transform.cl" },
486 { "winograd_output_transform_1x4_1x5_nchw", "winograd_output_transform.cl" },
Giorgio Arena149fdf32018-07-04 17:03:33 +0100487 { "winograd_output_transform_4x1_3x1_nhwc", "winograd_output_transform.cl" },
488 { "winograd_output_transform_1x4_1x3_nhwc", "winograd_output_transform.cl" },
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100489 { "winograd_output_transform_4x4_3x3_nhwc", "winograd_output_transform.cl" },
490 { "winograd_output_transform_4x4_5x5_nhwc", "winograd_output_transform.cl" },
Gian Marco Iodiced28b7512018-07-06 12:59:28 +0100491 { "winograd_output_transform_4x1_5x1_nhwc", "winograd_output_transform.cl" },
492 { "winograd_output_transform_1x4_1x5_nhwc", "winograd_output_transform.cl" },
giuros013bfacb22019-04-01 12:07:02 +0100493 { "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" },
Giorgio Arena73023022018-09-04 14:55:55 +0100496 { "yolo_layer_nchw", "yolo_layer.cl" },
497 { "yolo_layer_nhwc", "yolo_layer.cl" },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100498};
499
500const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
501{
502#ifdef EMBEDDED_KERNELS
503 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100504 "activation_layer.cl",
505#include "./cl_kernels/activation_layer.clembed"
506 },
507 {
Manuel Bottini30dbeef2019-06-26 16:23:03 +0100508 "activation_layer_quant.cl",
509#include "./cl_kernels/activation_layer_quant.clembed"
Michel Iwaniec00633802017-10-12 14:14:15 +0100510 },
511 {
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100512 "arg_min_max.cl",
513#include "./cl_kernels/arg_min_max.clembed"
514 },
515 {
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100516 "batch_to_space.cl",
517#include "./cl_kernels/batch_to_space.clembed"
518 },
519 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100520 "bitwise_op.cl",
521#include "./cl_kernels/bitwise_op.clembed"
522 },
523 {
giuros01c04a0e82018-10-03 12:44:35 +0100524 "bounding_box_transform.cl",
525#include "./cl_kernels/bounding_box_transform.clembed"
526 },
527 {
Michele Di Giorgio4aff98f2019-08-28 16:27:26 +0100528 "bounding_box_transform_quantized.cl",
529#include "./cl_kernels/bounding_box_transform_quantized.clembed"
530 },
531 {
Michele Di Giorgio72175632018-05-01 16:52:00 +0100532 "channel_shuffle.cl",
533#include "./cl_kernels/channel_shuffle.clembed"
534 },
535 {
Gian Marco76faef82018-01-29 12:15:32 +0000536 "col2im.cl",
537#include "./cl_kernels/col2im.clembed"
538 },
539 {
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000540 "comparisons.cl",
541#include "./cl_kernels/comparisons.clembed"
542 },
543 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100544 "concatenate.cl",
545#include "./cl_kernels/concatenate.clembed"
546 },
547 {
Giorgio Arena657bdb32018-04-26 18:52:01 +0100548 "convert_fc_weights.cl",
549#include "./cl_kernels/convert_fc_weights.clembed"
Michalis Spyrou473cb012021-02-23 11:48:12 +0000550 },
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100551 {
552 "convolution_layer.cl",
553#include "./cl_kernels/convolution_layer.clembed"
554 },
555 {
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +0000556 "copy_tensor.cl",
557#include "./cl_kernels/copy_tensor.clembed"
558 },
559 {
George Wort894066d2019-02-15 15:12:52 +0000560 "crop_tensor.cl",
561#include "./cl_kernels/crop_tensor.clembed"
562 },
563 {
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100564 "upsample_layer.cl",
565#include "./cl_kernels/upsample_layer.clembed"
566 },
567 {
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000568 "deconvolution_layer.cl",
569#include "./cl_kernels/deconvolution_layer.clembed"
570 },
571 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100572 "depth_convert.cl",
573#include "./cl_kernels/depth_convert.clembed"
574 },
575 {
Michalis Spyrou649962c2019-05-22 11:11:55 +0100576 "depth_to_space.cl",
577#include "./cl_kernels/depth_to_space.clembed"
578 },
579 {
Giorgio Arena93a690e2017-08-01 16:09:33 +0100580 "depthwise_convolution.cl",
581#include "./cl_kernels/depthwise_convolution.clembed"
582 },
583 {
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700584 "depthwise_convolution_quantized.cl",
585#include "./cl_kernels/depthwise_convolution_quantized.clembed"
586 },
587 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100588 "dequantization_layer.cl",
589#include "./cl_kernels/dequantization_layer.clembed"
590 },
591 {
SiCong Lic51b72f2017-07-28 14:46:20 +0100592 "direct_convolution1x1.cl",
593#include "./cl_kernels/direct_convolution1x1.clembed"
594 },
595 {
596 "direct_convolution3x3.cl",
597#include "./cl_kernels/direct_convolution3x3.clembed"
steniu0127b386c2017-07-18 17:37:43 +0100598 },
599 {
steniu01db006682017-08-09 16:26:22 +0100600 "direct_convolution5x5.cl",
601#include "./cl_kernels/direct_convolution5x5.clembed"
602 },
603 {
Sang-Hoon Parkab5b1a22019-10-15 09:29:13 +0100604 "direct_convolution_quantized.cl",
605#include "./cl_kernels/direct_convolution_quantized.clembed"
Chunosovd621bca2017-11-03 17:33:15 +0700606 },
607 {
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000608 "direct_convolution.cl",
609#include "./cl_kernels/direct_convolution.clembed"
Michalis Spyrou45091732019-05-13 17:41:01 +0100610 },
611 {
giuros01164a2722018-11-20 18:34:46 +0000612 "elementwise_operation.cl",
613#include "./cl_kernels/elementwise_operation.clembed"
614 },
615 {
616 "elementwise_operation_quantized.cl",
617#include "./cl_kernels/elementwise_operation_quantized.clembed"
618 },
619 {
Michalis Spyroue9362622018-11-23 17:41:37 +0000620 "elementwise_unary.cl",
621#include "./cl_kernels/elementwise_unary.clembed"
622 },
623 {
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000624 "fft.cl",
625#include "./cl_kernels/fft.clembed"
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100626 },
627 {
Georgios Pinitas8be91482019-03-26 17:23:28 +0000628 "fft_digit_reverse.cl",
629#include "./cl_kernels/fft_digit_reverse.clembed"
630 },
631 {
632 "fft_scale.cl",
633#include "./cl_kernels/fft_scale.clembed"
634 },
635 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100636 "fill_border.cl",
637#include "./cl_kernels/fill_border.clembed"
638 },
639 {
Georgios Pinitasd8e765b2017-08-02 13:44:33 +0100640 "floor.cl",
641#include "./cl_kernels/floor.clembed"
642 },
643 {
Manuel Bottini8529bd62018-11-21 11:53:04 +0000644 "gather.cl",
645#include "./cl_kernels/gather.clembed"
646 },
647 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100648 "gemm.cl",
649#include "./cl_kernels/gemm.clembed"
650 },
651 {
SiCong Li4abc9d12020-10-28 14:19:28 +0000652 "gemm_v1.cl",
653#include "./cl_kernels/gemm_v1.clembed"
654 },
655 {
Gian Marco05288a22017-11-21 10:57:50 +0000656 "gemmlowp.cl",
657#include "./cl_kernels/gemmlowp.clembed"
658 },
659 {
Giorgio Arena9fe41442017-08-23 16:36:24 +0100660 "gemv.cl",
661#include "./cl_kernels/gemv.clembed"
662 },
663 {
Manuel Bottini5209be52019-02-13 16:34:56 +0000664 "generate_proposals.cl",
665#include "./cl_kernels/generate_proposals.clembed"
666 },
667 {
Michele Di Giorgio6b612f52019-09-05 12:30:22 +0100668 "generate_proposals_quantized.cl",
669#include "./cl_kernels/generate_proposals_quantized.clembed"
670 },
671 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100672 "helpers.h",
673#include "./cl_kernels/helpers.hembed"
674 },
675 {
Chunosovd621bca2017-11-03 17:33:15 +0700676 "helpers_asymm.h",
677#include "./cl_kernels/helpers_asymm.hembed"
678 },
679 {
Gian Marco76faef82018-01-29 12:15:32 +0000680 "im2col.cl",
681#include "./cl_kernels/im2col.clembed"
682 },
683 {
Manuel Bottini79f88e62019-09-18 15:02:53 +0100684 "instance_normalization.cl",
685#include "./cl_kernels/instance_normalization.clembed"
686 },
687 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100688 "l2_normalize.cl",
689#include "./cl_kernels/l2_normalize.clembed"
690 },
691 {
Michele Di Giorgio5b48ad72019-06-04 18:43:35 +0100692 "mean_stddev_normalization.cl",
693#include "./cl_kernels/mean_stddev_normalization.clembed"
694 },
695 {
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100696 "memset.cl",
697#include "./cl_kernels/memset.clembed"
698 },
699 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100700 "minmax_layer.cl",
701#include "./cl_kernels/minmax_layer.clembed"
702 },
703 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100704 "nonmax.cl",
705#include "./cl_kernels/nonmax.clembed"
706 },
707 {
708 "normalization_layer.cl",
709#include "./cl_kernels/normalization_layer.clembed"
710 },
711 {
Michele Di Giorgiob57be0d2018-08-31 16:26:25 +0100712 "normalize_planar_yuv_layer.cl",
713#include "./cl_kernels/normalize_planar_yuv_layer.clembed"
714 },
715 {
Michele Di Giorgiod63dfa22018-09-12 10:18:54 +0100716 "normalize_planar_yuv_layer_quantized.cl",
717#include "./cl_kernels/normalize_planar_yuv_layer_quantized.clembed"
718 },
719 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100720 "batchnormalization_layer.cl",
721#include "./cl_kernels/batchnormalization_layer.clembed"
722 },
723 {
Giorgio Arena205eed82019-08-14 10:13:50 +0100724 "pad_layer.cl",
725#include "./cl_kernels/pad_layer.clembed"
726 },
727 {
Michalis Spyrou5237e012018-01-17 09:40:27 +0000728 "permute.cl",
729#include "./cl_kernels/permute.clembed"
730 },
731 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100732 "pixelwise_mul_float.cl",
733#include "./cl_kernels/pixelwise_mul_float.clembed"
734 },
735 {
736 "pixelwise_mul_int.cl",
737#include "./cl_kernels/pixelwise_mul_int.clembed"
738 },
739 {
740 "pooling_layer.cl",
741#include "./cl_kernels/pooling_layer.clembed"
742 },
743 {
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000744 "pooling_layer_quantized.cl",
745#include "./cl_kernels/pooling_layer_quantized.clembed"
746 },
747 {
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100748 "prior_box_layer.cl",
749#include "./cl_kernels/prior_box_layer.clembed"
750 },
751 {
Sheri Zhangb18252d2020-04-07 11:04:57 +0100752 "qlstm_layer_normalization.cl",
753#include "./cl_kernels/qlstm_layer_normalization.clembed"
754 },
755 {
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100756 "quantization_layer.cl",
757#include "./cl_kernels/quantization_layer.clembed"
758 },
759 {
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +0000760 "range.cl",
761#include "./cl_kernels/range.clembed"
762 },
763 {
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100764 "reduction_operation.cl",
765#include "./cl_kernels/reduction_operation.clembed"
766 },
767 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100768 "remap.cl",
769#include "./cl_kernels/remap.clembed"
770 },
771 {
Gian Marco Iodice477531c2018-08-21 17:53:38 +0100772 "reorg_layer.cl",
773#include "./cl_kernels/reorg_layer.clembed"
774 },
775 {
Georgios Pinitas5ee66ea2017-09-07 17:29:16 +0100776 "reshape_layer.cl",
777#include "./cl_kernels/reshape_layer.clembed"
778 },
779 {
Michele Di Giorgio5daeffd2018-11-26 10:01:15 +0000780 "reverse.cl",
781#include "./cl_kernels/reverse.clembed"
782 },
783 {
giuros0118870812018-09-13 09:31:40 +0100784 "roi_align_layer.cl",
785#include "./cl_kernels/roi_align_layer.clembed"
786 },
787 {
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +0100788 "roi_align_layer_quantized.cl",
789#include "./cl_kernels/roi_align_layer_quantized.clembed"
790 },
791 {
SiCong Li3e363692017-07-04 15:02:10 +0100792 "roi_pooling_layer.cl",
793#include "./cl_kernels/roi_pooling_layer.clembed"
794 },
795 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100796 "scale.cl",
797#include "./cl_kernels/scale.clembed"
798 },
799 {
Michalis Spyrou17220e22018-09-12 13:35:38 +0100800 "scale_quantized.cl",
801#include "./cl_kernels/scale_quantized.clembed"
802 },
803 {
Georgios Pinitasaaa27182018-11-21 16:32:15 +0000804 "select.cl",
805#include "./cl_kernels/select.clembed"
806 },
807 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100808 "softmax_layer.cl",
809#include "./cl_kernels/softmax_layer.clembed"
810 },
811 {
Chunosovf450caa2017-11-08 16:09:35 +0700812 "softmax_layer_quantized.cl",
813#include "./cl_kernels/softmax_layer_quantized.clembed"
814 },
815 {
Georgios Pinitasc1a72452018-08-24 11:25:32 +0100816 "slice_ops.cl",
817#include "./cl_kernels/slice_ops.clembed"
Georgios Pinitas77589b52018-08-21 14:41:35 +0100818 },
819 {
Michalis Spyrou16934a52018-08-21 18:03:58 +0100820 "space_to_batch.cl",
821#include "./cl_kernels/space_to_batch.clembed"
822 },
823 {
Michalis Spyroud69b3b22019-05-29 17:03:38 +0100824 "space_to_depth.cl",
825#include "./cl_kernels/space_to_depth.clembed"
826 },
827 {
Gian Marco Iodice8aa985e2018-11-27 15:58:08 +0000828 "stack_layer.cl",
829#include "./cl_kernels/stack_layer.clembed"
830 },
831 {
giuros013175fcf2018-11-21 09:59:17 +0000832 "tile.cl",
833#include "./cl_kernels/tile.clembed"
834 },
835 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100836 "transpose.cl",
837#include "./cl_kernels/transpose.clembed"
838 },
839 {
840 "types.h",
841#include "./cl_kernels/types.hembed"
842 },
843 {
Gian Marco Iodice4d81d752020-07-14 15:05:31 +0100844 "unpooling_layer.cl",
845#include "./cl_kernels/unpooling_layer.clembed"
846 },
847 {
Giorgio Arenaa50e5e02018-07-02 13:42:23 +0100848 "winograd_filter_transform.cl",
849#include "./cl_kernels/winograd_filter_transform.clembed"
850 },
851 {
852 "winograd_input_transform.cl",
853#include "./cl_kernels/winograd_input_transform.clembed"
854 },
855 {
856 "winograd_output_transform.cl",
857#include "./cl_kernels/winograd_output_transform.clembed"
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000858 },
Giorgio Arena73023022018-09-04 14:55:55 +0100859 {
860 "yolo_layer.cl",
861#include "./cl_kernels/yolo_layer.clembed"
862 },
Anthony Barbierac69aa12017-07-03 17:39:37 +0100863#endif /* EMBEDDED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100864};
865
866CLKernelLibrary::CLKernelLibrary()
Georgios Pinitasea857272021-01-22 05:47:37 +0000867 : _compile_context(), _kernel_path(), _decompressed_source_map()
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100868{
Anthony Barbierecb1c622018-04-17 11:45:10 +0100869 opencl_is_available(); // Make sure the OpenCL symbols are initialised *before* the CLKernelLibrary is built
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100870}
871
872CLKernelLibrary &CLKernelLibrary::get()
873{
874 static CLKernelLibrary _kernel_library;
875 return _kernel_library;
876}
877
Michalis Spyrou11d49182020-03-26 10:31:32 +0000878Kernel CLKernelLibrary::create_kernel(const std::string &kernel_name, const std::set<std::string> &build_options_set) const
879{
880 const std::string program_name = get_program_name(kernel_name);
881 auto program = get_program(program_name);
882
883 return _compile_context.create_kernel(kernel_name, program_name, program.first, _kernel_path, build_options_set, program.second);
884}
885
886std::string CLKernelLibrary::get_program_name(const std::string &kernel_name) const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100887{
888 // Find which program contains the kernel
889 auto kernel_program_it = _kernel_program_map.find(kernel_name);
890
891 if(_kernel_program_map.end() == kernel_program_it)
892 {
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100893 ARM_COMPUTE_ERROR_VAR("Kernel %s not found in the CLKernelLibrary", kernel_name.c_str());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100894 }
steniu0134702472017-07-11 09:22:58 +0100895
Michalis Spyrou11d49182020-03-26 10:31:32 +0000896 const std::string program_name = kernel_program_it->second;
Georgios Pinitasdf473ea2018-05-31 18:53:52 +0100897
Michalis Spyrou11d49182020-03-26 10:31:32 +0000898 return program_name;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100899}
900
Pablo Tellodb8485a2019-09-24 11:03:47 +0100901void CLKernelLibrary::init(std::string kernel_path, cl::Context context, cl::Device device)
902{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000903 _compile_context = CLCompileContext(context, device);
904 _kernel_path = kernel_path;
Pablo Tellodb8485a2019-09-24 11:03:47 +0100905}
906
907void CLKernelLibrary::set_kernel_path(const std::string &kernel_path)
908{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000909 _kernel_path = std::move(kernel_path);
Pablo Tellodb8485a2019-09-24 11:03:47 +0100910}
911
912cl::Context &CLKernelLibrary::context()
913{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000914 return _compile_context.context();
Pablo Tellodb8485a2019-09-24 11:03:47 +0100915}
916
Michalis Spyrou11d49182020-03-26 10:31:32 +0000917const cl::Device &CLKernelLibrary::get_device()
Pablo Tellodb8485a2019-09-24 11:03:47 +0100918{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000919 return _compile_context.get_device();
Pablo Tellodb8485a2019-09-24 11:03:47 +0100920}
921
922void CLKernelLibrary::set_device(cl::Device device)
923{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000924 _compile_context.set_device(device);
925}
926
927void CLKernelLibrary::set_context(cl::Context context)
928{
929 _compile_context.set_context(context);
Pablo Tellodb8485a2019-09-24 11:03:47 +0100930}
931
932std::string CLKernelLibrary::get_kernel_path()
933{
934 return _kernel_path;
935}
936
937void CLKernelLibrary::clear_programs_cache()
938{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000939 _compile_context.clear_programs_cache();
Pablo Tellodb8485a2019-09-24 11:03:47 +0100940}
941
942const std::map<std::string, cl::Program> &CLKernelLibrary::get_built_programs() const
943{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000944 return _compile_context.get_built_programs();
Pablo Tellodb8485a2019-09-24 11:03:47 +0100945}
946
giuros0146a49a02019-04-01 13:50:22 +0100947void CLKernelLibrary::add_built_program(const std::string &built_program_name, const cl::Program &program)
Anthony Barbier7da55aa2018-04-13 16:58:43 +0100948{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000949 _compile_context.add_built_program(built_program_name, program);
Anthony Barbier7da55aa2018-04-13 16:58:43 +0100950}
951
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100952bool CLKernelLibrary::fp16_supported() const
953{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000954 return _compile_context.fp16_supported();
Vidhya Sudhan Loganathanf1f49062018-05-25 13:21:26 +0100955}
956
Vidhya Sudhan Loganathan76c85642018-05-25 13:53:02 +0100957bool CLKernelLibrary::int64_base_atomics_supported() const
958{
Michalis Spyrou11d49182020-03-26 10:31:32 +0000959 return _compile_context.int64_base_atomics_supported();
Vidhya Sudhan Loganathan76c85642018-05-25 13:53:02 +0100960}
961
Manuel Bottinibe9f9f92021-01-25 15:07:17 +0000962bool CLKernelLibrary::is_wbsm_supported()
963{
964 return _compile_context.is_wbsm_supported();
965}
966
Michalis Spyrou11d49182020-03-26 10:31:32 +0000967std::pair<std::string, bool> CLKernelLibrary::get_program(const std::string &program_name) const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100968{
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100969#ifdef EMBEDDED_KERNELS
Georgios Pinitasea857272021-01-22 05:47:37 +0000970#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
971 const auto inflatted_program_source_it = _decompressed_source_map.find(program_name);
972 if(inflatted_program_source_it != _decompressed_source_map.end())
973 {
974 return std::make_pair(inflatted_program_source_it->second, false);
975 }
976#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100977
Georgios Pinitasea857272021-01-22 05:47:37 +0000978 const auto program_source_it = _program_source_map.find(program_name);
Michalis Spyroud7e82812017-06-20 15:00:14 +0100979 if(program_source_it == _program_source_map.end())
980 {
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100981 ARM_COMPUTE_ERROR_VAR("Embedded program for %s does not exist.", program_name.c_str());
Michalis Spyroud7e82812017-06-20 15:00:14 +0100982 }
Georgios Pinitasea857272021-01-22 05:47:37 +0000983 std::string program_source = program_source_it->second;
Michalis Spyroud7e82812017-06-20 15:00:14 +0100984
Georgios Pinitasea857272021-01-22 05:47:37 +0000985#ifdef ARM_COMPUTE_COMPRESSED_KERNELS
986 std::string decompressed_program_source = decompress_zlib(decode_base64(program_source_it->second));
987 ARM_COMPUTE_ERROR_ON_MSG(decompressed_program_source.empty(), "Cannot de-compress requested program");
988 _decompressed_source_map.insert(std::make_pair(program_name, decompressed_program_source));
989 program_source = std::move(decompressed_program_source);
990#endif /* ARM_COMPUTE_COMPRESSED_KERNELS */
991
992 return std::make_pair(program_source, false);
Michalis Spyrou11d49182020-03-26 10:31:32 +0000993#else /* EMBEDDED_KERNELS */
994 // Check for binary
995 std::string source_name = _kernel_path + program_name;
996 std::string binary_name = source_name + "bin";
997 std::string program_source{};
998 bool is_binary = false;
999
1000 if(std::ifstream(binary_name).is_open())
1001 {
1002 program_source = read_file(binary_name, true);
1003 is_binary = true;
1004 }
1005 else if(std::ifstream(source_name).is_open())
1006 {
1007 program_source = read_file(source_name, false);
1008 }
1009 else
1010 {
1011 ARM_COMPUTE_ERROR_VAR("Kernel file %s does not exist.", source_name.c_str());
1012 }
1013
1014 return std::make_pair(program_source, is_binary);
1015#endif /* EMBEDDED_KERNELS */
Michalis Spyroud7e82812017-06-20 15:00:14 +01001016}
steniu015f910722017-08-23 10:15:22 +01001017
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001018size_t CLKernelLibrary::max_local_workgroup_size(const cl::Kernel &kernel) const
steniu015f910722017-08-23 10:15:22 +01001019{
Michalis Spyrou11d49182020-03-26 10:31:32 +00001020 return _compile_context.max_local_workgroup_size(kernel);
steniu015f910722017-08-23 10:15:22 +01001021}
1022
Abel Bernabeu5a6e0532017-09-28 09:53:45 +01001023cl::NDRange CLKernelLibrary::default_ndrange() const
steniu015f910722017-08-23 10:15:22 +01001024{
Michalis Spyrou11d49182020-03-26 10:31:32 +00001025 return _compile_context.default_ndrange();
steniu015f910722017-08-23 10:15:22 +01001026}
Anthony Barbier847864d2018-03-07 11:35:53 +00001027
1028std::string CLKernelLibrary::get_device_version()
1029{
Michalis Spyrou11d49182020-03-26 10:31:32 +00001030 return _compile_context.get_device_version();
Anthony Barbier847864d2018-03-07 11:35:53 +00001031}
Giorgio Arena5d42b462019-07-26 15:54:20 +01001032
1033cl_uint CLKernelLibrary::get_num_compute_units()
1034{
Michalis Spyrou11d49182020-03-26 10:31:32 +00001035 return _compile_context.get_num_compute_units();
1036}
1037
1038CLCompileContext &CLKernelLibrary::get_compile_context()
1039{
1040 return _compile_context;
Michele Di Giorgio578a9fc2019-08-23 11:49:04 +01001041}