33 #include "src/core/NEON/kernels/convolution/common/utils.hpp" 34 #include "src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp" 48 const std::array<Size2D, 8> f32_support = { { Size2D(1, 3), Size2D(3, 1), Size2D(5, 5), Size2D(3, 3), Size2D(1, 5), Size2D(5, 1), Size2D(7, 1), Size2D(1, 7) } };
49 const std::array<Size2D, 8> f16_support = { { Size2D(3, 3) } };
54 return std::end(f16_support) != std::find(std::begin(f16_support),
std::end(f16_support), size);
56 return std::end(f32_support) != std::find(std::begin(f32_support),
std::end(f32_support), size);
62 Status validate_arguments_winograd_weight_trans(
const ITensorInfo *
input,
const ITensorInfo *output,
const WinogradInfo &
winograd_info)
73 "Only 1x3, 3x1, 1x5, 5x1, 7x1, 1x7, 3x3 and 5x5 kernels are supported");
76 const std::array<Size2D, 8> supported_tile_sizes = { { Size2D(2U, 2U), Size2D(4U, 4U), Size2D(1U, 6U), Size2D(6U, 1U), Size2D(4, 1), Size2D(1, 4), Size2D(2, 1), Size2D(1, 2) } };
80 if(output->total_size() != 0)
91 std::pair<Status, Window> validate_and_configure_window_winograd_weight_trans(ITensorInfo *
input, ITensorInfo *output,
const WinogradInfo &
winograd_info)
96 return std::make_pair(Status{}, win);
99 Status validate_arguments_winograd_input_trans(
const ITensorInfo *
input,
const ITensorInfo *output,
const WinogradInfo &
winograd_info)
108 "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
111 if(output->total_size() != 0)
122 std::pair<Status, Window> validate_and_configure_window_winograd_input_trans(ITensorInfo *
input, ITensorInfo *output,
const WinogradInfo &
winograd_info)
130 Status validate_arguments_winograd_output_trans(
const ITensorInfo *
input,
const ITensorInfo *bias,
const ITensorInfo *output,
const WinogradInfo &
winograd_info)
136 const unsigned int num_tiles_x = std::ceil((
winograd_info.input_dimensions.x() - (kernel_dims.width - 1) +
conv_info.pad_left() +
conv_info.pad_right()) / static_cast<float>
138 const unsigned int num_tiles_y = std::ceil((
winograd_info.input_dimensions.y() - (kernel_dims.height - 1) +
conv_info.pad_top() +
conv_info.pad_bottom()) / static_cast<float>
140 const Size2D num_tiles = Size2D(num_tiles_x, num_tiles_y);
147 "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
149 const std::array<unsigned int, 3> supported_gemm_sizes = { { 8
U, 16
U, 36
U } };
160 if(output->total_size() != 0)
169 std::pair<Status, Window> validate_and_configure_window_winograd_output_trans(ITensorInfo *
input, ITensorInfo *output,
const WinogradInfo &
winograd_info)
186 "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
191 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
194 const KernelShape
shape(num_output_channels, KernelRows, KernelCols, num_input_channels);
195 return static_cast<unsigned int>(
197 WinogradConv::get_kernel_storage_size(num_input_channels, num_output_channels) /
sizeof(T));
200 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
202 : _transform(nullptr), _weights_hwio(nullptr), _output(nullptr), _matrix_stride(0), _num_output_channels(0), _num_input_channels(0)
206 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
209 return WinogradConv::get_kernel_matrix_stride(num_input_channels, num_output_channels);
212 #ifndef DOXYGEN_SKIP_THIS 213 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
217 const int matrix_stride,
218 const int num_output_channels,
219 const int num_input_channels)
221 _weights_hwio = weights_hwio;
223 _matrix_stride = matrix_stride;
224 _num_output_channels = num_output_channels;
225 _num_input_channels = num_input_channels;
226 _transform = std::make_unique<WeightsTransform>(num_output_channels, num_input_channels);
229 auto win_last = _transform->get_window();
231 INEKernel::configure(win);
235 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
240 const size_t fst = window.
x().
start();
241 const size_t lst = window.
x().
end();
242 _transform->set_weight_tensor(_weights_hwio->buffer());
243 const int matrix_row_stride =
roundup(_num_output_channels, WinogradConv::N_BLOCK);
244 _transform->set_output_matrices(_output->
buffer(), _matrix_stride, matrix_row_stride);
245 _transform->set_working_space(_output->
buffer());
247 _transform->run(fst, lst);
250 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
256 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
276 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 278 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 282 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
292 const Tensor4DShape
input_shape(num_batches, num_rows, num_cols, num_channels);
293 const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels);
295 return static_cast<unsigned int>(WinogradConv::get_input_storage_size(num_batches, num_rows, num_cols, num_channels, same_padding) /
sizeof(T));
298 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
301 return _transform->get_working_space_size(num_threads) /
sizeof(T);
304 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
310 bool same_padding )
const 312 return WinogradConv::get_input_matrix_stride(num_batches, num_rows, num_cols, num_channels, same_padding);
315 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
317 : _transform(nullptr), _input_nhwc(nullptr), _num_batches(0), _num_rows(0), _num_cols(0), _num_channels(0), _padding(), _output(nullptr), _matrix_stride(0), _padding_top(), _padding_left(),
318 _padding_right(), _padding_bottom(), _workspace(nullptr)
322 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
325 const int num_batches,
328 const int num_channels,
329 const PaddingType padding,
331 const int matrix_stride,
334 _input_nhwc = input_nhwc;
335 _num_batches = num_batches;
336 _num_rows = num_rows;
337 _num_cols = num_cols;
338 _num_channels = num_channels;
341 _matrix_stride = matrix_stride;
342 _workspace = workspace;
344 _padding_top = (padding == PADDING_SAME) ? (KernelRows - 1) / 2 : 0;
345 _padding_left = (padding == PADDING_SAME) ? (KernelCols - 1) / 2 : 0;
346 _padding_bottom = (padding == PADDING_SAME) ?
iceildiv(KernelRows - 1, 2) : 0;
347 _padding_right = (padding == PADDING_SAME) ?
iceildiv(KernelCols - 1, 2) : 0;
349 _transform = std::make_unique<InputTransform>(
363 auto win_last = _transform->get_window();
365 INEKernel::configure(win);
368 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
375 const int element_size_in_bytes = _input_nhwc->info()->element_size();
376 const int input_col_stride = _input_nhwc->info()->strides_in_bytes().y() / element_size_in_bytes;
377 const int input_row_stride = _input_nhwc->info()->strides_in_bytes().z() / element_size_in_bytes;
378 const int input_batch_stride = _input_nhwc->info()->strides_in_bytes()[3] / element_size_in_bytes;
379 const auto input_nhwc_ptr = reinterpret_cast<const T *>(_input_nhwc->buffer() + _input_nhwc->info()->offset_first_element_in_bytes());
383 _transform->set_input_tensor(input_nhwc_ptr, input_batch_stride, input_row_stride, input_col_stride);
384 _transform->set_output_matrices(output_ptr, _matrix_stride, _num_channels);
386 _transform->set_working_space(_workspace->
buffer());
389 const size_t fst = window.
x().
start();
390 const size_t lst = window.
x().
end();
391 _transform->run(fst, lst,
info.thread_id);
394 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
414 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 416 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 420 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
425 int num_output_channels
429 const Tensor4DShape
input_shape(num_batches, num_rows, num_cols, 1);
430 const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1);
432 return static_cast<unsigned int>(
433 WinogradConv::get_output_storage_size(num_batches, num_rows, num_cols, num_output_channels) /
sizeof(T));
436 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
438 : _transform(nullptr), _biases(nullptr), _transformed_output(nullptr), _workspace(nullptr), _matrix_stride(0), _matrix_row_stride(0), _output_nhwc(nullptr), _num_batches(0), _num_rows(0),
439 _num_cols(0), _num_channels(0)
443 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
446 return _transform->get_working_space_size(num_threads) /
sizeof(T);
449 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
454 int num_output_channels
457 return WinogradConv::get_output_matrix_stride(num_batches, num_rows, num_cols, num_output_channels);
460 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
464 bool padding_same)
const 466 return WinogradConv::get_output_shape(std::make_pair<unsigned int, unsigned int>(num_rows, num_cols), padding_same);
469 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
472 const ITensor *transformed_output,
473 const int matrix_stride,
475 const int num_batches,
478 const int num_channels,
483 _workspace = workspace;
484 _transformed_output = transformed_output;
485 _matrix_stride = matrix_stride;
486 _matrix_row_stride =
roundup(num_channels, WinogradConv::N_BLOCK);
487 _output_nhwc = output_nhwc;
488 _num_batches = num_batches;
489 _num_rows = num_rows;
490 _num_cols = num_cols;
491 _num_channels = num_channels;
493 _transform = std::make_unique<OutputTransform>(num_batches, num_rows, num_cols, num_channels, activation);
495 auto win_last = _transform->get_window();
498 INEKernel::configure(win);
501 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
510 const int out_batch_stride = _output_nhwc->info()->strides_in_bytes()[3] /
sizeof(T);
511 const int out_row_stride = _output_nhwc->info()->strides_in_bytes()[2] /
sizeof(T);
512 const int out_col_stride = _output_nhwc->info()->strides_in_bytes()[1] /
sizeof(T);
514 _transform->set_input_matrices(_transformed_output->buffer(), _matrix_stride, _matrix_row_stride);
515 _transform->set_bias((_biases ? reinterpret_cast<T *>(_biases->buffer() + _biases->info()->offset_first_element_in_bytes()) :
nullptr));
516 _transform->set_output_tensor(_output_nhwc->buffer() + _output_nhwc->info()->offset_first_element_in_bytes(), out_batch_stride, out_row_stride, out_col_stride);
517 _transform->set_working_space(_workspace->
buffer());
519 const size_t fst = window.
x().
start();
520 const size_t lst = window.
x().
end();
521 _transform->run(fst, lst,
info.thread_id);
524 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
545 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 547 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC T roundup(const T a, const T b)
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)
TensorShape compute_winograd_input_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd input transform shape.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
T iceildiv(const T a, const T b)
1 channel, 1 F32 per channel
const DataLayout data_layout
Store the tensor's metadata.
Describe one of the image's dimensions with a start, end and step.
arm_compute::ActivationLayerInfo::ActivationFunction Activation
Constant TensorID specifying an equivalent of null tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for CPU tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
ITensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
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.
const size_t input_height
void end(TokenStream &in, bool &valid)
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
TensorShape compute_winograd_filter_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd filter transform shape.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
virtual size_t offset_first_element_in_bytes() const =0
The offset from the beginning of the memory allocation to the first element of the tensor.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
TensorShape compute_winograd_output_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd output transform shape.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Class for specifying the size of an image or rectangle.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
constexpr int end() const
Return the end of the dimension.
DataType
Available data types.
DataLayout
[DataLayout enum definition]
constexpr int start() const
Return the start of the dimension.
Describe a multidimensional execution window.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.