Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub
Other functions needed for quantization

These functions are used to accelerate quantization algorithms in Synet Framework. More...

Functions

SIMD_API void SimdSynetDequantizeLinear (const uint8_t *src, size_t size, int32_t bias, const float *norm, float *dst)
 Dequantizes a UINT8 tensor to FP32 with a single scale and zero-point correction. More...
 
SIMD_API void SimdSynetQuantizedConcatLayerForward (size_t count, const uint8_t **src, size_t num, const size_t *size, const int32_t *bias, const float *norm, const float *scale, int32_t zero, uint8_t *dst)
 Concatenates UINT8 tensors with requantization. More...
 
SIMD_API void SimdSynetQuantizedScaleLayerForward (const uint8_t *src, const float *srcScale, int srcZero, size_t channels, size_t spatial, const float *scale, const float *bias, uint8_t *dst, const float *dstScale, int dstZero, SimdTensorFormatType format)
 Performs forward propagation of UINT8 quantized scale layer. More...
 
SIMD_API void SimdSynetQuantizedShuffleLayerForward (const uint8_t *src0, int bias0, const float *norm0, size_t srcC0, const uint8_t *src1, int bias1, const float *norm1, size_t srcC1, size_t spatial, uint8_t *dst0, uint8_t *dst1, const float *scale, int zero, SimdTensorFormatType format, int type)
 Performs forward propagation of UINT8 quantized shuffle layer. More...
 
SIMD_API void SimdSynetQuantizeLinear (const float *src, size_t size, const float *norm, int32_t zero, uint8_t *dst)
 Performs FP32 to UINT8 linear quantization. More...
 

Detailed Description

These functions are used to accelerate quantization algorithms in Synet Framework.

Function Documentation

◆ SimdSynetDequantizeLinear()

void SimdSynetDequantizeLinear ( const uint8_t *  src,
size_t  size,
int32_t  bias,
const float *  norm,
float *  dst 
)

Dequantizes a UINT8 tensor to FP32 with a single scale and zero-point correction.

Algorithm's details for SimdSynetDequantizeLinear:

for(i = 0; i < size; ++i)
    dst[i] = (src[i] + bias) * norm[0];

This corresponds to dst = (src - zero) * scale when bias is equal to -zero and norm[0] is equal to scale.

Parameters
[in]src- a pointer to UINT8 input tensor.
[in]size- a number of elements in the input and output tensors.
[in]bias- an integer value added to every input element, typically negative zero-point.
[in]norm- a pointer to FP32 dequantization scale. Only norm[0] is used.
[out]dst- a pointer to FP32 output tensor.

◆ SimdSynetQuantizedConcatLayerForward()

void SimdSynetQuantizedConcatLayerForward ( size_t  count,
const uint8_t **  src,
size_t  num,
const size_t *  size,
const int32_t *  bias,
const float *  norm,
const float *  scale,
int32_t  zero,
uint8_t *  dst 
)

Concatenates UINT8 tensors with requantization.

Algorithm's details:

for(n = 0; n < num; ++n)
    for(s = 0, offset = 0; s < count; offset += size[s], ++s)
        for(i = 0; i < size[s]; ++i)
            dst[offset + i] = RestrictRange(Round((src[s][n*size[s] + i] + bias[s])*norm[s]*scale[0]) + zero, 0, 255);
Note
This function is used in Synet Framework.
Parameters
[in]count- a number of input tensors.
[in]src- an array with pointers to UINT8 input tensors.
[in]num- a number of concatenated blocks.
[in]size- an array with sizes of concatenated parts for each input tensor.
[in]bias- an array with dequantization biases of input tensors (usually -zero).
[in]norm- an array with dequantization scales of input tensors.
[in]scale- a pointer to output quantization norm (usually 1/scale).
[in]zero- an output quantization zero.
[out]dst- a pointer to the UINT8 output tensor.

◆ SimdSynetQuantizedScaleLayerForward()

