Skip to content

Commit d352473

Browse files
Improve FP32 deconvolution API documentation
Co-authored-by: Ihar Yermalayeu <ermig@tut.by>
1 parent 2e27184 commit d352473

1 file changed

Lines changed: 67 additions & 18 deletions

File tree

src/Simd/SimdLib.h

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7957,11 +7957,23 @@ extern "C"
79577957

79587958
\fn void * SimdSynetDeconvolution32fInit(size_t batch, const SimdConvolutionParameters * conv, SimdSynetCompatibilityType compatibility);
79597959

7960-
\short Initializes FP32 deconvolution algorithm.
7960+
\short Initializes an FP32 deconvolution context.
7961+
7962+
The function validates deconvolution parameters and chooses a suitable implementation (GEMM-based or
7963+
NHWC direct 2x2 when available). It supports FP32 source and destination tensors with matching NCHW format,
7964+
or matching NHWC format when group is 1. The destination spatial size must match deconvolution parameters:
7965+
\verbatim
7966+
dstH = strideY*(srcH - 1) + dilationY*(kernelY - 1) + 1 - padY - padH
7967+
dstW = strideX*(srcW - 1) + dilationX*(kernelX - 1) + 1 - padX - padW
7968+
\endverbatim
7969+
7970+
A created context stores tensor shape, format, deconvolution geometry, group count, activation type and
7971+
compatibility flags. Weights, bias and activation parameters are attached later by
7972+
::SimdSynetDeconvolution32fSetParams.
79617973

79627974
\param [in] batch - a batch size.
7963-
\param [in] conv - a pointer to deconvolution parameters.
7964-
\param [in] compatibility - a flags of calculation compatibility.
7975+
\param [in] conv - a pointer to deconvolution parameters. Source and destination tensor types must be FP32.
7976+
\param [in] compatibility - calculation compatibility flags.
79657977
\return a pointer to FP32 deconvolution context. On error it returns NULL. It must be released with using of function ::SimdRelease.
79667978
This pointer is used in functions ::SimdSynetDeconvolution32fExternalBufferSize, ::SimdSynetDeconvolution32fInternalBufferSize,
79677979
::SimdSynetDeconvolution32fInfo, ::SimdSynetDeconvolution32fSetParams and ::SimdSynetDeconvolution32fForward.
@@ -7972,59 +7984,96 @@ extern "C"
79727984

79737985
\fn size_t SimdSynetDeconvolution32fExternalBufferSize(const void * context);
79747986

7975-
\short Gets size of external temporary buffer required for FP32 deconvolution algorithm.
7987+
\short Gets the size of caller-provided temporary buffer for FP32 deconvolution.
7988+
7989+
The returned value is a number of 32-bit float elements, not bytes. It depends on the implementation selected
7990+
during initialization and can be used to allocate the \a buf argument of ::SimdSynetDeconvolution32fForward.
7991+
Some implementations return 1 when they do not need external temporary storage.
79767992

79777993
\param [in] context - a pointer to FP32 deconvolution context. It must be created by function ::SimdSynetDeconvolution32fInit and released by function ::SimdRelease.
7978-
\return size of external temporary buffer required for FP32 deconvolution algorithm.
7994+
\return a number of FP32 elements required for external temporary buffer.
79797995
*/
79807996
SIMD_API size_t SimdSynetDeconvolution32fExternalBufferSize(const void * context);
79817997

79827998
/*! @ingroup synet_deconvolution_fp32
79837999

79848000
\fn size_t SimdSynetDeconvolution32fInternalBufferSize(const void * context);
79858001

7986-
\short Gets size of internal buffer used inside FP32 deconvolution algorithm.
8002+
\short Gets the size of internal storage used by an FP32 deconvolution context.
8003+
8004+
The returned value is a number of 32-bit float elements, not bytes. It reports internal storage tracked by
8005+
the selected implementation, such as internal temporary buffers and implementation-specific reordered weights,
8006+
bias or activation parameters already allocated by the context.
79878007

79888008
\param [in] context - a pointer to FP32 deconvolution context. It must be created by function ::SimdSynetDeconvolution32fInit and released by function ::SimdRelease.
7989-
\return size of internal buffer used inside FP32 deconvolution algorithm.
8009+
\return a number of FP32 elements used by internal buffers.
79908010
*/
79918011
SIMD_API size_t SimdSynetDeconvolution32fInternalBufferSize(const void * context);
79928012

79938013
/*! @ingroup synet_deconvolution_fp32
79948014

79958015
\fn const char* SimdSynetDeconvolution32fInfo(const void* context);
79968016

7997-
\short Gets description of internal implementation of FP32 deconvolution algorithm.
8017+
\short Gets a short description of the selected FP32 deconvolution implementation.
8018+
8019+
The returned string contains the implementation extension and algorithm name, for example a GEMM-based or
8020+
NHWC direct 2x2 variant. The returned pointer is owned by the context and remains valid until the next call
8021+
of this function for the same context or until the context is released.
79988022

79998023
\param [in] context - a pointer to FP32 deconvolution context. It must be created by function ::SimdSynetDeconvolution32fInit and released by function ::SimdRelease.
8000-
\return string with description of internal implementation of FP32 deconvolution algorithm.
8024+
\return a string with description of internal implementation of FP32 deconvolution algorithm.
80018025
*/
80028026
SIMD_API const char* SimdSynetDeconvolution32fInfo(const void* context);
80038027

