Compute Library
 19.08
NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel Class Reference

NEON kernel used to quantize down the int32 accumulator values of GEMMLowp to QASYMM8. More...

#include <NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel.h>

Collaboration diagram for NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel ()
 Constructor. More...
 
 NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel (const NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKerneloperator= (const NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel (NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKerneloperator= (NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ITensor *input, const ITensor *bias, ITensor *output, int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift, int min=0, int max=0)
 Initialise the kernel's input and output. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. 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 *input, const ITensorInfo *bias, const ITensorInfo *output, int min=0, int max=0)
 Static function to check if given info will lead to a valid configuration of NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel. More...
 

Detailed Description

NEON kernel used to quantize down the int32 accumulator values of GEMMLowp to QASYMM8.

This kernel takes a final int32 accumulator value (the output of NEGEMMLowpMatrixMultiplyKernel), and processes it to obtain the final QASYMM8 value. The following computations will be performed by the kernel:

  1. Compute fixed point multiplication between each entry of input by result_fixedpoint_multiplier
  2. Add bias to final result if bias tensor is not a nullptr
  3. Round to nearest division by a power-of-two using result_shift
  4. Add offset to each result
  5. Clamp the value between the specified min and max bounds
  6. Clamp the resulting int32 values to the [0..255] range and cast to QASYMM8.

Definition at line 46 of file NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel.h.

Constructor & Destructor Documentation

◆ NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel() [1/3]

Constructor.

Definition at line 200 of file NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel.cpp.

201  : _func(nullptr), _input(nullptr), _bias(nullptr), _output(nullptr), _result_fixedpoint_multiplier(0), _result_shift(0), _result_offset_after_shift(0), _min(0), _max(0)
202 {
203 }

◆ NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel() [2/3]

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

◆ NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel() [3/3]

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
const ITensor bias,
ITensor output,
int  result_fixedpoint_multiplier,
int  result_shift,
int  result_offset_after_shift,
int  min = 0,
int  max = 0 
)

Initialise the kernel's input and output.

Parameters
[in]inputInput tensor. Data type supported: S32
[in]biasBiases tensor. Only shared biases supported and it can be a nullptr if the biases addition is not required. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as input.
[out]outputOutput tensor. Data type supported: Data type supported: QASYMM8
[in]result_fixedpoint_multiplierFixed point value to be multiplied to each element of the input matrix when once the result_offset has been add
[in]result_shiftInteger value used to round to nearest division by a power-of-two the result after the fixed point multiplication
[in]result_offset_after_shiftOffset to be applied to result before converting it back to QASYMM8
[in]min(Optional) Min value used to saturate down the output result before converting back to QASYMM8
[in]max(Optional) Max value used to saturate up the output result before converting back to QASYMM8, Along with min, this value can be used to implement "rectified linear unit" activation functions

Definition at line 205 of file NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel.cpp.

207 {
208  // Perform validate step
209  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
210  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (bias != nullptr) ? bias->info() : nullptr, output->info(), min, max));
211 
212  _input = input;
213  _bias = bias;
214  _output = output;
215  _result_fixedpoint_multiplier = result_fixedpoint_multiplier;
216  _result_shift = result_shift;
217  _result_offset_after_shift = result_offset_after_shift;
218  _min = min;
219  _max = max;
220 
221  // Configure kernel window
222  auto win_config = validate_and_configure_window(input->info(), output->info());
223  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
224  INEKernel::configure(win_config.second);
225 
226  // Check if we need to clamp the result using min and max
227  const bool is_bounded_relu = ((min != max) && !(min == 0 && max == 255));
228  _func = is_bounded_relu ? &NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run<true> : &NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run<false>;
229 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: CLTensor.cpp:35
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::test::validation::bias, ITensor::info(), CLTensor::info(), and arm_compute::validate_and_configure_window().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 49 of file NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel.h.

50  {
51  return "NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel";
52  }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Implements ICPPKernel.

Definition at line 240 of file NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel.cpp.

241 {
245 
246  (this->*_func)(window);
247 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::info, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo bias,
const ITensorInfo output,
int  min = 0,
int  max = 0 
)
static

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

Parameters
[in]inputInput tensor. Data type supported: S32
[in]biasBiases tensor. Only shared biases supported and it can be a nullptr if the biases addition is not required. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as input.
[in]outputOutput tensor. Data type supported: Data type supported: QASYMM8
[in]min(Optional) Min value used to saturate down the output result before converting back to QASYMM8
[in]max(Optional) Max value used to saturate up the output result before converting back to QASYMM8, Along with min, this value can be used to implement "rectified linear unit" activation functions
Returns
a status

Definition at line 231 of file NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel.cpp.

232 {
233  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
234  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, bias, output, min, max));
235  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first);
236 
237  return Status{};
238 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
Status class.
Definition: Error.h:52
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::bias, ICloneable< T >::clone(), and arm_compute::validate_and_configure_window().

Referenced by NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate().


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