Compute Library
 19.08
GCNormalizationLayerKernel Class Reference

Interface for the normalization layer kernel. More...

#include <GCNormalizationLayerKernel.h>

Collaboration diagram for GCNormalizationLayerKernel:
[legend]

Public Member Functions

 GCNormalizationLayerKernel ()
 Constructor. More...
 
 GCNormalizationLayerKernel (const GCNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
GCNormalizationLayerKerneloperator= (const GCNormalizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 GCNormalizationLayerKernel (GCNormalizationLayerKernel &&)=default
 Default Move Constructor. More...
 
GCNormalizationLayerKerneloperator= (GCNormalizationLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~GCNormalizationLayerKernel ()=default
 Default destrutor. More...
 
void configure (const IGCTensor *input, const IGCTensor *squared_input, IGCTensor *output, NormalizationLayerInfo norm_info)
 Set the input and output tensors. More...
 
void run (const Window &window) override
 Enqueue the OpenGL ES shader to process the given window. More...
 
BorderSize border_size () const override
 The size of the border for that kernel. 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...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Detailed Description

Interface for the normalization layer kernel.

Definition at line 35 of file GCNormalizationLayerKernel.h.

Constructor & Destructor Documentation

◆ GCNormalizationLayerKernel() [1/3]

Constructor.

Definition at line 39 of file GCNormalizationLayerKernel.cpp.

40  : _input(nullptr), _squared_input(nullptr), _output(nullptr), _border_size(0)
41 {
42 }

◆ GCNormalizationLayerKernel() [2/3]

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

◆ GCNormalizationLayerKernel() [3/3]

Default Move Constructor.

◆ ~GCNormalizationLayerKernel()

Default destrutor.

Member Function Documentation

◆ border_size()

BorderSize border_size ( ) const
overridevirtual

The size of the border for that kernel.

Returns
The width in number of elements of the border.

Reimplemented from IKernel.

Definition at line 44 of file GCNormalizationLayerKernel.cpp.

45 {
46  return _border_size;
47 }

Referenced by GCNormalizationLayer::configure().

◆ configure()

void configure ( const IGCTensor input,
const IGCTensor squared_input,
IGCTensor 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: F32.
[in]squared_inputSource with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM], Data types should match the input type.
[out]outputDestination tensor. Output will have the same number of dimensions as input. Data types should match the input type.
[in]norm_infoNormalization layer information like the normalization type, normalization size and other parameters.

Definition at line 49 of file GCNormalizationLayerKernel.cpp.

50 {
53  ARM_COMPUTE_ERROR_ON_MSG(!(norm_info.norm_size() % 2), "Normalization size should be odd");
54  ARM_COMPUTE_ERROR_ON_MSG(norm_info.type() == NormType::IN_MAP_2D, "2D In-Map Normalization not implemented");
55 
56  // Set build options
57  std::set<std::string> build_opts;
58 
59  _input = input;
60  _squared_input = squared_input;
61  _output = output;
62 
63  const bool is_in_map = norm_info.is_in_map();
64  const unsigned int border_width = is_in_map ? std::min(norm_info.norm_size() / 2, 3U) : 0;
65  _border_size = BorderSize(0, border_width);
66 
67  // Set kernel static arguments
68  std::string func_name = ((norm_info.type() == NormType::IN_MAP_1D) ? "IN_MAP_1D" : "CROSS_MAP");
69  build_opts.emplace(("#define " + func_name));
70  build_opts.emplace(("#define COEFF " + float_to_string_with_full_precision(norm_info.scale_coeff())));
71  build_opts.emplace(("#define BETA " + float_to_string_with_full_precision(norm_info.beta())));
72  build_opts.emplace(("#define KAPPA " + float_to_string_with_full_precision(norm_info.kappa())));
73  build_opts.emplace(("#define RADIUS " + support::cpp11::to_string(norm_info.norm_size() / 2)));
74  build_opts.emplace(("#define LOCAL_SIZE_X " + support::cpp11::to_string(1)));
75  build_opts.emplace(("#define LOCAL_SIZE_Y " + support::cpp11::to_string(1)));
76  build_opts.emplace(("#define LOCAL_SIZE_Z " + support::cpp11::to_string(1)));
77 
78  // Create kernel
79  _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("normalization_layer", build_opts));
80 
81  // Configure kernel window
82  const unsigned int num_elems_processed_per_iteration = 1;
83  const unsigned int num_elems_read_per_iteration = num_elems_processed_per_iteration + 2 * (norm_info.norm_size() / 2);
84 
85  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
86 
87  AccessWindowHorizontal input_access(input->info(), -_border_size.left, num_elems_read_per_iteration);
88  AccessWindowHorizontal squared_input_access(squared_input->info(), -_border_size.left, num_elems_read_per_iteration);
89  AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
90 
91  update_window_and_padding(win, input_access, squared_input_access, output_access);
92 
93  output_access.set_valid_region(win, input->info()->valid_region());
94 
95  IGCKernel::configure(win);
96 }
float scale_coeff() const
Return the scaling factor of the normalization function.
Definition: Types.h:1642
float kappa() const
Get the kappa value.
Definition: Types.h:1616
bool is_in_map() const
Check if normalization is not cross map.
Definition: Types.h:1631
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:543
Container for 2D border size.
Definition: Types.h:259
uint32_t norm_size() const
Get the normalization size.
Definition: Types.h:1601
NormType type() const
Get the normalization type.
Definition: Types.h:1596
std::string to_string(T &&value)
Convert integer and float values to string.
1 channel, 1 F32 per channel
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:402
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1066
Normalization applied within the same map in 1D region.
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Implementation of a row access pattern.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
float beta() const
Get the beta value.
Definition: Types.h:1611
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
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
static GCKernelLibrary & get()
Get the static instance of GCKernelLibrary.
Describe a multidimensional execution window.
Definition: Window.h:39
Normalization applied within the same map in 2D region.
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328

References ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_ERROR_ON_MSG, NormalizationLayerInfo::beta(), arm_compute::calculate_max_window(), arm_compute::create_kernel(), arm_compute::F32, arm_compute::float_to_string_with_full_precision(), GCKernelLibrary::get(), arm_compute::IN_MAP_1D, arm_compute::IN_MAP_2D, ITensor::info(), NormalizationLayerInfo::is_in_map(), NormalizationLayerInfo::kappa(), NormalizationLayerInfo::norm_size(), NormalizationLayerInfo::scale_coeff(), arm_compute::support::cpp11::to_string(), NormalizationLayerInfo::type(), arm_compute::U, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

Referenced by GCNormalizationLayer::configure().

◆ operator=() [1/2]

GCNormalizationLayerKernel& operator= ( const GCNormalizationLayerKernel )
delete

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 98 of file GCNormalizationLayerKernel.cpp.

99 {
102 
103  _kernel.use();
104 
106 
107  do
108  {
109  unsigned int idx = 0;
110  unsigned int binding = 1;
111  add_3D_tensor_argument(idx, _input, binding++, slice);
112  add_3D_tensor_argument(idx, _squared_input, binding++, slice);
113  add_3D_tensor_argument(idx, _output, binding++, slice);
114 
115  _kernel.update_shader_params();
116 
117  enqueue(*this, slice);
118  }
120 }
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
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
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References IGCKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_3D(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), and IKernel::window().


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