Compute Library
 21.02
CLRangeKernel Class Reference

Kernel class for Range. More...

#include <CLRangeKernel.h>

Collaboration diagram for CLRangeKernel:
[legend]

Public Member Functions

 CLRangeKernel ()
 Default constructor. More...
 
 CLRangeKernel (const CLRangeKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLRangeKerneloperator= (const CLRangeKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLRangeKernel (CLRangeKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLRangeKerneloperator= (CLRangeKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLRangeKernel ()=default
 Default destructor. More...
 
void configure (ICLTensor *output, float start, float end, float step)
 Initialize the kernel's output tensor, start, end and step of the sequence. More...
 
void configure (const CLCompileContext &compile_context, ICLTensor *output, float start, float end, float step)
 Initialize the kernel's output tensor, start, end and step of the sequence. 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 *output, float start, float end, float step)
 Static function to check if given info will lead to a valid configuration of CLRangeKernel. 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

Kernel class for Range.

range generates a 1-D tensor containing a sequence of numbers that begins at 'start' and extends by increments of 'step' up to but not including 'end'.

Definition at line 39 of file CLRangeKernel.h.

Constructor & Destructor Documentation

◆ CLRangeKernel() [1/3]

Default constructor.

Definition at line 68 of file CLRangeKernel.cpp.

69  : _start(0), _end(1), _step(1), _output(nullptr)
70 {
71 }

◆ CLRangeKernel() [2/3]

CLRangeKernel ( const CLRangeKernel )
delete

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

◆ CLRangeKernel() [3/3]

CLRangeKernel ( CLRangeKernel &&  )
default

Allow instances of this class to be moved.

◆ ~CLRangeKernel()

~CLRangeKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure() [1/2]

void configure ( ICLTensor output,
float  start,
float  end,
float  step 
)

Initialize the kernel's output tensor, start, end and step of the sequence.

Parameters
[out]outputOutput tensor. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32.
[in]startThe starting value of the sequence.
[in]endThe ending (not including) value of the sequence.
[in]stepThe gap between each pair of values in the sequence.

Definition at line 73 of file CLRangeKernel.cpp.

References CLKernelLibrary::get().

74 {
75  configure(CLKernelLibrary::get().get_compile_context(), output, start, end, step);
76 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
void configure(ICLTensor *output, float start, float end, float step)
Initialize the kernel&#39;s output tensor, start, end and step of the sequence.
constexpr int step
Definition: fp32.cpp:35

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
ICLTensor output,
float  start,
float  end,
float  step 
)

Initialize the kernel's output tensor, start, end and step of the sequence.

Parameters
[in]compile_contextThe compile context to be used.
[out]outputOutput tensor. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32.
[in]startThe starting value of the sequence.
[in]endThe ending (not including) value of the sequence.
[in]stepThe gap between each pair of values in the sequence.

Definition at line 78 of file CLRangeKernel.cpp.

References CLBuildOptions::add_option(), arm_compute::adjust_vec_size(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), ITensorInfo::element_size(), arm_compute::mlgo::parser::end(), 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::is_data_type_quantized_asymmetric(), kernel_name, arm_compute::lower_string(), num_elems_processed_per_iteration, UniformQuantizationInfo::offset, CLBuildOptions::options(), arm_compute::test::validation::qinfo, ITensorInfo::quantization_info(), UniformQuantizationInfo::scale, enable_tracing::start, arm_compute::cpu::step, arm_compute::string_from_data_type(), arm_compute::support::cpp11::to_string(), QuantizationInfo::uniform(), and arm_compute::validate_arguments().

79 {
82 
83  // Configure kernel window
84  unsigned int num_elems_processed_per_iteration = adjust_vec_size(vector_size_byte_opencl / output->info()->element_size(), output->info()->dimension(0));
85  Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
86 
87  auto padding_info = get_padding_info({ output });
88 
89  _start = start;
90  _end = end;
91  _step = step;
92  _output = output;
93 
94  std::string kernel_name = "range";
95 
96  // Set build options
97  CLBuildOptions build_opts;
98  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(output->info()->data_type()));
99  build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration));
100  build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(output->info()->dimension(0) % num_elems_processed_per_iteration));
101  build_opts.add_option("-DSTART=" + support::cpp11::to_string(start));
102  build_opts.add_option("-DSTEP=" + support::cpp11::to_string(step));
103  if(is_data_type_quantized_asymmetric(output->info()->data_type()))
104  {
105  const UniformQuantizationInfo qinfo = output->info()->quantization_info().uniform();
106  build_opts.add_option("-DOFFSET_OUT=" + support::cpp11::to_string(qinfo.offset));
107  build_opts.add_option("-DSCALE_OUT=" + float_to_string_with_full_precision(qinfo.scale));
108  kernel_name += "_quantized";
109  }
110  // Create kernel
111  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
112  ICLKernel::configure_internal(win);
113 
114  // Set config_id for enabling LWS tuning
115  _config_id = kernel_name;
116  _config_id += "_";
117  _config_id += lower_string(string_from_data_type(output->info()->data_type()));
118  _config_id += "_";
119  _config_id += support::cpp11::to_string(output->info()->dimension(0));
121 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
std::string to_string(T &&value)
Convert integer and float values to string.
#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
#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
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
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1262
std::string kernel_name
UniformQuantizationInfo uniform() const
Return per layer quantization info.
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
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
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
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1190
constexpr int step
Definition: fp32.cpp:35
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155
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

◆ operator=() [1/2]

CLRangeKernel& operator= ( const CLRangeKernel )
delete

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

◆ operator=() [2/2]

CLRangeKernel& operator= ( CLRangeKernel &&  )
default

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.

Reimplemented from ICLKernel.

Definition at line 129 of file CLRangeKernel.cpp.

References ICLKernel::add_1D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), ICLKernel::lws_hint(), and IKernel::window().

130 {
133  unsigned int idx = 0;
134  add_1D_tensor_argument(idx, _output, window);
135 
136  enqueue(queue, *this, window, lws_hint());
137 }
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
#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
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

Status validate ( const ITensorInfo output,
float  start,
float  end,
float  step 
)
static

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

Parameters
[in]outputOutput tensor info. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32.
[in]startThe starting value of the sequence.
[in]endThe ending (not including) value of the sequence.
[in]stepThe gap between each pair of values in the sequence.
Returns
a status

Definition at line 123 of file CLRangeKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

Referenced by CLRange::validate().

124 {
126  return Status{};
127 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
constexpr int step
Definition: fp32.cpp:35
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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