Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub

Add accelerated functions used in Synet Framework. More...

Functions

SIMD_API void * SimdSynetAdd16bInit (const size_t *aShape, size_t aCount, SimdTensorDataType aType, const size_t *bShape, size_t bCount, SimdTensorDataType bType, SimdTensorDataType dstType, SimdTensorFormatType format)
 Initializes element-wise addition of two tensors in FP32 or BF16 format. More...
 
SIMD_API void SimdSynetAdd16bForward (void *context, const uint8_t *a, const uint8_t *b, uint8_t *dst)
 Performs element-wise addition of two FP32/BF16 tensors. More...
 
SIMD_API void SimdSynetAddBias (const float *bias, size_t channels, size_t spatial, float *dst, SimdTensorFormatType format)
 Adds per-channel bias to an FP32 tensor in place. More...
 

Detailed Description

Add accelerated functions used in Synet Framework.

Function Documentation

◆ SimdSynetAdd16bInit()

void * SimdSynetAdd16bInit ( const size_t *  aShape,
size_t  aCount,
SimdTensorDataType  aType,
const size_t *  bShape,
size_t  bCount,
SimdTensorDataType  bType,
SimdTensorDataType  dstType,
SimdTensorFormatType  format 
)

Initializes element-wise addition of two tensors in FP32 or BF16 format.

The created context adds two tensors with equal shapes:

for(i = 0; i < shapeSize; ++i)
{
    A = aType == SimdTensorData16b ? BFloat16ToFloat32(a[i]) : a[i];
    B = bType == SimdTensorData16b ? BFloat16ToFloat32(b[i]) : b[i];
    D = A + B;
    dst[i] = dstType == SimdTensorData16b ? Float32ToBFloat16(D) : D;
}

The current implementation creates a context only for equal input shapes, FP32/BF16 input and output tensor types, and SimdTensorFormatUnknown, SimdTensorFormatNchw or SimdTensorFormatNhwc tensor format.

Note
This function has a C++ wrapper: Simd::SynetAdd16b.
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. Can be FP32 or BF16.
[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. Can be FP32 or BF16.
[in]dstType- a type of output tensor. Can be FP32 or BF16.
[in]format- a format of input / output tensors.
Returns
a pointer to add context. On error it returns NULL. It must be released with using of function SimdRelease. This pointer is used in function SimdSynetAdd16bForward.

◆ SimdSynetAdd16bForward()

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

Performs element-wise addition of two FP32/BF16 tensors.

The function adds corresponding elements of input tensors A and B using a context created by SimdSynetAdd16bInit. The actual data types, tensor shape and output type are stored in the context. BF16 input values are converted to FP32 before addition, and BF16 output values are converted from FP32 after addition.

Note
This function has a C++ wrapper: Simd::SynetAdd16b.
Parameters
[in]context- a pointer to add context. It must be created by function SimdSynetAdd16bInit and released by function SimdRelease.
[in]a- a pointer to input A tensor.
[in]b- a pointer to input B tensor.
[out]dst- a pointer to output tensor.

◆ SimdSynetAddBias()

void SimdSynetAddBias ( const float *  bias,
size_t  channels,
size_t  spatial,
float *  dst,
SimdTensorFormatType  format 
)

Adds per-channel bias to an FP32 tensor in place.

Algorithm's details (example for NCHW tensor format):

for(c = 0; c < channels; ++c)
    for(s = 0; s < spatial; ++s)
         dst[c*spatial + s] += bias[c];

Algorithm's details (example for NHWC tensor format):

for(s = 0; s < spatial; ++s)
    for(c = 0; c < channels; ++c)
         dst[s*channels + c] += bias[c];
Note
This function is used in Synet Framework.
Parameters
[in]bias- a pointer to the 32-bit float array with bias coefficients. The size of the array is equal to channels.
[in]channels- a number of channels in the tensor.
[in]spatial- a spatial size (height * width) of the tensor.
[in,out]dst- a pointer to FP32 tensor updated in place. The size of the array is equal to channels * spatial.
[in]format- a format of the tensor.