24.02.1
|
Go to the documentation of this file.
48 const unsigned int channels =
54 "Channel shuffling with same number of groups as number of channels would be inefficient");
57 "The number of channels must be a multiple of the number of groups");
60 if (output->total_size() != 0)
69 void channel_shuffle_nhwc(
const ITensor *
input, ITensor *output,
unsigned int num_groups,
const Window &window)
74 const size_t element_size =
input->info()->element_size();
76 const double rK = 1.0 /
K;
78 Iterator in(
input, window);
82 [&](
const Coordinates &
id)
85 const unsigned int curr_channel =
id.x();
86 const unsigned int group_id = curr_channel * rK;
87 const unsigned int r = group_id *
K;
88 const unsigned int channel_id = curr_channel - r;
91 Coordinates out_coords = id;
93 std::copy_n(in.ptr(), element_size, output->ptr_to_element(out_coords));
97 void channel_shuffle_nchw(
const ITensor *
input, ITensor *output,
unsigned int num_groups,
const Window &window)
107 const unsigned int height =
input->info()->tensor_shape().y();
108 const size_t input_stride_y =
input->info()->strides_in_bytes().y();
109 const size_t output_stride_y = output->info()->strides_in_bytes().y();
110 const size_t row_size =
input->info()->dimension(
width_idx) *
input->info()->element_size();
113 const double rK = 1.0 /
K;
115 Iterator in(
input, win);
119 [&](
const Coordinates &
id)
122 const unsigned int curr_channel =
id.z();
123 const unsigned int group_id = curr_channel * rK;
124 const unsigned int r = group_id *
K;
125 const unsigned int channel_id = curr_channel - r;
128 Coordinates out_coords = id;
130 const uint8_t *input_ptr = in.ptr();
131 uint8_t *output_ptr = output->ptr_to_element(out_coords);
134 for (
unsigned int y = 0; y < height; ++y)
136 std::copy_n(input_ptr, row_size, output_ptr);
137 input_ptr += input_stride_y;
138 output_ptr += output_stride_y;
166 INEKernel::configure(win);
185 channel_shuffle_nhwc(_input, _output, _num_groups,
window);
188 channel_shuffle_nchw(_input, _output, _num_groups,
window);
Class to describe a number of elements in each dimension.
@ NCHW
Num samples, channels, height, width.
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
DataLayout
[DataLayout enum definition]
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
@ NHWC
Num samples, height, width, channels.
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Interface for CPU tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
constexpr auto data_layout
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
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 configure(const ITensor *input, ITensor *output, unsigned int num_groups)
Configure function's inputs and outputs.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
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...
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
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_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
NEChannelShuffleLayerKernel()
Default constructor.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(t,...)
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
const Window & window() const
The maximum window the kernel can be executed on.
Information about executing thread and CPU.
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
const unsigned int num_groups
Describe a multidimensional execution window.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Copyright (c) 2017-2024 Arm Limited.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
Store the tensor's metadata.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
@ UNKNOWN
Unknown data type.