Compute Library
 21.08
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...
 
CLKernelType type () const
 Returns the CL kernel type. 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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. 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 {
72 }
Elementeise CL kernel type.
Definition: CLTypes.h:84

◆ 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 74 of file CLRangeKernel.cpp.

References CLKernelLibrary::get().

75 {
76  configure(CLKernelLibrary::get().get_compile_context(), output, start, end, step);
77 }
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 79 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, arm_compute::cpu::step, arm_compute::string_from_data_type(), arm_compute::support::cpp11::to_string(), and QuantizationInfo::uniform().

80 {
82  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(output->info(), start, end, step));
83 
84  // Configure kernel window
85  unsigned int num_elems_processed_per_iteration = adjust_vec_size(vector_size_byte_opencl / output->info()->element_size(), output->info()->dimension(0));
86  Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
87 
88  auto padding_info = get_padding_info({ output });
89 
90  _start = start;
91  _end = end;
92  _step = step;
93  _output = output;
94 
95  std::string kernel_name = "range";
96 
97  // Set build options
98  CLBuildOptions build_opts;
99  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(output->info()->data_type()));
100  build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration));
101  build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(output->info()->dimension(0) % num_elems_processed_per_iteration));
102  build_opts.add_option("-DSTART=" + support::cpp11::to_string(start));
103  build_opts.add_option("-DSTEP=" + support::cpp11::to_string(step));
104  if(is_data_type_quantized_asymmetric(output->info()->data_type()))
105  {
106  const UniformQuantizationInfo qinfo = output->info()->quantization_info().uniform();
107  build_opts.add_option("-DOFFSET_OUT=" + support::cpp11::to_string(qinfo.offset));
108  build_opts.add_option("-DSCALE_OUT=" + float_to_string_with_full_precision(qinfo.scale));
109  kernel_name += "_quantized";
110  }
111  // Create kernel
112  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
113  ICLKernel::configure_internal(win);
114 
115  // Set config_id for enabling LWS tuning
116  _config_id = kernel_name;
117  _config_id += "_";
118  _config_id += lower_string(string_from_data_type(output->info()->data_type()));
119  _config_id += "_";
120  _config_id += support::cpp11::to_string(output->info()->dimension(0));
122 }
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:326
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:391
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:1075
unsigned int num_elems_processed_per_iteration
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:39
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:533
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1003
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:518
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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:1171
std::string kernel_name

◆ 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 130 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().

131 {
134  unsigned int idx = 0;
135  add_1D_tensor_argument(idx, _output, window);
136 
137  enqueue(queue, *this, window, lws_hint());
138 }
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:32
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:318
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
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:166
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ 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 124 of file CLRangeKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by CLRange::validate().

125 {
126  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(output, start, end, step));
127  return Status{};
128 }
#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

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