Compute Library
 21.08
CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel Class Reference

Kernel used to quantize down the int32 accumulator values of GEMMLowp to QASYMM8_SIGNED. More...

#include <CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel.h>

Collaboration diagram for CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel:
[legend]

Public Member Functions

 CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel)
 
void configure (ITensorInfo *src, ITensorInfo *bias, ITensorInfo *dst, 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_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
const char * name () const override
 Name of the kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version 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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, int min=0, int max=0)
 Static function to check if given info will lead to a valid configuration. More...
 

Detailed Description

Kernel used to quantize down the int32 accumulator values of GEMMLowp to QASYMM8_SIGNED.

This kernel takes a final int32 accumulator value (the output of CpuGemmLowpMatrixMultiplyKernel), and processes it to obtain the final QASYMM8_SIGNED 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 [-128..127] range and cast to QASYMM8_SIGNED.

Definition at line 52 of file CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel.h.

Constructor & Destructor Documentation

◆ CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel()

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel  )

◆ configure()

void configure ( ITensorInfo src,
ITensorInfo bias,
ITensorInfo dst,
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]srcInput tensor info. Data type supported: S32
[in]biasBiases tensor info. 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]dstOutput tensor info. Data type supported: 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_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_SIGNED
[in]min(Optional) Min value used to saturate down the output result before converting back to QASYMM8_SIGNED
[in]max(Optional) Max value used to saturate up the output result before converting back to QASYMM8_SIGNED, Along with min, this value can be used to implement "rectified linear unit" activation functions

Definition at line 185 of file CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), and arm_compute::QASYMM8_SIGNED.

187 {
188  ARM_COMPUTE_UNUSED(bias);
189  // Perform validate step
191  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, bias, dst, min, max));
192 
193  _result_fixedpoint_multiplier = result_fixedpoint_multiplier;
194  _result_shift = result_shift;
195  _result_offset_after_shift = result_offset_after_shift;
196  _min = min;
197  _max = max;
198 
199  // Output auto initialization if not yet initialized
200  auto_init_if_empty(*dst, src->clone()->set_data_type(DataType::QASYMM8_SIGNED));
201 
202  // Configure kernel window
203  Window win_config = calculate_max_window(*src, Steps());
204  ICpuKernel::configure(win_config);
205 
206  // Check if we need to clamp the result using min and max
207  const bool is_bounded_relu = !(min <= -128 && max >= 127);
208  _func = is_bounded_relu ? &CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel::run_internal<true> :
209  &CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel::run_internal<false>;
210 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
quantized, asymmetric fixed-point 8-bit number signed

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 233 of file CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel.cpp.

234 {
235  return "CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel";
236 }

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operate on.
[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.

Reimplemented from ICPPKernel.

Definition at line 219 of file CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel.cpp.

References arm_compute::ACL_BIAS, arm_compute::ACL_DST, arm_compute::ACL_SRC, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorPack::empty(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), and IKernel::window().

220 {
224  ARM_COMPUTE_ERROR_ON_MSG(tensors.empty(), "No inputs provided");
225 
226  auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
227  auto bias = tensors.get_const_tensor(TensorType::ACL_BIAS);
228  auto dst = tensors.get_tensor(TensorType::ACL_DST);
229 
230  (this->*_func)(src, bias, dst, window);
231 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo bias,
const ITensorInfo dst,
int  min = 0,
int  max = 0 
)
static

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

Similar to CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel::configure()

Returns
a status

Definition at line 212 of file CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, and ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by CpuGemmLowpOutputStage::validate().

213 {
215  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, bias, dst, min, max));
216  return Status{};
217 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

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