steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | ff1fe3e | 2021-01-02 09:58:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2021 Arm Limited. |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 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 | |
Moritz Pflanzer | 54f366a | 2017-09-25 15:36:14 +0100 | [diff] [blame] | 26 | #undef CONVERT_SAT |
| 27 | |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 28 | #define ADD_OP(a, b) ((a) + (b)) |
| 29 | #define MUL_OP(a, b) ((a) * (b)) |
| 30 | #define CONVERT_SAT(a, b) ((a)) |
| 31 | |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 32 | #if defined(DATA_TYPE) && defined(STRIDE_X) && defined(WEIGHTS_DEPTH) |
| 33 | |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 34 | #if STRIDE_X == 1 |
| 35 | #define CONVOLUTION1x3(acc, src_row_ptr, weights_row_ptr) CONVOLUTION1x3_STRIDE1(acc, src_row_ptr, weights_row_ptr) |
| 36 | #elif STRIDE_X == 2 /* STRIDE_X == 1 */ |
| 37 | #define CONVOLUTION1x3(acc, src_row_ptr, weights_row_ptr) CONVOLUTION1x3_STRIDE2(acc, src_row_ptr, weights_row_ptr) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 38 | #else /* STRIDE_X not equals 1 or 2 */ |
| 39 | #error "STRIDE_X larger than 2 is not supported" |
| 40 | #endif /* STRIDE_X == 2 */ |
| 41 | |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 42 | #define CONVOLUTION1x3_STRIDE1(acc, src_row_ptr, weights_row_ptr) \ |
| 43 | ({ \ |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 44 | VEC_DATA_TYPE(DATA_TYPE, 3) \ |
| 45 | weights_values0 = vload3(0, weights_row_ptr); \ |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 46 | VEC_DATA_TYPE(DATA_TYPE, 8) \ |
| 47 | src0 = vload8(0, src_row_ptr); \ |
| 48 | VEC_DATA_TYPE(DATA_TYPE, 2) \ |
| 49 | src1 = vload2(0, src_row_ptr + 8); \ |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 50 | \ |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 51 | acc = ADD_OP(acc, MUL_OP(src0, (VEC_DATA_TYPE(DATA_TYPE, 8))weights_values0.s0)); \ |
| 52 | acc = ADD_OP(acc, MUL_OP((VEC_DATA_TYPE(DATA_TYPE, 8))(src0.s1234, src0.s567, src1.s0), (VEC_DATA_TYPE(DATA_TYPE, 8))weights_values0.s1)); \ |
| 53 | acc = ADD_OP(acc, MUL_OP((VEC_DATA_TYPE(DATA_TYPE, 8))(src0.s234, src0.s567, src1.s01), (VEC_DATA_TYPE(DATA_TYPE, 8))weights_values0.s2)); \ |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 54 | }) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 55 | |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 56 | #define CONVOLUTION1x3_STRIDE2(acc, src_row_ptr, weights_row_ptr) \ |
| 57 | ({ \ |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 58 | VEC_DATA_TYPE(DATA_TYPE, 3) \ |
| 59 | weights_values0 = vload3(0, weights_row_ptr); \ |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 60 | VEC_DATA_TYPE(DATA_TYPE, 16) \ |
| 61 | src0 = vload16(0, src_row_ptr); \ |
| 62 | DATA_TYPE src1 = *(src_row_ptr + 16); \ |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 63 | \ |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 64 | acc = ADD_OP(acc, MUL_OP(src0.even, (VEC_DATA_TYPE(DATA_TYPE, 8))weights_values0.s0)); \ |
| 65 | acc = ADD_OP(acc, MUL_OP((VEC_DATA_TYPE(DATA_TYPE, 8))(src0.s1357, src0.s9BDF), (VEC_DATA_TYPE(DATA_TYPE, 8))weights_values0.s1)); \ |
| 66 | acc = ADD_OP(acc, MUL_OP((VEC_DATA_TYPE(DATA_TYPE, 8))(src0.s2468, src0.sACE, src1), (VEC_DATA_TYPE(DATA_TYPE, 8))weights_values0.s2)); \ |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 67 | }) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 68 | |
| 69 | /** This kernel performs a direct convolution to convolve the low three dimensions. |
| 70 | * |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 71 | * @note This OpenCL kernel works with stride_x = 1 and 2 |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 72 | * @note The data type must be passed at compile time using -DDATA_TYPE: e.g. -DDATA_TYPE=float |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 73 | * @note The third dimensions of the weights tensors must be passed at compile time using -DWEIGHTS_DEPTH |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 74 | * @note If biases are used then -DHAS_BIAS has to be passed at compile time |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 75 | * |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 76 | * @param[in] src_ptr Pointer to the source tensor. Supported data types: F16/F32 |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 77 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 78 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 79 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 80 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 81 | * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) |
| 82 | * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes) |
| 83 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
| 84 | * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr |
| 85 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 86 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 87 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 88 | * @param[in] dst_step_y dst_stride_y * number of elements along Z processed per workitem(in bytes) |
| 89 | * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) |
| 90 | * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes) |
| 91 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
Joel Liang | f1f3ebd | 2017-11-10 09:59:19 +0800 | [diff] [blame] | 92 | * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: same as @p src_ptr |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 93 | * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes) |
| 94 | * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes) |
| 95 | * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes) |
| 96 | * @param[in] weights_step_y weights_stride_y * number of elements along y processed per workitem(in bytes) |
| 97 | * @param[in] weights_stride_z Stride of the weights tensor in Z dimension (in bytes) |
| 98 | * @param[in] weights_step_z weights_stride_z * number of elements along Z processed per workitem(in bytes) |
| 99 | * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor |
| 100 | * @param[in] biases_ptr Pointer to the biases tensor. Same as @p src_ptr |
| 101 | * @param[in] biases_stride_x Stride of the biases tensor in X dimension (in bytes) |
| 102 | * @param[in] biases_step_x biases_stride_x * number of elements along X processed per workitem(in bytes) |
| 103 | * @param[in] biases_offset_first_element_in_bytes The offset of the first element in the biases tensor |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 104 | * @param[in] weights_stride_w Stride of the weights tensor in the 4th dimension |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 105 | */ |
| 106 | __kernel void direct_convolution3x3( |
| 107 | TENSOR3D_DECLARATION(src), |
| 108 | TENSOR3D_DECLARATION(dst), |
| 109 | TENSOR3D_DECLARATION(weights), |
| 110 | #ifdef HAS_BIAS |
| 111 | VECTOR_DECLARATION(biases), |
| 112 | #endif /* defined(HAS_BIAS) */ |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 113 | unsigned int weights_stride_w) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 114 | { |
| 115 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 116 | Tensor3D weights = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(weights); |
| 117 | Tensor3D dst = CONVERT_TO_TENSOR3D_STRUCT(dst); |
| 118 | |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 119 | VEC_DATA_TYPE(DATA_TYPE_PROMOTED, 8) |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 120 | values0 = 0; |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 121 | |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 122 | __global uchar *weights_addr = (__global uchar *)tensor3D_offset(&weights, 0, 0, 0); |
| 123 | __global uchar *src_addr = (__global uchar *)offset(&src, 0, 0); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 124 | |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 125 | const int kernel_index = get_global_id(2); |
| 126 | weights_addr += kernel_index * weights_stride_w; |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 127 | |
Gian Marco Iodice | 744b5ed | 2017-10-06 15:44:27 +0100 | [diff] [blame] | 128 | for(volatile int d = 0; d < WEIGHTS_DEPTH; ++d) |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 129 | { |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 130 | CONVOLUTION1x3(values0, (__global DATA_TYPE *)(src_addr + 0 * src_stride_y), (__global DATA_TYPE *)(weights_addr + 0 * weights_stride_y)); |
| 131 | CONVOLUTION1x3(values0, (__global DATA_TYPE *)(src_addr + 1 * src_stride_y), (__global DATA_TYPE *)(weights_addr + 1 * weights_stride_y)); |
| 132 | CONVOLUTION1x3(values0, (__global DATA_TYPE *)(src_addr + 2 * src_stride_y), (__global DATA_TYPE *)(weights_addr + 2 * weights_stride_y)); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 133 | |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 134 | src_addr += src_stride_z; |
| 135 | weights_addr += weights_stride_z; |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | #ifdef HAS_BIAS |
Gian Marco Iodice | 5cb4d6a | 2017-08-08 10:53:00 +0100 | [diff] [blame] | 139 | Vector biases = CONVERT_TO_VECTOR_STRUCT_NO_STEP(biases); |
| 140 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 141 | values0 = ADD_OP(values0, (VEC_DATA_TYPE(DATA_TYPE_PROMOTED, 8)) * ((__global DATA_TYPE *)(vector_offset(&biases, kernel_index)))); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 142 | #endif /* defined(HAS_BIAS) */ |
| 143 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 144 | vstore8(CONVERT_SAT(values0, VEC_DATA_TYPE(DATA_TYPE, 8)), 0, (__global DATA_TYPE *)dst.ptr); |
steniu01 | 27b386c | 2017-07-18 17:37:43 +0100 | [diff] [blame] | 145 | } |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 146 | #endif //defined(DATA_TYPE) && defined(STRIDE_X) && defined(WEIGHTS_DEPTH) |
| 147 | |
| 148 | #if defined(WEIGHTS_DEPTH) |
| 149 | |
| 150 | #define CONVOLUTION1x3_BIFROST(acc, src0, src1, weights_row0) \ |
| 151 | ({ \ |
| 152 | acc.s0 = mad(src0.s0, weights_row0.s0, acc.s0); \ |
| 153 | acc.s1 = mad(src0.s1, weights_row0.s0, acc.s1); \ |
| 154 | acc.s2 = mad(src0.s2, weights_row0.s0, acc.s2); \ |
| 155 | acc.s3 = mad(src0.s3, weights_row0.s0, acc.s3); \ |
| 156 | acc.s0 = mad(src0.s1, weights_row0.s1, acc.s0); \ |
| 157 | acc.s1 = mad(src0.s2, weights_row0.s1, acc.s1); \ |
| 158 | acc.s2 = mad(src0.s3, weights_row0.s1, acc.s2); \ |
| 159 | acc.s3 = mad(src1.s0, weights_row0.s1, acc.s3); \ |
| 160 | acc.s0 = mad(src0.s2, weights_row0.s2, acc.s0); \ |
| 161 | acc.s1 = mad(src0.s3, weights_row0.s2, acc.s1); \ |
| 162 | acc.s2 = mad(src1.s0, weights_row0.s2, acc.s2); \ |
| 163 | acc.s3 = mad(src1.s1, weights_row0.s2, acc.s3); \ |
| 164 | }) |
| 165 | |
| 166 | /** An optimized direct convolution 3x3 OpenCL kernel for Bifrost architectures when the data type is F32 |
| 167 | * |
| 168 | * @note This OpenCL kernel works only with stride_x and stride_y equal to 1 |
| 169 | * @note The third dimensions of the weights tensors must be passed at compile time using -DWEIGHTS_DEPTH |
| 170 | * @note In case biases, -DHAS_BIAS must to be passed at compile |
| 171 | * |
| 172 | * @param[in] src_ptr Pointer to the source tensor. Supported data types: F32 |
| 173 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 174 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 175 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 176 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 177 | * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) |
| 178 | * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes) |
| 179 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
| 180 | * @param[out] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr |
| 181 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 182 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 183 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 184 | * @param[in] dst_step_y dst_stride_y * number of elements along Z processed per workitem(in bytes) |
| 185 | * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) |
| 186 | * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes) |
| 187 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
Joel Liang | f1f3ebd | 2017-11-10 09:59:19 +0800 | [diff] [blame] | 188 | * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: same as @p src_ptr |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 189 | * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes) |
| 190 | * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes) |
| 191 | * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes) |
| 192 | * @param[in] weights_step_y weights_stride_y * number of elements along y processed per workitem(in bytes) |
| 193 | * @param[in] weights_stride_z Stride of the weights tensor in Z dimension (in bytes) |
| 194 | * @param[in] weights_step_z weights_stride_z * number of elements along Z processed per workitem(in bytes) |
| 195 | * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor |
| 196 | * @param[in] biases_ptr Pointer to the biases tensor. Same as @p src_ptr |
| 197 | * @param[in] biases_stride_x Stride of the biases tensor in X dimension (in bytes) |
| 198 | * @param[in] biases_step_x biases_stride_x * number of elements along X processed per workitem(in bytes) |
| 199 | * @param[in] biases_offset_first_element_in_bytes The offset of the first element in the biases tensor |
| 200 | * @param[in] weights_stride_w Stride of the weights tensor in the 4th dimension |
| 201 | */ |
| 202 | __kernel void direct_convolution3x3_f32_bifrost( |
| 203 | TENSOR3D_DECLARATION(src), |
| 204 | TENSOR3D_DECLARATION(dst), |
| 205 | TENSOR3D_DECLARATION(weights), |
| 206 | #ifdef HAS_BIAS |
| 207 | VECTOR_DECLARATION(biases), |
| 208 | #endif /* defined(HAS_BIAS) */ |
| 209 | unsigned int weights_stride_w) |
| 210 | { |
| 211 | // Get the kernel index |
| 212 | const int kernel_index = get_global_id(2); |
| 213 | |
| 214 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 215 | Tensor3D dst = CONVERT_TO_TENSOR3D_STRUCT(dst); |
| 216 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 217 | float4 values0 = 0; |
| 218 | float4 values1 = 0; |
| 219 | float4 values2 = 0; |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 220 | |
| 221 | __global uchar *weights_addr = (__global uchar *)(weights_ptr + weights_offset_first_element_in_bytes + kernel_index * weights_stride_w); |
| 222 | __global uchar *src_addr = (__global uchar *)offset(&src, 0, 0); |
| 223 | |
| 224 | // Note: Since each work-item computes 4x3 elements, we need to load 5 rows from the input tensor |
| 225 | |
| 226 | for(ushort d = 0; d < (ushort)WEIGHTS_DEPTH; ++d) |
| 227 | { |
| 228 | // Load the weights |
| 229 | float3 weights_row0 = vload3(0, (__global float *)(weights_addr + 0 * weights_stride_y)); |
| 230 | float3 weights_row1 = vload3(0, (__global float *)(weights_addr + 1 * weights_stride_y)); |
| 231 | float3 weights_row2 = vload3(0, (__global float *)(weights_addr + 2 * weights_stride_y)); |
| 232 | float4 src0; |
| 233 | float2 src1; |
| 234 | |
| 235 | // Load values from row0 of input tensor |
| 236 | src0 = vload4(0, (__global float *)(src_addr + 0 * src_stride_y)); |
| 237 | src1 = vload2(0, (__global float *)(src_addr + 0 * src_stride_y) + 4); |
| 238 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 239 | CONVOLUTION1x3_BIFROST(values0, src0, src1, weights_row0); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 240 | |
| 241 | // Load values from row1 of input tensor |
| 242 | src0 = vload4(0, (__global float *)(src_addr + 1 * src_stride_y)); |
| 243 | src1 = vload2(0, (__global float *)(src_addr + 1 * src_stride_y) + 4); |
| 244 | |
| 245 | // Accumulate |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 246 | CONVOLUTION1x3_BIFROST(values0, src0, src1, weights_row1); |
| 247 | CONVOLUTION1x3_BIFROST(values1, src0, src1, weights_row0); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 248 | |
| 249 | // Load values from row2 of input tensor |
| 250 | src0 = vload4(0, (__global float *)(src_addr + 2 * src_stride_y)); |
| 251 | src1 = vload2(0, (__global float *)(src_addr + 2 * src_stride_y) + 4); |
| 252 | |
| 253 | // Accumulate |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 254 | CONVOLUTION1x3_BIFROST(values0, src0, src1, weights_row2); |
| 255 | CONVOLUTION1x3_BIFROST(values1, src0, src1, weights_row1); |
| 256 | CONVOLUTION1x3_BIFROST(values2, src0, src1, weights_row0); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 257 | |
| 258 | // Load values from row3 of input tensor |
| 259 | src0 = vload4(0, (__global float *)(src_addr + 3 * src_stride_y)); |
| 260 | src1 = vload2(0, (__global float *)(src_addr + 3 * src_stride_y) + 4); |
| 261 | |
| 262 | // Accumulate |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 263 | CONVOLUTION1x3_BIFROST(values1, src0, src1, weights_row2); |
| 264 | CONVOLUTION1x3_BIFROST(values2, src0, src1, weights_row1); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 265 | |
| 266 | // Row4 |
| 267 | src0 = vload4(0, (__global float *)(src_addr + 4 * src_stride_y)); |
| 268 | src1 = vload2(0, (__global float *)(src_addr + 4 * src_stride_y) + 4); |
| 269 | |
| 270 | // Accumulate |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 271 | CONVOLUTION1x3_BIFROST(values2, src0, src1, weights_row2); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 272 | |
| 273 | src_addr += src_stride_z; |
| 274 | weights_addr += weights_stride_z; |
| 275 | } |
| 276 | |
| 277 | #ifdef HAS_BIAS |
| 278 | Vector biases = CONVERT_TO_VECTOR_STRUCT_NO_STEP(biases); |
| 279 | |
Gian Marco Iodice | 1c8409d | 2017-09-06 17:24:25 +0100 | [diff] [blame] | 280 | float bias = (float) * ((__global float *)(vector_offset(&biases, kernel_index))); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 281 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 282 | values0 += (float4)bias; |
| 283 | values1 += (float4)bias; |
| 284 | values2 += (float4)bias; |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 285 | #endif /* defined(HAS_BIAS) */ |
| 286 | |
Pablo Tello | 3d31946 | 2018-06-21 15:13:17 +0100 | [diff] [blame] | 287 | vstore4(values0, 0, (__global float *)(dst.ptr + 0 * dst_stride_y)); |
| 288 | vstore4(values1, 0, (__global float *)(dst.ptr + 1 * dst_stride_y)); |
| 289 | vstore4(values2, 0, (__global float *)(dst.ptr + 2 * dst_stride_y)); |
Gian Marco Iodice | 1246b63 | 2017-08-16 18:38:32 +0100 | [diff] [blame] | 290 | } |
| 291 | #endif // defined(WEIGHTS_DEPTH) |