Compute Library
 21.02
CLBatchNormalizationLayerKernel Class Reference

Interface for the BatchNormalization layer kernel. More...

#include <CLBatchNormalizationLayerKernel.h>

Collaboration diagram for CLBatchNormalizationLayerKernel:
[legend]

Public Member Functions

 CLBatchNormalizationLayerKernel ()
 Constructor. More...
 
 CLBatchNormalizationLayerKernel (const CLBatchNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLBatchNormalizationLayerKerneloperator= (const CLBatchNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLBatchNormalizationLayerKernel (CLBatchNormalizationLayerKernel &&)=default
 Default Move Constructor. More...
 
CLBatchNormalizationLayerKerneloperator= (CLBatchNormalizationLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~CLBatchNormalizationLayerKernel ()=default
 Default destructor. More...
 
void configure (ICLTensor *input, ICLTensor *output, const ICLTensor *mean, const ICLTensor *var, const ICLTensor *beta=nullptr, const ICLTensor *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
 Set the input and output tensors. More...
 
void configure (const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *output, const ICLTensor *mean, const ICLTensor *var, const ICLTensor *beta=nullptr, const ICLTensor *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
 Set the input and output tensors. More...
 
void run (const Window &window, cl::CommandQueue &queue) override
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. More...
 
- Public Member Functions inherited from ICLKernel
 ICLKernel ()
 Constructor. More...
 
cl::Kernel & kernel ()
 Returns a reference to the OpenCL kernel of this object. More...
 
template<typename T >
void add_1D_array_argument (unsigned int &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed 1D array's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_2D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_2D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_3D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_4D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. More...
 
template<typename T >
void add_argument (unsigned int &idx, T value)
 Add the passed parameters to the object's kernel's arguments starting from the index idx. More...
 
void set_lws_hint (const cl::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
cl::NDRange lws_hint () const
 Return the Local-Workgroup-Size hint. More...
 
void set_wbsm_hint (const cl_int &wbsm_hint)
 Set the workgroup batch size modifier hint. More...
 
cl_int wbsm_hint () const
 Return the workgroup batch size modifier hint. More...
 
const std::string & config_id () const
 Get the configuration ID. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
void set_target (cl::Device &device)
 Set the targeted GPU architecture according to the CL device. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. More...
 
size_t get_max_workgroup_size ()
 Get the maximum workgroup size for the device the CLKernelLibrary uses. More...
 
template<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
template<typename T , unsigned int dimension_size>
void add_array_argument (unsigned &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed array's parameters to the object's kernel's arguments starting from the index idx. 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 ITensorInfo *mean, const ITensorInfo *var, const ITensorInfo *beta=nullptr, const ITensorInfo *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
 Static function to check if given info will lead to a valid configuration of CLBatchNormalizationLayerKernel. More...
 
- Static Public Member Functions inherited from ICLKernel
static constexpr unsigned int num_arguments_per_1D_array ()
 Returns the number of arguments enqueued per 1D array object. More...
 
static constexpr unsigned int num_arguments_per_1D_tensor ()
 Returns the number of arguments enqueued per 1D tensor object. More...
 
static constexpr unsigned int num_arguments_per_2D_tensor ()
 Returns the number of arguments enqueued per 2D tensor object. More...
 
static constexpr unsigned int num_arguments_per_3D_tensor ()
 Returns the number of arguments enqueued per 3D tensor object. More...
 
static constexpr unsigned int num_arguments_per_4D_tensor ()
 Returns the number of arguments enqueued per 4D tensor object. More...
 
static cl::NDRange gws_from_window (const Window &window)
 Get the global work size given an execution window. More...
 

Detailed Description

Interface for the BatchNormalization layer kernel.

Definition at line 35 of file CLBatchNormalizationLayerKernel.h.

Constructor & Destructor Documentation

◆ CLBatchNormalizationLayerKernel() [1/3]

Constructor.

Definition at line 109 of file CLBatchNormalizationLayerKernel.cpp.

110  : _input(nullptr), _output(nullptr), _mean(nullptr), _var(nullptr), _beta(nullptr), _gamma(nullptr), _epsilon(0), _run_in_place(false)
111 {
112 }

◆ CLBatchNormalizationLayerKernel() [2/3]

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

◆ CLBatchNormalizationLayerKernel() [3/3]

Default Move Constructor.

◆ ~CLBatchNormalizationLayerKernel()

Default destructor.

Member Function Documentation

◆ configure() [1/2]

void configure ( ICLTensor input,
ICLTensor output,
const ICLTensor mean,
const ICLTensor var,
const ICLTensor beta = nullptr,
const ICLTensor gamma = nullptr,
float  epsilon = 0.001f,
ActivationLayerInfo  act_info = ActivationLayerInfo() 
)

Set the input and output tensors.

Note
If the output tensor is a nullptr, the batch normalization function will be performed in-place
Parameters
[in,out]inputSource tensor. In case of output tensor = nullptr, this tensor will store the result. 3 lower dimensions represent a single input with dimensions [width, height, FM]. The rest are optional and used for representing batches. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC.
[out]outputDestination tensor. Output will have the same number of dimensions as input. Data type supported: same as input
[in]meanMean values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]varVariance values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]beta(Optional) Beta values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for beta is 0. Data types supported: Same as input
[in]gamma(Optional) Gamma values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for gamma is 1. Data types supported: Same as input
[in]epsilon(Optional) Small value to avoid division with zero. Default value is 0.001f.
[in]act_info(Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.

Definition at line 114 of file CLBatchNormalizationLayerKernel.cpp.

References CLKernelLibrary::get().

116 {
117  configure(CLKernelLibrary::get().get_compile_context(), input, output, mean, var, beta, gamma, epsilon, act_info);
118 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(ICLTensor *input, ICLTensor *output, const ICLTensor *mean, const ICLTensor *var, const ICLTensor *beta=nullptr, const ICLTensor *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
Set the input and output tensors.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
ICLTensor input,
ICLTensor output,
const ICLTensor mean,
const ICLTensor var,
const ICLTensor beta = nullptr,
const ICLTensor gamma = nullptr,
float  epsilon = 0.001f,
ActivationLayerInfo  act_info = ActivationLayerInfo() 
)

Set the input and output tensors.

Note
If the output tensor is a nullptr, the batch normalization function will be performed in-place
Parameters
[in]compile_contextThe compile context to be used.
[in,out]inputSource tensor. In case of output tensor = nullptr, this tensor will store the result. 3 lower dimensions represent a single input with dimensions [width, height, FM]. The rest are optional and used for representing batches. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC.
[out]outputDestination tensor. Output will have the same number of dimensions as input. Data type supported: same as input
[in]meanMean values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]varVariance values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]beta(Optional) Beta values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for beta is 0. Data types supported: Same as input
[in]gamma(Optional) Gamma values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for gamma is 1. Data types supported: Same as input
[in]epsilon(Optional) Small value to avoid division with zero. Default value is 0.001f.
[in]act_info(Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.

Definition at line 120 of file CLBatchNormalizationLayerKernel.cpp.

References ActivationLayerInfo::a(), ActivationLayerInfo::activation(), CLBuildOptions::add_option(), arm_compute::adjust_vec_size(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ActivationLayerInfo::b(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), arm_compute::create_kernel(), ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::dimension(), ITensorInfo::element_size(), ActivationLayerInfo::enabled(), arm_compute::quantization::epsilon, arm_compute::float_to_string_with_full_precision(), arm_compute::get_cl_type_from_data_type(), arm_compute::get_padding_info(), arm_compute::has_padding_changed(), ITensor::info(), arm_compute::test::validation::input, arm_compute::lower_string(), arm_compute::NHWC, ICLKernel::num_arguments_per_1D_tensor(), ICLKernel::num_arguments_per_3D_tensor(), num_elems_processed_per_iteration, arm_compute::string_from_activation_func(), arm_compute::string_from_data_layout(), arm_compute::string_from_data_type(), arm_compute::support::cpp11::to_string(), and arm_compute::validate_arguments().

123 {
124  ARM_COMPUTE_ERROR_ON_NULLPTR(input, mean, var);
125 
126  auto padding_info = get_padding_info({ input, output, mean, var, beta, gamma });
127  _input = input;
128  _output = output;
129  _mean = mean;
130  _var = var;
131  _beta = beta;
132  _gamma = gamma;
133  _epsilon = epsilon;
134 
135  _run_in_place = (output == nullptr) || (output == input);
136 
137  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (output != nullptr) ? output->info() : nullptr,
138  mean->info(), var->info(), (beta != nullptr) ? beta->info() : nullptr,
139  (gamma != nullptr) ? gamma->info() : nullptr, epsilon, act_info));
140 
141  unsigned int num_elems_processed_per_iteration = adjust_vec_size(16 / input->info()->element_size(), input->info()->dimension(0));
142 
143  // Set build options
144  CLBuildOptions build_opts;
145  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
146  build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration));
147  build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(input->info()->dimension(0) % num_elems_processed_per_iteration));
148  build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(act_info.activation())));
149  build_opts.add_option_if(act_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(act_info.a()));
150  build_opts.add_option_if(act_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(act_info.b()));
151  build_opts.add_option_if(_run_in_place, "-DIN_PLACE");
152  build_opts.add_option_if(beta == nullptr, "-DUSE_DEFAULT_BETA");
153  build_opts.add_option_if(gamma == nullptr, "-DUSE_DEFAULT_GAMMA");
154 
155  // Create kernel
156  _kernel = create_kernel(compile_context, "batchnormalization_layer_" + lower_string(string_from_data_layout(input->info()->data_layout())), build_opts.options());
157 
158  // Set kernel static arguments
159  unsigned int include_output = (!_run_in_place) ? 1 : 0;
160  unsigned int idx = (1 + include_output) * num_arguments_per_3D_tensor() + 2 * num_arguments_per_1D_tensor(); // Skip the input and output parameters
161  if(_beta != nullptr)
162  {
163  idx += num_arguments_per_1D_tensor(); // Skip beta parameter
164  }
165  if(_gamma != nullptr)
166  {
167  idx += num_arguments_per_1D_tensor(); // Skip gamma parameter
168  }
169  _kernel.setArg<cl_float>(idx++, _epsilon);
170 
171  if(output != nullptr)
172  {
173  // Output tensor auto initialization if not yet initialized
174  auto_init_if_empty(*output->info(), *input->info()->clone());
175  }
176 
177  // Configure kernel window
178  if(input->info()->data_layout() == DataLayout::NHWC)
179  {
180  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
181  ICLKernel::configure_internal(win);
182  }
183  else
184  {
185  auto win_config = validate_and_configure_window_nchw(input->info(), (_run_in_place) ? nullptr : output->info());
186  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
187  ICLKernel::configure_internal(win_config.second);
188  }
189 
191 
192  _config_id = "batch_normalization_layer_";
193  _config_id += string_from_data_type(input->info()->data_type());
194  _config_id += "_";
195  _config_id += support::cpp11::to_string(input->info()->dimension(0));
196  _config_id += "_";
197  _config_id += support::cpp11::to_string(input->info()->dimension(1));
198  _config_id += "_";
199  _config_id += support::cpp11::to_string(input->info()->dimension(2));
200  _config_id += "_";
201  _config_id += lower_string(string_from_data_layout(input->info()->data_layout()));
202 }
static constexpr unsigned int num_arguments_per_1D_tensor()
Returns the number of arguments enqueued per 1D tensor object.
Definition: ICLKernel.h:198
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
bool enabled() const
Check if initialised.
Definition: Types.h:1600
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
float a() const
Get the alpha value.
Definition: Types.h:1590
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#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
const std::string & string_from_activation_func(ActivationLayerInfo::ActivationFunction act)
Translates a given activation function to a string.
Definition: Utils.cpp:163
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:350
void add_option(std::string option)
Adds option to the existing build option list.
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
Definition: CLHelpers.cpp:403
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
static constexpr unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Definition: ICLKernel.h:214
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1262
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:37
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...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
bool has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
Definition: Utils.cpp:528
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
Definition: Utils.cpp:123
Num samples, height, width, channels.
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo *> infos)
Stores padding information before configuring a kernel.
Definition: Utils.cpp:513
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input&#39;s first dimension, getting rounded down to its closest valid vector size.
Definition: Utils.h:1358
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1585
float b() const
Get the beta value.
Definition: Types.h:1595
Describe a multidimensional execution window.
Definition: Window.h:39
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

