Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub
FP32 convolution framework

A framework to accelerate FP32 convolution in Synet Framework. More...

Functions

SIMD_API void * SimdSynetConvolution32fInit (size_t batch, const SimdConvolutionParameters *conv)
 Initializes an FP32 convolution context. More...
 
SIMD_API size_t SimdSynetConvolution32fExternalBufferSize (const void *context)
 Gets the size of caller-provided temporary buffer for FP32 convolution. More...
 
SIMD_API size_t SimdSynetConvolution32fInternalBufferSize (const void *context)
 Gets the size of internal storage used by an FP32 convolution context. More...
 
SIMD_API const char * SimdSynetConvolution32fInfo (const void *context)
 Gets a short description of the selected FP32 convolution implementation. More...
 
SIMD_API void SimdSynetConvolution32fSetParams (void *context, const float *weight, SimdBool *internal, const float *bias, const float *params)
 Sets weights, bias and activation parameters for FP32 convolution. More...
 
SIMD_API void SimdSynetConvolution32fForward (void *context, const float *src, float *buf, float *dst)
 Performs forward propagation of FP32 convolution. More...
 

Detailed Description

A framework to accelerate FP32 convolution in Synet Framework.

Function Documentation

◆ SimdSynetConvolution32fInit()

void * SimdSynetConvolution32fInit ( size_t  batch,
const SimdConvolutionParameters conv 
)

Initializes an FP32 convolution context.

The function validates convolution parameters and chooses a suitable implementation (direct, depthwise, Winograd, NHWC-specialized or GEMM-based). It supports FP32 source and destination tensors with matching NCHW or NHWC format. The destination spatial size must match convolution parameters:

dstH = (srcH + padY + padH - (dilationY*(kernelY - 1) + 1)) / strideY + 1
dstW = (srcW + padX + padW - (dilationX*(kernelX - 1) + 1)) / strideX + 1

A created context stores tensor shape, format, convolution geometry, group count and activation type. Weights, bias and activation parameters are attached later by SimdSynetConvolution32fSetParams.

Parameters
[in]batch- a batch size.
[in]conv- a pointer to convolution parameters. Source and destination tensor types must be FP32.
Returns
a pointer to FP32 convolution context. On error it returns NULL. It must be released with using of function SimdRelease. This pointer is used in functions SimdSynetConvolution32fExternalBufferSize, SimdSynetConvolution32fInternalBufferSize, SimdSynetConvolution32fInfo, SimdSynetConvolution32fSetParams and SimdSynetConvolution32fForward.

◆ SimdSynetConvolution32fExternalBufferSize()

size_t SimdSynetConvolution32fExternalBufferSize ( const void *  context)

Gets the size of caller-provided temporary buffer for FP32 convolution.

The returned value is a number of 32-bit float elements, not bytes. It depends on the implementation selected during initialization and can be used to allocate the buf argument of SimdSynetConvolution32fForward. Some implementations return 1 when they do not need external temporary storage.

Parameters
[in]context- a pointer to FP32 convolution context. It must be created by function SimdSynetConvolution32fInit and released by function SimdRelease.
Returns
a number of FP32 elements required for external temporary buffer.

◆ SimdSynetConvolution32fInternalBufferSize()

size_t SimdSynetConvolution32fInternalBufferSize ( const void *  context)

Gets the size of internal storage used by an FP32 convolution context.

The returned value is a number of 32-bit float elements, not bytes. It reports internal storage tracked by the selected implementation, such as internal temporary buffers and implementation-specific reordered weights, bias or activation parameters already allocated by the context.

Parameters
[in]context- a pointer to FP32 convolution context. It must be created by function SimdSynetConvolution32fInit and released by function SimdRelease.
Returns
a number of FP32 elements used by internal buffers.

◆ SimdSynetConvolution32fInfo()

const char * SimdSynetConvolution32fInfo ( const void *  context)

Gets a short description of the selected FP32 convolution implementation.

The returned string contains the implementation extension and algorithm name, for example a direct, depthwise, Winograd, NHWC direct or GEMM-based variant. The returned pointer is owned by the context and remains valid until the next call of this function for the same context or until the context is released.

Parameters
[in]context- a pointer to FP32 convolution context. It must be created by function SimdSynetConvolution32fInit and released by function SimdRelease.
Returns
a string with description of internal implementation of FP32 convolution algorithm.

◆ SimdSynetConvolution32fSetParams()

void SimdSynetConvolution32fSetParams ( void *  context,
const float *  weight,
SimdBool internal,
const float *  bias,
const float *  params 
)

Sets weights, bias and activation parameters for FP32 convolution.

This function must be called before SimdSynetConvolution32fForward. The weight array contains FP32 convolution weights with kernelY*kernelX*srcC*dstC/group elements. Depending on the selected implementation, weights can be used directly or transformed and stored inside the context. If internal is not NULL, the selected implementation writes the weight storage mode to it: SimdTrue means that weights were transformed and stored internally, while SimdFalse means that the implementation may use the original weight array directly, so the caller must keep it valid for later forward calls. Bias and activation parameters can also be copied internally by some implementations; otherwise their pointers are stored in the context.

Parameters
[in,out]context- a pointer to FP32 convolution context. It must be created by function SimdSynetConvolution32fInit and released by function SimdRelease.
[in]weight- a pointer to FP32 convolution weights.
[out]internal- a pointer to a flag receiving weight ownership mode. Can be NULL.
[in]bias- a pointer to FP32 bias array with dstC elements. Can be NULL.
[in]params- a pointer to FP32 parameters of activation function (see SimdConvolutionActivationType). Can be NULL when activation does not require parameters.

◆ SimdSynetConvolution32fForward()

void SimdSynetConvolution32fForward ( void *  context,
const float *  src,
float *  buf,
float *  dst 
)

Performs forward propagation of FP32 convolution.

The function convolves each image in the batch, adds bias when it was set, and applies the activation specified in SimdConvolutionParameters:

sum = bias == NULL ? 0 : bias[dc];
for(sc = 0; sc < srcC/group; ++sc)
    for(ky = 0; ky < kernelY; ++ky)
        for(kx = 0; kx < kernelX; ++kx)
            sum += src[inputOffset] * weight[weightOffset];
dst[outputOffset] = Activate(sum, activation, params);

The exact offsets depend on tensor format, padding, dilation, stride and group. The input and output tensors use the shape and format from the context created by SimdSynetConvolution32fInit.

Parameters
[in]context- a pointer to FP32 convolution context. It must be created by function SimdSynetConvolution32fInit and released by function SimdRelease.
[in]src- a pointer to FP32 input tensor.
[out]buf- a pointer to external temporary FP32 buffer. The required number of elements is determined by function SimdSynetConvolution32fExternalBufferSize. Can be NULL (it causes usage of internal buffer).
[out]dst- a pointer to FP32 output tensor.