Compute Library
 21.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...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. 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 67 of file NENormalizationLayerKernel.cpp.

References arm_compute::IN_MAP_1D.

Referenced by NENormalizationLayerKernel::name().

68  : _func(nullptr), _input(nullptr), _input_squared(nullptr), _output(nullptr), _norm_info(NormType::IN_MAP_1D)
69 {
70 }
Normalization applied within the same map in 1D region.

◆ 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.

Referenced by NENormalizationLayerKernel::name().

Member Function Documentation

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

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), NormalizationLayerInfo::beta(), arm_compute::calculate_max_window(), ITensorInfo::data_layout(), ITensorInfo::dimension(), Window::DimX, Window::Dimension::end(), arm_compute::execute_window_loop(), arm_compute::F16, arm_compute::F32, arm_compute::get_normalization_dimension_index(), arm_compute::IN_MAP_2D, ITensor::info(), arm_compute::test::validation::input, NormalizationLayerInfo::kappa(), arm_compute::NCHW, NormalizationLayerInfo::norm_size(), Iterator::ptr(), NormalizationLayerInfo::scale_coeff(), Window::set(), Window::Dimension::start(), ITensorInfo::strides_in_bytes(), NormalizationLayerInfo::type(), arm_compute::wrapper::vadd(), arm_compute::wrapper::vdup_n(), arm_compute::wrapper::vinv(), arm_compute::wrapper::vloadq(), arm_compute::wrapper::vmla(), arm_compute::wrapper::vmul(), arm_compute::wrapper::vpow(), arm_compute::wrapper::vstore(), IKernel::window(), and Window::x().

Referenced by NENormalizationLayerKernel::name().

73 {
74  ARM_COMPUTE_ERROR_ON_NULLPTR(input, input_squared, output);
75  // Output tensor auto initialization if not yet initialized
76  auto_init_if_empty(*output->info(), *input->info());
77 
78  // Perform validation step
79  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), input_squared->info(), output->info(), norm_info));
80 
81  const unsigned int norm_idx = get_normalization_dimension_index(input->info()->data_layout(), norm_info);
82 
83  _input = input;
84  _input_squared = input_squared;
85  _output = output;
86  _norm_info = norm_info;
87 
88  switch(_input->info()->data_type())
89  {
90  case DataType::F32:
91  {
92  switch(norm_idx)
93  {
94  case 0:
95  {
96  if(norm_info.type() == NormType::IN_MAP_2D)
97  {
98  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 0, true>;
99  }
100  else
101  {
102  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 0, false>;
103  }
104  break;
105  }
106  case 1:
107  if(norm_info.type() == NormType::IN_MAP_2D)
108  {
109  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 1, true>;
110  }
111  else
112  {
113  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 1, false>;
114  }
115  break;
116  case 2:
117  _func = &NENormalizationLayerKernel::normalize_float<float, 4, 2, false>;
118  break;
119  default:
120  break;
121  }
122  break;
123  }
124 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
125  case DataType::F16:
126  {
127  switch(norm_idx)
128  {
129  case 0:
130  {
131  if(norm_info.type() == NormType::IN_MAP_2D)
132  {
133  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 0, true>;
134  }
135  else
136  {
137  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 0, false>;
138  }
139  break;
140  }
141  case 1:
142  if(norm_info.type() == NormType::IN_MAP_2D)
143  {
144  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 1, true>;
145  }
146  else
147  {
148  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 1, false>;
149  }
150  break;
151  case 2:
152  _func = &NENormalizationLayerKernel::normalize_float<float16_t, 8, 2, false>;
153  break;
154  default:
155  break;
156  }
157  break;
158  }
159 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
160  default:
161  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
162  }
163 
164  // Configure kernel window
165  Window win = calculate_max_window(*input->info(), Steps());
166  INEKernel::configure(win);
167 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
1 channel, 1 F16 per channel
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_NULLPTR(...)
Definition: Validate.h:157
unsigned int get_normalization_dimension_index(DataLayout layout, const NormalizationLayerInfo &info)
Calculate the normalization dimension index for a given normalization type.
Normalization applied within the same map in 2D region.

◆ name()

◆ operator=() [1/2]

NENormalizationLayerKernel& operator= ( const NENormalizationLayerKernel )
delete

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

Referenced by NENormalizationLayerKernel::name().

◆ 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.

Reimplemented from ICPPKernel.

Definition at line 284 of file NENormalizationLayerKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by NENormalizationLayerKernel::name().

285 {
289  ARM_COMPUTE_ERROR_ON(_func == nullptr);
290 
291  // Run function
292  (this->*_func)(window);
293 }
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:466
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

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

References ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by NENormalizationLayerKernel::name(), and NENormalizationLayer::validate().

278 {
279  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, input_squared, output, norm_info));
280 
281  return Status{};
282 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

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