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

Class to perform EmbeddingLookup operation with opencl kernel. More...

#include <CLEmbeddingLookupKernel.h>

Collaboration diagram for arm_compute::CLEmbeddingLookupKernel:

Public Member Functions

 CLEmbeddingLookupKernel ()
 Construct a CLEmbeddingLookupKernel object.
 
 CLEmbeddingLookupKernel (const CLEmbeddingLookupKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers)
 
CLEmbeddingLookupKerneloperator= (const CLEmbeddingLookupKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers)
 
 CLEmbeddingLookupKernel (CLEmbeddingLookupKernel &&)=default
 Construct a CLEmbeddingLookupKernel object by using default move constructor.
 
CLEmbeddingLookupKerneloperator= (CLEmbeddingLookupKernel &&)=default
 Move assignment operator.
 
 ~CLEmbeddingLookupKernel ()=default
 Destruct this object.
 
void configure (const ICLTensor *input, ICLTensor *output, const ICLTensor *lookups)
 Set the input and output of the kernel.
 
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 *output, const ITensorInfo *lookups)
 Static function to check if given info will lead to a valid configuration of CLEmbeddingLookupKernel.
 

Detailed Description

Class to perform EmbeddingLookup operation with opencl kernel.

Definition at line 59 of file CLEmbeddingLookupKernel.h.

Constructor & Destructor Documentation

◆ CLEmbeddingLookupKernel() [1/3]

CLEmbeddingLookupKernel::CLEmbeddingLookupKernel ( )

Construct a CLEmbeddingLookupKernel object.

Definition at line 73 of file CLEmbeddingLookupKernel.cpp.

74 : _input(nullptr), _output(nullptr), _lookups(nullptr)
75{
76}

◆ CLEmbeddingLookupKernel() [2/3]

arm_compute::CLEmbeddingLookupKernel::CLEmbeddingLookupKernel ( const CLEmbeddingLookupKernel )
delete

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

◆ CLEmbeddingLookupKernel() [3/3]

arm_compute::CLEmbeddingLookupKernel::CLEmbeddingLookupKernel ( CLEmbeddingLookupKernel &&  )
default

Construct a CLEmbeddingLookupKernel object by using default move constructor.

Parameters
[in]CLEmbeddingLookupKernelobject to move

◆ ~CLEmbeddingLookupKernel()

arm_compute::CLEmbeddingLookupKernel::~CLEmbeddingLookupKernel ( )
default

Destruct this object.

References validate().

Member Function Documentation

◆ configure()

void CLEmbeddingLookupKernel::configure ( const ICLTensor *  input,
ICLTensor *  output,
const ICLTensor *  lookups 
)

Set the input and output of the kernel.

Parameters
[in]inputSource tensor. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
[out]outputDestination tensor. Data type supported: Same as input
[in]lookupsLookups are 1D tensor that values are indices into the first dimension of input. Data types supported: S32.
Returns
N/A

Definition at line 94 of file CLEmbeddingLookupKernel.cpp.

96{
97 ARM_COMPUTE_ERROR_THROW_ON(validate(input->info(), output->info(), lookups->info()));
98
99 _input = input;
100 _output = output;
101 _lookups = lookups;
102
103 // Set kernel build options
104 std::stringstream kernel_name;
105 std::set<std::string> build_opts;
106 kernel_name << "embedding_lookup";
107
108 build_opts.emplace("-DDEPTH_OUT=" + support::cpp11::to_string(output->info()->dimension(2)));
109 build_opts.emplace("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
110 build_opts.emplace("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration));
111 build_opts.emplace("-DNUM_DIMS=" + support::cpp11::to_string(_input->info()->num_dimensions()));
112
113 // Create kernel
114 _kernel =
115 static_cast<cl::Kernel>(CLKernelLibraryEx::get().create_kernel(kernel_name.str(), build_opts));
116
117 // Configure kernel window
118 auto win_config = validate_and_configure_window(input->info(), output->info());
119 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
120 ICLKernel::configure_internal(win_config.second);
121}
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ITensorInfo *lookups)
Static function to check if given info will lead to a valid configuration of CLEmbeddingLookupKernel.
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(), arm_compute::CLKernelLibraryEx::get(), and validate().

◆ operator=() [1/2]

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

Move assignment operator.

Parameters
[in]CLEmbeddingLookupKernelobject to move

◆ operator=() [2/2]

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

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

◆ run()

void CLEmbeddingLookupKernel::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 123 of file CLEmbeddingLookupKernel.cpp.

124{
125 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
126 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
127
128 Window slice_in = window.first_slice_window_4D().collapse(ICLKernel::window(), 2, 4);
129
130 Window win_lookup;
131 win_lookup.set(Window::DimX, Window::Dimension(0, 0, 0));
132
133 do
134 {
135 unsigned int idx = 0;
136 add_4D_tensor_argument(idx, _input, slice_in);
137 add_4D_tensor_argument(idx, _output, slice_in);
138 add_1D_tensor_argument(idx, _lookups, win_lookup);
139
140 enqueue(queue, *this, slice_in);
141 } while (window.slide_window_slice_4D(slice_in) && window.slide_window_slice_1D(win_lookup));
142}

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

◆ validate()

Status CLEmbeddingLookupKernel::validate ( const ITensorInfo *  input,
const ITensorInfo *  output,
const ITensorInfo *  lookups 
)
static

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

Parameters
[in]inputThe input tensor info. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
[in]outputThe output tensor info, Data types supported: same as input1.
[in]lookupsLookups info. Data types supported: S32.
Returns
a status

Definition at line 78 of file CLEmbeddingLookupKernel.cpp.

80{
81 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, lookups);
82 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(
83 input, 1, DataType::U8, DataType::S8, DataType::QASYMM8, DataType::U16, DataType::S16,
84 DataType::U32, DataType::S32, DataType::F16, DataType::F32);
85 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(lookups, 1, DataType::S32);
86 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
87
88 ARM_COMPUTE_ERROR_ON(input->num_dimensions() < 2 && input->num_dimensions() > 4);
89 ARM_COMPUTE_ERROR_ON(lookups->num_dimensions() > 1);
90
91 return Status{};
92}

Referenced by configure(), and ~CLEmbeddingLookupKernel().


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