blob: dc381803e606a69127f775c2dd4c90c2a9bb38ed [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgio8e150a12018-12-21 15:20:56 +00002 * Copyright (c) 2017-2019 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 "helpers.h"
25
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +010026#if defined(DATA_TYPE) && defined(VEC_SIZE)
27
Michele Di Giorgio27400b92018-11-01 13:44:05 +000028#if defined(DEPTH) && defined(ELEMENT_SIZE)
29
30#if defined(INPUT1_WIDTH)
31
32#if ELEMENT_SIZE == 1
33#define COND_DATA_TYPE char
34#elif ELEMENT_SIZE == 2
35#define COND_DATA_TYPE short
36#elif ELEMENT_SIZE == 4
37#define COND_DATA_TYPE int
38#else // ELEMENT_SIZE
39#error "Element size not supported"
40#endif // ELEMENT_SIZE
41
42#if VEC_SIZE == 2
43#define SEQ ((int2)(0, 1))
44#elif VEC_SIZE == 4
45#define SEQ ((int4)(0, 1, 2, 3))
46#elif VEC_SIZE == 8
47#define SEQ ((int8)(0, 1, 2, 3, 4, 5, 6, 7))
48#elif VEC_SIZE == 16
49#define SEQ ((int16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15))
50#else // VEC_SIZE
51#error "Vector size not supported"
52#endif // VEC_SIZE
53/** This kernel concatenates two input tensors into the output tensor along the first dimension
54 *
55 * @note The data type has to be passed at compile time using -DDATA_TYPE. i.e. -DDATA_TYPE=float
56 * @note Vector size has to be passed at compile time using -DVEC_SIZE. i.e. -DVEC_SIZE=16
57 * @note The offset for the first spatial dimension has to be passed at compile time using -DWIDTH_OFFSET. i.e. -DWIDTH_OFFSET=128
58 * @note Tensor depth should be given as a preprocessor argument using -DDEPTH=size. e.g. -DDEPTH=16
59 * @note First input tensor width should be given as a preprocessor argument using -DINPUT1_WIDTH=width. e.g. -DINPUT1_WIDTH=8
60 *
61 * @param[in] src1_ptr Pointer to the source tensor. Supported data types: U8/S8/QASYMM8/U16/S16/F16/U32/F32
62 * @param[in] src1_stride_x Stride of the source tensor in X dimension (in bytes)
63 * @param[in] src1_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
64 * @param[in] src1_stride_y Stride of the source tensor in Y dimension (in bytes)
65 * @param[in] src1_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
66 * @param[in] src1_stride_z Stride of the source tensor in Z dimension (in bytes)
67 * @param[in] src1_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
68 * @param[in] src1_stride_w Stride of the first source tensor in Z dimension (in bytes)
69 * @param[in] src1_step_w src_stride_z * number of elements along Z processed per workitem(in bytes)
70 * @param[in] src1_offset_first_element_in_bytes The offset of the first element in the source tensor
71 * @param[in] src2_ptr Pointer to the source tensor. Supported data types: same as @p src1_ptr
72 * @param[in] src2_stride_x Stride of the source tensor in X dimension (in bytes)
73 * @param[in] src2_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
74 * @param[in] src2_stride_y Stride of the source tensor in Y dimension (in bytes)
75 * @param[in] src2_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
76 * @param[in] src2_stride_z Stride of the source tensor in Z dimension (in bytes)
77 * @param[in] src2_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
78 * @param[in] src2_stride_w Stride of the first source tensor in Z dimension (in bytes)
79 * @param[in] src2_step_w src_stride_z * number of elements along Z processed per workitem(in bytes)
80 * @param[in] src2_offset_first_element_in_bytes The offset of the first element in the source tensor
81 * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src1_ptr
82 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
83 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
84 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
85 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
86 * @param[in] dst_stride_z Stride of the source tensor in Z dimension (in bytes)
87 * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes)
88 * @param[in] dst_stride_w Stride of the destination tensor in Z dimension (in bytes)
89 * @param[in] dst_step_w output_stride_z * number of elements along Z processed per workitem(in bytes)
90 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
Michele Di Giorgio8e150a12018-12-21 15:20:56 +000091 * @param[in] src1_pad_right Right paddings of the first input tensor in unit of elements
92 * @param[in] src1_pad_left Left paddings of the second input tensor in unit of elements
Michele Di Giorgio27400b92018-11-01 13:44:05 +000093 */
94__kernel void concatenate_width_x2(
95 TENSOR4D_DECLARATION(src1),
96 TENSOR4D_DECLARATION(src2),
Michele Di Giorgio8e150a12018-12-21 15:20:56 +000097 TENSOR4D_DECLARATION(dst),
98 uint src1_pad_right,
99 uint src2_pad_left)
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000100{
101 Tensor4D dst = CONVERT_TO_TENSOR4D_STRUCT(dst, DEPTH);
102
103 // Calculate input indices
104 const int x = get_global_id(0) * (int)VEC_SIZE;
105 const int y = get_global_id(1);
106 const int z = get_global_id(2) % (int)DEPTH;
107 const int w = get_global_id(2) / (int)DEPTH;
Michele Di Giorgio8e150a12018-12-21 15:20:56 +0000108 const int x1 = min(x, (int)INPUT1_WIDTH + (int)src1_pad_right - (int)VEC_SIZE);
109 const int x2 = max(x - (int)INPUT1_WIDTH, -(int)src2_pad_left);
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000110
111 // Calculate inputs and output addresses
112 const __global uchar *in1_ptr = src1_ptr + (int)src1_offset_first_element_in_bytes + x1 * (int)src1_stride_x + y * (int)src1_stride_y + z * (int)src1_stride_z + w * (int)src1_stride_w;
113 const __global uchar *in2_ptr = src2_ptr + (int)src2_offset_first_element_in_bytes + x2 * (int)src2_stride_x + y * (int)src2_stride_y + z * (int)src2_stride_z + w * (int)src2_stride_w;
114
115 const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) src1_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in1_ptr);
116 const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) src2_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in2_ptr);
117
118 const VEC_DATA_TYPE(int, VEC_SIZE) x_coords = SEQ + (VEC_DATA_TYPE(int, VEC_SIZE))(x);
119 const VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE) cond = CONVERT(x_coords < (VEC_DATA_TYPE(int, VEC_SIZE))(INPUT1_WIDTH), VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE));
120 const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) values = select(src2_values, src1_values, cond);
121
122 VSTORE(VEC_SIZE)
123 (values, 0, (__global DATA_TYPE *)dst.ptr);
124}
125
126#if defined(INPUT2_WIDTH) && defined(INPUT3_WIDTH)
127/** This kernel concatenates four input tensors into the output tensor along the first dimension
128 *
129 * @note The data type has to be passed at compile time using -DDATA_TYPE. i.e. -DDATA_TYPE=float
130 * @note Vector size has to be passed at compile time using -DVEC_SIZE. i.e. -DVEC_SIZE=16
131 * @note The offset for the first spatial dimension has to be passed at compile time using -DWIDTH_OFFSET. i.e. -DWIDTH_OFFSET=128
132 * @note Tensor depth should be given as a preprocessor argument using -DDEPTH=size. e.g. -DDEPTH=16
133 * @note First input tensor width should be given as a preprocessor argument using -DINPUT1_WIDTH=width. e.g. -DINPUT1_WIDTH=8
134 * @note Second input tensor width should be given as a preprocessor argument using -DINPUT2_WIDTH=width. e.g. -DINPUT2_WIDTH=8
135 * @note Third input tensor width should be given as a preprocessor argument using -DINPUT3_WIDTH=width. e.g. -DINPUT3_WIDTH=8
136 *
137 * @param[in] src1_ptr Pointer to the source tensor. Supported data types: U8/S8/QASYMM8/U16/S16/F16/U32/F32
138 * @param[in] src1_stride_x Stride of the source tensor in X dimension (in bytes)
139 * @param[in] src1_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
140 * @param[in] src1_stride_y Stride of the source tensor in Y dimension (in bytes)
141 * @param[in] src1_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
142 * @param[in] src1_stride_z Stride of the source tensor in Z dimension (in bytes)
143 * @param[in] src1_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
144 * @param[in] src1_stride_w Stride of the first source tensor in Z dimension (in bytes)
145 * @param[in] src1_step_w src_stride_z * number of elements along Z processed per workitem(in bytes)
146 * @param[in] src1_offset_first_element_in_bytes The offset of the first element in the source tensor
147 * @param[in] src2_ptr Pointer to the source tensor. Supported data types: same as @p src1_ptr
148 * @param[in] src2_stride_x Stride of the source tensor in X dimension (in bytes)
149 * @param[in] src2_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
150 * @param[in] src2_stride_y Stride of the source tensor in Y dimension (in bytes)
151 * @param[in] src2_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
152 * @param[in] src2_stride_z Stride of the source tensor in Z dimension (in bytes)
153 * @param[in] src2_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
154 * @param[in] src2_stride_w Stride of the first source tensor in Z dimension (in bytes)
155 * @param[in] src2_step_w src_stride_z * number of elements along Z processed per workitem(in bytes)
156 * @param[in] src2_offset_first_element_in_bytes The offset of the first element in the source tensor
157 * @param[in] src3_ptr Pointer to the source tensor. Supported data types: same as @p src1_ptr
158 * @param[in] src3_stride_x Stride of the source tensor in X dimension (in bytes)
159 * @param[in] src3_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
160 * @param[in] src3_stride_y Stride of the source tensor in Y dimension (in bytes)
161 * @param[in] src3_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
162 * @param[in] src3_stride_z Stride of the source tensor in Z dimension (in bytes)
163 * @param[in] src3_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
164 * @param[in] src3_stride_w Stride of the first source tensor in Z dimension (in bytes)
165 * @param[in] src3_step_w src_stride_z * number of elements along Z processed per workitem(in bytes)
166 * @param[in] src3_offset_first_element_in_bytes The offset of the first element in the source tensor
167 * @param[in] src4_ptr Pointer to the source tensor. Supported data types: same as @p src1_ptr
168 * @param[in] src4_stride_x Stride of the source tensor in X dimension (in bytes)
169 * @param[in] src4_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
170 * @param[in] src4_stride_y Stride of the source tensor in Y dimension (in bytes)
171 * @param[in] src4_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
172 * @param[in] src4_stride_z Stride of the source tensor in Z dimension (in bytes)
173 * @param[in] src4_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
174 * @param[in] src4_stride_w Stride of the first source tensor in Z dimension (in bytes)
175 * @param[in] src4_step_w src_stride_z * number of elements along Z processed per workitem(in bytes)
176 * @param[in] src4_offset_first_element_in_bytes The offset of the first element in the source tensor
177 * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src1_ptr
178 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
179 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
180 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
181 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
182 * @param[in] dst_stride_z Stride of the source tensor in Z dimension (in bytes)
183 * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes)
184 * @param[in] dst_stride_w Stride of the destination tensor in Z dimension (in bytes)
185 * @param[in] dst_step_w output_stride_z * number of elements along Z processed per workitem(in bytes)
186 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
Michele Di Giorgio8e150a12018-12-21 15:20:56 +0000187 * @param[in] src1_pad_right Right paddings of the first input tensor in unit of elements
188 * @param[in] src2_pad_left Left paddings of the second input tensor in unit of elements
189 * @param[in] src2_pad_right Right paddings of the second input tensor in unit of elements
190 * @param[in] src3_pad_left Left paddings of the third input tensor in unit of elements
191 * @param[in] src3_pad_right Right paddings of the third input tensor in unit of elements
192 * @param[in] src4_pad_left Left paddings of the fourth input tensor in unit of elements
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000193 */
194__kernel void concatenate_width_x4(
195 TENSOR4D_DECLARATION(src1),
196 TENSOR4D_DECLARATION(src2),
197 TENSOR4D_DECLARATION(src3),
198 TENSOR4D_DECLARATION(src4),
Michele Di Giorgio8e150a12018-12-21 15:20:56 +0000199 TENSOR4D_DECLARATION(dst),
200 uint src1_pad_right,
201 uint src2_pad_left,
202 uint src2_pad_right,
203 uint src3_pad_left,
204 uint src3_pad_right,
205 uint src4_pad_left)
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000206{
207 Tensor4D dst = CONVERT_TO_TENSOR4D_STRUCT(dst, DEPTH);
208
209 // Calculate input indices
210 const int x = get_global_id(0) * (int)VEC_SIZE;
211 const int y = get_global_id(1);
212 const int z = get_global_id(2) % (int)DEPTH;
213 const int w = get_global_id(2) / (int)DEPTH;
214
Michele Di Giorgio8e150a12018-12-21 15:20:56 +0000215 const int x1 = min(x, (int)INPUT1_WIDTH + (int)src1_pad_right - (int)VEC_SIZE);
216 const int x2 = min(max(x - (int)INPUT1_WIDTH, -(int)src2_pad_left), (int)INPUT2_WIDTH + (int)src2_pad_right - (int)VEC_SIZE);
217 const int x3 = min(max(x - (int)INPUT1_WIDTH - (int)INPUT2_WIDTH, -(int)src3_pad_left), (int)INPUT3_WIDTH + (int)src3_pad_right - (int)VEC_SIZE);
218 const int x4 = max(x - (int)INPUT1_WIDTH - (int)INPUT2_WIDTH - (int)INPUT3_WIDTH, -(int)src4_pad_left);
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000219
220 // Calculate inputs and output addresses
221 const __global uchar *in1_ptr = src1_ptr + (int)src1_offset_first_element_in_bytes + x1 * (int)src1_stride_x + y * (int)src1_stride_y + z * (int)src1_stride_z + w * (int)src1_stride_w;
222 const __global uchar *in2_ptr = src2_ptr + (int)src2_offset_first_element_in_bytes + x2 * (int)src2_stride_x + y * (int)src2_stride_y + z * (int)src2_stride_z + w * (int)src2_stride_w;
223 const __global uchar *in3_ptr = src3_ptr + (int)src3_offset_first_element_in_bytes + x3 * (int)src3_stride_x + y * (int)src3_stride_y + z * (int)src3_stride_z + w * (int)src3_stride_w;
224 const __global uchar *in4_ptr = src4_ptr + (int)src4_offset_first_element_in_bytes + x4 * (int)src4_stride_x + y * (int)src4_stride_y + z * (int)src4_stride_z + w * (int)src4_stride_w;
225
226 const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) src1_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in1_ptr);
227 const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) src2_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in2_ptr);
228 const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) src3_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in3_ptr);
229 const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) src4_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in4_ptr);
230
231 const VEC_DATA_TYPE(int, VEC_SIZE) x_coords = SEQ + (VEC_DATA_TYPE(int, VEC_SIZE))(x);
232
233 const VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE) cond_in2 = CONVERT(x_coords < (VEC_DATA_TYPE(int, VEC_SIZE))(INPUT1_WIDTH), VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE));
234 const VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE) cond_in3 = CONVERT(x_coords < (VEC_DATA_TYPE(int, VEC_SIZE))(INPUT1_WIDTH + INPUT2_WIDTH), VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE));
235 const VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE) cond_in4 = CONVERT(x_coords < (VEC_DATA_TYPE(int, VEC_SIZE))(INPUT1_WIDTH + INPUT2_WIDTH + INPUT3_WIDTH), VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE));
236
237 VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE)
238 values = select(src2_values, src1_values, cond_in2);
239 values = select(src3_values, values, cond_in3);
240 values = select(src4_values, values, cond_in4);
241
242 VSTORE(VEC_SIZE)
243 (values, 0, (__global DATA_TYPE *)dst.ptr);
244}
245#endif /* defined(INPUT2_WIDTH) && defined(INPUT3_WIDTH) */
246#endif /* defined(INPUT1_WIDTH) */
247#endif /* defined(DEPTH) && defined(ELEMENT_SIZE) */
248
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +0100249#if defined(WIDTH_OFFSET) && defined(DEPTH)
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100250/** This kernel concatenates the input tensor into the output tensor along the first dimension
251 *
Gian Marco Iodice1d1f32c2018-08-10 09:34:11 +0100252 * @note The data type has to be passed at compile time using -DDATA_TYPE. i.e. -DDATA_TYPE=float
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +0100253 * @note Vector size has to be passed at compile time using -DVEC_SIZE. i.e. -DVEC_SIZE=16
Gian Marco Iodice1d1f32c2018-08-10 09:34:11 +0100254 * @note The offset for the first spatial dimension has to be passed at compile time using -DWIDTH_OFFSET. i.e. -DWIDTH_OFFSET=128
Michele Di Giorgio27400b92018-11-01 13:44:05 +0000255 * @note Tensor depth should be given as a preprocessor argument using -DDEPTH=size. e.g. -DDEPTH=16
Gian Marco Iodice1d1f32c2018-08-10 09:34:11 +0100256 *
257 * @param[in] src_ptr Pointer to the source tensor. Supported data types: U8/S8/QASYMM8/U16/S16/F16/U32/F32
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100258 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
259 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
260 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
261 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
262 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
263 * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +0100264 * @param[in] src_stride_w Stride of the first source tensor in Z dimension (in bytes)
265 * @param[in] src_step_w src_stride_z * number of elements along Z processed per workitem(in bytes)
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100266 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
267 * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
268 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
269 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
270 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
271 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
272 * @param[in] dst_stride_z Stride of the source tensor in Z dimension (in bytes)
273 * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes)
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +0100274 * @param[in] dst_stride_w Stride of the destination tensor in Z dimension (in bytes)
275 * @param[in] dst_step_w output_stride_z * number of elements along Z processed per workitem(in bytes)
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100276 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100277 */
278__kernel void concatenate_width(
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +0100279 TENSOR4D_DECLARATION(src),
280 TENSOR4D_DECLARATION(dst))
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100281{
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +0100282 Tensor4D src = CONVERT_TO_TENSOR4D_STRUCT(src, DEPTH);
283 Tensor4D dst = CONVERT_TO_TENSOR4D_STRUCT(dst, DEPTH);
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100284
285 VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE)
286 source_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)src.ptr);
287
288 VSTORE(VEC_SIZE)
Gian Marco Iodice1d1f32c2018-08-10 09:34:11 +0100289 (source_values, 0, (__global DATA_TYPE *)(dst.ptr) + WIDTH_OFFSET);
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100290}
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +0100291#endif /* defined(WIDTH_OFFSET) && defined(DEPTH) */
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100292
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100293/** This kernel concatenates the input tensor into the output tensor along the third dimension
294 *
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +0100295 * @note The data type has to be passed at compile time using -DDATA_TYPE. i.e. -DDATA_TYPE=float
296 * @note Vector size has to be passed at compile time using -DVEC_SIZE. i.e. -DVEC_SIZE=16
297 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100298 * @param[in] src_ptr Pointer to the source tensor. Supported data types: F16, F32
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100299 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
300 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
301 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
302 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100303 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
304 * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100305 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100306 * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100307 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
308 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
309 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
310 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100311 * @param[in] dst_stride_z Stride of the source tensor in Z dimension (in bytes)
312 * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100313 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100314 * @param[in] offsets The offsets to the first valid element of the output tensor in bytes
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100315 */
316__kernel void concatenate_depth(
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100317 TENSOR3D_DECLARATION(src),
318 TENSOR3D_DECLARATION(dst),
319 int3 offsets)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100320{
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100321 Tensor3D src = CONVERT_TO_TENSOR3D_STRUCT(src);
322 Tensor3D dst = CONVERT_TO_TENSOR3D_STRUCT(dst);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100323
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100324 VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE)
325 source_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)tensor3D_offset(&src, -offsets.x, -offsets.y, 0));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100326
Georgios Pinitasac4e8732017-07-05 17:02:25 +0100327 VSTORE(VEC_SIZE)
328 (source_values, 0, (__global DATA_TYPE *)(dst.ptr + offsets.z));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100329}
Michele Di Giorgioe6dbde02018-10-19 15:46:19 +0100330#endif /* defined(DATA_TYPE) && defined(VEC_SIZE) */