Conv3DBackpropFilter Usage Description
Ascend C provides a group of Conv3DBackpropFilter high-level APIs for users to quickly implement convolution inverse operations and solve backpropagation errors.
Figure 1 shows the weight propagation in convolution backpropagation, and Figure 2 shows the weight computation in convolution backpropagation.
The formula for Conv3dBackpropFilter is as follows:

- X is the convolution feature matrix Input.
- ∂L/∂Y is the gradient GradOutput of the forward convolution loss function with respect to the output Y, and is used as the input for calculating the backpropagation error ∂L/∂W, that is, the backward GradOutput of the convolution output.
- ∂L/∂W is the backpropagation error GradWeight of the weight.
The procedure for implementing the backpropagation error calculation of Conv3DBackpropFilter on the kernel side is as follows:
- Create a Conv3DBackpropFilter object.
- Perform the initialization operation.
- Set the convolution feature matrix Input and the output gradient GradOutput.
- Perform the convolution backpropagation operation.
- End the convolution backpropagation operation.
The procedure for using the high-level API Conv3DBackpropFilter to calculate the backpropagation error is as follows:
- Create a Conv3DBackpropFilter object.
1 2 3 4 5 6 7
#include "lib/conv_backprop/conv3d_bp_filter_api.h" using inputType = ConvBackpropApi::ConvType <ConvCommonApi::TPosition::GM, ConvCommonApi::ConvFormat::NDC1HWC0, inputType>; using weightSizeType = ConvBackpropApi::ConvType<ConvCommonApi::TPosition::GM, ConvCommonApi::ConvFormat::ND, int32_t>; using gradOutputType = ConvBackpropApi::ConvType<ConvCommonApi::TPosition::GM, ConvCommonApi::ConvFormat::NDC1HWC0, gradOutputType>; using gradWeightType = ConvBackpropApi::ConvType <ConvCommonApi::TPosition::GM, ConvCommonApi::ConvFormat::FRACTAL_Z_3D, gradWeightType>; ConvBackpropApi::Conv3DBackpropFilter <inputType, weightSizeType, gradOutputType, gradWeightType> gradWeight_;
During object creation, input the feature matrix Input, the shape information WeightSize of the weight matrix Weight, and the parameter type information of GradOutput and GradWeight. The type information is defined by ConvType, including the logical location of memory, data format, and data type.
1 2 3 4 5 6
template <TPosition POSITION, ConvFormat FORMAT, typename T> struct ConvType { constexpr static TPosition pos = POSITION; // Logical position of the Convolution input or output constexpr static ConvFormat format = FORMAT; // Convolution input or output data format using T = TYPE; // Convolution input or output data type };
The following briefly describes the data structures used for object creation. Developers can selectively understand these content. The data structure used to create a Conv3DBackpropFilter object is defined as follows:
1using Conv3DBackpropFilter = Conv3DBpFilterIntf<Conv3DBpFilterCfg<INPUT_TYPE, WEIGHT_TYPE, GRAD_OUTPUT_TYPE, GRAD_WEIGHT_TYPE>, Conv3DBpFilterImpl>;
The Conv3DBpFilterIntf and Conv3DBpFilterCfg data structures are defined as follows:
1 2 3
template <class Config_, template <typename, class> class Impl> struct Conv3DBpFilterIntf { }
1 2 3
template <class A, class B, class C, class D> struct Conv3DBpFilterCfg : public ConvBpContext<A, B, C, D>{ }
Table 1 ConvType parameters Parameter
Description
POSITION
Logical memory location.
- This parameter can be set to TPosition::GM for the Input X matrix.
- This parameter can be set to TPosition::GM for the WeightSize matrix.
- This parameter can be set to TPosition::GM for the GradOutput matrix.
- This parameter can be set to TPosition::GM for the GradWeight matrix.
ConvFormat
Data format.
- This parameter can be set to ConvFormat::NDC1HWC0 for the Input matrix.
- This parameter can be set to ConvFormat::ND for the WeightSize matrix.
- This parameter can be set to ConvFormat::NDC1HWC0 for the GradOutput matrix.
- This parameter can be set to ConvFormat::FRACTAL_Z_3D for the GradWeight matrix.
TYPE
Data type.- This parameter can be set to half or bfloat16_t for the input matrix.
- This parameter can be set to int32_t for the WeightSize matrix.
- This parameter can be set to half or bfloat16_t for the GradOutput matrix.
- This parameter can be set to float for the GradWeight matrix.
Note: The data types of Input and GradOutput must be the same. For details about the data type combinations, see Table 2.
Table 2 Combinations of Conv3DBackpropFilter input and output data types Input
WeightSize
GradOutput
GradWeight
Supported Platform
half
int32_t
half
float
Atlas A3 training products /Atlas A3 inference products Atlas A2 training products /Atlas A2 inference products
bfloat16_t
int32_t
bfloat16_t
float
Atlas A3 training products /Atlas A3 inference products Atlas A2 training products /Atlas A2 inference products
- Perform the initialization operation.
1gradWeight_.Init(&(tilingData->dwTiling)); //: Initialize parameters related to gradWeight_.
- Set the convolution feature matrix Input and the output gradient GradOutput.
1 2 3 4
gradWeight_.SetGradOutput(gradOutputGm_[offsetA_]); // Set the gradOutput matrix. gradWeight_.SetInput(inputGm_[offsetB_]); // Set the Input matrix. gradWeight_.SetSingleShape(singleShapeM, singleShapeN, singleShapeK); // Set the shape to be computed. gradWeight_.SetStartPosition(hoStartIdx_); // Set the initial position.
- Perform the convolution backpropagation operation.Call Iterate to complete a single iteration calculation, and add a while loop to complete the calculation of full data on a single core. The Iterate method allows for flexible control over the number of iterations required to compute the desired amount of data.
1 2 3
while (gradWeight_.Iterate()) { gradWeight_.GetTensorC(gradWeightGm_[offsetC_]); }
- End the convolution backpropagation operation.
1gradWeight_.End();
Header File to Be Included
1 | #include "lib/conv_backprop/conv3d_bp_filter_api.h" |

