blob: 08d8f8ce56e7c3a0f53c9a06fece20ccb560de3b [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 }
Georgios Pinitas19d05472018-02-01 16:44:12 +000062 else if(is_data_type_quantized_asymmetric(input->data_type()))
63 {
64 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(bias, 1, DataType::S32);
65 }
Michalis Spyroub91e34c2017-12-20 15:50:55 +000066 else
67 {
68 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, bias);
69 }
70
Michalis Spyroub91e34c2017-12-20 15:50:55 +000071 ARM_COMPUTE_RETURN_ERROR_ON(bias->num_dimensions() > 1);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000072 }
73 else
74 {
Georgios Pinitas19d05472018-02-01 16:44:12 +000075 ARM_COMPUTE_RETURN_ERROR_ON_MSG(is_data_type_float(input->data_type()), "Calling output stage kernel with floating point arguments");
Michalis Spyrouafa5d812017-11-30 14:25:57 +000076 }
77
Michalis Spyrouafa5d812017-11-30 14:25:57 +000078 // Checks performed when output is configured
79 if((output != nullptr) && (output->total_size() != 0))
80 {
Georgios Pinitasf72f9362018-01-12 16:29:45 +000081 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::QS8, DataType::QASYMM8, DataType::QS16, DataType::F32);
82 if(is_data_type_fixed_point(input->data_type()))
Michalis Spyroub91e34c2017-12-20 15:50:55 +000083 {
84 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QS8 && output->data_type() != DataType::QS8, "Wrong data type for output");
85 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QS16 && output->data_type() != DataType::QS8, "Wrong data type for output");
86 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 +000087 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(input, output);
88 }
89 else if(is_data_type_quantized_asymmetric(output->data_type()))
90 {
91 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 +000092 }
93 else
94 {
95 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
96 }
Michalis Spyrouafa5d812017-11-30 14:25:57 +000097 }
98
Michalis Spyrouafa5d812017-11-30 14:25:57 +000099 return Status{};
100}
101
102std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *bias, ITensorInfo *output)
103{
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000104 bool window_changed = false;
105 unsigned int num_elems_processed_per_iteration = 16 / element_size_from_data_type(input->data_type());
106
107 // Update processed elements when input is S32 (comes from quantization input)
108 if(input->data_type() == DataType::S32)
109 {
110 num_elems_processed_per_iteration = 16;
111 }
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000112
113 // Configure kernel window
114 Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration));
115 AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration);
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000116
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000117 if(output != nullptr && (output->total_size() != 0))
118 {
119 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000120
121 if(bias == nullptr)
122 {
123 window_changed = update_window_and_padding(win, input_access, output_access);
124 }
125 else
126 {
127 AccessWindowStatic bias_access(bias, 0, 0, bias->dimension(0), bias->dimension(1));
128 window_changed = update_window_and_padding(win, input_access, output_access, bias_access);
129 }
130
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000131 output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape()));
132 }
133 else
134 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000135 if(bias == nullptr)
136 {
137 window_changed = update_window_and_padding(win, input_access);
138 }
139 else
140 {
141 AccessWindowStatic bias_access(bias, 0, 0, bias->dimension(0), bias->dimension(1));
142 window_changed = update_window_and_padding(win, input_access, bias_access);
143 }
144
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000145 input_access.set_valid_region(win, ValidRegion(Coordinates(), input->tensor_shape()));
146 }
147
148 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
149 return std::make_pair(err, win);
150}
151
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152// Internal load
153inline float32x4_t internal_vld1q(const float *in)
154{
155 return vld1q_f32(in);
156}
157inline qint8x16_t internal_vld1q(const qint8_t *in)
158{
159 return vld1q_qs8(in);
160}
161inline qint16x8_t internal_vld1q(const qint16_t *in)
162{
163 return vld1q_qs16(in);
164}
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100165inline qint32x4_t internal_vld1q(const qint32_t *in)
166{
167 return vld1q_s32(in);
168}
169
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100170// Internal store
171inline void internal_vst1q(float *p, const float32x4_t &v)
172{
173 vst1q_f32(p, v);
174}
175inline void internal_vst1q(qint8_t *p, const qint8x16_t &v)
176{
177 vst1q_qs8(p, v);
178}
179inline void internal_vst1q(qint8_t *p, const qint16x8_t &v)
180{
181 vst1_qs8(p, vqmovn_s16(v));
182}
183inline void internal_vst1q(qint16_t *p, const qint16x8_t &v)
184{
185 vst1q_qs16(p, v);
186}
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100187inline void internal_vst1q(qint32_t *p, const qint32x4_t &v)
188{
189 vst1q_s32(p, v);
190}
191
192inline void internal_vst1q(qint16_t *p, const qint32x4_t &v)
193{
194 vst1_qs16(p, vqmovn_qs32(v));
195}
196
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100197// Internal vdup
198inline float32x4_t internal_vdupq_n(float v)
199{
200 return vdupq_n_f32(v);
201}
202inline qint8x16_t internal_vdupq_n(qint8_t v)
203{
204 return vdupq_n_qs8(v);
205}
206inline qint16x8_t internal_vdupq_n(qint16_t v)
207{
208 return vdupq_n_qs16(v);
209}
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100210inline qint32x4_t internal_vdupq_n(qint32_t v)
211{
212 return vdupq_n_qs32(v);
213}
214
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100215// Internal vadd
216inline float32x4_t internal_vqaddq(const float32x4_t &x, const float32x4_t &y)
217{
218 return vaddq_f32(x, y);
219}
220inline qint8x16_t internal_vqaddq(const qint8x16_t &x, const qint8x16_t &y)
221{
222 return vqaddq_qs8(x, y);
223}
224inline qint16x8_t internal_vqaddq(const qint16x8_t &x, const qint16x8_t &y)
225{
226 return vqaddq_qs16(x, y);
227}
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100228inline qint32x4_t internal_vqaddq(const qint32x4_t &x, const qint32x4_t &y)
229{
230 return vqaddq_qs32(x, y);
231}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100232
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000233#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Pablo Tello0d176142017-07-06 16:43:14 +0100234inline float16x8_t internal_vld1q(const float16_t *in)
235{
236 return vld1q_f16(in);
237}
238inline void internal_vst1q(float16_t *p, const float16x8_t &v)
239{
240 vst1q_f16(p, v);
241}
242inline float16x8_t internal_vdupq_n(float16_t v)
243{
244 return vdupq_n_f16(v);
245}
246inline float16x8_t internal_vqaddq(const float16x8_t &x, const float16x8_t &y)
247{
248 return vaddq_f16(x, y);
249}
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000250#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Pablo Tello0d176142017-07-06 16:43:14 +0100251
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000252template <typename T1, typename T2, bool in_place, bool has_bias>
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000253void output_stage(ITensor *input, const ITensor *bias, const Window &window, ITensor *output,
254 int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100255{
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000256 ARM_COMPUTE_UNUSED(result_fixedpoint_multiplier);
257 ARM_COMPUTE_UNUSED(result_shift);
258 ARM_COMPUTE_UNUSED(result_offset_after_shift);
259
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100260 Iterator in(input, window);
261
262 if(in_place) // In place accumulate
263 {
264 execute_window_loop(window, [&](const Coordinates & id)
265 {
266 // Get bias and pointer to input
267 const auto in_ptr = reinterpret_cast<T1 *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100268
269 // Accumulate bias
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000270 if(has_bias)
271 {
272 const auto vb = internal_vdupq_n(static_cast<T1>(*reinterpret_cast<const T2 *>(bias->ptr_to_element(Coordinates(id.z())))));
273 internal_vst1q(in_ptr, internal_vqaddq(internal_vld1q(in_ptr), vb));
274 }
275 else
276 {
277 internal_vst1q(in_ptr, internal_vld1q(in_ptr));
278 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100279 },
280 in);
281 }
282 else // Out of place accumulate
283 {
284 Iterator out(output, window);
285 execute_window_loop(window, [&](const Coordinates & id)
286 {
287 // Get bias and pointer to input
288 const auto in_ptr = reinterpret_cast<const T1 *>(in.ptr());
289 const auto out_ptr = reinterpret_cast<T2 *>(out.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100290
291 // Accumulate bias
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000292 if(has_bias)
293 {
294 const auto vb = internal_vdupq_n(static_cast<T1>(*reinterpret_cast<const T2 *>(bias->ptr_to_element(Coordinates(id.z())))));
295 internal_vst1q(out_ptr, internal_vqaddq(internal_vld1q(in_ptr), vb));
296 }
297 else
298 {
299 internal_vst1q(out_ptr, internal_vld1q(in_ptr));
300 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100301 },
302 in, out);
303 }
304}
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000305
306// QASYMM8 specializations
307template <>
308void output_stage<int32_t, uint8_t, false, true>(ITensor *input, const ITensor *bias, const Window &window, ITensor *output,
309 int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift)
310{
311 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(result_offset_after_shift);
312 uint8x16_t min = vdupq_n_u8(0);
313 uint8x16_t max = vdupq_n_u8(255);
314
315 Iterator in(input, window);
316 Iterator out(output, window);
317
318 execute_window_loop(window, [&](const Coordinates & id)
319 {
320 // Get bias and pointer to input
321 const auto in_ptr = reinterpret_cast<int32_t *>(in.ptr());
322 int32x4x4_t v_in =
323 {
324 {
325 vld1q_s32(in_ptr),
326 vld1q_s32(in_ptr + 4),
327 vld1q_s32(in_ptr + 8),
328 vld1q_s32(in_ptr + 12)
329 }
330 };
331
332 // Accumulate bias
333 const auto vb = vdupq_n_s32(*reinterpret_cast<const int32_t *>(bias->ptr_to_element(Coordinates(id.z()))));
334 v_in =
335 {
336 {
337 vaddq_s32(v_in.val[0], vb),
338 vaddq_s32(v_in.val[1], vb),
339 vaddq_s32(v_in.val[2], vb),
340 vaddq_s32(v_in.val[3], vb)
341 }
342 };
343
344 const auto out_ptr = reinterpret_cast<uint8_t *>(out.ptr());
345 vst1q_u8(out_ptr, finalize_quantization<false>(v_in, result_fixedpoint_multiplier, result_shift, result_offset_after_shift_s32, min, max));
346 },
347 in, out);
348}
349template <>
350void output_stage<int32_t, uint8_t, false, false>(ITensor *input, const ITensor *bias, const Window &window, ITensor *output,
351 int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift)
352{
353 ARM_COMPUTE_UNUSED(bias);
354
355 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(result_offset_after_shift);
356 uint8x16_t min = vdupq_n_u8(0);
357 uint8x16_t max = vdupq_n_u8(255);
358
359 Iterator in(input, window);
360 Iterator out(output, window);
361 execute_window_loop(window, [&](const Coordinates & id)
362 {
363 // Get bias and pointer to input
364 const auto in_ptr = reinterpret_cast<int32_t *>(in.ptr());
365 int32x4x4_t v_in =
366 {
367 {
368 vld1q_s32(in_ptr),
369 vld1q_s32(in_ptr + 4),
370 vld1q_s32(in_ptr + 8),
371 vld1q_s32(in_ptr + 12)
372 }
373 };
374
375 const auto out_ptr = reinterpret_cast<uint8_t *>(out.ptr());
376 vst1q_u8(out_ptr, finalize_quantization<false>(v_in, result_fixedpoint_multiplier, result_shift, result_offset_after_shift_s32, min, max));
377 },
378 in, out);
379}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100380} // namespace
381
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000382NEDirectConvolutionLayerOutputStageKernel::NEDirectConvolutionLayerOutputStageKernel()
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000383 : _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 +0100384{
385}
386
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000387void NEDirectConvolutionLayerOutputStageKernel::configure(ITensor *input, const ITensor *bias, ITensor *output,
388 int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100389{
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000390 ARM_COMPUTE_ERROR_ON_NULLPTR(input);
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000391
Georgios Pinitas0223a782017-12-12 11:44:44 +0000392 // Auto-initialize output output if required
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100393 if(output != nullptr)
394 {
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000395 // Work out expected output data type
396 const DataType output_dt = (input->info()->data_type() == DataType::S32) ? DataType::QASYMM8 : input->info()->data_type();
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000397 // Output tensor auto initialization if not yet initialized
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000398 auto_init_if_empty(*output->info(), input->info()->clone()->set_data_type(output_dt));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100399 }
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000400
401 // Perform validation step
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000402 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 +0100403
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000404 _func = nullptr;
405 _bias = bias;
406 _input = input;
407 _output = output;
408 _result_fixedpoint_multiplier = result_fixedpoint_multiplier;
409 _result_shift = result_shift;
410 _result_offset_after_shift = result_offset_after_shift;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100411
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100412 // Configure kernel window
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000413 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 +0000414 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
415 INEKernel::configure(win_config.second);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100416
417 // Set appropriate function
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100418 switch(input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100419 {
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100420 case DataType::QS8:
421 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000422 if(bias == nullptr)
423 {
424 _func = (output == nullptr) ? &output_stage<qint8_t, qint8_t, true, false> : &output_stage<qint8_t, qint8_t, false, false>;
425 }
426 else
427 {
428 _func = (output == nullptr) ? &output_stage<qint8_t, qint8_t, true, true> : &output_stage<qint8_t, qint8_t, false, true>;
429 }
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100430 break;
431 }
432 case DataType::QS16:
433 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000434 if(bias != nullptr && bias->info()->data_type() == DataType::QS8)
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100435 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000436 _func = (output == nullptr) ? &output_stage<qint16_t, qint8_t, true, true> : &output_stage<qint16_t, qint8_t, false, true>;
437 }
438 else if(bias == nullptr)
439 {
440 _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 +0100441 }
442 else
443 {
444 ARM_COMPUTE_ERROR("Not implemented");
445 }
446 break;
447 }
448 case DataType::QS32:
449 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000450 _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 +0100451 break;
452 }
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000453 case DataType::S32:
Georgios Pinitas9be0c5a2018-02-19 12:46:29 +0000454 {
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000455 _func = (bias == nullptr) ? &output_stage<int32_t, uint8_t, false, false> : &output_stage<int32_t, uint8_t, false, true>;
456 break;
Georgios Pinitas9be0c5a2018-02-19 12:46:29 +0000457 }
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000458#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100459 case DataType::F16:
460 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000461 _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 +0100462 break;
463 }
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000464#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100465 case DataType::F32:
466 {
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000467 _func = (output == nullptr) ? &output_stage<float, float, true, true> : &output_stage<float, float, false, true>;
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100468 break;
469 }
470 default:
471 {
472 ARM_COMPUTE_ERROR("Unsupported combination of types among the inputs.");
Pablo Tellof87cc7f2017-07-26 10:28:40 +0100473 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100474 }
475}
476
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000477Status NEDirectConvolutionLayerOutputStageKernel::validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output)
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000478{
479 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, bias, output));
480 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), bias->clone().get(), output == nullptr ? nullptr : output->clone().get()).first);
481
482 return Status{};
483}
484
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000485void NEDirectConvolutionLayerOutputStageKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100486{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100487 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100488 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
489 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
490 ARM_COMPUTE_ERROR_ON(_func == nullptr);
491
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000492 (*_func)(_input, _bias, window, _output, _result_fixedpoint_multiplier, _result_shift, _result_offset_after_shift);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100493}