Compute Library
 19.08
GCArithmeticAdditionKernel Class Reference

Interface for the arithmetic addition kernel. More...

#include <GCArithmeticAdditionKernel.h>

Collaboration diagram for GCArithmeticAdditionKernel:
[legend]

Public Member Functions

 GCArithmeticAdditionKernel ()
 Default constructor. More...
 
 GCArithmeticAdditionKernel (const GCArithmeticAdditionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
GCArithmeticAdditionKerneloperator= (const GCArithmeticAdditionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 GCArithmeticAdditionKernel (GCArithmeticAdditionKernel &&)=default
 Allow instances of this class to be moved. More...
 
GCArithmeticAdditionKerneloperator= (GCArithmeticAdditionKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~GCArithmeticAdditionKernel ()=default
 Default destructor. More...
 
void configure (const IGCTensor *input1, const IGCTensor *input2, IGCTensor *output, ConvertPolicy policy)
 Initialise the kernel's inputs, output and convertion policy. 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 *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy)
 Static function to check if given info will lead to a valid configuration of GCArithmeticAdditionKernel. More...
 

Detailed Description

Interface for the arithmetic addition kernel.

Arithmetic addition is computed by:

\[ output(x,y) = input1(x,y) + input2(x,y) \]

Definition at line 39 of file GCArithmeticAdditionKernel.h.

Constructor & Destructor Documentation

◆ GCArithmeticAdditionKernel() [1/3]

Default constructor.

Definition at line 86 of file GCArithmeticAdditionKernel.cpp.

87  : _input1(nullptr), _input2(nullptr), _output(nullptr)
88 {
89 }

◆ GCArithmeticAdditionKernel() [2/3]

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

◆ GCArithmeticAdditionKernel() [3/3]

Allow instances of this class to be moved.

◆ ~GCArithmeticAdditionKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const IGCTensor input1,
const IGCTensor input2,
IGCTensor output,
ConvertPolicy  policy 
)

Initialise the kernel's inputs, output and convertion policy.

Parameters
[in]input1First tensor input. Data types supported: F16.
[in]input2Second tensor input. Data types supported: F16.
[out]outputOutput tensor. Data types supported: F16.
[in]policyPolicy to use to handle overflow.

Definition at line 91 of file GCArithmeticAdditionKernel.cpp.

92 {
94  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
95 
96  // Auto initialize output if not initialized
97  {
98  set_shape_if_empty(*output->info(), input1->info()->tensor_shape());
100  }
101 
102  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input1->info(), input2->info(), output->info(), policy));
103 
104  _input1 = input1;
105  _input2 = input2;
106  _output = output;
107 
108  // Set kernel build options
109  std::set<std::string> build_opts;
110  build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(1));
111  build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(1));
112  build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(1));
113 
114  // Create kernel
115  _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("arithmetic_add", build_opts));
116 
117  // Configure kernel window
118  auto win_config = validate_and_configure_window(input1->info(), input2->info(), output->info());
119  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
120  IGCKernel::configure(win_config.second);
121 }
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.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
1 channel, 1 F16 per channel
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
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
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
Definition: Helpers.inl:234
bool set_format_if_unknown(ITensorInfo &info, Format format)
Set the format, data type and number of channels to the specified value if the current data type is u...
Definition: Helpers.inl:245

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, arm_compute::create_kernel(), arm_compute::F16, GCKernelLibrary::get(), ITensor::info(), arm_compute::test::validation::policy, arm_compute::set_format_if_unknown(), arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), and arm_compute::validate_and_configure_window().

◆ operator=() [1/2]

GCArithmeticAdditionKernel& operator= ( const GCArithmeticAdditionKernel )
delete

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)
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 131 of file GCArithmeticAdditionKernel.cpp.

132 {
135 
136  _kernel.use();
137 
138  _output->set_needs_shifting(true);
139 
141  Window slice_in = window.first_slice_window_3D();
142 
143  slice.shift(Window::DimX, -(_output->info()->padding()).left);
144 
145  do
146  {
147  unsigned int idx = 0;
148  unsigned int binding = 1; // SSBO binding starts from 1.
149  add_3D_tensor_argument(idx, _input1, binding++, slice_in);
150  add_3D_tensor_argument(idx, _input2, binding++, slice_in);
151  add_3D_tensor_argument(idx, _output, binding++, slice);
152 
153  _kernel.update_shader_params();
154 
155  enqueue(*this, slice);
156  }
158 }
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
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.
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
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, Window::DimX, arm_compute::enqueue(), Window::first_slice_window_3D(), ITensor::info(), ITensorInfo::padding(), IGCTensor::set_needs_shifting(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input1,
const ITensorInfo input2,
const ITensorInfo output,
ConvertPolicy  policy 
)
static

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

Parameters
[in]input1First tensor input info. Data types supported: F16.
[in]input2Second tensor input info. Data types supported: F16.
[out]outputOutput tensor info. Data types supported: F16.
[in]policyPolicy to use to handle overflow.
Returns
a status

Definition at line 123 of file GCArithmeticAdditionKernel.cpp.

124 {
125  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input1, input2, output, policy));
126  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input1->clone().get(), input2->clone().get(), output->clone().get()).first);
127 
128  return Status{};
129 }
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(), arm_compute::test::validation::policy, and arm_compute::validate_and_configure_window().

Referenced by GCArithmeticAddition::validate().


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