Compute Library
 19.08
GCBatchNormalizationLayerKernel Class Reference

Interface for the BatchNormalization layer kernel. More...

#include <GCBatchNormalizationLayerKernel.h>

Collaboration diagram for GCBatchNormalizationLayerKernel:
[legend]

Public Member Functions

 GCBatchNormalizationLayerKernel ()
 Constructor. More...
 
 GCBatchNormalizationLayerKernel (const GCBatchNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
GCBatchNormalizationLayerKerneloperator= (const GCBatchNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 GCBatchNormalizationLayerKernel (GCBatchNormalizationLayerKernel &&)=default
 Default Move Constructor. More...
 
GCBatchNormalizationLayerKerneloperator= (GCBatchNormalizationLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~GCBatchNormalizationLayerKernel ()=default
 Default destructor. More...
 
void configure (const IGCTensor *input, IGCTensor *output, const IGCTensor *mean, const IGCTensor *var, const IGCTensor *beta=nullptr, const IGCTensor *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
 Set the input and output tensors. More...
 
void run (const Window &window) override
 Enqueue the OpenGL ES shader to process the given window. More...
 
- Public Member Functions inherited from IGCKernel
 IGCKernel ()
 Constructor. More...
 
GCKernelkernel ()
 Returns a reference to the GLES kernel of this object. More...
 
void add_1D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, 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_2D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, 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_3D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
unsigned int num_arguments_per_1D_tensor () const
 Returns the number of arguments enqueued per 1D tensor object. More...
 
unsigned int num_arguments_per_2D_tensor () const
 Returns the number of arguments enqueued per 2D tensor object. More...
 
unsigned int num_arguments_per_3D_tensor () const
 Returns the number of arguments enqueued per 3D tensor object. More...
 
void set_lws_hint (gles::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. 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 GCBatchNormalizationLayerKernel. More...
 

Detailed Description

Interface for the BatchNormalization layer kernel.

Definition at line 35 of file GCBatchNormalizationLayerKernel.h.

Constructor & Destructor Documentation

◆ GCBatchNormalizationLayerKernel() [1/3]

Constructor.

Definition at line 134 of file GCBatchNormalizationLayerKernel.cpp.

135  : _input(nullptr), _output(nullptr), _mean(nullptr), _var(nullptr), _beta(nullptr), _gamma(nullptr), _epsilon(0.0f)
136 {
137 }

◆ GCBatchNormalizationLayerKernel() [2/3]

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

◆ GCBatchNormalizationLayerKernel() [3/3]

Default Move Constructor.

◆ ~GCBatchNormalizationLayerKernel()

Default destructor.

Member Function Documentation

◆ configure()

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

Set the input and output tensors.

Parameters
[in]inputSource tensor. 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.
[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.
[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 139 of file GCBatchNormalizationLayerKernel.cpp.

141 {
142  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, mean, var);
143 
144  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), mean->info(), var->info(),
145  (beta != nullptr) ? beta->info() : nullptr, (gamma != nullptr) ? gamma->info() : nullptr,
146  epsilon, act_info));
147 
148  _input = input;
149  _output = output;
150  _mean = mean;
151  _var = var;
152  _beta = beta;
153  _gamma = gamma;
154  _epsilon = epsilon;
155 
156  // Set build options
157  std::set<std::string> build_opts;
158  std::string dt_name = (input->info()->data_type() == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16";
159  build_opts.emplace(("#define " + dt_name));
160  build_opts.emplace(("#define ESPILON " + float_to_string_with_full_precision(_epsilon)));
161  build_opts.emplace(("#define LOCAL_SIZE_X " + support::cpp11::to_string(1)));
162  build_opts.emplace(("#define LOCAL_SIZE_Y " + support::cpp11::to_string(1)));
163  build_opts.emplace(("#define LOCAL_SIZE_Z " + support::cpp11::to_string(1)));
164  if(beta == nullptr)
165  {
166  build_opts.emplace("#define USE_DEFAULT_BETA");
167  }
168  if(gamma == nullptr)
169  {
170  build_opts.emplace("#define USE_DEFAULT_GAMMA");
171  }
172 
173  if(act_info.enabled())
174  {
175  build_opts.emplace("#define " + string_from_activation_func(act_info.activation()));
176  build_opts.emplace("#define A_VAL " + float_to_string_with_full_precision(act_info.a()));
177  build_opts.emplace("#define B_VAL " + float_to_string_with_full_precision(act_info.b()));
178  }
179 
180  // Create kernel
181  _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("batchnormalization_layer", build_opts));
182 
183  // Configure kernel window
184  auto win_config = validate_and_configure_window(input->info(), output->info(), mean->info(), var->info(),
185  (beta != nullptr) ? beta->info() : nullptr, (gamma != nullptr) ? gamma->info() : nullptr);
186  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
187 
188  IGCKernel::configure(win_config.second);
189 }
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)
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.
constexpr float epsilon
1 channel, 1 F32 per channel
const std::string & string_from_activation_func(ActivationLayerInfo::ActivationFunction act)
Translates a given activation function to a string.
Definition: Utils.cpp:170
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1066
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
std::unique_ptr< Kernel > create_kernel()
Helper function to create and return a unique_ptr pointed to a CL/GLES kernel object.
Definition: Helpers.h:86
static GCKernelLibrary & get()
Get the static instance of GCKernelLibrary.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References arm_compute::test::validation::act_info, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::create_kernel(), ITensorInfo::data_type(), epsilon, arm_compute::F32, arm_compute::float_to_string_with_full_precision(), GCKernelLibrary::get(), ITensor::info(), arm_compute::string_from_activation_func(), arm_compute::support::cpp11::to_string(), and arm_compute::validate_and_configure_window().

Referenced by GCBatchNormalizationLayer::configure().

◆ 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)
overridevirtual

Enqueue the OpenGL ES shader to process the given window.

Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).