80048028
/*! @ingroup synet_deconvolution_fp32
80058029

80068030
\fn void SimdSynetDeconvolution32fSetParams(void * context, const float * weight, SimdBool * internal, const float * bias, const float * params);
80078031

8008-
\short Sets weights, biases and parameters of activation function required for FP32 deconvolution algorithm.
8032+
\short Sets weights, bias and activation parameters for FP32 deconvolution.
8033+
8034+
This function must be called before ::SimdSynetDeconvolution32fForward. The \a weight array contains FP32
8035+
deconvolution weights with kernelY*kernelX*srcC*dstC/group elements. Depending on the selected implementation,
8036+
weights can be used directly or transformed and stored inside the context. If \a internal is not NULL, the
8037+
selected implementation writes the weight storage mode to it: SimdTrue means that weights were transformed and
8038+
stored internally, while SimdFalse means that the implementation may use the original \a weight array directly,
8039+
so the caller must keep it valid for later forward calls. Bias and activation parameters can also be copied
8040+
internally by some implementations; otherwise their pointers are stored in the context.
80098041

80108042
\param [in, out] context - a pointer to FP32 deconvolution context. It must be created by function ::SimdSynetDeconvolution32fInit and released by function ::SimdRelease.
8011-
\param [in] weight - a pointer to deconvolution weights.
8012-
\param [out] internal - a flag signalizing that weight is stored in the internal buffer. Can be NULL.
8013-
\param [in] bias - a pointer to bias. Can be NULL.
8014-
\param [in] params - a pointer to parameters of activation functions (see ::SimdConvolutionActivationType). Can be NULL.
8043+
\param [in] weight - a pointer to FP32 deconvolution weights.
8044+
\param [out] internal - a pointer to a flag receiving weight ownership mode. Can be NULL.
8045+
\param [in] bias - a pointer to FP32 bias array with dstC elements. Can be NULL.
8046+
\param [in] params - a pointer to FP32 parameters of activation function (see ::SimdConvolutionActivationType).
8047+
Can be NULL when activation does not require parameters.
80158048
*/
80168049
SIMD_API void SimdSynetDeconvolution32fSetParams(void * context, const float * weight, SimdBool * internal, const float * bias, const float * params);
80178050

80188051
/*! @ingroup synet_deconvolution_fp32
80198052

80208053
\fn void SimdSynetDeconvolution32fForward(void * context, const float * src, float * buf, float * dst);
80218054

8022-
\short Performs forward propagation of FP32 deconvolution algorithm.
8055+
\short Performs forward propagation of FP32 deconvolution.
8056+
8057+
The function applies transposed convolution to each image in the batch, adds bias when it was set, and applies
8058+
the activation specified in ::SimdConvolutionParameters:
8059+
\verbatim
8060+
dst[:] = 0;
8061+
for(sc = 0; sc < srcC/group; ++sc)
8062+
for(sy = 0; sy < srcH; ++sy)
8063+
for(sx = 0; sx < srcW; ++sx)
8064+
for(ky = 0; ky < kernelY; ++ky)
8065+
for(kx = 0; kx < kernelX; ++kx)
8066+
dst[outputOffset] += src[inputOffset] * weight[weightOffset];
8067+
dst[outputOffset] = Activate(dst[outputOffset] + bias[dc], activation, params);
8068+
\endverbatim
8069+
The exact offsets depend on tensor format, padding, dilation, stride and group. The input and output tensors
8070+
use the shape and format from the context created by ::SimdSynetDeconvolution32fInit.
80238071

80248072
\param [in] context - a pointer to FP32 deconvolution context. It must be created by function ::SimdSynetDeconvolution32fInit and released by function ::SimdRelease.
8025-
\param [in] src - a pointer to input tensor.
8026-
\param [out] buf - a pointer to external temporary buffer. The size of the external temporary buffer is determined by function ::SimdSynetDeconvolution32fExternalBufferSize. Can be NULL (it causes usage of internal buffer).
8027-
\param [out] dst - a pointer to output tensor.
8073+
\param [in] src - a pointer to FP32 input tensor.
8074+
\param [out] buf - a pointer to external temporary FP32 buffer. The required number of elements is determined by
8075+
function ::SimdSynetDeconvolution32fExternalBufferSize. Can be NULL (it causes usage of internal buffer).
8076+
\param [out] dst - a pointer to FP32 output tensor.
80288077
*/
80298078
SIMD_API void SimdSynetDeconvolution32fForward(void * context, const float * src, float * buf, float * dst);
80308079

0 commit comments

Comments
 (0)