Compute Library
 21.08
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...
 
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 *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 212 of file NEInstanceNormalizationLayerKernel.cpp.

Referenced by NEInstanceNormalizationLayerKernel::name().

213  : _func(nullptr), _input(nullptr), _output(nullptr), _gamma(1), _beta(0), _epsilon(1e-12)
214 {
215 }

◆ 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 217 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, and InstanceNormalizationLayerKernelInfo::use_mixed_precision.

Referenced by NEInstanceNormalizationLayerKernel::name().

218 {
220 
221  _input = input;
222  _output = output == nullptr ? input : output;
223  _gamma = info.gamma;
224  _beta = info.beta;
225  _epsilon = info.epsilon;
226  _use_mixed_precision = info.use_mixed_precision;
227 
228  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(_input->info(), _output->info(), _gamma, _beta, _epsilon));
229 
230  if(_input->info()->data_type() == DataType::F32)
231  {
232  _func = &instance_normalization_nchw<float>;
233  }
234 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
235  else if(_input->info()->data_type() == DataType::F16)
236  {
237  if(_use_mixed_precision)
238  {
239  _func = &instance_normalization_nchw<float16_t, float>;
240  }
241  else
242  {
243  _func = &instance_normalization_nchw<float16_t>;
244  }
245  }
246 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
247  else
248  {
249  ARM_COMPUTE_ERROR("Unsupported data type");
250  }
251 
252  // Configure kernel window
253  auto win_config = validate_and_configure_window(_input->info(), _output->info());
254  ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config));
255 
256  INEKernel::configure(std::get<1>(win_config));
257 }
#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)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ 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 266 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().

267 {
271  (*_func)(_input, _output, _gamma, _beta, _epsilon, window);
272 }
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: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 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 259 of file NEInstanceNormalizationLayerKernel.cpp.

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

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

260 {
261  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, info.gamma, info.beta, info.epsilon));
262  ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input->clone().get(), (output == nullptr ? input->clone().get() : output->clone().get()))));
263  return Status{};
264 }
#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)

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