blob: 52880a378f3b071133422c522286790f6ba1b58e [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitasf72f9362018-01-12 16:29:45 +00002 * Copyright (c) 2017-2018 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 */
Michalis Spyroub91e34c2017-12-20 15:50:55 +000024#include "arm_compute/core/NEON/kernels/NEDirectConvolutionLayerOutputStageKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025
26#include "arm_compute/core/AccessWindowStatic.h"
27#include "arm_compute/core/Error.h"
28#include "arm_compute/core/Helpers.h"
29#include "arm_compute/core/ITensor.h"
Georgios Pinitasf72f9362018-01-12 16:29:45 +000030#include "arm_compute/core/NEON/NEAsymm.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include "arm_compute/core/NEON/NEFixedPoint.h"
32#include "arm_compute/core/Types.h"
33#include "arm_compute/core/Validate.h"
34#include "arm_compute/core/Window.h"
35
36#include <arm_neon.h>
37#include <cstddef>
38#include <cstdint>
39
40using namespace arm_compute;
41
42namespace
43{
Michalis Spyrouafa5d812017-11-30 14:25:57 +000044Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output)
45{
Michalis Spyroub91e34c2017-12-20 15:50:55 +000046 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input);
Georgios Pinitasf72f9362018-01-12 16:29:45 +000047 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QASYMM8,
48 DataType::QS16, DataType::F16,
49 DataType::QS32, DataType::S32, DataType::F32);
Michalis Spyroub91e34c2017-12-20 15:50:55 +000050
51 if(bias != nullptr)
Michalis Spyrouafa5d812017-11-30 14:25:57 +000052 {
Georgios Pinitasf72f9362018-01-12 16:29:45 +000053 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(bias, 1, DataType::QS8, DataType::QS16, DataType::F16, DataType::QS32, DataType::S32, DataType::F32);
Michalis Spyroub91e34c2017-12-20 15:50:55 +000054
Georgios Pinitasf72f9362018-01-12 16:29:45 +000055 if(is_data_type_fixed_point(input->data_type()))
Michalis Spyroub91e34c2017-12-20 15:50:55 +000056 {
57 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QS8 && bias->data_type() != DataType::QS8, "Wrong data type for bias");
58 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QS16 && bias->data_type() != DataType::QS8, "Wrong data type for bias");
59 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QS32 && bias->data_type() != DataType::QS16, "Wrong data type for bias");
Georgios Pinitasf72f9362018-01-12 16:29:45 +000060 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(input, bias);
Michalis Spyroub91e34c2017-12-20 15:50:55 +000061 }
62 else
63 {
64 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, bias);
65 }
66
Michalis Spyroub91e34c2017-12-20 15:50:55 +000067 ARM_COMPUTE_RETURN_ERROR_ON(bias->num_dimensions() > 1);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000068 }
69 else
70 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +000071 ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_data_type_quantized(input->data_type()), "Calling output stage kernel with floating point arguments");
Michalis Spyrouafa5d812017-11-30 14:25:57 +000072 }
73
Michalis Spyrouafa5d812017-11-30 14:25:57 +000074 // Checks performed when output is configured
75 if((output != nullptr) && (output->total_size() != 0))
76 {
Georgios Pinitasf72f9362018-01-12 16:29:45 +000077 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::QS8, DataType::QASYMM8, DataType::QS16, DataType::F32);
78 if(is_data_type_fixed_point(input->data_type()))
Michalis Spyroub91e34c2017-12-20 15:50:55 +000079 {
80 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QS8 && output->data_type() != DataType::QS8, "Wrong data type for output");
81 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QS16 && output->data_type() != DataType::QS8, "Wrong data type for output");
82 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QS32 && output->data_type() != DataType::QS16, "Wrong data type for output");
Georgios Pinitasf72f9362018-01-12 16:29:45 +000083 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(input, output);
84 }
85 else if(is_data_type_quantized_asymmetric(output->data_type()))
86 {
87 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::S32 && output->data_type() != DataType::QASYMM8, "Wrong data type for bias");
Michalis Spyroub91e34c2017-12-20 15:50:55 +000088 }
89 else
90 {
91 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
92 }
Michalis Spyrouafa5d812017-11-30 14:25:57 +000093 }
94
Michalis Spyrouafa5d812017-11-30 14:25:57 +000095 return Status{};
96}
97
98std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *bias, ITensorInfo *output)
99{
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000100 bool window_changed = false;
101 unsigned int num_elems_processed_per_iteration = 16 / element_size_from_data_type(input->data_type());
102
103 // Update processed elements when input is S32 (comes from quantization input)
104 if(input->data_type() == DataType::S32)
105 {
106 num_elems_processed_per_iteration = 16;
107 }
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000108
109 // Configure kernel window
110 Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration));
111 AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration);
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000112
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000113 if(output != nullptr && (output->total_size() != 0))
114 {
115 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000116
117 if(bias == nullptr)
118 {
119 window_changed = update_window_and_padding(win, input_access, output_access);
120 }
121 else
122 {
123 AccessWindowStatic bias_access(bias, 0, 0, bias->dimension(0), bias->dimension(1));
124 window_changed = update_window_and_padding(win, input_access, output_access, bias_access);
125 }
126
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000127 output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape()));
128 }
129 else
130 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000131 if(bias == nullptr)
132 {
133 window_changed = update_window_and_padding(win, input_access);
134 }
135 else
136 {
137 AccessWindowStatic bias_access(bias, 0, 0, bias->dimension(0), bias->dimension(1));
138 window_changed = update_window_and_padding(win, input_access, bias_access);
139 }
140
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000141 input_access.set_valid_region(win, ValidRegion(Coordinates(), input->tensor_shape()));
142 }
143
144 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
145 return std::make_pair(err, win);
146}
147
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100148// Internal load
149inline float32x4_t internal_vld1q(const float *in)
150{
151 return vld1q_f32(in);
152}
153inline qint8x16_t internal_vld1q(const qint8_t *in)
154{
155 return vld1q_qs8(in);
156}
157inline qint16x8_t internal_vld1q(const qint16_t *in)
158{
159 return vld1q_qs16(in);
160}
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100161inline qint32x4_t internal_vld1q(const qint32_t *in)
162{
163 return vld1q_s32(in);
164}
165
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100166// Internal store
167inline void internal_vst1q(float *p, const float32x4_t &v)
168{
169 vst1q_f32(p, v);
170}
171inline void internal_vst1q(qint8_t *p, const qint8x16_t &v)
172{
173 vst1q_qs8(p, v);
174}
175inline void internal_vst1q(qint8_t *p, const qint16x8_t &v)
176{
177 vst1_qs8(p, vqmovn_s16(v));
178}
179inline void internal_vst1q(qint16_t *p, const qint16x8_t &v)
180{
181 vst1q_qs16(p, v);
182}
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100183inline void internal_vst1q(qint32_t *p, const qint32x4_t &v)
184{
185 vst1q_s32(p, v);
186}
187
188inline void internal_vst1q(qint16_t *p, const qint32x4_t &v)
189{
190 vst1_qs16(p, vqmovn_qs32(v));
191}
192
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100193// Internal vdup
194inline float32x4_t internal_vdupq_n(float v)
195{
196 return vdupq_n_f32(v);
197}
198inline qint8x16_t internal_vdupq_n(qint8_t v)
199{
200 return vdupq_n_qs8(v);
201}
202inline qint16x8_t internal_vdupq_n(qint16_t v)
203{
204 return vdupq_n_qs16(v);
205}
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100206inline qint32x4_t internal_vdupq_n(qint32_t v)
207{
208 return vdupq_n_qs32(v);
209}
210
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100211// Internal vadd
212inline float32x4_t internal_vqaddq(const float32x4_t &x, const float32x4_t &y)
213{
214 return vaddq_f32(x, y);
215}
216inline qint8x16_t internal_vqaddq(const qint8x16_t &x, const qint8x16_t &y)
217{
218 return vqaddq_qs8(x, y);
219}
220inline qint16x8_t internal_vqaddq(const qint16x8_t &x, const qint16x8_t &y)
221{
222 return vqaddq_qs16(x, y);
223}
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100224inline qint32x4_t internal_vqaddq(const qint32x4_t &x, const qint32x4_t &y)
225{
226 return vqaddq_qs32(x, y);
227}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100228
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000229#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Pablo Tello0d176142017-07-06 16:43:14 +0100230inline float16x8_t internal_vld1q(const float16_t *in)
231{
232 return vld1q_f16(in);
233}
234inline void internal_vst1q(float16_t *p, const float16x8_t &v)
235{
236 vst1q_f16(p, v);
237}
238inline float16x8_t internal_vdupq_n(float16_t v)
239{
240 return vdupq_n_f16(v);
241}
242inline float16x8_t internal_vqaddq(const float16x8_t &x, const float16x8_t &y)
243{
244 return vaddq_f16(x, y);
245}
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000246#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Pablo Tello0d176142017-07-06 16:43:14 +0100247
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000248template <typename T1, typename T2, bool in_place, bool has_bias>
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000249void output_stage(ITensor *input, const ITensor *bias, const Window &window, ITensor *output,
250 int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100251{
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000252 ARM_COMPUTE_UNUSED(result_fixedpoint_multiplier);
253 ARM_COMPUTE_UNUSED(result_shift);
254 ARM_COMPUTE_UNUSED(result_offset_after_shift);
255
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100256 Iterator in(input, window);
257
258 if(in_place) // In place accumulate
259 {
260 execute_window_loop(window, [&](const Coordinates & id)
261 {
262 // Get bias and pointer to input
263 const auto in_ptr = reinterpret_cast<T1 *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100264
265 // Accumulate bias
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000266 if(has_bias)
267 {
268 const auto vb = internal_vdupq_n(static_cast<T1>(*reinterpret_cast<const T2 *>(bias->ptr_to_element(Coordinates(id.z())))));
269 internal_vst1q(in_ptr, internal_vqaddq(internal_vld1q(in_ptr), vb));
270 }
271 else
272 {
273 internal_vst1q(in_ptr, internal_vld1q(in_ptr));
274 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100275 },
276 in);
277 }
278 else // Out of place accumulate
279 {
280 Iterator out(output, window);
281 execute_window_loop(window, [&](const Coordinates & id)
282 {
283 // Get bias and pointer to input
284 const auto in_ptr = reinterpret_cast<const T1 *>(in.ptr());
285 const auto out_ptr = reinterpret_cast<T2 *>(out.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100286
287 // Accumulate bias
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000288 if(has_bias)
289 {
290 const auto vb = internal_vdupq_n(static_cast<T1>(*reinterpret_cast<const T2 *>(bias->ptr_to_element(Coordinates(id.z())))));
291 internal_vst1q(out_ptr, internal_vqaddq(internal_vld1q(in_ptr), vb));
292 }
293 else
294 {
295 internal_vst1q(out_ptr, internal_vld1q(in_ptr));
296 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100297 },
298 in, out);
299 }
300}
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000301
302// QASYMM8 specializations
303template <>
304void output_stage<int32_t, uint8_t, false, true>(ITensor *input, const ITensor *bias, const Window &window, ITensor *output,
305 int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift)
306{
307 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(result_offset_after_shift);
308 uint8x16_t min = vdupq_n_u8(0);
309 uint8x16_t max = vdupq_n_u8(255);
310
311 Iterator in(input, window);
312 Iterator out(output, window);
313
314 execute_window_loop(window, [&](const Coordinates & id)
315 {
316 // Get bias and pointer to input
317 const auto in_ptr = reinterpret_cast<int32_t *>(in.ptr());
318 int32x4x4_t v_in =
319 {
320 {
321 vld1q_s32(in_ptr),
322 vld1q_s32(in_ptr + 4),
323 vld1q_s32(in_ptr + 8),
324 vld1q_s32(in_ptr + 12)
325 }
326 };
327
328 // Accumulate bias
329 const auto vb = vdupq_n_s32(*reinterpret_cast<const int32_t *>(bias->ptr_to_element(Coordinates(id.z()))));
330 v_in =
331 {
332 {
333 vaddq_s32(v_in.val[0], vb),
334 vaddq_s32(v_in.val[1], vb),
335 vaddq_s32(v_in.val[2], vb),
336 vaddq_s32(v_in.val[3], vb)
337 }
338 };
339
340 const auto out_ptr = reinterpret_cast<uint8_t *>(out.ptr());
341 vst1q_u8(out_ptr, finalize_quantization<false>(v_in, result_fixedpoint_multiplier, result_shift, result_offset_after_shift_s32, min, max));
342 },
343 in, out);
344}
345template <>
346void output_stage<int32_t, uint8_t, false, false>(ITensor *input, const ITensor *bias, const Window &window, ITensor *output,
347 int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift)
348{
349 ARM_COMPUTE_UNUSED(bias);
350
351 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(result_offset_after_shift);
352 uint8x16_t min = vdupq_n_u8(0);
353 uint8x16_t max = vdupq_n_u8(255);
354
355 Iterator in(input, window);
356 Iterator out(output, window);
357 execute_window_loop(window, [&](const Coordinates & id)
358 {
359 // Get bias and pointer to input
360 const auto in_ptr = reinterpret_cast<int32_t *>(in.ptr());
361 int32x4x4_t v_in =
362 {
363 {
364 vld1q_s32(in_ptr),
365 vld1q_s32(in_ptr + 4),
366 vld1q_s32(in_ptr + 8),
367 vld1q_s32(in_ptr + 12)
368 }
369 };
370
371 const auto out_ptr = reinterpret_cast<uint8_t *>(out.ptr());
372 vst1q_u8(out_ptr, finalize_quantization<false>(v_in, result_fixedpoint_multiplier, result_shift, result_offset_after_shift_s32, min, max));
373 },
374 in, out);
375}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100376} // namespace
377
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000378NEDirectConvolutionLayerOutputStageKernel::NEDirectConvolutionLayerOutputStageKernel()
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000379 : _func(nullptr), _input(nullptr), _bias(nullptr), _output(nullptr), _result_fixedpoint_multiplier(0), _result_shift(0), _result_offset_after_shift(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100380{
381}
382
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000383void NEDirectConvolutionLayerOutputStageKernel::configure(ITensor *input, const ITensor *bias, ITensor *output,
384 int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100385{
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000386 ARM_COMPUTE_ERROR_ON_NULLPTR(input);
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000387
Georgios Pinitas0223a782017-12-12 11:44:44 +0000388 // Auto-initialize output output if required
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100389 if(output != nullptr)
390 {
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000391 // Work out expected output data type
392 const DataType output_dt = (input->info()->data_type() == DataType::S32) ? DataType::QASYMM8 : input->info()->data_type();
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000393 // Output tensor auto initialization if not yet initialized
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000394 auto_init_if_empty(*output->info(), input->info()->clone()->set_data_type(output_dt));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100395 }
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000396
397 // Perform validation step
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000398 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (bias == nullptr) ? nullptr : bias->info(), (output == nullptr) ? nullptr : output->info()));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100399
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000400 _func = nullptr;
401 _bias = bias;
402 _input = input;
403 _output = output;
404 _result_fixedpoint_multiplier = result_fixedpoint_multiplier;
405 _result_shift = result_shift;
406 _result_offset_after_shift = result_offset_after_shift;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100407
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100408 // Configure kernel window
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000409 auto win_config = validate_and_configure_window(input->info(), (bias == nullptr) ? nullptr : bias->info(), (output == nullptr) ? nullptr : output->info());
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000410 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
411 INEKernel::configure(win_config.second);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100412
413 // Set appropriate function
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100414 switch(input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100415 {
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100416 case DataType::QS8:
417 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000418 if(bias == nullptr)
419 {
420 _func = (output == nullptr) ? &output_stage<qint8_t, qint8_t, true, false> : &output_stage<qint8_t, qint8_t, false, false>;
421 }
422 else
423 {
424 _func = (output == nullptr) ? &output_stage<qint8_t, qint8_t, true, true> : &output_stage<qint8_t, qint8_t, false, true>;
425 }
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100426 break;
427 }
428 case DataType::QS16:
429 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000430 if(bias != nullptr && bias->info()->data_type() == DataType::QS8)
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100431 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000432 _func = (output == nullptr) ? &output_stage<qint16_t, qint8_t, true, true> : &output_stage<qint16_t, qint8_t, false, true>;
433 }
434 else if(bias == nullptr)
435 {
436 _func = (output == nullptr) ? &output_stage<qint16_t, qint8_t, true, false> : &output_stage<qint16_t, qint8_t, false, false>;
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100437 }
438 else
439 {
440 ARM_COMPUTE_ERROR("Not implemented");
441 }
442 break;
443 }
444 case DataType::QS32:
445 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000446 _func = (output == nullptr) ? &output_stage<qint32_t, qint16_t, true, true> : &output_stage<qint32_t, qint16_t, false, true>;
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100447 break;
448 }
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000449 case DataType::S32:
450 _func = (bias == nullptr) ? &output_stage<int32_t, uint8_t, false, false> : &output_stage<int32_t, uint8_t, false, true>;
451 break;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000452#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100453 case DataType::F16:
454 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000455 _func = (output == nullptr) ? &output_stage<float16_t, float16_t, true, true> : &output_stage<float16_t, float16_t, false, true>;
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100456 break;
457 }
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000458#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100459 case DataType::F32:
460 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000461 _func = (output == nullptr) ? &output_stage<float, float, true, true> : &output_stage<float, float, false, true>;
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100462 break;
463 }
464 default:
465 {
466 ARM_COMPUTE_ERROR("Unsupported combination of types among the inputs.");
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100467 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100468 }
469}
470
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000471Status NEDirectConvolutionLayerOutputStageKernel::validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output)
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000472{
473 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, bias, output));
474 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), bias->clone().get(), output == nullptr ? nullptr : output->clone().get()).first);
475
476 return Status{};
477}
478
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000479void NEDirectConvolutionLayerOutputStageKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100480{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100481 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100482 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
483 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
484 ARM_COMPUTE_ERROR_ON(_func == nullptr);
485
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000486 (*_func)(_input, _bias, window, _output, _result_fixedpoint_multiplier, _result_shift, _result_offset_after_shift);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100487}