Implements IGCKernel.

Definition at line 205 of file GCBatchNormalizationLayerKernel.cpp.

206 {
209 
210  _kernel.use();
211 
212  _output->set_needs_shifting(true);
213 
215  Window slice_in = window.first_slice_window_3D();
216 
217  Window vector_slice = window.first_slice_window_1D();
218  vector_slice.set(Window::DimX, Window::Dimension(0, 0, 0));
219 
220  unsigned int idx = 2 * num_arguments_per_3D_tensor();
221  unsigned int binding_point = 3;
222  add_1D_tensor_argument(idx, _mean, binding_point, vector_slice);
223  add_1D_tensor_argument(idx, _var, ++binding_point, vector_slice);
224  if(_beta != nullptr)
225  {
226  add_1D_tensor_argument(idx, _beta, ++binding_point, vector_slice);
227  }
228  if(_gamma != nullptr)
229  {
230  add_1D_tensor_argument(idx, _gamma, ++binding_point, vector_slice);
231  }
232 
233  slice.shift(Window::DimX, -(_output->info()->padding()).left);
234 
235  do
236  {
237  idx = 0;
238  add_3D_tensor_argument(idx, _input, 1, slice_in);
239  add_3D_tensor_argument(idx, _output, 2, slice);
240 
241  _kernel.update_shader_params();
242  enqueue(*this, slice);
243  }
245 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void add_3D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: IGCKernel.cpp:132
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
Definition: ICLKernel.cpp:39
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
unsigned int num_arguments_per_3D_tensor() const
Returns the number of arguments enqueued per 3D tensor object.
Definition: IGCKernel.cpp:147
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
void set_needs_shifting(bool needs_shifting)
Set the flag indicating whether or not a tensor needs shifting.
Definition: IGCTensor.cpp:61
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:48
virtual PaddingSize padding() const =0
Padding of tensor.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:319
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:275
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
void add_1D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: IGCKernel.cpp:122
Window first_slice_window_1D() const
First 1D slice of the window.
Definition: Window.h:259
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References IGCKernel::add_1D_tensor_argument(), IGCKernel::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(), ITensor::info(), IGCKernel::num_arguments_per_3D_tensor(), ITensorInfo::padding(), Window::set(), IGCTensor::set_needs_shifting(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), and IKernel::window().

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

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.
[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 191 of file GCBatchNormalizationLayerKernel.cpp.

195 {
196  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, mean, var, beta, gamma, epsilon, act_info));
198  mean->clone().get(), var->clone().get(),
199  beta->clone().get(), gamma->clone().get())
200  .first);
201 
202  return Status{};
203 }
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
constexpr float epsilon
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::test::validation::act_info, ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), epsilon, and arm_compute::validate_and_configure_window().


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