53 const DirectConvolutionLayerOutputStageKernelInfo &
info)
73 if((
dst !=
nullptr) && (
dst->total_size() != 0))
95 typename std::enable_if<arm_compute::utils::traits::is_floating_point<T>::value,
void>
::type 96 output_stage_nchw(ITensor *
src,
const ITensor *bias,
const Window &window, ITensor *
dst,
97 int result_fixedpoint_multiplier,
int result_shift,
int result_offset_after_shift)
99 const bool has_bias = bias !=
nullptr;
101 using ExactTagType =
typename wrapper::traits::neon_bitvector_tag_t<T, wrapper::traits::BitWidth::W128>;
108 const int window_start_x = window.x().start();
109 const int window_end_x = window.x().end();
110 const int window_step_x = 16 /
src->info()->element_size();
114 Iterator in(
src, win);
115 Iterator out(
dst, win);
118 int x = window_start_x;
119 for(; x <= (window_end_x - window_step_x); x += window_step_x)
122 const auto in_ptr = reinterpret_cast<const T *>(in.ptr()) + x;
128 const auto vb =
wrapper::vdup_n(*reinterpret_cast<const T *>(bias->ptr_to_element(Coordinates(
id.z()))), ExactTagType{});
132 const auto out_ptr = reinterpret_cast<T *>(out.ptr()) + x;
137 for(; x < window_end_x; ++x)
140 auto s_in = *(reinterpret_cast<const T *>(in.ptr()) + x);
145 const auto b = *reinterpret_cast<const T *>(bias->ptr_to_element(Coordinates(
id.z())));
149 *(reinterpret_cast<T *>(out.ptr()) + x) = s_in;
156 template <
typename T>
157 typename std::enable_if<arm_compute::utils::traits::is_floating_point<T>::value,
void>
::type 158 output_stage_nhwc(ITensor *
src,
const ITensor *bias,
const Window &window, ITensor *
dst,
159 int result_fixedpoint_multiplier,
int result_shift,
int result_offset_after_shift)
161 const bool has_bias = bias !=
nullptr;
166 Window window_bias = window;
167 window_bias.set(
Window::DimX, Window::Dimension(0, 1, 1));
168 window_bias.set(
Window::DimY, Window::Dimension(0, 0, 0));
169 window_bias.set(
Window::DimZ, Window::Dimension(0, 0, 0));
170 window_bias.set(3, Window::Dimension(0, 0, 0));
172 const int window_start_x = window.x().start();
173 const int window_end_x = window.x().end();
174 const int window_step_x = 16 /
src->info()->element_size();
178 Iterator in(
src, win);
179 Iterator bi(bias, window_bias);
180 Iterator out(
dst, win);
184 int x = window_start_x;
185 for(; x <= (window_end_x - window_step_x); x += window_step_x)
188 const auto in_ptr = reinterpret_cast<const T *>(in.ptr());
194 const auto bias_ptr = reinterpret_cast<T *>(bi.ptr()) + x;
198 const auto out_ptr = reinterpret_cast<T *>(out.ptr());
203 for(; x < window_end_x; ++x)
206 auto s_in = *(reinterpret_cast<const T *>(in.ptr()) + x);
211 const auto bias_ptr = reinterpret_cast<T *>(bi.ptr()) + x;
215 const auto out_ptr = reinterpret_cast<T *>(out.ptr());
216 *(out_ptr + x) = s_in;
223 template < typename TOut, typename std::enable_if < std::is_same<TOut, uint8_t>::value || std::is_same<TOut, int8_t>::value,
int >
::type = 0 >
224 void output_stage_nchw(ITensor *
src,
const ITensor *bias,
const Window &window, ITensor *
dst,
225 int result_fixedpoint_multiplier,
int result_shift,
int result_offset_after_shift)
227 const bool has_bias = bias !=
nullptr;
228 using VectorType =
typename wrapper::traits::neon_bitvector_t<TOut, wrapper::traits::BitWidth::W128>;
229 using TagType =
typename wrapper::traits::neon_bitvector_tag_t<TOut, wrapper::traits::BitWidth::W128>;
231 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(result_offset_after_shift);
234 const VectorType max =
wrapper::vdup_n(std::numeric_limits<TOut>::max(), TagType{});
236 const int window_start_x = window.x().start();
237 const int window_end_x = window.x().end();
238 const int window_step_x = 16 /
src->info()->element_size();
242 Iterator in(
src, win);
243 Iterator out(
dst, win);
248 int x = window_start_x;
249 for(; x <= (window_end_x - window_step_x); x += window_step_x)
252 const auto in_ptr = reinterpret_cast<int32_t *>(in.ptr()) + x;
266 const auto vb =
wrapper::vdup_n(*reinterpret_cast<const int32_t *>(bias->ptr_to_element(Coordinates(
id.z()))), TagType{});
278 const auto out_ptr = reinterpret_cast<TOut *>(out.ptr()) + x;
284 for(; x < window_end_x; ++x)
287 int32_t s_in = *(reinterpret_cast<const int32_t *>(in.ptr()) + x);
292 const auto b = *reinterpret_cast<const int32_t *>(bias->ptr_to_element(Coordinates(
id.z())));
296 const auto out_ptr = reinterpret_cast<TOut *>(out.ptr()) + x;
297 *out_ptr =
finalize_quantization(s_in, result_fixedpoint_multiplier, result_shift, result_offset_after_shift,
303 template < typename TOut, typename std::enable_if < std::is_same<TOut, uint8_t>::value || std::is_same<TOut, int8_t>::value,
int >
::type = 0 >
304 void output_stage_nhwc(ITensor *
src,
const ITensor *bias,
const Window &window, ITensor *
dst,
305 int result_fixedpoint_multiplier,
int result_shift,
int result_offset_after_shift)
307 const bool has_bias = bias !=
nullptr;
308 using VectorType =
typename wrapper::traits::neon_bitvector_t<TOut, wrapper::traits::BitWidth::W128>;
309 using TagType =
typename wrapper::traits::neon_bitvector_tag_t<TOut, wrapper::traits::BitWidth::W128>;
311 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(result_offset_after_shift);
314 const VectorType max =
wrapper::vdup_n(std::numeric_limits<TOut>::max(), TagType{});
316 Window window_bias = window;
317 window_bias.set(
Window::DimX, Window::Dimension(0, 1, 1));
318 window_bias.set(
Window::DimY, Window::Dimension(0, 0, 0));
319 window_bias.set(
Window::DimZ, Window::Dimension(0, 0, 0));
320 window_bias.set(3, Window::Dimension(0, 0, 0));
322 const int window_start_x = window.x().start();
323 const int window_end_x = window.x().end();
324 const int window_step_x = 16 /
src->info()->element_size();
328 Iterator in(
src, win);
329 Iterator bi(bias, window_bias);
330 Iterator out(
dst, win);
334 int x = window_start_x;
335 for(; x <= (window_end_x - window_step_x); x += window_step_x)
338 const auto in_ptr = reinterpret_cast<int32_t *>(in.ptr()) + x;
352 const auto bias_ptr = reinterpret_cast<int32_t *>(bi.ptr()) + x;
360 const auto out_ptr = reinterpret_cast<TOut *>(out.ptr()) + x;
365 for(; x < window_end_x; ++x)
368 const auto in_ptr = reinterpret_cast<int32_t *>(in.ptr()) + x;
369 int32_t s_in = *in_ptr;
374 const auto bias_ptr = reinterpret_cast<int32_t *>(bi.ptr()) + x;
378 const auto out_ptr = reinterpret_cast<TOut *>(out.ptr()) + x;
379 *out_ptr =
finalize_quantization(s_in, result_fixedpoint_multiplier, result_shift, result_offset_after_shift,
396 _result_fixedpoint_multiplier =
info.result_fixedpoint_multiplier;
397 _result_shift =
info.result_shift;
398 _result_offset_after_shift =
info.result_offset_after_shift;
411 ICpuKernel::configure(win);
418 switch(
src->data_type())
422 if(is_qasymm8_signed)
424 _func = &output_stage_nchw<int8_t>;
428 _func = &output_stage_nchw<uint8_t>;
432 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 435 _func = &output_stage_nchw<float16_t>;
441 _func = &output_stage_nchw<float>;
452 switch(
src->data_type())
456 if(is_qasymm8_signed)
458 _func = &output_stage_nhwc<int8_t>;
462 _func = &output_stage_nhwc<uint8_t>;
466 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 469 _func = &output_stage_nhwc<float16_t>;
475 _func = &output_stage_nhwc<float>;
504 (*_func)(
src, bias,
window,
dst, _result_fixedpoint_multiplier, _result_shift, _result_offset_after_shift);
509 return "CpuDirectConvolutionOutputStageKernel";
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)
#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.
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
static Status validate(const ITensorInfo *src, const ITensorInfo *bias=nullptr, const ITensorInfo *dst=nullptr, const DirectConvolutionLayerOutputStageKernelInfo &info=DirectConvolutionLayerOutputStageKernelInfo())
Static function to check if given info will lead to a valid configuration of CpuDirectConvolutionOutp...
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
1 channel, 1 S32 per channel
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
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...
void configure(ITensorInfo *src, const ITensorInfo *bias=nullptr, ITensorInfo *dst=nullptr, const DirectConvolutionLayerOutputStageKernelInfo &info=DirectConvolutionLayerOutputStageKernelInfo())
Set the accumulate buffer and the biases of the kernel.
#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)
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Information about executing thread and CPU.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
#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...
quantized, asymmetric fixed-point 8-bit number signed
Includes all wrapper headers at once.
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)
const char * name() const override
Name of the kernel.