Compute Library
 19.08
CLGEMMMatrixAccumulateBiasesKernel Class Reference

Interface to add a bias to each row of the input tensor. More...

#include <CLGEMMMatrixAccumulateBiasesKernel.h>

Collaboration diagram for CLGEMMMatrixAccumulateBiasesKernel:
[legend]

Public Member Functions

 CLGEMMMatrixAccumulateBiasesKernel ()
 Default constructor. More...
 
 CLGEMMMatrixAccumulateBiasesKernel (const CLGEMMMatrixAccumulateBiasesKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLGEMMMatrixAccumulateBiasesKerneloperator= (const CLGEMMMatrixAccumulateBiasesKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLGEMMMatrixAccumulateBiasesKernel (CLGEMMMatrixAccumulateBiasesKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLGEMMMatrixAccumulateBiasesKerneloperator= (CLGEMMMatrixAccumulateBiasesKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (ICLTensor *accum, const ICLTensor *biases)
 Set the accumulate buffer and the biases of the kernel. 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...
 
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...
 
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<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...
 
template<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
- 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 *accum, const ITensorInfo *biases, GPUTarget gpu_target)
 Static function to check if given info will lead to a valid configuration of CLGEMMMatrixAccumulateBiasesKernel. 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 to add a bias to each row of the input tensor.

Definition at line 34 of file CLGEMMMatrixAccumulateBiasesKernel.h.

Constructor & Destructor Documentation

◆ CLGEMMMatrixAccumulateBiasesKernel() [1/3]

Default constructor.

Definition at line 74 of file CLGEMMMatrixAccumulateBiasesKernel.cpp.

75  : _accum(nullptr), _biases(nullptr)
76 {
77 }

◆ CLGEMMMatrixAccumulateBiasesKernel() [2/3]

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

◆ CLGEMMMatrixAccumulateBiasesKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

void configure ( ICLTensor accum,
const ICLTensor biases 
)

Set the accumulate buffer and the biases of the kernel.

Parameters
[in,out]accumThe accumulate tensor to convert. Data types supported: F16/F32
[in]biasesThe shared biases tensor to append. It must be 1D tensor. Data types supported: Same as input

Definition at line 79 of file CLGEMMMatrixAccumulateBiasesKernel.cpp.

80 {
81  // Perform validate step
82  ARM_COMPUTE_ERROR_ON_NULLPTR(accum, biases);
83  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(accum->info(), biases->info()));
84 
85  _biases = biases;
86  _accum = accum;
87 
88  // Get the target gpu
89  GPUTarget gpu_target = get_target();
90  unsigned int vector_size = 0;
91 
92  // Configure kernel window
93  auto win_config = validate_and_configure_window(accum->info(), biases->info(), gpu_target, vector_size);
94  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
95  ICLKernel::configure_internal(win_config.second);
96 
97  // Add build options
98  CLBuildOptions build_opts;
99  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(accum->info()->data_type()));
100  build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(vector_size));
101 
102  // Create kernel
103  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("gemm_accumulate_biases", build_opts.options()));
104 }
const StringSet & options() const
Gets the current options list set.
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.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
void add_option(std::string option)
Adds option to the existing build option list.
GPUTarget get_target() const
Get the targeted GPU architecture.
Definition: ICLKernel.h:286
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:35
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
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
GPUTarget
Available GPU Targets.
Definition: GPUTarget.h:34

References CLBuildOptions::add_option(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::create_kernel(), ITensorInfo::data_type(), CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), ICLKernel::get_target(), ITensor::info(), CLBuildOptions::options(), arm_compute::support::cpp11::to_string(), and arm_compute::validate_and_configure_window().

Referenced by CLFullyConnectedLayer::configure().

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Allow instances of this class to be moved.

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

Implements ICLKernel.

Definition at line 115 of file CLGEMMMatrixAccumulateBiasesKernel.cpp.

116 {
119 
120  Window accum_slice = window.first_slice_window_2D();
121 
122  Window biases_slice(accum_slice);
123  biases_slice.set(Window::DimY, Window::Dimension(0, 1, 1));
124 
125  // Run kernel
126  do
127  {
128  // Set arguments
129  unsigned int idx = 0;
130  add_2D_tensor_argument(idx, _accum, accum_slice);
131  add_1D_tensor_argument(idx, _biases, biases_slice);
132 
133  enqueue(queue, *this, accum_slice, lws_hint());
134  }
135  while(window.slide_window_slice_2D(accum_slice));
136 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:267
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
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
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:247
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:307
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
Definition: Validate.h:183
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
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.
Definition: ICLKernel.h:134
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.
Definition: ICLKernel.h:110
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

References ICLKernel::add_1D_tensor_argument(), ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::DimY, arm_compute::enqueue(), Window::first_slice_window_2D(), ICLKernel::lws_hint(), Window::set(), Window::slide_window_slice_2D(), and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo accum,
const ITensorInfo biases,
GPUTarget  gpu_target 
)
static

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

Parameters
[in]accumThe accumulate tensor to convert. Data types supported: F16/F32
[in]biasesThe shared biases tensor to append. It must be 1D tensor. Data types supported: Same as input
[in]gpu_targetGPU target
Returns
a status

Definition at line 106 of file CLGEMMMatrixAccumulateBiasesKernel.cpp.

107 {
108  unsigned int num_elems_processed_per_iteration = 0;
109  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(accum, biases));
110  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(accum->clone().get(), biases->clone().get(), gpu_target, num_elems_processed_per_iteration).first);
111 
112  return Status{};
113 }
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
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_RETURN_ON_ERROR, ICloneable< T >::clone(), and arm_compute::validate_and_configure_window().

Referenced by CLFullyConnectedLayer::validate().


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