Compute Library
 19.08
NEChannelShuffleLayerKernel Class Reference

Interface for the channel shuffle kernel. More...

#include <NEChannelShuffleLayerKernel.h>

Collaboration diagram for NEChannelShuffleLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEChannelShuffleLayerKernel ()
 Default constructor. More...
 
 NEChannelShuffleLayerKernel (const NEChannelShuffleLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEChannelShuffleLayerKerneloperator= (const NEChannelShuffleLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEChannelShuffleLayerKernel (NEChannelShuffleLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEChannelShuffleLayerKerneloperator= (NEChannelShuffleLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEChannelShuffleLayerKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, unsigned int num_groups)
 Configure function's inputs and outputs. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Static Public Member Functions

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 NEChannelShuffleLayerKernel. More...
 

Detailed Description

Interface for the channel shuffle kernel.

Definition at line 35 of file NEChannelShuffleLayerKernel.h.

Constructor & Destructor Documentation

◆ NEChannelShuffleLayerKernel() [1/3]

Default constructor.

Definition at line 139 of file NEChannelShuffleLayerKernel.cpp.

140  : _input(nullptr), _output(nullptr), _num_groups()
141 {
142 }

◆ NEChannelShuffleLayerKernel() [2/3]

Prevent instances of this class from being copied (As this class contains pointers)

◆ NEChannelShuffleLayerKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEChannelShuffleLayerKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
unsigned int  num_groups 
)

Configure function's inputs and outputs.

Parameters
[in]inputInput tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[out]outputOutput tensor. Data type supported: Same as input
[in]num_groupsNumber of groups. Must be greater than 1 and the number of channels of the tensors must be a multiple of the number of groups.

Definition at line 144 of file NEChannelShuffleLayerKernel.cpp.

145 {
146  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
147 
148  // Output tensor auto initialization if not yet initialized
149  auto_init_if_empty(*output->info(), *input->info()->clone());
150 
151  _input = input;
152  _output = output;
153  _num_groups = num_groups;
154 
155  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), num_groups));
156 
157  // Configure kernel window
158  Window win = calculate_max_window(*input->info(), Steps());
159 
160  // The NEChannelShuffleLayerKernel doesn't need padding so update_window_and_padding() can be skipped
161  Coordinates coord;
162  coord.set_num_dimensions(output->info()->num_dimensions());
163  output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
164 
165  INEKernel::configure(win);
166 }
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
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...
Definition: Helpers.inl:201
const unsigned int num_groups
Definition: Im2Col.cpp:148
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), ITensor::info(), ITensorInfo::num_dimensions(), arm_compute::test::validation::num_groups, Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), and ITensorInfo::tensor_shape().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 38 of file NEChannelShuffleLayerKernel.h.

39  {
40  return "NEChannelShuffleLayerKernel";
41  }

◆ operator=() [1/2]

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Implements ICPPKernel.

Definition at line 174 of file NEChannelShuffleLayerKernel.cpp.

175 {
179 
180  switch(_input->info()->data_layout())
181  {
182  case DataLayout::NHWC:
183  channel_shuffle_nhwc(_input, _output, _num_groups, window);
184  break;
185  case DataLayout::NCHW:
186  channel_shuffle_nchw(_input, _output, _num_groups, window);
187  break;
188  default:
189  ARM_COMPUTE_ERROR("Unsupported data layout!");
190  break;
191  }
192 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
Num samples, channels, height, width.
Num samples, height, width, channels.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorInfo::data_layout(), ITensor::info(), arm_compute::test::validation::info, arm_compute::NCHW, arm_compute::NHWC, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
unsigned int  num_groups 
)
static

Static function to check if given info will lead to a valid configuration of NEChannelShuffleLayerKernel.

Parameters
[in]inputInput tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[out]outputOutput tensor. Data type supported: Same as input
[in]num_groupsNumber of groups. Must be greater than 1 and the number of channels of the tensors must be a multiple of the number of groups.
Returns
a status

Definition at line 168 of file NEChannelShuffleLayerKernel.cpp.

169 {
170  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, num_groups));
171  return Status{};
172 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
const unsigned int num_groups
Definition: Im2Col.cpp:148

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::test::validation::num_groups.

Referenced by NEChannelShuffleLayer::validate().


The documentation for this class was generated from the following files: