Simd Library Documentation.

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

Functions to accelerate layer scale in Synet Framework. More...

Functions

SIMD_API void * SimdSynetScale16bInit (size_t channels, size_t spatial, SimdTensorDataType srcType, SimdTensorDataType dstType, SimdTensorFormatType format, SimdBool norm, SimdBool bias)
 Initializes FP32/BF16 scale and bias algorithm. More...
 
SIMD_API void SimdSynetScale16bForward (void *context, const uint8_t *src, const float *norm, const float *bias, uint8_t *dst)
 Performs forward propagation of FP32/BF16 scale and bias algorithm. More...
 
SIMD_API void SimdSynetScaleLayerForward (const float *src, const float *scale, const float *bias, size_t channels, size_t height, size_t width, float *dst, SimdTensorFormatType format, SimdSynetCompatibilityType compatibility)
 Performs forward propagation of FP32 ScaleLayer. More...
 

Detailed Description

Functions to accelerate layer scale in Synet Framework.

Function Documentation

◆ SimdSynetScale16bInit()

void * SimdSynetScale16bInit ( size_t  channels,
size_t  spatial,
SimdTensorDataType  srcType,
SimdTensorDataType  dstType,
SimdTensorFormatType  format,
SimdBool  norm,
SimdBool  bias 
)

Initializes FP32/BF16 scale and bias algorithm.

The context applies per-channel operation dst = src*norm + bias, dst = src*norm or dst = src + bias depending on norm and bias flags. Source and destination tensors can be FP32 or BF16.

Parameters
[in]channels- a number of channels in the (input/output) image tensor.
[in]spatial- a spatial size (height*width) of (input/output) image tensor.
[in]srcType- a type of input tensor. It can be SimdTensorData32f or SimdTensorData16b.
[in]dstType- a type of output tensor. It can be SimdTensorData32f or SimdTensorData16b.
[in]format- a format of input/output tensors. It can be SimdTensorFormatNchw or SimdTensorFormatNhwc.
[in]norm- a flag of presence of per-channel multiplication by norm.
[in]bias- a flag of presence of per-channel addition of bias.
Returns
a pointer to scale context. On error it returns NULL. It must be released with using of function SimdRelease. This pointer is used in function SimdSynetScale16bForward.

◆ SimdSynetScale16bForward()

void SimdSynetScale16bForward ( void *  context,
const uint8_t *  src,
const float *  norm,
const float *  bias,
uint8_t *  dst 
)

Performs forward propagation of FP32/BF16 scale and bias algorithm.

Algorithm's details:

value = ConvertToFloat(src);
if(norm) value *= norm[c];
if(bias) value += bias[c];
dst = ConvertFromFloat(value);
Parameters
[in]context- a pointer to scale context. It must be created by function SimdSynetScale16bInit and released by function SimdRelease.
[in]src- a pointer to input tensor data. Its type is defined by parameter srcType of SimdSynetScale16bInit.
[in]norm- a pointer to FP32 array with per-channel scale coefficients. Can be NULL if norm flag is SimdFalse.
[in]bias- a pointer to FP32 array with per-channel bias coefficients. Can be NULL if bias flag is SimdFalse.
[out]dst- a pointer to output tensor data. Its type is defined by parameter dstType of SimdSynetScale16bInit.

◆ SimdSynetScaleLayerForward()

void SimdSynetScaleLayerForward ( const float *  src,
const float *  scale,
const float *  bias,
size_t  channels,
size_t  height,
size_t  width,
float *  dst,
SimdTensorFormatType  format,
SimdSynetCompatibilityType  compatibility 
)

Performs forward propagation of FP32 ScaleLayer.

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

for(c = 0; c < channels; ++c)
    for(h = 0; h < height; ++h)
        for(w = 0; w < width; ++w)
            dst[(c*height + h)*width + w] = src[(c*height + h)*width + w]*scale[c] + (bias ? bias[c] : 0);
Note
This function is used in Synet Framework.
Parameters
[in]src- a pointer to the 32-bit float array with input image tensor. The size of the array is equal to channels*height*width.
[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.
[in]channels- a number of channels in the (input/output) image tensor.
[in]height- a height of (input/output) image tensor.
[in]width- a width of (input/output) image tensor.
[out]dst- a pointer to the 32-bit float array with output image tensor. The size of the array is equal to channels*height*width.
[in]format- a format of input and output image tensors. It can be SimdTensorFormatNchw or SimdTensorFormatNhwc.
[in]compatibility- reserved compatibility flags. Current implementation does not use this parameter.