55 if(output->total_size() != 0)
64 void channel_shuffle_nhwc(
const ITensor *input, ITensor *output,
unsigned int num_groups,
const Window &window)
69 const size_t element_size = input->info()->element_size();
70 const unsigned int K = input->info()->dimension(channel_idx) /
num_groups;
71 const float rK = 1.f /
K;
73 Iterator in(input, window);
78 const unsigned int curr_channel =
id.x();
79 const unsigned int group_id = curr_channel * rK;
80 const unsigned int r = group_id *
K;
81 const unsigned int channel_id = curr_channel - r;
84 Coordinates out_coords = id;
85 out_coords.set(
Window::DimX, channel_id * num_groups + group_id);
86 std::copy_n(in.ptr(), element_size, output->ptr_to_element(out_coords));
90 void channel_shuffle_nchw(
const ITensor *input, ITensor *output,
unsigned int num_groups,
const Window &window)
96 const DataLayout data_layout = input->info()->data_layout();
100 const unsigned int height = input->info()->tensor_shape().y();
101 const size_t input_stride_y = input->info()->strides_in_bytes().y();
102 const size_t output_stride_y = output->info()->strides_in_bytes().y();
103 const size_t row_size = input->info()->dimension(width_idx) * input->info()->element_size();
105 const unsigned int K = input->info()->dimension(channel_idx) /
num_groups;
106 const float rK = 1.f /
K;
108 Iterator in(input, win);
113 const unsigned int curr_channel =
id.z();
114 const unsigned int group_id = curr_channel * rK;
115 const unsigned int r = group_id *
K;
116 const unsigned int channel_id = curr_channel - r;
119 Coordinates out_coords = id;
120 out_coords.set(
Window::DimZ, channel_id * num_groups + group_id);
121 const uint8_t *input_ptr = in.ptr();
122 uint8_t *output_ptr = output->ptr_to_element(out_coords);
125 for(
unsigned int y = 0; y < height; ++y)
127 std::copy_n(input_ptr, row_size, output_ptr);
129 output_ptr += output_stride_y;
137 : _input(nullptr), _output(nullptr), _num_groups()
162 INEKernel::configure(win);
180 channel_shuffle_nhwc(_input, _output, _num_groups, window);
183 channel_shuffle_nchw(_input, _output, _num_groups, window);
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.
void configure(const ITensor *input, ITensor *output, unsigned int num_groups)
Configure function's inputs and outputs.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(t,...)
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
const DataLayout data_layout
Store the tensor's metadata.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int num_groups)
Static function to check if given info will lead to a valid configuration of NEChannelShuffleLayerKer...
#define ARM_COMPUTE_ERROR_THROW_ON(status)
const size_t input_stride_y
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for Neon tensor.
Copyright (c) 2017-2021 Arm Limited.
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
NEChannelShuffleLayerKernel()
Default constructor.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Class to describe a number of elements in each dimension.
const unsigned int num_groups
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.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
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)
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(...)
Num samples, height, width, channels.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
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.
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.
DataLayout
[DataLayout enum definition]
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.