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... | |
| SIMD_API void * | SimdSynetScale8iInit (size_t batch, size_t channels, size_t spatial, SimdTensorDataType srcType, SimdTensorDataType dstType, SimdTensorFormatType format, SimdSynetCompatibilityType compatibility) |
| Initializes FP32/UINT8 scale and bias algorithm. More... | |
| SIMD_API size_t | SimdSynetScale8iInternalBufferSize (const void *context) |
| Gets size in bytes of internal buffers allocated by FP32/UINT8 scale context. More... | |
| SIMD_API void | SimdSynetScale8iSetParams (void *context, const float *scale, const float *bias, const float *const *stats) |
| Sets per-channel scale, bias and tensor statistics for FP32/UINT8 scale algorithm. More... | |
| SIMD_API void | SimdSynetScale8iForward (void *context, const uint8_t *src, uint8_t *dst) |
| Performs forward propagation of FP32/UINT8 scale algorithm. 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.
◆ SimdSynetScale8iInit()
| void * SimdSynetScale8iInit | ( | size_t | batch, |
| size_t | channels, | ||
| size_t | spatial, | ||
| SimdTensorDataType | srcType, | ||
| SimdTensorDataType | dstType, | ||
| SimdTensorFormatType | format, | ||
| SimdSynetCompatibilityType | compatibility | ||
| ) |
Initializes FP32/UINT8 scale and bias algorithm.
The context performs per-channel affine transformation between FP32 and UINT8 tensors. When UINT8 is used, conversion parameters are derived from statistics passed to SimdSynetScale8iSetParams.
- Parameters
-
[in] batch - a batch size. [in] channels - a number of channels in input and output tensors. [in] spatial - a spatial size (height*width) of input and output tensors. [in] srcType - an input data type. It can be SimdTensorData32f or SimdTensorData8u. [in] dstType - an output data type. It can be SimdTensorData32f or SimdTensorData8u. [in] format - a format of input and output tensors. It can be SimdTensorFormatNchw or SimdTensorFormatNhwc. [in] compatibility - a flags of calculation compatibility.
- Returns
- a pointer to INT8 scale context. On error it returns NULL. It must be released with using of function SimdRelease. This pointer is used in functions SimdSynetScale8iInternalBufferSize, SimdSynetScale8iSetParams and SimdSynetScale8iForward.
◆ SimdSynetScale8iInternalBufferSize()
| size_t SimdSynetScale8iInternalBufferSize | ( | const void * | context | ) |
Gets size in bytes of internal buffers allocated by FP32/UINT8 scale context.
- Parameters
-
[in] context - a pointer to INT8 scale context. It must be created by function SimdSynetScale8iInit and released by function SimdRelease.
- Returns
- size in bytes of internal buffers used to store conversion parameters, scale and shift arrays.
◆ SimdSynetScale8iSetParams()
| void SimdSynetScale8iSetParams | ( | void * | context, |
| const float * | scale, | ||
| const float * | bias, | ||
| const float *const * | stats | ||
| ) |
Sets per-channel scale, bias and tensor statistics for FP32/UINT8 scale algorithm.
- Parameters
-
[in,out] context - a pointer to INT8 scale context. It must be created by function SimdSynetScale8iInit and released by function SimdRelease. [in] scale - a pointer to original FP32 per-channel scale coefficients. [in] bias - a pointer to original FP32 per-channel bias coefficients. Can be NULL. [in] stats - a pointer to pointers with input and output statistics: input min (stats[0]), input max (stats[1]), output min (stats[2]) and output max (stats[3]). Can be NULL for subsequent calls after statistics were initialized.
◆ SimdSynetScale8iForward()
| void SimdSynetScale8iForward | ( | void * | context, |
| const uint8_t * | src, | ||
| uint8_t * | dst | ||
| ) |
Performs forward propagation of FP32/UINT8 scale algorithm.
Algorithm's details after SimdSynetScale8iSetParams prepares internal coefficients:
dst = Convert(src*internalScale[c] + internalShift[c]);
- Parameters
-
[in] context - a pointer to INT8 scale context. It must be created by function SimdSynetScale8iInit and released by function SimdRelease. [in] src - a pointer to input tensor data. Its type is defined by parameter srcType of SimdSynetScale8iInit. [out] dst - a pointer to output tensor data. Its type is defined by parameter dstType of SimdSynetScale8iInit.