Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub
Quantized multiplication framework

A framework to accelerate Quantized multiplication in Synet Framework. More...

Functions

SIMD_API void * SimdSynetQuantizedMulInit (const size_t *aShape, size_t aCount, SimdTensorDataType aType, const float *aScale, int32_t aZero, const size_t *bShape, size_t bCount, SimdTensorDataType bType, const float *bScale, int32_t bZero, SimdTensorDataType dstType, const float *dstScale, int32_t dstZero)
 Initializes element-wise quantized multiplication of two tensors. More...
 
SIMD_API void SimdSynetQuantizedMulForward (void *context, const uint8_t *a, const uint8_t *b, uint8_t *dst)
 Performs element-wise quantized multiplication. More...
 

Detailed Description

A framework to accelerate Quantized multiplication in Synet Framework.

Function Documentation

◆ SimdSynetQuantizedMulInit()

void * SimdSynetQuantizedMulInit ( const size_t *  aShape,
size_t  aCount,
SimdTensorDataType  aType,
const float *  aScale,
int32_t  aZero,
const size_t *  bShape,
size_t  bCount,
SimdTensorDataType  bType,
const float *  bScale,
int32_t  bZero,
SimdTensorDataType  dstType,
const float *  dstScale,
int32_t  dstZero 
)

Initializes element-wise quantized multiplication of two tensors.

The current implementation supports compatible input shapes (equal or broadcast). For each element it dequantizes UINT8 inputs as (value - zero)*scale, multiplies the two values and converts the result to FP32 or UINT8 output. FP32 inputs and outputs ignore the corresponding quantization zero.

Note
This function has a C++ wrapper: Simd::SynetQuantizedMul.
Parameters
[in]aShape- a pointer to shape of input A tensor.
[in]aCount- a count of dimensions of input A tensor.
[in]aType- a type of input A tensor. It can be SimdTensorData32f or SimdTensorData8u.
[in]aScale- a pointer to quantization scale of input A tensor. Can be NULL (scale is 1.0).
[in]aZero- a quantization zero of input A tensor.
[in]bShape- a pointer to shape of input B tensor.
[in]bCount- a count of dimensions of input B tensor.
[in]bType- a type of input B tensor. It can be SimdTensorData32f or SimdTensorData8u.
[in]bScale- a pointer to quantization scale of input B tensor. Can be NULL (scale is 1.0).
[in]bZero- a quantization zero of input B tensor.
[in]dstType- a type of output tensor. It can be SimdTensorData32f or SimdTensorData8u.
[in]dstScale- a pointer to output quantization scale. Can be NULL (scale is 1.0).
[in]dstZero- an output quantization zero.
Returns
a pointer to quantized multiplication context. On error it returns NULL. It must be released with using of function SimdRelease. This pointer is used in function SimdSynetQuantizedMulForward.

◆ SimdSynetQuantizedMulForward()

void SimdSynetQuantizedMulForward ( void *  context,
const uint8_t *  a,
const uint8_t *  b,
uint8_t *  dst 
)

Performs element-wise quantized multiplication.

Algorithm's details for UINT8 output:

for(i = 0; i < size; ++i)
{
    _a = (a[i] - aZero)*aScale;
    _b = (b[i] - bZero)*bScale;
    dst[i] = RestrictRange(Round((_a * _b)/dstScale) + dstZero, 0, 255);
}
Note
This function has a C++ wrapper: Simd::SynetQuantizedMul.
Parameters
[in]context- a pointer to quantized multiplication context. It must be created by function SimdSynetQuantizedMulInit and released by function SimdRelease.
[in]a- a pointer to input A tensor data. Its type is defined by parameter aType of SimdSynetQuantizedMulInit.
[in]b- a pointer to input B tensor data. Its type is defined by parameter bType of SimdSynetQuantizedMulInit.
[out]dst- a pointer to output tensor data. Its type is defined by parameter dstType of SimdSynetQuantizedMulInit.