Compute Library
 19.08
NENormalizationLayerKernel Class Reference

Interface for the normalization layer kernel. More...

#include <NENormalizationLayerKernel.h>

Collaboration diagram for NENormalizationLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NENormalizationLayerKernel ()
 Default constructor. More...
 
 NENormalizationLayerKernel (const NENormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NENormalizationLayerKerneloperator= (const NENormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NENormalizationLayerKernel (NENormalizationLayerKernel &&)=default
 Default Move Constructor. More...
 
NENormalizationLayerKerneloperator= (NENormalizationLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~NENormalizationLayerKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, const ITensor *input_squared, ITensor *output, NormalizationLayerInfo norm_info)
 Set the input and output tensors. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
BorderSize border_size () const override
 The size of the border for that kernel. 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...
 
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 *input_squared, const ITensorInfo *output, NormalizationLayerInfo norm_info)
 Static function to check if given info will lead to a valid configuration of NENormalizationLayerKernel. More...
 

Detailed Description

Interface for the normalization layer kernel.

Definition at line 35 of file NENormalizationLayerKernel.h.

Constructor & Destructor Documentation

◆ NENormalizationLayerKernel() [1/3]

Default constructor.

Definition at line 105 of file NENormalizationLayerKernel.cpp.

106  : _func(nullptr), _input(nullptr), _input_squared(nullptr), _output(nullptr), _norm_info(NormType::IN_MAP_1D), _border_size()
107 {
108 }
Normalization applied within the same map in 1D region.

References arm_compute::IN_MAP_1D.

◆ NENormalizationLayerKernel() [2/3]

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

◆ NENormalizationLayerKernel() [3/3]

Default Move Constructor.

◆ ~NENormalizationLayerKernel()

Default destructor.

Member Function Documentation

◆ border_size()

BorderSize border_size ( ) const
overridevirtual

The size of the border for that kernel.

Returns
The width in number of elements of the border.

Reimplemented from IKernel.

Definition at line 110 of file NENormalizationLayerKernel.cpp.

111 {
112  return _border_size;
113 }

Referenced by NENormalizationLayer::configure().

◆ configure()

void configure ( const ITensor input,
const ITensor input_squared,
ITensor output,
NormalizationLayerInfo  norm_info 
)

Set the input and output tensors.

Parameters
[in]inputSource tensor. 3 lower dims represent a single input with dimensions [width, height, IFM], and an optional 4th dimension for batch of inputs. Data types supported: FP16/F32. Data layouts supported: NCHW/NHWC.
[in]input_squaredSource with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM], Data type and layout supported: same as input.
[out]outputDestination tensor. Output will have the same number of dimensions as input. Data type and layout supported: same as input.
[in]norm_infoNormalization layer information like the normalization type, normalization size and other parameters.

Definition at line 115 of file NENormalizationLayerKernel.cpp.

116 {
117  ARM_COMPUTE_ERROR_ON_NULLPTR(input, input_squared, output);
118  // Output tensor auto initialization if not yet initialized
119  auto_init_if_empty(*output->info(), *input->info());
120 
121  // Perform validation step
122  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), input_squared->info(), output->info(), norm_info));
123 
124  const unsigned int num_elems_processed_per_iteration = 16 / input->info()->element_size();
125 
126  const unsigned int norm_idx = get_normalization_dimension_index(input->info()->data_layout(), norm_info);
127  const bool is_norm_accross_width = norm_idx == 0;
128  const unsigned int border_width = is_norm_accross_width ? num_elems_processed_per_iteration - 1 : 0;
129 
130  _input = input;
131  _input_squared = input_squared;
132  _output = output;
133  _norm_info = norm_info;
134  _border_size = BorderSize(0, border_width);
135 
136  switch(_input->info()->data_type())
137  {
138  case DataType::F32:
139  {
140  switch(norm_idx)
141  {
142  case 0:
143  {
144  if(norm_info.type() == NormType::IN_MAP_2D)
145  {
146  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 0, true>;
147  }
148  else
149  {
150  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 0, false>;
151  }
152  break;
153  }
154  case 1:
155  if(norm_info.type() == NormType::IN_MAP_2D)
156  {
157  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 1, true>;
158  }
159  else
160  {
161  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 1, false>;
162  }
163  break;
164  case 2:
165  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 2, false>;
166  break;
167  default:
168  break;
169  }
170  break;
171  }
172 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
173  case DataType::F16:
174  {
175  switch(norm_idx)
176  {
177  case 0:
178  {
179  if(norm_info.type() == NormType::IN_MAP_2D)
180  {
181  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 0, true>;
182  }
183  else
184  {
185  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 0, false>;
186  }
187  break;
188  }
189  case 1:
190  if(norm_info.type() == NormType::IN_MAP_2D)
191  {
192  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 1, true>;
193  }
194  else
195  {
196  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 1, false>;
197  }
198  break;
199  case 2:
200  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 2, false>;
201  break;
202  default:
203  break;
204  }
205  break;
206  }
207 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
208  default:
209  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
210  }
211 
212  // Configure kernel window
213  auto win_config = validate_and_configure_window(input->info(), input_squared->info(), output->info(), norm_info);
214  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
215  INEKernel::configure(win_config.second);
216 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
Container for 2D border size.
Definition: Types.h:259
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
NormType type() const
Get the normalization type.
Definition: Types.h:1596
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
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
1 channel, 1 F16 per channel
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()
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
unsigned int get_normalization_dimension_index(DataLayout layout, const NormalizationLayerInfo &info)
Calculate the normalization dimension index for a given normalization type.
Definition: Helpers.h:726
Normalization applied within the same map in 2D region.
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::element_size(), arm_compute::F16, arm_compute::F32, arm_compute::get_normalization_dimension_index(), arm_compute::IN_MAP_2D, ITensor::info(), NormalizationLayerInfo::type(), and arm_compute::validate_and_configure_window().

Referenced by NENormalizationLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 38 of file NENormalizationLayerKernel.h.

39  {
40  return "NENormalizationLayerKernel";
41  }

◆ operator=() [1/2]

NENormalizationLayerKernel& operator= ( const NENormalizationLayerKernel )
delete

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

◆ operator=() [2/2]

Default move assignment operator.

◆ 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 279 of file NENormalizationLayerKernel.cpp.

280 {
284  ARM_COMPUTE_ERROR_ON(_func == nullptr);
285 
286  // Run function
287  (this->*_func)(window);
288 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
#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

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::info, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo input_squared,
const ITensorInfo output,
NormalizationLayerInfo  norm_info 
)
static

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

Parameters
[in]inputSource tensor. 3 lower dims represent a single input with dimensions [width, height, IFM], and an optional 4th dimension for batch of inputs. Data types supported: FP16/F32. Data layouts supported: NCHW/NHWC.
[in]input_squaredSource with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM], Data type and layout supported: same as input.
[in]outputDestination tensor. Output will have the same number of dimensions as input. Data type and layout supported: same as input.
[in]norm_infoNormalization layer information like the normalization type, normalization size and other parameters.
Returns
a status

Definition at line 271 of file NENormalizationLayerKernel.cpp.

272 {
273  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, input_squared, output, norm_info));
274  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), input_squared->clone().get(), output->clone().get(), norm_info).first);
275 
276  return Status{};
277 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
Status class.
Definition: Error.h:52
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.

References ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), and arm_compute::validate_and_configure_window().

Referenced by NENormalizationLayer::validate().


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