Compute Library
 21.02
CLGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint Class Reference

Basic function to execute CLGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint on OpenCL. More...

#include <CLGEMMLowpOutputStage.h>

Collaboration diagram for CLGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint:
[legend]

Public Member Functions

void configure (const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
 Initialise the kernel's inputs, output. More...
 
void configure (const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
 Initialise the kernel's inputs, output. More...
 
- Public Member Functions inherited from ICLSimpleFunction
 ICLSimpleFunction (CLRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 ICLSimpleFunction (const ICLSimpleFunction &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICLSimpleFunction (ICLSimpleFunction &&)=default
 Default move constructor. More...
 
ICLSimpleFunctionoperator= (const ICLSimpleFunction &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICLSimpleFunctionoperator= (ICLSimpleFunction &&)=default
 Default move assignment operator. More...
 
 ~ICLSimpleFunction ()
 Default destructor. More...
 
void run () override final
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
 Static function to check if given info will lead to a valid configuration of CLGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint. More...
 

Detailed Description

Basic function to execute CLGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint on OpenCL.

CLGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint depends on 3 parameters:

result_fixedpoint_multiplier, result_shift, result_offset_after_shift

The final result is:

(FixedPointMul(input[i][k], result_fixedpoint_multiplier) >> result_shift) + result_offset_after_shift

where FixedPointMul(x, y) is the nearest integer to the following mathematical expression, evaluated without overflow or intermediate rounding:

(x * y) / 2^31

For more information: https://github.com/google/gemmlowp/blob/master/public/output_stages.h#L68

In case the bias tensor is provided, the final result is:

((FixedPointMul(input[i][k] + bias[k], result_fixedpoint_multiplier)) >> result_shift) + result_offset_after_shift

This function calls the following OpenCL kernels:

  1. CLGEMMLowpQuantizeDownInt32ScaleByFixedPointKernel
Note
The function accepts also 2 optional input arguments (min and max) which can be used to implement "rectified linear unit" activation functions after the result is shifted right by result_shift

Definition at line 154 of file CLGEMMLowpOutputStage.h.

Member Function Documentation

◆ configure() [1/2]

void configure ( const ICLTensor input,
const ICLTensor bias,
ICLTensor output,
int  result_fixedpoint_multiplier,
int  result_shift,
int  result_offset_after_shift,
int  min = std::numeric_limits<int32_t>::lowest(),
int  max = std::numeric_limits<int32_t>::max() 
)

Initialise the kernel's inputs, 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: QASYMM8_SIGNED
[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_shiftNumber of bits to shift right the result after the fixed point multiplication
[in]result_offset_after_shiftOffset to be applied to result before converting it back to QASYMM8_SIGNED
[in]min(Optional) Min value used to saturate down the output result before converting back to QASYMM8_SIGNED. Defaults to the minimum possible 32-bit signed integer.
[in]max(Optional) Max value used to saturate up the output result before converting back to QASYMM8_SIGNED. Defaults to 0 Along with min, this value can be used to implement "rectified linear unit" activation functions. Defaults to the maximum possible 32-bit signed integer.

Definition at line 69 of file CLGEMMLowpOutputStage.cpp.

References CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::configure(), and CLKernelLibrary::get().

72 {
73  configure(CLKernelLibrary::get().get_compile_context(), input, bias, output, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
74 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift, int min=std::numeric_limits< int32_t >::lowest(), int max=std::numeric_limits< int32_t >::max())
Initialise the kernel&#39;s inputs, output.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ICLTensor input,
const ICLTensor bias,
ICLTensor output,
int  result_fixedpoint_multiplier,
int  result_shift,
int  result_offset_after_shift,
int  min = std::numeric_limits<int32_t>::lowest(),
int  max = std::numeric_limits<int32_t>::max() 
)

Initialise the kernel's inputs, output.

Parameters
[in]compile_contextThe compile context to be used.
[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: QASYMM8_SIGNED
[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_shiftNumber of bits to shift right the result after the fixed point multiplication
[in]result_offset_after_shiftOffset to be applied to result before converting it back to QASYMM8_SIGNED
[in]min(Optional) Min value used to saturate down the output result before converting back to QASYMM8_SIGNED. Defaults to the minimum possible 32-bit signed integer.
[in]max(Optional) Max value used to saturate up the output result before converting back to QASYMM8_SIGNED. Defaults to 0 Along with min, this value can be used to implement "rectified linear unit" activation functions. Defaults to the maximum possible 32-bit signed integer.

Definition at line 76 of file CLGEMMLowpOutputStage.cpp.

References arm_compute::test::validation::info, and arm_compute::QASYMM8_SIGNED.

79 {
80  GEMMLowpOutputStageInfo info{};
81  info.gemmlowp_multiplier = result_fixedpoint_multiplier;
82  info.gemmlowp_shift = result_shift;
83  info.gemmlowp_offset = result_offset_after_shift;
84  info.gemmlowp_min_bound = min;
85  info.gemmlowp_max_bound = max;
86  info.output_data_type = DataType::QASYMM8_SIGNED;
87  auto k = std::make_unique<CLGEMMLowpQuantizeDownInt32ScaleByFixedPointKernel>();
88  k->configure(compile_context, input, bias, output, &info);
89  _kernel = std::move(k);
90 }
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
quantized, asymmetric fixed-point 8-bit number signed

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo bias,
const ITensorInfo output,
int  min = std::numeric_limits<int32_t>::lowest(),
int  max = std::numeric_limits<int32_t>::max() 
)
static

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

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

Definition at line 92 of file CLGEMMLowpOutputStage.cpp.

References arm_compute::test::validation::info, arm_compute::QASYMM8_SIGNED, and CLGEMMLowpQuantizeDownInt32ScaleByFixedPointKernel::validate().

94 {
95  GEMMLowpOutputStageInfo info{};
96  info.gemmlowp_min_bound = min;
97  info.gemmlowp_max_bound = max;
98  info.output_data_type = DataType::QASYMM8_SIGNED;
100 }
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *info)
Static function to check if given info will lead to a valid configuration of CLGEMMLowpQuantizeDownIn...
quantized, asymmetric fixed-point 8-bit number signed

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