◆ operator=() [1/2]

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,
cl::CommandQueue &  queue 
)
overridevirtual

Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.

Note
The queue is not flushed by this method, and therefore the kernel will not have been executed by the time this method returns.
Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).
[in,out]queueCommand queue on which to enqueue the kernel.

Reimplemented from ICLKernel.

Definition at line 221 of file CLBatchNormalizationLayerKernel.cpp.

References ICLKernel::add_1D_tensor_argument(), ICLKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::DimX, arm_compute::enqueue(), Window::first_slice_window_1D(), Window::first_slice_window_3D(), ICLKernel::lws_hint(), ICLKernel::num_arguments_per_3D_tensor(), Window::set(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), and IKernel::window().

222 {
225 
227 
228  Window vector_slice = window.first_slice_window_1D();
229  vector_slice.set(Window::DimX, Window::Dimension(0, 0, 0));
230 
231  unsigned int include_output = (!_run_in_place) ? 1 : 0;
232  unsigned int idx = (1 + include_output) * num_arguments_per_3D_tensor();
233  add_1D_tensor_argument(idx, _mean, vector_slice);
234  add_1D_tensor_argument(idx, _var, vector_slice);
235  if(_beta != nullptr)
236  {
237  add_1D_tensor_argument(idx, _beta, vector_slice);
238  }
239  if(_gamma != nullptr)
240  {
241  add_1D_tensor_argument(idx, _gamma, vector_slice);
242  }
243 
244  do
245  {
246  idx = 0;
247  add_3D_tensor_argument(idx, _input, slice);
248  if(!_run_in_place)
249  {
250  add_3D_tensor_argument(idx, _output, slice);
251  }
252  enqueue(queue, *this, slice, lws_hint());
253  }
254  while(window.slide_window_slice_3D(slice));
255 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws=gles::NDRange(1U, 1U, 1U))
Add the kernel to the command queue with the given window.
Definition: IGCKernel.cpp:41
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:77
void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 3D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:172
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
static constexpr unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Definition: ICLKernel.h:214
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:335
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
void add_1D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 1D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:124
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:291
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
Window first_slice_window_1D() const
First 1D slice of the window.
Definition: Window.h:275
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const ITensorInfo mean,
const ITensorInfo var,
const ITensorInfo beta = nullptr,
const ITensorInfo gamma = nullptr,
float  epsilon = 0.001f,
ActivationLayerInfo  act_info = ActivationLayerInfo() 
)
static

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