void SimdSynetQuantizedScaleLayerForward ( const uint8_t *  src,
const float *  srcScale,
int  srcZero,
size_t  channels,
size_t  spatial,
const float *  scale,
const float *  bias,
uint8_t *  dst,
const float *  dstScale,
int  dstZero,
SimdTensorFormatType  format 
)

Performs forward propagation of UINT8 quantized scale layer.

Algorithm's details:

value = (src - srcZero)*srcScale[0];
value = value*scale[c] + (bias ? bias[c] : 0);
dst = RestrictRange(Round(value/dstScale[0]) + dstZero, 0, 255);
Note
This function is used in Synet Framework.
Parameters
[in]src- a pointer to UINT8 input tensor.
[in]srcScale- a pointer to quantization scale of input tensor.
[in]srcZero- a quantization zero parameter of input tensor.
[in]channels- a number of channels in (input/output) tensors.
[in]spatial- a spatial size of (input/output) tensors.
[in]scale- a pointer to the 32-bit float array with scale coefficients. The size of the array is equal to channels.
[in]bias- a pointer to the 32-bit float array with bias coefficients. The size of the array is equal to channels. Can be NULL.
[out]dst- a pointer to UINT8 output tensor.
[in]dstScale- a pointer to output quantization scale.
[in]dstZero- an output quantization zero.
[in]format- a format of input and output tensors. It can be SimdTensorFormatNchw or SimdTensorFormatNhwc.

◆ SimdSynetQuantizedShuffleLayerForward()

void SimdSynetQuantizedShuffleLayerForward ( const uint8_t *  src0,
int  bias0,
const float *  norm0,
size_t  srcC0,
const uint8_t *  src1,
int  bias1,
const float *  norm1,
size_t  srcC1,
size_t  spatial,
uint8_t *  dst0,
uint8_t *  dst1,
const float *  scale,
int  zero,
SimdTensorFormatType  format,
int  type 
)

Performs forward propagation of UINT8 quantized shuffle layer.

The function dequantizes channels from two input tensors, performs channel shuffle and requantizes results to two output tensors. For type 0 pairs of channels from src0 and src1 are split between dst0 and dst1. For type 1 channels from src0 and src1 are interleaved back into dst0 and dst1.

Note
This function is used in Synet Framework.
Parameters
[in]src0- a pointer to UINT8 data of the first input tensor.
[in]bias0- a dequantization bias parameter of the first input tensor (-zero).
[in]norm0- a dequantization norm parameter of the first input tensor (scale).
[in]srcC0- a number of channels in the first input tensor.
[in]src1- a pointer to UINT8 data of the second input tensor.
[in]bias1- a dequantization bias parameter of the second input tensor (-zero).
[in]norm1- a dequantization norm parameter of the second input tensor (scale).
[in]srcC1- a number of channels in the second input tensor.
[in]spatial- a spatial size of (input/output) tensors.
[out]dst0- a pointer to UINT8 data of the first output tensor.
[out]dst1- a pointer to UINT8 data of the second output tensor.
[in]scale- an output quantization norm (1/scale).
[in]zero- an output quantization zero.
[in]format- a format of input and output tensors. It can be SimdTensorFormatNchw or SimdTensorFormatNhwc.
[in]type- a shuffle type: 0 for split operation, 1 for interleave operation.

◆ SimdSynetQuantizeLinear()

void SimdSynetQuantizeLinear ( const float *  src,
size_t  size,
const float *  norm,
int32_t  zero,
uint8_t *  dst 
)

Performs FP32 to UINT8 linear quantization.

Algorithm's details for SimdSynetQuantizeLinear:

for(i = 0; i < size; ++i)
    dst[i] = RestrictRange(Round(src[i]*norm[0]) + zero, 0, 255);
Parameters
[in]src- a pointer to FP32 input tensor.
[in]size- a size of the input and output tensors.
[in]norm- a pointer to quantization norm (usually 1/scale).
[in]zero- a quantization zero.
[out]dst- a pointer to UINT8 output tensor.