33 #include "src/core/NEON/kernels/convolution/common/utils.hpp" 34 #include "src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp" 50 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) } };
51 const std::array<Size2D, 8> f16_support = { { Size2D(3, 3) } };
56 return std::end(f16_support) != std::find(std::begin(f16_support),
std::end(f16_support), size);
58 return std::end(f32_support) != std::find(std::begin(f32_support),
std::end(f32_support), size);
64 Status validate_arguments_winograd_weight_trans(
const ITensorInfo *
input,
const ITensorInfo *output,
const WinogradInfo &winograd_info)
72 const auto input_width = input->dimension(idx_width);
75 "Only 1x3, 3x1, 1x5, 5x1, 7x1, 1x7, 3x3 and 5x5 kernels are supported");
77 const Size2D &output_tile = winograd_info.output_tile_size;
78 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) } };
82 if(output->total_size() != 0)
93 std::pair<Status, Window> validate_and_configure_window_winograd_weight_trans(ITensorInfo *input, ITensorInfo *output,
const WinogradInfo &winograd_info)
98 return std::make_pair(Status{}, win);
101 Status validate_arguments_winograd_input_trans(
const ITensorInfo *input,
const ITensorInfo *output,
const WinogradInfo &winograd_info)
103 const Size2D &kernel_dims = winograd_info.kernel_size;
104 const PadStrideInfo &
conv_info = winograd_info.convolution_info;
108 ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1,
"Winograd input transform only supports unit strides");
110 "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
113 if(output->total_size() != 0)
124 std::pair<Status, Window> validate_and_configure_window_winograd_input_trans(ITensorInfo *input, ITensorInfo *output,
const WinogradInfo &winograd_info)
132 Status validate_arguments_winograd_output_trans(
const ITensorInfo *input,
const ITensorInfo *bias,
const ITensorInfo *output,
const WinogradInfo &winograd_info)
134 const PadStrideInfo &conv_info = winograd_info.convolution_info;
135 const Size2D kernel_dims = winograd_info.kernel_size;
138 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>
139 (winograd_info.output_tile_size.width));
140 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>
141 (winograd_info.output_tile_size.height));
142 const Size2D num_tiles = Size2D(num_tiles_x, num_tiles_y);
149 "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
151 const std::array<unsigned int, 3> supported_gemm_sizes = { { 8
U, 16
U, 36U } };
162 if(output->total_size() != 0)
171 std::pair<Status, Window> validate_and_configure_window_winograd_output_trans(ITensorInfo *input, ITensorInfo *output,
const WinogradInfo &winograd_info)
188 "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
193 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
196 const KernelShape
shape(num_output_channels, KernelRows, KernelCols, num_input_channels);
197 return static_cast<unsigned int>(
198 WinogradConv::get_kernel_storage_size(num_input_channels, num_output_channels));
201 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
203 : _transform(nullptr), _num_output_channels(0), _matrix_stride(0)
207 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
210 return WinogradConv::get_kernel_matrix_stride(num_input_channels, num_output_channels);
213 #ifndef DOXYGEN_SKIP_THIS 214 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
218 const int matrix_stride,
219 const int num_output_channels,
220 const int num_input_channels)
224 _transform = std::make_unique<WeightsTransform>(num_output_channels, num_input_channels);
225 _num_output_channels = num_output_channels;
226 _matrix_stride = matrix_stride;
229 auto win_last = _transform->get_window();
231 ICpuKernel::configure(win);
235 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
242 const size_t fst = window.
x().
start();
243 const size_t lst = window.
x().
end();
248 _transform->set_weight_tensor(weights_hwio->
buffer());
249 const int matrix_row_stride =
roundup(_num_output_channels, WinogradConv::N_BLOCK);
250 _transform->set_output_matrices(output->
buffer(), _matrix_stride, matrix_row_stride);
251 _transform->set_working_space(output->
buffer());
253 _transform->run(fst, lst);
256 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
262 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
282 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 284 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 288 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
298 const Tensor4DShape
input_shape(num_batches, num_rows, num_cols, num_channels);
299 const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels);
300 return static_cast<unsigned int>(WinogradConv::get_input_storage_size(num_batches, num_rows, num_cols, num_channels, same_padding));
303 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
306 return _transform->get_working_space_size(num_threads);
309 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
315 bool same_padding )
const 317 return WinogradConv::get_input_matrix_stride(num_batches, num_rows, num_cols, num_channels, same_padding);
320 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
322 : _transform(nullptr), _num_channels(0), _matrix_stride(0)
326 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
329 const int num_batches,
332 const int num_channels,
333 const PaddingType padding,
335 const int matrix_stride,
340 _num_channels = num_channels;
341 _matrix_stride = matrix_stride;
343 const int padding_top = (padding == PADDING_SAME) ? (KernelRows - 1) / 2 : 0;
344 const int padding_left = (padding == PADDING_SAME) ? (KernelCols - 1) / 2 : 0;
345 const int padding_bottom = (padding == PADDING_SAME) ?
iceildiv(KernelRows - 1, 2) : 0;
346 const int padding_right = (padding == PADDING_SAME) ?
iceildiv(KernelCols - 1, 2) : 0;
348 _transform = std::make_unique<InputTransform>(
362 auto win_last = _transform->get_window();
364 ICpuKernel::configure(win);
367 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
379 const int input_col_stride = input_nhwc->info()->strides_in_bytes().y() / element_size_in_bytes;
380 const int input_row_stride = input_nhwc->info()->strides_in_bytes().z() / element_size_in_bytes;
381 const int input_batch_stride = input_nhwc->info()->strides_in_bytes()[3] / element_size_in_bytes;
382 const auto input_nhwc_ptr =
reinterpret_cast<const T *
>(input_nhwc->buffer() + input_nhwc->info()->offset_first_element_in_bytes());
386 _transform->set_input_tensor(input_nhwc_ptr, input_batch_stride, input_row_stride, input_col_stride);
387 _transform->set_output_matrices(output_ptr, _matrix_stride, _num_channels);
389 _transform->set_working_space(workspace->
buffer());
392 const size_t fst = window.
x().
start();
393 const size_t lst = window.
x().
end();
394 _transform->run(fst, lst, info.
thread_id);
397 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
418 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 420 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 424 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
429 int num_output_channels
433 const Tensor4DShape
input_shape(num_batches, num_rows, num_cols, 1);
434 const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1);
435 return static_cast<unsigned int>(
436 WinogradConv::get_output_storage_size(num_batches, num_rows, num_cols, num_output_channels));
439 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
441 : _transform(nullptr), _matrix_stride(0), _matrix_row_stride(0)
445 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
448 return _transform->get_working_space_size(num_threads);
451 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
456 int num_output_channels
459 return WinogradConv::get_output_matrix_stride(num_batches, num_rows, num_cols, num_output_channels);
462 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
466 bool padding_same)
const 468 return WinogradConv::get_output_shape(std::make_pair<unsigned int, unsigned int>(num_rows, num_cols), padding_same);
471 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
475 const int matrix_stride,
477 const int num_batches,
480 const int num_channels,
484 ARM_COMPUTE_UNUSED(biases, transformed_output, output_nhwc, num_batches, num_rows, num_cols, workspace, activation);
486 _matrix_stride = matrix_stride;
487 _matrix_row_stride =
roundup(num_channels, WinogradConv::N_BLOCK);
490 _transform = std::make_unique<OutputTransform>(num_batches, num_rows, num_cols, num_channels, activation);
492 auto win_last = _transform->get_window();
495 ICpuKernel::configure(win);
498 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
513 _transform->set_input_matrices(transformed_output->
buffer(), _matrix_stride, _matrix_row_stride);
514 _transform->set_bias((biases ? reinterpret_cast<T *>(biases->buffer() + biases->info()->offset_first_element_in_bytes()) :
nullptr));
516 _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)
const Window & window() const
The maximum window the kernel can be executed on.
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.
bool empty() const
Checks if pack is empty.
#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.
T iceildiv(const T a, const 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.
const DataLayout data_layout
Store the tensor's metadata.
Describe one of the image's dimensions with a start, end and step.
#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
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
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.
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
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.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
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)
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
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(...)
const size_t input_height
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
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.
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.