Compute Library
 21.02
NEInstanceNormalizationLayerKernel Class Reference

Interface for performing an instance normalization. More...

#include <NEInstanceNormalizationLayerKernel.h>

Collaboration diagram for NEInstanceNormalizationLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEInstanceNormalizationLayerKernel ()
 Default constructor. More...
 
 NEInstanceNormalizationLayerKernel (const NEInstanceNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEInstanceNormalizationLayerKerneloperator= (const NEInstanceNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEInstanceNormalizationLayerKernel (NEInstanceNormalizationLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEInstanceNormalizationLayerKerneloperator= (NEInstanceNormalizationLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEInstanceNormalizationLayerKernel ()=default
 Default destructor. More...
 
void configure (ITensor *input, ITensor *output, const InstanceNormalizationLayerKernelInfo &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...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const InstanceNormalizationLayerKernelInfo &info)
 Static function to check if given info will lead to a valid configuration of NEInstanceNormalizationLayer. More...
 

Detailed Description

Interface for performing an instance normalization.

Definition at line 35 of file NEInstanceNormalizationLayerKernel.h.

Constructor & Destructor Documentation

◆ NEInstanceNormalizationLayerKernel() [1/3]

Default constructor.

Definition at line 215 of file NEInstanceNormalizationLayerKernel.cpp.

Referenced by NEInstanceNormalizationLayerKernel::name().

216  : _func(nullptr), _input(nullptr), _output(nullptr), _gamma(1), _beta(0), _epsilon(1e-12)
217 {
218 }

◆ NEInstanceNormalizationLayerKernel() [2/3]

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

◆ NEInstanceNormalizationLayerKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEInstanceNormalizationLayerKernel()

Default destructor.

Referenced by NEInstanceNormalizationLayerKernel::name().

Member Function Documentation

◆ configure()

void configure ( ITensor input,
ITensor output,
const InstanceNormalizationLayerKernelInfo info 
)

Set the input and output tensors.

Parameters
[in,out]inputSource tensor. Data types supported: F16/F32. Data layout supported: NCHW In case of output tensor = nullptr this tensor will store the result of the normalization.
[out]outputDestination tensor. Data types and data layouts supported: same as input.
[in]infoKernel meta-data descriptor

Definition at line 220 of file NEInstanceNormalizationLayerKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, InstanceNormalizationLayerKernelInfo::beta, ITensorInfo::data_type(), InstanceNormalizationLayerKernelInfo::epsilon, arm_compute::F16, arm_compute::F32, InstanceNormalizationLayerKernelInfo::gamma, ITensor::info(), arm_compute::test::validation::input, InstanceNormalizationLayerKernelInfo::use_mixed_precision, and arm_compute::validate_arguments().

Referenced by NEInstanceNormalizationLayerKernel::name().

221 {
223 
224  _input = input;
225  _output = output == nullptr ? input : output;
226  _gamma = info.gamma;
227  _beta = info.beta;
228  _epsilon = info.epsilon;
229  _use_mixed_precision = info.use_mixed_precision;
230 
231  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(_input->info(), _output->info(), _gamma, _beta, _epsilon));
232 
233  if(_input->info()->data_type() == DataType::F32)
234  {
235  _func = &instance_normalization_nchw<float>;
236  }
237 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
238  else if(_input->info()->data_type() == DataType::F16)
239  {
240  if(_use_mixed_precision)
241  {
242  _func = &instance_normalization_nchw<float16_t, float>;
243  }
244  else
245  {
246  _func = &instance_normalization_nchw<float16_t>;
247  }
248  }
249 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
250  else
251  {
252  ARM_COMPUTE_ERROR("Unsupported data type");
253  }
254 
255  // Configure kernel window
256  auto win_config = validate_and_configure_window(_input->info(), _output->info());
257  ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config));
258 
259  INEKernel::configure(std::get<1>(win_config));
260 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
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:455
1 channel, 1 F16 per channel
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

◆ name()

◆ operator=() [1/2]

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

Referenced by NEInstanceNormalizationLayerKernel::name().

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

Reimplemented from ICPPKernel.

Definition at line 269 of file NEInstanceNormalizationLayerKernel.cpp.

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

Referenced by NEInstanceNormalizationLayerKernel::name().

270 {
274  (*_func)(_input, _output, _gamma, _beta, _epsilon, window);
275 }
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:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const InstanceNormalizationLayerKernelInfo info 
)
static

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

Parameters
[in]inputSource tensor info. Data types supported: F16/F32. Data layout supported: NCHW
[in]outputDestination tensor info. Data types and data layouts supported: same as input.
[in]infoKernel meta-data descriptor
Returns
a status

Definition at line 262 of file NEInstanceNormalizationLayerKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, InstanceNormalizationLayerKernelInfo::beta, ICloneable< T >::clone(), InstanceNormalizationLayerKernelInfo::epsilon, InstanceNormalizationLayerKernelInfo::gamma, and arm_compute::validate_arguments().

Referenced by NEInstanceNormalizationLayerKernel::name(), and NEInstanceNormalizationLayer::validate().

263 {
264  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, info.gamma, info.beta, info.epsilon));
265  ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input->clone().get(), (output == nullptr ? input->clone().get() : output->clone().get()))));
266  return Status{};
267 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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