ONE - On-device Neural Engine
Loading...
Searching...
No Matches
arm_compute::CLGatherExKernel Class Reference

Class to define an interface for the gather kernel. More...

#include <CLGatherExKernel.h>

Collaboration diagram for arm_compute::CLGatherExKernel:

Public Member Functions

 CLGatherExKernel ()
 Construct CLGatherExKernel object.
 
 CLGatherExKernel (const CLGatherExKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers).
 
CLGatherExKerneloperator= (const CLGatherExKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers).
 
 CLGatherExKernel (CLGatherExKernel &&)=default
 Construct CLGatherExKernel object by using default move constructor.
 
CLGatherExKerneloperator= (CLGatherExKernel &&)=default
 Move assignment operator.
 
void configure (const ICLTensor *input, const ICLTensor *indices, ICLTensor *output, int axis=0)
 Initialise the kernel's input, output and border mode.
 
void run (const Window &window, cl::CommandQueue &queue) override
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *indices, const ITensorInfo *output, int axis=0)
 Static function to check if given info will lead to a valid configuration of CLGatherExKernel.
 

Detailed Description

Class to define an interface for the gather kernel.

Definition at line 59 of file CLGatherExKernel.h.

Constructor & Destructor Documentation

◆ CLGatherExKernel() [1/3]

CLGatherExKernel::CLGatherExKernel ( )

Construct CLGatherExKernel object.

Definition at line 106 of file CLGatherExKernel.cpp.

107 : _input(nullptr), _indices(nullptr), _output(nullptr), _axis(0)
108{
109}

◆ CLGatherExKernel() [2/3]

arm_compute::CLGatherExKernel::CLGatherExKernel ( const CLGatherExKernel )
delete

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

◆ CLGatherExKernel() [3/3]

arm_compute::CLGatherExKernel::CLGatherExKernel ( CLGatherExKernel &&  )
default

Construct CLGatherExKernel object by using default move constructor.

Parameters
[in]CLGatherExKernelobject to move

Member Function Documentation

◆ configure()

void CLGatherExKernel::configure ( const ICLTensor *  input,
const ICLTensor *  indices,
ICLTensor *  output,
int  axis = 0 
)

Initialise the kernel's input, output and border mode.

Parameters
[in]inputAn input tensor. Data types supported: U8/QASYMM8/S32/F32.
[in]indicesIndices tensor. Data types supported: S32.
[out]outputThe output tensor, Data types supported: same as input1.
[in]axis(Optional) The axis in input to gather indices from. Negative values wrap around. Defaults to 0
Returns
N/A

Definition at line 111 of file CLGatherExKernel.cpp.

113{
114 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, indices);
115 ARM_COMPUTE_ERROR_THROW_ON(
116 validate_arguments(input->info(), indices->info(), output->info(), axis));
117
118 // Configure kernel window
119 auto win_config =
120 validate_and_configure_window(input->info(), indices->info(), output->info(), axis);
121 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
122
123 _input = input;
124 _output = output;
125 _indices = indices;
126 _axis = wrap_around(axis, static_cast<int>(input->info()->num_dimensions()));
127
128 // Set build options
129 CLBuildOptions build_opts;
130 build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
131 build_opts.add_option("-DOUTPUT_DIM_Z=" +
132 support::cpp11::to_string(output->info()->dimension(2)));
133 build_opts.add_option("-DINPUT_DIM_Z=" + support::cpp11::to_string(input->info()->dimension(2)));
134 build_opts.add_option("-DAXIS=" + support::cpp11::to_string(_axis));
135 build_opts.add_option("-DINDICES_DIM=" +
136 support::cpp11::to_string(indices->info()->num_dimensions()));
137
138 // Create kernel
139 _kernel = static_cast<cl::Kernel>(
140 CLKernelLibraryEx::get().create_kernel("gather_ex", build_opts.options()));
141 ICLKernel::configure_internal(win_config.second);
142}
static CLKernelLibraryEx & get()
Get the KernelLibrary singleton.
Kernel create_kernel(const std::string &kernel_name, const StringSet &build_options_set={}) const
Create a kernel from the kernel library.

References arm_compute::CLKernelLibraryEx::create_kernel(), and arm_compute::CLKernelLibraryEx::get().

◆ operator=() [1/2]

CLGatherExKernel & arm_compute::CLGatherExKernel::operator= ( CLGatherExKernel &&  )
default

Move assignment operator.

Parameters
[in]CLGatherExKernelobject to move

References validate().

◆ operator=() [2/2]

CLGatherExKernel & arm_compute::CLGatherExKernel::operator= ( const CLGatherExKernel )
delete

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

◆ run()

void CLGatherExKernel::run ( const Window &  window,
cl::CommandQueue &  queue 
)
override

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.
Returns
N/A
N/A

Definition at line 155 of file CLGatherExKernel.cpp.

156{
157 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
158 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
159
160 Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ, 4);
161 unsigned int idx = 0;
162 add_4D_tensor_argument(idx, _input, window_collapsed);
163 add_3D_tensor_argument(idx, _indices, window_collapsed);
164 add_4D_tensor_argument(idx, _output, window_collapsed);
165 enqueue(queue, *this, window_collapsed, lws_hint());
166}

Referenced by package.infer.session::inference().

◆ validate()

Status CLGatherExKernel::validate ( const ITensorInfo *  input,
const ITensorInfo *  indices,
const ITensorInfo *  output,
int  axis = 0 
)
static

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

Parameters
[in]inputAn input tensor. Data types supported: U8/QASYMM8/S32/F32.
[in]indicesIndices tensor. Data types supported: S32.
[out]outputThe output tensor, Data types supported: same as input1.
[in]axis(Optional) The axis in input to gather indices from. Negative values wrap around. Defaults to 0
Returns
a status

Definition at line 144 of file CLGatherExKernel.cpp.

146{
147 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, indices, output, axis));
148 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(),
149 indices->clone().get(),
150 output->clone().get(), axis)
151 .first);
152 return Status{};
153}

Referenced by operator=(), and arm_compute::CLGatherEx::validate().


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