conv2d_?
General 2D convolution interface that automatically selects a high-performance implementation based on the input features.
Interface Definition
C interface:
void conv2d_fp32(const float *input, const int batch, const int inputChannels, const int inputHeight, const int inputWidth, const float *kernel, const int kernelHeight, const int kernelWidth, const int strideY, const int strideX, const int padHeight, const int padWidth, const int dilationY, const int dilationX, const float *bias, float *output, const int outputChannels);
void conv2d_fp16(const __fp16 *input, const int batch, const int inputChannels, const int inputHeight, const int inputWidth, const __fp16 *kernel, const int kernelHeight, const int kernelWidth, const int strideY, const int strideX, const int padHeight, const int padWidth, const int dilationY, const int dilationX, const __fp16 *bias, __fp16 *output, const int outputChannels);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
input |
|
Input data. |
Input |
batch |
Int |
Number of batches of input data. |
Input |
inputChannels |
Int |
Number of input channels. |
Input |
inputHeight |
Int |
Height of the input data. |
Input |
inputWidth |
Int |
Width of the input data. |
Input |
kernel |
|
Convolution kernel. |
Input |
kernelHeight |
Int |
Height of the convolution kernel. |
Input |
kernelWidth |
Int |
Width of the convolution kernel. |
Input |
strideY |
Int |
Stride of the convolution kernel in the height direction. |
Input |
strideX |
Int |
Stride of the convolution kernel in the width direction. |
Input |
padHeight |
Int |
Zero-padding length at both ends of the original input data's height. |
Input |
padWidth |
Int |
Zero-padding length at both ends of the original input data's width. |
Input |
dilationY |
Int |
Dilation rate in the height direction. |
Input |
dilationX |
Int |
Dilation rate in the width direction. |
Input |
bias |
|
Bias. The value NULL indicates that there is no bias. |
Input |
output |
|
Output result data. |
Output |
outputChannels |
Int |
Number of output channels. |
Input |
Dependencies
#include "conv.h"
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | int batch = 1; int inputChannels = 1; int inputHeight = 6; int inputWidth = 6; int kernelHeight = 3; int kernelWidth = 3; int strideY = 1; int strideX = 1; int padHeight = 0; int padWidth = 0; int dilationY = 1; int dilationX = 1; int outputChannels = 1; float input[36] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0}; float kernel[9] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; float *bias = NULL; int outputHeight = (inputHeight + 2 * padHeight - dilationY * (kernelHeight - 1) - 1) / strideY + 1; int outputWidth = (inputWidth + 2 * padWidth - dilationX * (kernelWidth - 1) - 1) / strideX + 1; /* * outputHeight x outputWidth = 4 x 4 */ float output[16] = {0.0}; conv2d_fp32(input, batch, inputChannels, inputHeight, inputWidth, kernel, kernelHeight, kernelWidth, strideY, strideX, padHeight, padWidth, dilationY, dilationX, bias, output, outputChannels); /* * output = [474.0 519.0 564.0 609.0, * 744.0 789.0 834.0 879.0, * 1014.0 1059.0 1104.0 1149.0, * 1284.0 1329.0 1374.0 1419.0] */ |