35 #include "src/core/NEON/kernels/convolution/common/utils.hpp" 36 #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) } };
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>(
199 WinogradConv::get_kernel_storage_size(num_input_channels, num_output_channels) /
sizeof(T));
202 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
204 : _transform(nullptr), _weights_hwio(nullptr), _output(nullptr), _matrix_stride(0), _num_output_channels(0), _num_input_channels(0)
208 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
211 return WinogradConv::get_kernel_matrix_stride(num_input_channels, num_output_channels);
214 #ifndef DOXYGEN_SKIP_THIS 215 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
219 const int matrix_stride,
220 const int num_output_channels,
221 const int num_input_channels)
223 _weights_hwio = weights_hwio;
225 _matrix_stride = matrix_stride;
226 _num_output_channels = num_output_channels;
227 _num_input_channels = num_input_channels;
228 _transform = std::make_unique<WeightsTransform>(num_output_channels, num_input_channels);
231 auto win_last = _transform->get_window();
233 INEKernel::configure(win);
237 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();
244 _transform->set_weight_tensor(_weights_hwio->
buffer());
245 const int matrix_row_stride =
roundup(_num_output_channels, WinogradConv::N_BLOCK);
246 _transform->set_output_matrices(_output->
buffer(), _matrix_stride, matrix_row_stride);
247 _transform->set_working_space(_output->
buffer());
249 _transform->run(fst, lst);
252 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
258 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
278 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 280 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 284 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
294 const Tensor4DShape
input_shape(num_batches, num_rows, num_cols, num_channels);
295 const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels);
297 return static_cast<unsigned int>(WinogradConv::get_input_storage_size(num_batches, num_rows, num_cols, num_channels, same_padding) /
sizeof(T));
300 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
303 return _transform->get_working_space_size(num_threads) /
sizeof(T);
306 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
312 bool same_padding )
const 314 return WinogradConv::get_input_matrix_stride(num_batches, num_rows, num_cols, num_channels, same_padding);
317 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
319 : _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(),
320 _padding_right(), _padding_bottom(), _workspace(nullptr)
324 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
327 const int num_batches,
330 const int num_channels,
331 const PaddingType padding,
333 const int matrix_stride,
336 _input_nhwc = input_nhwc;
337 _num_batches = num_batches;
338 _num_rows = num_rows;
339 _num_cols = num_cols;
340 _num_channels = num_channels;
343 _matrix_stride = matrix_stride;
344 _workspace = workspace;
346 _padding_top = (padding == PADDING_SAME) ? (KernelRows - 1) / 2 : 0;
347 _padding_left = (padding == PADDING_SAME) ? (KernelCols - 1) / 2 : 0;
348 _padding_bottom = (padding == PADDING_SAME) ?
iceildiv(KernelRows - 1, 2) : 0;
349 _padding_right = (padding == PADDING_SAME) ?
iceildiv(KernelCols - 1, 2) : 0;
351 _transform = std::make_unique<InputTransform>(
365 auto win_last = _transform->get_window();
367 INEKernel::configure(win);
370 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
380 const int input_batch_stride = _input_nhwc->
info()->
strides_in_bytes()[3] / element_size_in_bytes;
385 _transform->set_input_tensor(input_nhwc_ptr, input_batch_stride, input_row_stride, input_col_stride);
386 _transform->set_output_matrices(output_ptr, _matrix_stride, _num_channels);
388 _transform->set_working_space(_workspace->
buffer());
391 const size_t fst = window.
x().
start();
392 const size_t lst = window.
x().
end();
393 _transform->run(fst, lst, info.
thread_id);
396 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
416 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 418 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 422 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
427 int num_output_channels
431 const Tensor4DShape
input_shape(num_batches, num_rows, num_cols, 1);
432 const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1);
434 return static_cast<unsigned int>(
435 WinogradConv::get_output_storage_size(num_batches, num_rows, num_cols, num_output_channels) /
sizeof(T));
438 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
440 : _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),
441 _num_cols(0), _num_channels(0)
445 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
448 return _transform->get_working_space_size(num_threads) /
sizeof(T);
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>
474 const ITensor *transformed_output,
475 const int matrix_stride,
477 const int num_batches,
480 const int num_channels,
485 _workspace = workspace;
486 _transformed_output = transformed_output;
487 _matrix_stride = matrix_stride;
488 _matrix_row_stride =
roundup(num_channels, WinogradConv::N_BLOCK);
489 _output_nhwc = output_nhwc;
490 _num_batches = num_batches;
491 _num_rows = num_rows;
492 _num_cols = num_cols;
493 _num_channels = num_channels;
495 _transform = std::make_unique<OutputTransform>(num_batches, num_rows, num_cols, num_channels, activation);
497 auto win_last = _transform->get_window();
501 INEKernel::configure(win);
504 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
517 _transform->set_input_matrices(_transformed_output->
buffer(), _matrix_stride, _matrix_row_stride);
520 _transform->set_working_space(_workspace->
buffer());
522 const size_t fst = window.
x().
start();
523 const size_t lst = window.
x().
end();
524 _transform->run(fst, lst, info.
thread_id);
527 template <
typename T,
int OutputTileRows,
int OutputTileCols,
int KernelRows,
int KernelCols>
548 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 550 #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.
#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
const size_t input_height
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 Neon tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
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(...)
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 const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
T z() const
Alias to access the size of the third dimension.
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)
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,...)
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
T y() const
Alias to access the size of the second dimension.
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
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.
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.