ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
arm_compute::CLQuantizationSymmetricKernel Class Reference

#include <CLQuantizationSymmetricKernel.h>

Collaboration diagram for arm_compute::CLQuantizationSymmetricKernel:

Public Member Functions

 CLQuantizationSymmetricKernel ()
 
 CLQuantizationSymmetricKernel (const CLQuantizationSymmetricKernel &)=delete
 
CLQuantizationSymmetricKerneloperator= (const CLQuantizationSymmetricKernel &)=delete
 
 CLQuantizationSymmetricKernel (CLQuantizationSymmetricKernel &&)=default
 
CLQuantizationSymmetricKerneloperator= (CLQuantizationSymmetricKernel &&)=default
 
 ~CLQuantizationSymmetricKernel ()=default
 
void configure (const ICLTensor *input, const ICLTensor *scale_factor, ICLTensor *output)
 
void run (const Window &window, cl::CommandQueue &queue) override
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *scale_factor, const ITensorInfo *output)
 

Detailed Description

Interface for the quantization layer kernel.

Note
The implementation supports only 2D input tensors.

Definition at line 54 of file CLQuantizationSymmetricKernel.h.

Constructor & Destructor Documentation

◆ CLQuantizationSymmetricKernel() [1/3]

arm_compute::CLQuantizationSymmetricKernel::CLQuantizationSymmetricKernel ( )

Default constructor

Definition at line 107 of file CLQuantizationSymmetricKernel.cpp.

108 : _input(nullptr), _scale_factor(nullptr), _output(nullptr)
109{
110}

◆ CLQuantizationSymmetricKernel() [2/3]

arm_compute::CLQuantizationSymmetricKernel::CLQuantizationSymmetricKernel ( const CLQuantizationSymmetricKernel )
delete

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

◆ CLQuantizationSymmetricKernel() [3/3]

arm_compute::CLQuantizationSymmetricKernel::CLQuantizationSymmetricKernel ( CLQuantizationSymmetricKernel &&  )
default

Default Move Constructor.

◆ ~CLQuantizationSymmetricKernel()

arm_compute::CLQuantizationSymmetricKernel::~CLQuantizationSymmetricKernel ( )
default

Default destructor

References validate().

Member Function Documentation

◆ configure()

void arm_compute::CLQuantizationSymmetricKernel::configure ( const ICLTensor *  input,
const ICLTensor *  scale_factor,
ICLTensor *  output 
)

Set the input, output.

Parameters
[in]inputSource tensor. Data types supported: F32/F16.
[in]scale_factorScale tensor of output. Data type supported: Same as input.
[out]outputDestination tensor with the same dimensions of input. Data types supported: S8.
Note
Output auto initialization is not supported by this kernel

Definition at line 112 of file CLQuantizationSymmetricKernel.cpp.

114{
115 ARM_COMPUTE_ERROR_ON_NULLPTR(input, scale_factor, output);
116 ARM_COMPUTE_ERROR_THROW_ON(
117 validate_arguments(input->info(), scale_factor->info(), output->info()));
118
119 _input = input;
120 _scale_factor = scale_factor;
121 _output = output;
122
123 const int vec_size_x = 16 / input->info()->element_size();
124 const int input_width_x = input->info()->tensor_shape().x();
125 const bool multi_access_x = (input_width_x / vec_size_x > 0);
126
127 // Configure kernel window
128 auto [error, window] = validate_and_configure_window(input->info(), output->info());
129 ARM_COMPUTE_ERROR_THROW_ON(error);
130 ICLKernel::configure_internal(window);
131
132 // Create kernel
133 CLBuildOptions build_opts;
134 build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x));
135 build_opts.add_option("-DDATA_TYPE_IN=" + get_cl_type_from_data_type(input->info()->data_type()));
136 build_opts.add_option("-DDATA_TYPE_OUT=" +
137 get_cl_type_from_data_type(output->info()->data_type()));
138 build_opts.add_option_if(
139 multi_access_x,
140 "-DLAST_ACCESSED_X=" + support::cpp11::to_string(std::max<int>(input_width_x - vec_size_x, 0)));
141
142 _kernel = static_cast<cl::Kernel>(
143 CLKernelLibraryEx::get().create_kernel("quantization_symm8", build_opts.options()));
144}
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.
Severity error(void)
Definition Severity.h:76

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

Referenced by arm_compute::CLFullyConnectedHybridLayer::configure().

◆ operator=() [1/2]

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

Default move assignment operator

◆ operator=() [2/2]

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

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

◆ run()

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

Definition at line 157 of file CLQuantizationSymmetricKernel.cpp.

158{
159 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
160 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window);
161
162 // Support only 2D
163 Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ);
164 Window slice = window_collapsed.first_slice_window_2D();
165
166 do
167 {
168 Window scale_slice = slice.shift_dimensions(1);
169
170 unsigned int idx = 0;
171 add_2D_tensor_argument(idx, _input, slice);
172 add_1D_tensor_argument(idx, _scale_factor, scale_slice);
173 add_2D_tensor_argument(idx, _output, slice);
174 enqueue(queue, *this, slice, lws_hint());
175 } while (window_collapsed.slide_window_slice_2D(slice));
176}

◆ validate()

Status arm_compute::CLQuantizationSymmetricKernel::validate ( const ITensorInfo *  input,
const ITensorInfo *  scale_factor,
const ITensorInfo *  output 
)
static

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

Parameters
[in]inputInput tensor info. Data types supported: F32/F16.
[in]scale_factorScale tensor of output. Data type supported: Same as input.
[in]outputDestination tensor info with the same dimensions of input. Data types supported: S8.
Returns
a status

Definition at line 146 of file CLQuantizationSymmetricKernel.cpp.

149{
150 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, scale_factor, output));
151 ARM_COMPUTE_RETURN_ON_ERROR(
152 validate_and_configure_window(input->clone().get(), output->clone().get()).first);
153
154 return Status{};
155}

Referenced by arm_compute::CLFullyConnectedHybridLayer::validate(), and ~CLQuantizationSymmetricKernel().


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