blob: 010135eb7bb0e9b7a1850b8c967b474e0026435f [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "helpers.h"
25
Anthony Barbierac69aa12017-07-03 17:39:37 +010026#ifdef FIXED_POINT_POSITION
Georgios Pinitase5f8fd62017-06-23 18:03:44 +010027
28#include "fixed_point.h"
29#define MAX_OP(x, y, type, size) MAX_OP_EXPAND(x, y, type, size)
30#define ADD_OP(x, y, type, size) ADD_SAT_OP_EXPAND((x), (y), type, size)
31#define SUB_OP(x, y, type, size) SUB_SAT_OP_EXPAND((x), (y), type, size)
Pablo Palmier48a60f92017-10-18 11:03:08 +010032#define MUL_OP(x, y, type, size) MUL_SAT_OP_EXPAND((x), (y), type, size, FIXED_POINT_POSITION)
steniu010c7614f2017-06-23 17:00:26 +010033#define DIV_OP(x, y, type, size) DIV_SAT_OP_VEC_EXPAND((x), (y), type, size, FIXED_POINT_POSITION)
Georgios Pinitase5f8fd62017-06-23 18:03:44 +010034#define EXP_OP(x, type, size) EXP_OP_EXPAND((x), type, size, FIXED_POINT_POSITION)
35
36#define MIN_VAL_EXPAND(type) type##_MIN
37#define MIN_VAL(type) MIN_VAL_EXPAND(type)
38#define MINVAL MIN_VAL(DATA_TYPE)
39#define SELECT_DATA_TYPE EXPAND(DATA_TYPE)
40
Anthony Barbierac69aa12017-07-03 17:39:37 +010041#else /* FIXED_POINT_POSITION */
Georgios Pinitase5f8fd62017-06-23 18:03:44 +010042
43#define MAX_OP(x, y, type, size) max((x), (y))
44#define ADD_OP(x, y, type, size) ((x) + (y))
45#define SUB_OP(x, y, type, size) ((x) - (y))
Pablo Palmier48a60f92017-10-18 11:03:08 +010046#define MUL_OP(x, y, type, size) ((x) * (y))
Georgios Pinitase5f8fd62017-06-23 18:03:44 +010047#define DIV_OP(x, y, type, size) ((x) / (y))
48#define EXP_OP(x, type, size) exp((x))
49
Anthony Barbierac69aa12017-07-03 17:39:37 +010050#ifdef USE_F16
Georgios Pinitase5f8fd62017-06-23 18:03:44 +010051#define MINVAL -HALF_MAX
52#define SELECT_DATA_TYPE short
Anthony Barbierac69aa12017-07-03 17:39:37 +010053#else /* USE_F16 */
Georgios Pinitase5f8fd62017-06-23 18:03:44 +010054#define MINVAL -FLT_MAX
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055#define SELECT_DATA_TYPE int
Anthony Barbierac69aa12017-07-03 17:39:37 +010056#endif /* USE_F16 */
Georgios Pinitase5f8fd62017-06-23 18:03:44 +010057
Anthony Barbierac69aa12017-07-03 17:39:37 +010058#endif /* FIXED_POINT_POSITION */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059
60__constant VEC_DATA_TYPE(DATA_TYPE, 16) type_min = (VEC_DATA_TYPE(DATA_TYPE, 16))(MINVAL);
61__constant uint16 idx16 = (uint16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
62
63/** Identifies the maximum value across the 1st dimension.
64 *
65 * @note Datatype must be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short
Georgios Pinitase5f8fd62017-06-23 18:03:44 +010066 * @note Fixed point position must be given as a preprocessor argument using -DFIXED_POINT_POSITION=pos. e.g. DFIXED_POINT_POSITION=4
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067 * @note In case the input is not multiple of 16 -DNON_MULTIPLE_OF_16 must be passed.
68 *
Georgios Pinitas09796752017-07-10 16:05:21 +010069 * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: QS8/QS16/F16/F32
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
71 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
72 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
73 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
steniu010d523cc2017-07-13 14:24:23 +010074 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
75 * @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 +010076 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
Georgios Pinitase5f8fd62017-06-23 18:03:44 +010077 * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: same as @p src_ptr
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
79 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
80 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
81 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
steniu010d523cc2017-07-13 14:24:23 +010082 * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
83 * @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 +010084 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
85 * @param[in] width Input image width
86 */
87__kernel void softmax_layer_max(
steniu010d523cc2017-07-13 14:24:23 +010088 TENSOR3D_DECLARATION(src),
89 TENSOR3D_DECLARATION(dst),
Anthony Barbier6ff3b192017-09-04 18:44:23 +010090 uint width)
91{
steniu010d523cc2017-07-13 14:24:23 +010092 Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src);
93 Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010094
95 // Initialize local maximum
96 VEC_DATA_TYPE(DATA_TYPE, 16)
97 max_val = (VEC_DATA_TYPE(DATA_TYPE, 16))type_min;
98
99 // Calculate max of row
100 const uint width4 = width >> 4;
101 for(uint i = 0; i < width4; i++)
102 {
103 VEC_DATA_TYPE(DATA_TYPE, 16)
104 data = vload16(0, (__global DATA_TYPE *)offset(&src, i << 4, 0));
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100105 max_val = MAX_OP(data, max_val, DATA_TYPE, 16);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106 }
107
Anthony Barbierac69aa12017-07-03 17:39:37 +0100108#ifdef NON_MULTIPLE_OF_16
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109 // Handle non multiple of 16
110 VEC_DATA_TYPE(DATA_TYPE, 16)
111 data = vload16(0, (__global DATA_TYPE *)offset(&src, width4 << 4, 0));
112 VEC_DATA_TYPE(SELECT_DATA_TYPE, 16)
113 widx = CONVERT(((uint16)(width4 << 4) + idx16) < width, VEC_DATA_TYPE(SELECT_DATA_TYPE, 16));
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100114 max_val = MAX_OP(max_val, select(type_min, data, widx), DATA_TYPE, 16);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100115#endif /* NON_MULTIPLE_OF_16 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100116
117 // Perform max reduction
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100118 max_val.s01234567 = MAX_OP(max_val.s01234567, max_val.s89ABCDEF, DATA_TYPE, 8);
119 max_val.s0123 = MAX_OP(max_val.s0123, max_val.s4567, DATA_TYPE, 4);
120 max_val.s01 = MAX_OP(max_val.s01, max_val.s23, DATA_TYPE, 2);
121 max_val.s0 = MAX_OP(max_val.s0, max_val.s1, DATA_TYPE, 1);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100122
123 // Store result
124 *((__global DATA_TYPE *)dst.ptr) = max_val.s0;
125}
126
127/** Shifts the values of the input tensor by the max calculated in softmax_layer_max kernel,
128 * then gets the exponent of each element as sums all elements across each row.
129 *
130 * @note Datatype must be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100131 * @note Fixed point position must be given as a preprocessor argument using -DFIXED_POINT_POSITION=pos. e.g. DFIXED_POINT_POSITION=4
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100132 * @note In case the input is not multiple of 16 -DNON_MULTIPLE_OF_16 must be passed.
Pablo Palmier48a60f92017-10-18 11:03:08 +0100133 * @note Beta can be optionally passed at compile time using -DBETA (if undefined, assume it equals 1.0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134 *
Georgios Pinitas09796752017-07-10 16:05:21 +0100135 * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: QS8/QS16/F16/F32
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100136 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
137 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
138 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
139 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
steniu010d523cc2017-07-13 14:24:23 +0100140 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
141 * @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 +0100142 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100143 * @param[in] max_ptr Pointer to the max values tensor slice. Supported data types: same as @p src_ptr
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100144 * @param[in] max_stride_x Stride of the max values tensor in X dimension (in bytes)
145 * @param[in] max_step_x max_stride_x * number of elements along X processed per workitem(in bytes)
146 * @param[in] max_stride_y Stride of the max values tensor in Y dimension (in bytes)
147 * @param[in] max_step_y max_stride_y * number of elements along Y processed per workitem(in bytes)
steniu010d523cc2017-07-13 14:24:23 +0100148 * @param[in] max_stride_z Stride of the max values tensor in Z dimension (in bytes)
149 * @param[in] max_step_z max_stride_z * number of elements along Z processed per workitem(in bytes)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100150 * @param[in] max_offset_first_element_in_bytes The offset of the first element in the max values tensor
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100151 * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: same as @p src_ptr
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
153 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
154 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
155 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
steniu010d523cc2017-07-13 14:24:23 +0100156 * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
157 * @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 +0100158 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100159 * @param[out] sum_ptr Pointer to the sum values tensor slice. Supported data types: same as @p src_ptr
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100160 * @param[in] sum_stride_x Stride of the sum values tensor in X dimension (in bytes)
161 * @param[in] sum_step_x sum_stride_x * number of elements along X processed per workitem(in bytes)
162 * @param[in] sum_stride_y Stride of the sum values tensor in Y dimension (in bytes)
steniu010d523cc2017-07-13 14:24:23 +0100163 * @param[in] sum_step_y sum_stride_z * number of elements along Z processed per workitem(in bytes)
164 * @param[in] sum_stride_z Stride of the sum values tensor in Z dimension (in bytes)
165 * @param[in] sum_step_z sum_stride_z * number of elements along Z processed per workitem(in bytes)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100166 * @param[in] sum_offset_first_element_in_bytes The offset of the first element in the sum values tensor
167 * @param[in] width Input image width
168 */
169__kernel void softmax_layer_shift_exp_sum(
steniu010d523cc2017-07-13 14:24:23 +0100170 TENSOR3D_DECLARATION(src),
171 TENSOR3D_DECLARATION(max),
172 TENSOR3D_DECLARATION(dst),
173 TENSOR3D_DECLARATION(sum),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100174 uint width)
175{
steniu010d523cc2017-07-13 14:24:23 +0100176 Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src);
177 Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
178 Image max = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(max);
179 Image sum = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(sum);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100180
Pablo Palmier48a60f92017-10-18 11:03:08 +0100181#ifdef BETA
182 // Initialize beta
183 VEC_DATA_TYPE(DATA_TYPE, 16)
184 beta = (VEC_DATA_TYPE(DATA_TYPE, 16))BETA;
185#endif /* BETA */
186
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187 // Load max value of 1D logits vector (row)
188 DATA_TYPE max_val = *((__global DATA_TYPE *)offset(&max, 0, 0));
189
190 // Set sum vector
191 VEC_DATA_TYPE(DATA_TYPE, 16)
192 sum1D = 0;
193
194 // Shift values, exp and sum
195 const uint width4 = width >> 4;
196 for(uint i = 0; i < width4; i++)
197 {
198 VEC_DATA_TYPE(DATA_TYPE, 16)
199 data = vload16(0, (__global DATA_TYPE *)offset(&src, i << 4, 0));
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100200 data = SUB_OP(data, max_val, DATA_TYPE, 16);
Pablo Palmier48a60f92017-10-18 11:03:08 +0100201#ifdef BETA
202 data = MUL_OP(data, beta, DATA_TYPE, 16);
203#endif /* BETA */
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100204 data = EXP_OP(data, DATA_TYPE, 16);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100205 vstore16(data, 0, (__global DATA_TYPE *)offset(&dst, i << 4, 0));
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100206 sum1D = ADD_OP(sum1D, data, DATA_TYPE, 16);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100207 }
208
Anthony Barbierac69aa12017-07-03 17:39:37 +0100209#ifdef NON_MULTIPLE_OF_16
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100210 // Handle non multiple of 16
211 VEC_DATA_TYPE(DATA_TYPE, 16)
212 data = vload16(0, (__global DATA_TYPE *)offset(&src, width4 << 4, 0));
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100213 data = SUB_OP(data, max_val, DATA_TYPE, 16);
Pablo Palmier48a60f92017-10-18 11:03:08 +0100214#ifdef BETA
215 data = MUL_OP(data, beta, DATA_TYPE, 16);
216#endif /* BETA */
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100217 data = EXP_OP(data, DATA_TYPE, 16);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100218 VEC_DATA_TYPE(SELECT_DATA_TYPE, 16)
219 widx = CONVERT(((uint16)(width4 << 4) + idx16) < width, VEC_DATA_TYPE(SELECT_DATA_TYPE, 16));
220 data = select(0, data, widx);
221 vstore16(data, 0, (__global DATA_TYPE *)offset(&dst, width4 << 4, 0));
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100222 sum1D = ADD_OP(sum1D, data, DATA_TYPE, 16);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100223#endif /* NON_MULTIPLE_OF_16 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100224
225 // Perform min/max reduction
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100226 sum1D.s01234567 = ADD_OP(sum1D.s01234567, sum1D.s89ABCDEF, DATA_TYPE, 8);
227 sum1D.s0123 = ADD_OP(sum1D.s0123, sum1D.s4567, DATA_TYPE, 4);
228 sum1D.s01 = ADD_OP(sum1D.s01, sum1D.s23, DATA_TYPE, 2);
229 sum1D.s0 = ADD_OP(sum1D.s0, sum1D.s1, DATA_TYPE, 1);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100230
231 // Calculate and store result
232 *((__global DATA_TYPE *)sum.ptr) = sum1D.s0;
233}
234
235/** Divides all the values of the input tensor by the sum calculated from softmax_layer_shift_exp_sum kernel.
236 *
237 * @note Datatype must be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100238 * @note Fixed point position must be given as a preprocessor argument using -DFIXED_POINT_POSITION=pos. e.g. DFIXED_POINT_POSITION=4
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100239 *
Georgios Pinitas09796752017-07-10 16:05:21 +0100240 * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: QS8/QS16/F16/F32
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100241 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
242 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
243 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
244 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
steniu010d523cc2017-07-13 14:24:23 +0100245 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
246 * @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 +0100247 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100248 * @param[in] sum_ptr Pointer to the sum values tensor slice. Supported data types: same as @p src_ptr
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100249 * @param[in] sum_stride_x Stride of the sum values tensor in X dimension (in bytes)
250 * @param[in] sum_step_x sum_stride_x * number of elements along X processed per workitem(in bytes)
251 * @param[in] sum_stride_y Stride of the sum values tensor in Y dimension (in bytes)
252 * @param[in] sum_step_y sum_stride_y * number of elements along Y processed per workitem(in bytes)
steniu010d523cc2017-07-13 14:24:23 +0100253 * @param[in] sum_stride_z Stride of the sum values tensor in Z dimension (in bytes)
254 * @param[in] sum_step_z sum_stride_z * number of elements along Z processed per workitem(in bytes)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100255 * @param[in] sum_offset_first_element_in_bytes The offset of the first element in the sum values tensor
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100256 * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: same as @p src_ptr
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100257 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
258 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
259 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
260 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
steniu010d523cc2017-07-13 14:24:23 +0100261 * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
262 * @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 +0100263 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
264 */
265__kernel void softmax_layer_norm(
steniu010d523cc2017-07-13 14:24:23 +0100266 TENSOR3D_DECLARATION(src),
267 TENSOR3D_DECLARATION(sum),
268 TENSOR3D_DECLARATION(dst))
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100269{
steniu010d523cc2017-07-13 14:24:23 +0100270 Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src);
271 Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
272 Image sum = CONVERT_TENSOR3D_TO_IMAGE_STRUCT_NO_STEP(sum);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100273
274 // Load max value of 1D logits vector (row)
275 DATA_TYPE sum_val = *((__global DATA_TYPE *)offset(&sum, 0, get_global_id(1)));
276 VEC_DATA_TYPE(DATA_TYPE, 16)
277 data = vload16(0, (__global DATA_TYPE *)offset(&src, 0, 0));
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100278 vstore16(DIV_OP(data, sum_val, DATA_TYPE, 16), 0, (__global DATA_TYPE *)offset(&dst, 0, 0));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100279}