Parameters
[in]inputSource tensor info. In case of output tensor info = nullptr, this tensor will store the result. 3 lower dimensions represent a single input with dimensions [width, height, FM]. The rest are optional and used for representing batches. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC.
[in]outputDestination tensor info. Output will have the same number of dimensions as input. Data type supported: same as input
[in]meanMean values tensor info. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]varVariance values tensor info. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]beta(Optional) Beta values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for beta is 0. Data types supported: Same as input
[in]gamma(Optional) Gamma values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for gamma is 1. Data types supported: Same as input
[in]epsilon(Optional) Small value to avoid division with zero. Default value is 0.001f.
[in]act_info(Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Returns
a status

Definition at line 204 of file CLBatchNormalizationLayerKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), ITensorInfo::data_layout(), arm_compute::NHWC, and arm_compute::validate_arguments().

Referenced by CLBatchNormalizationLayer::validate().

208 {
209  const bool run_in_place = (output == nullptr) || (output == input);
210  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, mean, var, beta, gamma, epsilon, act_info));
211 
212  if(input->data_layout() != DataLayout::NHWC)
213  {
214  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_nchw(input->clone().get(), (run_in_place) ? nullptr : output->clone().get())
215  .first);
216  }
217 
218  return Status{};
219 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status class.
Definition: Error.h:52
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
Num samples, height, width, channels.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

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