50 const DirectConvolutionLayerOutputStageKernelInfo &
info)
70 if((output !=
nullptr) && (output->total_size() != 0))
92 typename std::enable_if<arm_compute::utils::traits::is_floating_point<T>::value,
void>
::type 93 output_stage_nchw(ITensor *input,
const ITensor *bias,
const Window &window, ITensor *output,
94 int result_fixedpoint_multiplier,
int result_shift,
int result_offset_after_shift,
bool has_bias)
97 using ExactTagType =
typename wrapper::traits::neon_bitvector_tag_t<T, wrapper::traits::BitWidth::W128>;
104 const int window_start_x = window.x().start();
105 const int window_end_x = window.x().end();
106 const int window_step_x = 16 / input->info()->element_size();
110 Iterator in(input, win);
111 Iterator out(output, win);
114 int x = window_start_x;
115 for(; x <= (window_end_x - window_step_x); x += window_step_x)
118 const auto in_ptr =
reinterpret_cast<const T *
>(in.ptr()) + x;
124 const auto vb =
wrapper::vdup_n(*reinterpret_cast<const T *>(bias->ptr_to_element(Coordinates(
id.z()))), ExactTagType{});
128 const auto out_ptr =
reinterpret_cast<T *
>(out.ptr()) + x;
133 for(; x < window_end_x; ++x)
136 auto s_in = *(
reinterpret_cast<const T *
>(in.ptr()) + x);
141 const auto b = *
reinterpret_cast<const T *
>(bias->ptr_to_element(Coordinates(
id.z())));
145 *(
reinterpret_cast<T *
>(out.ptr()) + x) = s_in;
152 template <
typename T>
153 typename std::enable_if<arm_compute::utils::traits::is_floating_point<T>::value,
void>
::type 154 output_stage_nhwc(ITensor *input,
const ITensor *bias,
const Window &window, ITensor *output,
155 int result_fixedpoint_multiplier,
int result_shift,
int result_offset_after_shift,
bool has_bias)
161 Window window_bias = window;
162 window_bias.set(
Window::DimX, Window::Dimension(0, 1, 1));
163 window_bias.set(
Window::DimY, Window::Dimension(0, 0, 0));
164 window_bias.set(
Window::DimZ, Window::Dimension(0, 0, 0));
165 window_bias.set(3, Window::Dimension(0, 0, 0));
167 const int window_start_x = window.x().start();
168 const int window_end_x = window.x().end();
169 const int window_step_x = 16 / input->info()->element_size();
173 Iterator in(input, win);
174 Iterator bi(bias, window_bias);
175 Iterator out(output, win);
179 int x = window_start_x;
180 for(; x <= (window_end_x - window_step_x); x += window_step_x)
183 const auto in_ptr =
reinterpret_cast<const T *
>(in.ptr());
189 const auto bias_ptr =
reinterpret_cast<T *
>(bi.ptr()) + x;
193 const auto out_ptr =
reinterpret_cast<T *
>(out.ptr());
198 for(; x < window_end_x; ++x)
201 auto s_in = *(
reinterpret_cast<const T *
>(in.ptr()) + x);
206 const auto bias_ptr =
reinterpret_cast<T *
>(bi.ptr()) + x;
210 const auto out_ptr =
reinterpret_cast<T *
>(out.ptr());
211 *(out_ptr + x) = s_in;
218 template < typename TOut, typename std::enable_if < std::is_same<TOut, uint8_t>::value || std::is_same<TOut, int8_t>::value,
int >
::type = 0 >
219 void output_stage_nchw(ITensor *input,
const ITensor *bias,
const Window &window, ITensor *output,
220 int result_fixedpoint_multiplier,
int result_shift,
int result_offset_after_shift,
bool has_bias)
222 using VectorType =
typename wrapper::traits::neon_bitvector_t<TOut, wrapper::traits::BitWidth::W128>;
223 using TagType =
typename wrapper::traits::neon_bitvector_tag_t<TOut, wrapper::traits::BitWidth::W128>;
225 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(result_offset_after_shift);
228 const VectorType max =
wrapper::vdup_n(std::numeric_limits<TOut>::max(), TagType{});
230 const int window_start_x = window.x().start();
231 const int window_end_x = window.x().end();
232 const int window_step_x = 16 / input->info()->element_size();
236 Iterator in(input, win);
237 Iterator out(output, win);
242 int x = window_start_x;
243 for(; x <= (window_end_x - window_step_x); x += window_step_x)
246 const auto in_ptr =
reinterpret_cast<int32_t *
>(in.ptr()) + x;
260 const auto vb =
wrapper::vdup_n(*reinterpret_cast<const int32_t *>(bias->ptr_to_element(Coordinates(
id.z()))), TagType{});
272 const auto out_ptr =
reinterpret_cast<TOut *
>(out.ptr()) + x;
278 for(; x < window_end_x; ++x)
281 int32_t s_in = *(
reinterpret_cast<const int32_t *
>(in.ptr()) + x);
286 const auto b = *
reinterpret_cast<const int32_t *
>(bias->ptr_to_element(Coordinates(
id.z())));
290 const auto out_ptr =
reinterpret_cast<TOut *
>(out.ptr()) + x;
291 *out_ptr =
finalize_quantization(s_in, result_fixedpoint_multiplier, result_shift, result_offset_after_shift,
297 template < typename TOut, typename std::enable_if < std::is_same<TOut, uint8_t>::value || std::is_same<TOut, int8_t>::value,
int >::type = 0 >
298 void output_stage_nhwc(ITensor *input,
const ITensor *bias,
const Window &window, ITensor *output,
299 int result_fixedpoint_multiplier,
int result_shift,
int result_offset_after_shift,
bool has_bias)
301 using VectorType =
typename wrapper::traits::neon_bitvector_t<TOut, wrapper::traits::BitWidth::W128>;
302 using TagType =
typename wrapper::traits::neon_bitvector_tag_t<TOut, wrapper::traits::BitWidth::W128>;
304 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(result_offset_after_shift);
307 const VectorType max =
wrapper::vdup_n(std::numeric_limits<TOut>::max(), TagType{});
309 Window window_bias = window;
310 window_bias.set(
Window::DimX, Window::Dimension(0, 1, 1));
311 window_bias.set(
Window::DimY, Window::Dimension(0, 0, 0));
312 window_bias.set(
Window::DimZ, Window::Dimension(0, 0, 0));
313 window_bias.set(3, Window::Dimension(0, 0, 0));
315 const int window_start_x = window.x().start();
316 const int window_end_x = window.x().end();
317 const int window_step_x = 16 / input->info()->element_size();
321 Iterator in(input, win);
322 Iterator bi(bias, window_bias);
323 Iterator out(output, win);
327 int x = window_start_x;
328 for(; x <= (window_end_x - window_step_x); x += window_step_x)
331 const auto in_ptr =
reinterpret_cast<int32_t *
>(in.ptr()) + x;
345 const auto bias_ptr =
reinterpret_cast<int32_t *
>(bi.ptr()) + x;
353 const auto out_ptr =
reinterpret_cast<TOut *
>(out.ptr()) + x;
358 for(; x < window_end_x; ++x)
361 const auto in_ptr =
reinterpret_cast<int32_t *
>(in.ptr()) + x;
362 int32_t s_in = *in_ptr;
367 const auto bias_ptr =
reinterpret_cast<int32_t *
>(bi.ptr()) + x;
371 const auto out_ptr =
reinterpret_cast<TOut *
>(out.ptr()) + x;
372 *out_ptr =
finalize_quantization(s_in, result_fixedpoint_multiplier, result_shift, result_offset_after_shift,
381 : _func(nullptr), _input(nullptr), _bias(nullptr), _output(nullptr), _result_fixedpoint_multiplier(0), _result_shift(0), _result_offset_after_shift(0)
395 _output = (output !=
nullptr) ? output : input;
401 if(output !=
nullptr && output->
info() !=
nullptr)
422 INEKernel::configure(win);
433 if(is_qasymm8_signed)
435 _func = &output_stage_nchw<int8_t>;
439 _func = &output_stage_nchw<uint8_t>;
443 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 446 _func = &output_stage_nchw<float16_t>;
452 _func = &output_stage_nchw<float>;
467 if(is_qasymm8_signed)
469 _func = &output_stage_nhwc<int8_t>;
473 _func = &output_stage_nhwc<uint8_t>;
477 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 480 _func = &output_stage_nhwc<float16_t>;
486 _func = &output_stage_nhwc<float>;
512 const bool has_bias = _bias !=
nullptr;
513 (*_func)(_input, _bias,
window, _output, _result_fixedpoint_multiplier, _result_shift, _result_offset_after_shift,
has_bias);
int32_t result_fixedpoint_multiplier
Result output stage multiplier used for quantizing.
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
const Window & window() const
The maximum window the kernel can be executed on.
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
int32_t result_offset_after_shift
Result offset used for quantizing.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
uint8x16_t vloadq(const uint8_t *ptr)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
uint8x8_t vadd(const uint8x8_t &a, const uint8x8_t &b)
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
decltype(strategy::transforms) typedef type
Interface for Neon tensor.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
NEDirectConvolutionLayerOutputStageKernel()
Default constructor.
Copyright (c) 2017-2021 Arm Limited.
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
1 channel, 1 S32 per channel
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void configure(ITensor *input, const ITensor *bias=nullptr, ITensor *output=nullptr, const DirectConvolutionLayerOutputStageKernelInfo &info=DirectConvolutionLayerOutputStageKernelInfo())
Set the accumulate buffer and the biases of the kernel.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
bool is_data_type_quantized_asymmetric_signed(DataType dt)
Check if a given data type is of asymmetric quantized signed type.
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Num samples, channels, height, width.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
static Status validate(const ITensorInfo *input, const ITensorInfo *bias=nullptr, const ITensorInfo *output=nullptr, const DirectConvolutionLayerOutputStageKernelInfo &info=DirectConvolutionLayerOutputStageKernelInfo())
Static function to check if given info will lead to a valid configuration of NEDirectConvolutionLayer...
Information about executing thread and CPU.
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
DataType output_data_type
Output tensor data type to use if the output is not initialized.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
void vstore(uint8_t *ptr, uint8x8_t val)
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
uint8x8_t vdup_n(uint8_t value, traits::vector_64_tag)
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
void set_num_dimensions(size_t num_dimensions)
Set number of dimensions.
quantized, asymmetric fixed-point 8-bit number signed
Includes all wrapper headers at once.
Container for valid region of a window.
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
DataType
Available data types.
Describe a multidimensional execution window.
wrapper::traits::neon_vector< T, 16 >::type finalize_quantization(int32x4x4_t &in_s32, int32x4_t result_shift_s32, typename wrapper::traits::neon_vector< T, 16 >::type min, typename wrapper::traits::neon_vector< T, 16 >::type max)
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Descriptor used by the direct convolution layer output stage kernels.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
int32_t result_shift
Result output stage shift used for quantizing.