Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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 Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 26 | #ifdef FIXED_POINT_POSITION |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 27 | |
| 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) |
| 32 | #define DIV_OP(x, y, type, size) DIV_SAT_OP_EXPAND((x), (y), type, size, FIXED_POINT_POSITION) |
| 33 | #define EXP_OP(x, type, size) EXP_OP_EXPAND((x), type, size, FIXED_POINT_POSITION) |
| 34 | |
| 35 | #define MIN_VAL_EXPAND(type) type##_MIN |
| 36 | #define MIN_VAL(type) MIN_VAL_EXPAND(type) |
| 37 | #define MINVAL MIN_VAL(DATA_TYPE) |
| 38 | #define SELECT_DATA_TYPE EXPAND(DATA_TYPE) |
| 39 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 40 | #else /* FIXED_POINT_POSITION */ |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 41 | |
| 42 | #define MAX_OP(x, y, type, size) max((x), (y)) |
| 43 | #define ADD_OP(x, y, type, size) ((x) + (y)) |
| 44 | #define SUB_OP(x, y, type, size) ((x) - (y)) |
| 45 | #define DIV_OP(x, y, type, size) ((x) / (y)) |
| 46 | #define EXP_OP(x, type, size) exp((x)) |
| 47 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 48 | #ifdef USE_F16 |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 49 | #define MINVAL -HALF_MAX |
| 50 | #define SELECT_DATA_TYPE short |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 51 | #else /* USE_F16 */ |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 52 | #define MINVAL -FLT_MAX |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | #define SELECT_DATA_TYPE int |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 54 | #endif /* USE_F16 */ |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 55 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 56 | #endif /* FIXED_POINT_POSITION */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 57 | |
| 58 | __constant VEC_DATA_TYPE(DATA_TYPE, 16) type_min = (VEC_DATA_TYPE(DATA_TYPE, 16))(MINVAL); |
| 59 | __constant uint16 idx16 = (uint16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); |
| 60 | |
| 61 | /** Identifies the maximum value across the 1st dimension. |
| 62 | * |
| 63 | * @note Datatype must be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 64 | * @note Fixed point position must be given as a preprocessor argument using -DFIXED_POINT_POSITION=pos. e.g. DFIXED_POINT_POSITION=4 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 65 | * @note In case the input is not multiple of 16 -DNON_MULTIPLE_OF_16 must be passed. |
| 66 | * |
Georgios Pinitas | 0979675 | 2017-07-10 16:05:21 +0100 | [diff] [blame] | 67 | * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: QS8/QS16/F16/F32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 69 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 70 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 71 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 72 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 73 | * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: same as @p src_ptr |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 75 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 76 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 77 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 78 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
| 79 | * @param[in] width Input image width |
| 80 | */ |
| 81 | __kernel void softmax_layer_max( |
| 82 | IMAGE_DECLARATION(src), |
| 83 | IMAGE_DECLARATION(dst), |
| 84 | uint width) |
| 85 | { |
| 86 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 87 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 88 | |
| 89 | // Initialize local maximum |
| 90 | VEC_DATA_TYPE(DATA_TYPE, 16) |
| 91 | max_val = (VEC_DATA_TYPE(DATA_TYPE, 16))type_min; |
| 92 | |
| 93 | // Calculate max of row |
| 94 | const uint width4 = width >> 4; |
| 95 | for(uint i = 0; i < width4; i++) |
| 96 | { |
| 97 | VEC_DATA_TYPE(DATA_TYPE, 16) |
| 98 | data = vload16(0, (__global DATA_TYPE *)offset(&src, i << 4, 0)); |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 99 | max_val = MAX_OP(data, max_val, DATA_TYPE, 16); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 102 | #ifdef NON_MULTIPLE_OF_16 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 103 | // Handle non multiple of 16 |
| 104 | VEC_DATA_TYPE(DATA_TYPE, 16) |
| 105 | data = vload16(0, (__global DATA_TYPE *)offset(&src, width4 << 4, 0)); |
| 106 | VEC_DATA_TYPE(SELECT_DATA_TYPE, 16) |
| 107 | widx = CONVERT(((uint16)(width4 << 4) + idx16) < width, VEC_DATA_TYPE(SELECT_DATA_TYPE, 16)); |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 108 | max_val = MAX_OP(max_val, select(type_min, data, widx), DATA_TYPE, 16); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 109 | #endif /* NON_MULTIPLE_OF_16 */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 110 | |
| 111 | // Perform max reduction |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 112 | max_val.s01234567 = MAX_OP(max_val.s01234567, max_val.s89ABCDEF, DATA_TYPE, 8); |
| 113 | max_val.s0123 = MAX_OP(max_val.s0123, max_val.s4567, DATA_TYPE, 4); |
| 114 | max_val.s01 = MAX_OP(max_val.s01, max_val.s23, DATA_TYPE, 2); |
| 115 | max_val.s0 = MAX_OP(max_val.s0, max_val.s1, DATA_TYPE, 1); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | |
| 117 | // Store result |
| 118 | *((__global DATA_TYPE *)dst.ptr) = max_val.s0; |
| 119 | } |
| 120 | |
| 121 | /** Shifts the values of the input tensor by the max calculated in softmax_layer_max kernel, |
| 122 | * then gets the exponent of each element as sums all elements across each row. |
| 123 | * |
| 124 | * @note Datatype must be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 125 | * @note Fixed point position must be given as a preprocessor argument using -DFIXED_POINT_POSITION=pos. e.g. DFIXED_POINT_POSITION=4 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 126 | * @note In case the input is not multiple of 16 -DNON_MULTIPLE_OF_16 must be passed. |
| 127 | * |
Georgios Pinitas | 0979675 | 2017-07-10 16:05:21 +0100 | [diff] [blame] | 128 | * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: QS8/QS16/F16/F32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 129 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 130 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 131 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 132 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 133 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 134 | * @param[in] max_ptr Pointer to the max values tensor slice. Supported data types: same as @p src_ptr |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 135 | * @param[in] max_stride_x Stride of the max values tensor in X dimension (in bytes) |
| 136 | * @param[in] max_step_x max_stride_x * number of elements along X processed per workitem(in bytes) |
| 137 | * @param[in] max_stride_y Stride of the max values tensor in Y dimension (in bytes) |
| 138 | * @param[in] max_step_y max_stride_y * number of elements along Y processed per workitem(in bytes) |
| 139 | * @param[in] max_offset_first_element_in_bytes The offset of the first element in the max values tensor |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 140 | * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: same as @p src_ptr |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 141 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 142 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 143 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 144 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 145 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 146 | * @param[out] sum_ptr Pointer to the sum values tensor slice. Supported data types: same as @p src_ptr |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 147 | * @param[in] sum_stride_x Stride of the sum values tensor in X dimension (in bytes) |
| 148 | * @param[in] sum_step_x sum_stride_x * number of elements along X processed per workitem(in bytes) |
| 149 | * @param[in] sum_stride_y Stride of the sum values tensor in Y dimension (in bytes) |
| 150 | * @param[in] sum_step_y sum_stride_y * number of elements along Y processed per workitem(in bytes) |
| 151 | * @param[in] sum_offset_first_element_in_bytes The offset of the first element in the sum values tensor |
| 152 | * @param[in] width Input image width |
| 153 | */ |
| 154 | __kernel void softmax_layer_shift_exp_sum( |
| 155 | IMAGE_DECLARATION(src), |
| 156 | IMAGE_DECLARATION(max), |
| 157 | IMAGE_DECLARATION(dst), |
| 158 | IMAGE_DECLARATION(sum), |
| 159 | uint width) |
| 160 | { |
| 161 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 162 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 163 | Image max = CONVERT_TO_IMAGE_STRUCT(max); |
| 164 | Image sum = CONVERT_TO_IMAGE_STRUCT(sum); |
| 165 | |
| 166 | // Load max value of 1D logits vector (row) |
| 167 | DATA_TYPE max_val = *((__global DATA_TYPE *)offset(&max, 0, 0)); |
| 168 | |
| 169 | // Set sum vector |
| 170 | VEC_DATA_TYPE(DATA_TYPE, 16) |
| 171 | sum1D = 0; |
| 172 | |
| 173 | // Shift values, exp and sum |
| 174 | const uint width4 = width >> 4; |
| 175 | for(uint i = 0; i < width4; i++) |
| 176 | { |
| 177 | VEC_DATA_TYPE(DATA_TYPE, 16) |
| 178 | data = vload16(0, (__global DATA_TYPE *)offset(&src, i << 4, 0)); |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 179 | data = SUB_OP(data, max_val, DATA_TYPE, 16); |
| 180 | data = EXP_OP(data, DATA_TYPE, 16); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 181 | vstore16(data, 0, (__global DATA_TYPE *)offset(&dst, i << 4, 0)); |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 182 | sum1D = ADD_OP(sum1D, data, DATA_TYPE, 16); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 185 | #ifdef NON_MULTIPLE_OF_16 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 186 | // Handle non multiple of 16 |
| 187 | VEC_DATA_TYPE(DATA_TYPE, 16) |
| 188 | data = vload16(0, (__global DATA_TYPE *)offset(&src, width4 << 4, 0)); |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 189 | data = SUB_OP(data, max_val, DATA_TYPE, 16); |
| 190 | data = EXP_OP(data, DATA_TYPE, 16); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 191 | VEC_DATA_TYPE(SELECT_DATA_TYPE, 16) |
| 192 | widx = CONVERT(((uint16)(width4 << 4) + idx16) < width, VEC_DATA_TYPE(SELECT_DATA_TYPE, 16)); |
| 193 | data = select(0, data, widx); |
| 194 | vstore16(data, 0, (__global DATA_TYPE *)offset(&dst, width4 << 4, 0)); |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 195 | sum1D = ADD_OP(sum1D, data, DATA_TYPE, 16); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 196 | #endif /* NON_MULTIPLE_OF_16 */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 197 | |
| 198 | // Perform min/max reduction |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 199 | sum1D.s01234567 = ADD_OP(sum1D.s01234567, sum1D.s89ABCDEF, DATA_TYPE, 8); |
| 200 | sum1D.s0123 = ADD_OP(sum1D.s0123, sum1D.s4567, DATA_TYPE, 4); |
| 201 | sum1D.s01 = ADD_OP(sum1D.s01, sum1D.s23, DATA_TYPE, 2); |
| 202 | sum1D.s0 = ADD_OP(sum1D.s0, sum1D.s1, DATA_TYPE, 1); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 203 | |
| 204 | // Calculate and store result |
| 205 | *((__global DATA_TYPE *)sum.ptr) = sum1D.s0; |
| 206 | } |
| 207 | |
| 208 | /** Divides all the values of the input tensor by the sum calculated from softmax_layer_shift_exp_sum kernel. |
| 209 | * |
| 210 | * @note Datatype must be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 211 | * @note Fixed point position must be given as a preprocessor argument using -DFIXED_POINT_POSITION=pos. e.g. DFIXED_POINT_POSITION=4 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 212 | * |
Georgios Pinitas | 0979675 | 2017-07-10 16:05:21 +0100 | [diff] [blame] | 213 | * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: QS8/QS16/F16/F32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 214 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 215 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 216 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 217 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 218 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 219 | * @param[in] sum_ptr Pointer to the sum values tensor slice. Supported data types: same as @p src_ptr |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 220 | * @param[in] sum_stride_x Stride of the sum values tensor in X dimension (in bytes) |
| 221 | * @param[in] sum_step_x sum_stride_x * number of elements along X processed per workitem(in bytes) |
| 222 | * @param[in] sum_stride_y Stride of the sum values tensor in Y dimension (in bytes) |
| 223 | * @param[in] sum_step_y sum_stride_y * number of elements along Y processed per workitem(in bytes) |
| 224 | * @param[in] sum_offset_first_element_in_bytes The offset of the first element in the sum values tensor |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 225 | * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: same as @p src_ptr |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 226 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 227 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 228 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 229 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 230 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
| 231 | */ |
| 232 | __kernel void softmax_layer_norm( |
| 233 | IMAGE_DECLARATION(src), |
| 234 | IMAGE_DECLARATION(sum), |
| 235 | IMAGE_DECLARATION(dst)) |
| 236 | { |
| 237 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 238 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 239 | Image sum = CONVERT_TO_IMAGE_STRUCT_NO_STEP(sum); |
| 240 | |
| 241 | // Load max value of 1D logits vector (row) |
| 242 | DATA_TYPE sum_val = *((__global DATA_TYPE *)offset(&sum, 0, get_global_id(1))); |
| 243 | VEC_DATA_TYPE(DATA_TYPE, 16) |
| 244 | data = vload16(0, (__global DATA_TYPE *)offset(&src, 0, 0)); |
Georgios Pinitas | e5f8fd6 | 2017-06-23 18:03:44 +0100 | [diff] [blame] | 245 | vstore16(DIV_OP(data, sum_val, DATA_TYPE, 16), 0, (__global DATA_TYPE *)offset(&dst, 0, 0)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 246 | } |