Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | 4646d2e | 2019-06-19 12:28:47 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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 "arm_compute/core/NEON/kernels/NELocallyConnectedMatrixMultiplyKernel.h" |
| 25 | |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CPP/Validate.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/Helpers.h" |
| 29 | #include "arm_compute/core/IAccessWindow.h" |
| 30 | #include "arm_compute/core/ITensor.h" |
| 31 | #include "arm_compute/core/NEON/NEFixedPoint.h" |
| 32 | #include "arm_compute/core/TensorInfo.h" |
| 33 | #include "arm_compute/core/Types.h" |
| 34 | #include "arm_compute/core/Utils.h" |
| 35 | #include "arm_compute/core/Validate.h" |
| 36 | #include "arm_compute/core/Window.h" |
| 37 | |
| 38 | #include <arm_neon.h> |
| 39 | #include <cstddef> |
| 40 | #include <cstdint> |
| 41 | #include <tuple> |
| 42 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | namespace arm_compute |
| 44 | { |
| 45 | class Coordinates; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 46 | |
| 47 | namespace |
| 48 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 49 | void vector_matrix_multiply_f16(const ITensor *input0, const ITensor *input1, ITensor *output, const Window &window, const ThreadInfo &info) |
Pablo Tello | afde732 | 2017-07-25 09:19:46 +0100 | [diff] [blame] | 50 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 51 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Pablo Tello | afde732 | 2017-07-25 09:19:46 +0100 | [diff] [blame] | 52 | const auto width_matrix_b = static_cast<int>(output->info()->dimension(0)); |
| 53 | const auto in_b_stride = static_cast<int>(input1->info()->strides_in_bytes()[1] / data_size_from_type(input1->info()->data_type())); |
| 54 | const auto num_elems_vec_a = static_cast<int>(input0->info()->dimension(0)); |
| 55 | |
| 56 | // The implementation computes 16 elements per iteration |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 57 | const int window_start_x = 16 * info.thread_id; |
| 58 | const int window_step_x = 16 * info.num_threads; |
Pablo Tello | afde732 | 2017-07-25 09:19:46 +0100 | [diff] [blame] | 59 | // Make sure (window_end_x - window_start_x) is a multiple of window_step_x |
| 60 | const int window_end_x = ceil_to_multiple(width_matrix_b - window_start_x, window_step_x) + window_start_x; |
| 61 | |
| 62 | Window win_out(window); |
| 63 | win_out.set(Window::DimX, Window::Dimension(window_start_x, window_end_x, window_step_x)); |
| 64 | |
| 65 | Window win_a(window); |
| 66 | win_a.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 67 | |
| 68 | Iterator ina(input0, win_a); |
| 69 | Iterator out(output, win_out); |
| 70 | |
| 71 | execute_window_loop(win_out, [&](const Coordinates & id) |
| 72 | { |
| 73 | if(id.x() > width_matrix_b) |
| 74 | { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | float16x8_t acc0 = vdupq_n_f16(0.f); |
| 79 | float16x8_t acc1 = vdupq_n_f16(0.f); |
| 80 | float16x8_t acc2 = vdupq_n_f16(0.f); |
| 81 | float16x8_t acc3 = vdupq_n_f16(0.f); |
| 82 | |
| 83 | auto vec_a = reinterpret_cast<const float16_t *>(ina.ptr()); |
| 84 | auto matrix_b = reinterpret_cast<const float16_t *>(input1->ptr_to_element(Coordinates(id[0], 0, id[1]))); |
| 85 | |
| 86 | const float16_t *vec_a_end_addr = vec_a + num_elems_vec_a; |
| 87 | |
| 88 | for(; vec_a <= (vec_a_end_addr - 4);) |
| 89 | { |
| 90 | const float16x4_t a0l = vld1_f16(vec_a); |
| 91 | |
| 92 | float16x8_t b00 = vld1q_f16(matrix_b); |
| 93 | float16x8_t b01 = vld1q_f16(matrix_b + 8 + 0 * in_b_stride); |
| 94 | float16x8_t b02 = vld1q_f16(matrix_b + 16 + 0 * in_b_stride); |
| 95 | float16x8_t b03 = vld1q_f16(matrix_b + 24 + 0 * in_b_stride); |
| 96 | |
| 97 | float16x8_t b10 = vld1q_f16(matrix_b + 0 + 1 * in_b_stride); |
| 98 | float16x8_t b11 = vld1q_f16(matrix_b + 8 + 1 * in_b_stride); |
| 99 | float16x8_t b12 = vld1q_f16(matrix_b + 16 + 1 * in_b_stride); |
| 100 | float16x8_t b13 = vld1q_f16(matrix_b + 24 + 1 * in_b_stride); |
| 101 | |
| 102 | acc0 = vaddq_f16(acc0, vmulq_lane_f16(b00, a0l, 0)); |
| 103 | acc1 = vaddq_f16(acc1, vmulq_lane_f16(b01, a0l, 0)); |
| 104 | acc2 = vaddq_f16(acc2, vmulq_lane_f16(b02, a0l, 0)); |
| 105 | acc3 = vaddq_f16(acc3, vmulq_lane_f16(b03, a0l, 0)); |
| 106 | acc0 = vaddq_f16(acc0, vmulq_lane_f16(b10, a0l, 1)); |
| 107 | acc1 = vaddq_f16(acc1, vmulq_lane_f16(b11, a0l, 1)); |
| 108 | acc2 = vaddq_f16(acc2, vmulq_lane_f16(b12, a0l, 1)); |
| 109 | acc3 = vaddq_f16(acc3, vmulq_lane_f16(b13, a0l, 1)); |
| 110 | |
| 111 | matrix_b += 2 * in_b_stride; |
| 112 | |
| 113 | b00 = vld1q_f16(matrix_b); |
| 114 | b01 = vld1q_f16(matrix_b + 8 + 0 * in_b_stride); |
| 115 | b02 = vld1q_f16(matrix_b + 16 + 0 * in_b_stride); |
| 116 | b03 = vld1q_f16(matrix_b + 24 + 0 * in_b_stride); |
| 117 | b10 = vld1q_f16(matrix_b + 0 + 1 * in_b_stride); |
| 118 | b11 = vld1q_f16(matrix_b + 8 + 1 * in_b_stride); |
| 119 | b12 = vld1q_f16(matrix_b + 16 + 1 * in_b_stride); |
| 120 | b13 = vld1q_f16(matrix_b + 24 + 1 * in_b_stride); |
| 121 | |
| 122 | acc0 = vaddq_f16(acc0, vmulq_lane_f16(b00, a0l, 2)); |
| 123 | acc1 = vaddq_f16(acc1, vmulq_lane_f16(b01, a0l, 2)); |
| 124 | acc2 = vaddq_f16(acc2, vmulq_lane_f16(b02, a0l, 2)); |
| 125 | acc3 = vaddq_f16(acc3, vmulq_lane_f16(b03, a0l, 2)); |
| 126 | acc0 = vaddq_f16(acc0, vmulq_lane_f16(b10, a0l, 3)); |
| 127 | acc1 = vaddq_f16(acc1, vmulq_lane_f16(b11, a0l, 3)); |
| 128 | acc2 = vaddq_f16(acc2, vmulq_lane_f16(b12, a0l, 3)); |
| 129 | acc3 = vaddq_f16(acc3, vmulq_lane_f16(b13, a0l, 3)); |
| 130 | |
| 131 | vec_a += 4; |
| 132 | matrix_b += 2 * in_b_stride; |
| 133 | } |
| 134 | |
| 135 | for(; vec_a < vec_a_end_addr;) |
| 136 | { |
| 137 | const float16_t a0 = *vec_a; |
| 138 | const float16x8_t b00 = vld1q_f16(matrix_b); |
| 139 | const float16x8_t b01 = vld1q_f16(matrix_b + 8 + 0 * in_b_stride); |
| 140 | const float16x8_t b02 = vld1q_f16(matrix_b + 16 + 0 * in_b_stride); |
| 141 | const float16x8_t b03 = vld1q_f16(matrix_b + 24 + 0 * in_b_stride); |
| 142 | |
| 143 | acc0 = vaddq_f16(acc0, vmulq_n_f16(b00, a0)); |
| 144 | acc1 = vaddq_f16(acc1, vmulq_n_f16(b01, a0)); |
| 145 | acc2 = vaddq_f16(acc2, vmulq_n_f16(b02, a0)); |
| 146 | acc3 = vaddq_f16(acc3, vmulq_n_f16(b03, a0)); |
| 147 | |
| 148 | vec_a += 1; |
| 149 | matrix_b += in_b_stride; |
| 150 | } |
| 151 | |
| 152 | const auto vec_out = reinterpret_cast<float16_t *>(out.ptr()); |
| 153 | |
| 154 | vst1q_f16(vec_out + 0, acc0); |
| 155 | vst1q_f16(vec_out + 8, acc1); |
| 156 | vst1q_f16(vec_out + 16, acc2); |
| 157 | vst1q_f16(vec_out + 24, acc3); |
| 158 | }, |
| 159 | ina, out); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 160 | #else /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Pablo Tello | afde732 | 2017-07-25 09:19:46 +0100 | [diff] [blame] | 161 | ARM_COMPUTE_UNUSED(input0); |
| 162 | ARM_COMPUTE_UNUSED(input1); |
| 163 | ARM_COMPUTE_UNUSED(output); |
| 164 | ARM_COMPUTE_UNUSED(window); |
Georgios Pinitas | 30f0215 | 2017-09-27 11:20:48 +0100 | [diff] [blame] | 165 | ARM_COMPUTE_UNUSED(info); |
Pablo Tello | afde732 | 2017-07-25 09:19:46 +0100 | [diff] [blame] | 166 | ARM_COMPUTE_ERROR("Not supported, recompile with -march=armv8.2-a+fp16+simd."); |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 167 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Pablo Tello | afde732 | 2017-07-25 09:19:46 +0100 | [diff] [blame] | 168 | } |
| 169 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 170 | void vector_matrix_multiply_f32(const ITensor *input0, const ITensor *input1, ITensor *output, const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 171 | { |
| 172 | const auto width_matrix_b = static_cast<int>(output->info()->dimension(0)); |
| 173 | const auto in_b_stride = static_cast<int>(input1->info()->strides_in_bytes()[1] / data_size_from_type(input1->info()->data_type())); |
| 174 | const auto num_elems_vec_a = static_cast<int>(input0->info()->dimension(0)); |
| 175 | |
| 176 | // The implementation computes 16 elements per iteration |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 177 | const int window_start_x = 16 * info.thread_id; |
| 178 | const int window_step_x = 16 * info.num_threads; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 179 | // Make sure (window_end_x - window_start_x) is a multiple of window_step_x |
| 180 | const int window_end_x = ceil_to_multiple(width_matrix_b - window_start_x, window_step_x) + window_start_x; |
| 181 | |
| 182 | Window win_out(window); |
| 183 | win_out.set(Window::DimX, Window::Dimension(window_start_x, window_end_x, window_step_x)); |
| 184 | |
| 185 | Window win_a(window); |
Sanghoon Lee | f47bfb9 | 2018-01-23 15:16:47 +0000 | [diff] [blame] | 186 | win_a.set(Window::DimX, Window::Dimension(0, 0, 0)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 187 | |
| 188 | Iterator ina(input0, win_a); |
| 189 | Iterator out(output, win_out); |
| 190 | |
| 191 | execute_window_loop(win_out, [&](const Coordinates & id) |
| 192 | { |
| 193 | if(id.x() > width_matrix_b) |
| 194 | { |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | float32x4_t acc0 = vdupq_n_f32(0.f); |
| 199 | float32x4_t acc1 = vdupq_n_f32(0.f); |
| 200 | float32x4_t acc2 = vdupq_n_f32(0.f); |
| 201 | float32x4_t acc3 = vdupq_n_f32(0.f); |
| 202 | |
| 203 | auto vec_a = reinterpret_cast<const float *>(ina.ptr()); |
| 204 | auto matrix_b = reinterpret_cast<const float *>(input1->ptr_to_element(Coordinates(id[0], 0, id[1]))); |
| 205 | |
| 206 | #if __arm__ |
| 207 | asm volatile("PLD [%0, #128*4]" ::"r"(reinterpret_cast<const uint8_t *>(vec_a))); |
| 208 | asm volatile("PLD [%0, #128*4]" ::"r"(reinterpret_cast<const uint8_t *>(matrix_b))); |
| 209 | asm volatile("PLD [%0, #128*4]" ::"r"(reinterpret_cast<const uint8_t *>(matrix_b + in_b_stride))); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 210 | #endif /* __arm__ */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 211 | |
| 212 | const float *vec_a_end_addr = vec_a + num_elems_vec_a; |
| 213 | |
| 214 | for(; vec_a <= (vec_a_end_addr - 4);) |
| 215 | { |
| 216 | float32x2_t a0l = vld1_f32(vec_a); |
| 217 | |
| 218 | float32x4_t b00 = vld1q_f32(matrix_b + 0 + 0 * in_b_stride); |
| 219 | float32x4_t b01 = vld1q_f32(matrix_b + 4 + 0 * in_b_stride); |
| 220 | float32x4_t b02 = vld1q_f32(matrix_b + 8 + 0 * in_b_stride); |
| 221 | float32x4_t b03 = vld1q_f32(matrix_b + 12 + 0 * in_b_stride); |
| 222 | |
| 223 | float32x4_t b10 = vld1q_f32(matrix_b + 0 + 1 * in_b_stride); |
| 224 | float32x4_t b11 = vld1q_f32(matrix_b + 4 + 1 * in_b_stride); |
| 225 | float32x4_t b12 = vld1q_f32(matrix_b + 8 + 1 * in_b_stride); |
| 226 | float32x4_t b13 = vld1q_f32(matrix_b + 12 + 1 * in_b_stride); |
| 227 | |
| 228 | #if __arm__ |
| 229 | asm volatile("PLD [%0, #128*4]" ::"r"(reinterpret_cast<const uint8_t *>(vec_a))); |
| 230 | asm volatile("PLD [%0, #128*1]" ::"r"(reinterpret_cast<const uint8_t *>(matrix_b + 1 * in_b_stride))); |
| 231 | asm volatile("PLD [%0, #128*1]" ::"r"(reinterpret_cast<const uint8_t *>(matrix_b + 2 * in_b_stride))); |
| 232 | asm volatile("PLD [%0, #128*1]" ::"r"(reinterpret_cast<const uint8_t *>(matrix_b + 3 * in_b_stride))); |
| 233 | asm volatile("PLD [%0, #128*1]" ::"r"(reinterpret_cast<const uint8_t *>(matrix_b + 4 * in_b_stride))); |
Sanghoon Lee | f47bfb9 | 2018-01-23 15:16:47 +0000 | [diff] [blame] | 234 | #endif /* __arm__ */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 235 | |
| 236 | acc0 = vmlaq_lane_f32(acc0, b00, a0l, 0); |
| 237 | acc1 = vmlaq_lane_f32(acc1, b01, a0l, 0); |
| 238 | acc2 = vmlaq_lane_f32(acc2, b02, a0l, 0); |
| 239 | acc3 = vmlaq_lane_f32(acc3, b03, a0l, 0); |
| 240 | |
| 241 | acc0 = vmlaq_lane_f32(acc0, b10, a0l, 1); |
| 242 | acc1 = vmlaq_lane_f32(acc1, b11, a0l, 1); |
| 243 | acc2 = vmlaq_lane_f32(acc2, b12, a0l, 1); |
| 244 | acc3 = vmlaq_lane_f32(acc3, b13, a0l, 1); |
| 245 | |
| 246 | vec_a += 2; |
| 247 | matrix_b += 2 * in_b_stride; |
| 248 | |
| 249 | a0l = vld1_f32(vec_a); |
| 250 | |
| 251 | b00 = vld1q_f32(matrix_b + 0 + 0 * in_b_stride); |
| 252 | b01 = vld1q_f32(matrix_b + 4 + 0 * in_b_stride); |
| 253 | b02 = vld1q_f32(matrix_b + 8 + 0 * in_b_stride); |
| 254 | b03 = vld1q_f32(matrix_b + 12 + 0 * in_b_stride); |
| 255 | |
| 256 | b10 = vld1q_f32(matrix_b + 0 + 1 * in_b_stride); |
| 257 | b11 = vld1q_f32(matrix_b + 4 + 1 * in_b_stride); |
| 258 | b12 = vld1q_f32(matrix_b + 8 + 1 * in_b_stride); |
| 259 | b13 = vld1q_f32(matrix_b + 12 + 1 * in_b_stride); |
| 260 | |
| 261 | acc0 = vmlaq_lane_f32(acc0, b00, a0l, 0); |
| 262 | acc1 = vmlaq_lane_f32(acc1, b01, a0l, 0); |
| 263 | acc2 = vmlaq_lane_f32(acc2, b02, a0l, 0); |
| 264 | acc3 = vmlaq_lane_f32(acc3, b03, a0l, 0); |
| 265 | |
| 266 | acc0 = vmlaq_lane_f32(acc0, b10, a0l, 1); |
| 267 | acc1 = vmlaq_lane_f32(acc1, b11, a0l, 1); |
| 268 | acc2 = vmlaq_lane_f32(acc2, b12, a0l, 1); |
| 269 | acc3 = vmlaq_lane_f32(acc3, b13, a0l, 1); |
| 270 | |
| 271 | vec_a += 2; |
| 272 | matrix_b += 2 * in_b_stride; |
| 273 | } |
| 274 | |
| 275 | for(; vec_a < vec_a_end_addr;) |
| 276 | { |
| 277 | const float a0 = *vec_a; |
| 278 | |
| 279 | const float32x4_t b00 = vld1q_f32(matrix_b + 0 + 0 * in_b_stride); |
| 280 | const float32x4_t b01 = vld1q_f32(matrix_b + 4 + 0 * in_b_stride); |
| 281 | const float32x4_t b02 = vld1q_f32(matrix_b + 8 + 0 * in_b_stride); |
| 282 | const float32x4_t b03 = vld1q_f32(matrix_b + 12 + 0 * in_b_stride); |
| 283 | |
| 284 | acc0 = vmlaq_n_f32(acc0, b00, a0); |
| 285 | acc1 = vmlaq_n_f32(acc1, b01, a0); |
| 286 | acc2 = vmlaq_n_f32(acc2, b02, a0); |
| 287 | acc3 = vmlaq_n_f32(acc3, b03, a0); |
| 288 | |
| 289 | vec_a += 1; |
| 290 | matrix_b += in_b_stride; |
| 291 | } |
| 292 | |
| 293 | const auto vec_out = reinterpret_cast<float *>(out.ptr()); |
| 294 | |
| 295 | vst1q_f32(vec_out + 0, acc0); |
| 296 | vst1q_f32(vec_out + 4, acc1); |
| 297 | vst1q_f32(vec_out + 8, acc2); |
| 298 | vst1q_f32(vec_out + 12, acc3); |
| 299 | }, |
| 300 | ina, out); |
| 301 | } |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 302 | |
| 303 | Status validate_arguments(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output) |
| 304 | { |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 305 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input0); |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 306 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input0, 1, DataType::F16, DataType::F32); |
| 307 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input1, 1, DataType::F16, DataType::F32); |
| 308 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::F16, DataType::F32); |
| 309 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input0, input1, output); |
| 310 | ARM_COMPUTE_RETURN_ERROR_ON(input0->dimension(0) != input1->dimension(1)); |
| 311 | |
| 312 | return Status{}; |
| 313 | } |
| 314 | |
| 315 | std::tuple<Status, Window> validate_and_configure_window(ITensorInfo *input0, ITensorInfo *input1, ITensorInfo *output) |
| 316 | { |
Michele Di Giorgio | 4646d2e | 2019-06-19 12:28:47 +0100 | [diff] [blame] | 317 | constexpr unsigned int num_elems_processed_per_iteration_x = 16; |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 318 | |
| 319 | Window win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration_x)); |
| 320 | |
| 321 | AccessWindowHorizontal input0_access(input0, 0, num_elems_processed_per_iteration_x); |
| 322 | AccessWindowHorizontal input1_access(input1, 0, num_elems_processed_per_iteration_x); |
| 323 | AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration_x); |
| 324 | |
| 325 | bool window_changed = update_window_and_padding(win, input0_access, input1_access, output_access); |
| 326 | |
| 327 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 328 | |
| 329 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 330 | |
| 331 | return std::make_tuple(err, win); |
| 332 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 333 | } // namespace |
| 334 | |
| 335 | NELocallyConnectedMatrixMultiplyKernel::NELocallyConnectedMatrixMultiplyKernel() |
| 336 | : _input0(nullptr), _input1(nullptr), _output(nullptr) |
| 337 | { |
| 338 | } |
| 339 | |
| 340 | void NELocallyConnectedMatrixMultiplyKernel::configure(const ITensor *input0, const ITensor *input1, ITensor *output) |
| 341 | { |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 342 | ARM_COMPUTE_ERROR_ON_NULLPTR(input0, input1, output); |
| 343 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input0->info(), input1->info(), output->info())); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 344 | |
| 345 | _input0 = input0; |
| 346 | _input1 = input1; |
| 347 | _output = output; |
| 348 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 349 | // Configure kernel window |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 350 | auto win_config = validate_and_configure_window(input0->info(), input1->info(), output->info()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 351 | |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 352 | ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 353 | |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 354 | INEKernel::configure(std::get<1>(win_config)); |
| 355 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 356 | |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 357 | Status NELocallyConnectedMatrixMultiplyKernel::validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output) |
| 358 | { |
| 359 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input0, input1, output)); |
| 360 | ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input0->clone().get(), input1->clone().get(), output->clone().get()))); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 361 | |
Alex Gilday | 27c08ab | 2018-02-22 11:36:16 +0000 | [diff] [blame] | 362 | return Status{}; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 363 | } |
| 364 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 365 | void NELocallyConnectedMatrixMultiplyKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 366 | { |
| 367 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 368 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 369 | |
Pablo Tello | afde732 | 2017-07-25 09:19:46 +0100 | [diff] [blame] | 370 | switch(_input0->info()->data_type()) |
| 371 | { |
| 372 | case DataType::F16: |
| 373 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 374 | vector_matrix_multiply_f16(_input0, _input1, _output, window, info); |
Pablo Tello | afde732 | 2017-07-25 09:19:46 +0100 | [diff] [blame] | 375 | break; |
| 376 | } |
| 377 | case DataType::F32: |
| 378 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 379 | vector_matrix_multiply_f32(_input0, _input1, _output, window, info); |
Pablo Tello | afde732 | 2017-07-25 09:19:46 +0100 | [diff] [blame] | 380 | break; |
| 381 | } |
| 382 | default: |
| 383 | { |
| 384 | ARM_COMPUTE_ERROR("Data type not supported"); |
| 385 | break; |
| 386 | } |
| 387 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 388 | } |
Michele Di Giorgio | 4646d2e | 2019-06-19 12:28:47 +0100 | [diff] [blame] | 389 | } // namespace arm_compute |