Simd Library Documentation.

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

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

Functions

SIMD_API void * SimdSynetQuantizedAddInit (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, SimdConvolutionActivationType actType, const float *actParams, SimdTensorDataType dstType, const float *dstScale, int32_t dstZero)
 Initializes element-wise quantized addition of two tensors with optional activation. More...
 
SIMD_API void SimdSynetQuantizedAddForward (void *context, const uint8_t *a, const uint8_t *b, uint8_t *dst)
 Performs element-wise quantized addition. More...
 

Detailed Description

A framework to accelerate Quantized addition in Synet Framework.

Function Documentation

◆ SimdSynetQuantizedAddInit()

void * SimdSynetQuantizedAddInit ( 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,
SimdConvolutionActivationType  actType,
const float *  actParams,
SimdTensorDataType  dstType,
const float *  dstScale,
int32_t  dstZero 
)

Initializes element-wise quantized addition of two tensors with optional activation.

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

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]actType- an activation function type applied after addition. Supported optimized path uses SimdConvolutionActivationIdentity or SimdConvolutionActivationRelu.
[in]actParams- a pointer to activation function parameters. Can be NULL.
[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 addition context. On error it returns NULL. It must be released with using of function SimdRelease. This pointer is used in function SimdSynetQuantizedAddForward.

◆ SimdSynetQuantizedAddForward()

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

Performs element-wise quantized addition.

Algorithm's details for UINT8 output:

for(i = 0; i < size; ++i)
{
    value = Activate((a[i] - aZero)*aScale + (b[i] - bZero)*bScale, actType, actParams);
    dst[i] = RestrictRange(Round(value/dstScale) + dstZero, 0, 255);
}
Parameters
[in]context- a pointer to quantized addition context. It must be created by function SimdSynetQuantizedAddInit and released by function SimdRelease.
[in]a- a pointer to input A tensor data. Its type is defined by parameter aType of SimdSynetQuantizedAddInit.
[in]b- a pointer to input B tensor data. Its type is defined by parameter bType of SimdSynetQuantizedAddInit.
[out]dst- a pointer to output tensor data. Its type is defined by parameter dstType of SimdSynetQuantizedAddInit.