Convolution¶
General¶
Convolution operation performs the convolution between src tensor and weight tensor, which is defined as by the following formulas. Variable names follow the standard Naming Conventions.
Let \(\src\), \(\weights\) and \(\dst\) tensors have shape \(N \times IC \times IH \times IW\), \(OC \times IC \times KH \times KW\), and \(N \times OC \times OH \times OW\) respectively.
Furthermore, let the remaining convolution parameters be:
Parameter |
Depth |
Height |
Width |
Comment |
---|---|---|---|---|
Paddings: Front, top, and left |
\(PD_L\) |
\(PH_L\) |
\(PW_L\) |
In the attributes we use |
Padding: Back, bottom, and right |
\(PD_R\) |
\(PH_R\) |
\(PW_R\) |
In the attributes we use |
Stride |
\(SD\) |
\(SH\) |
\(SW\) |
In the attributes we use |
Dilation |
\(DD\) |
\(DH\) |
\(DW\) |
In the attributes we use |
To further simplify the formulas, we assume that the attribute data_format
and weights_format
are set to NCX
and OIX
respectively. NCX
means the fist axis represents batch dimension, the second axis represents channel dimension and the rest represents spatial dimensions. OIX
means the first axis represents output channel dimension, the second axis represents input channel dimension and the rest represents weights spatial dimensions.
Regular Convolution¶
This is the same as the formula in Convolution primitive.
Here:
\(OH = \left\lfloor{\frac{IH - KH + PH_L + PH_R}{SH}} \right\rfloor + 1,\)
\(OW = \left\lfloor{\frac{IW - KW + PW_L + PW_R}{SW}} \right\rfloor + 1.\)
Convolution with Groups¶
The attribute groups
is set to \(>1\).
where
\(IC_G = \frac{IC}{G}\),
\(OC_G = \frac{OC}{G}\), and
\(oc_g \in [0, OC_G).\)
Convolution with Dilation¶
The attribute dilation
contains the element which is \(>1\).
Here:
\(OH = \left\lfloor{\frac{IH - DKH + PH_L + PH_R}{SH}} \right\rfloor + 1,\) where \(DKH = 1 + (KH - 1) \cdot DH\), and
\(OW = \left\lfloor{\frac{IW - DKW + PW_L + PW_R}{SW}} \right\rfloor + 1,\) where \(DKW = 1 + (KW - 1) \cdot DW\).
Operation attributes¶
Attribute Name |
Description |
Value Type |
Supported Values |
Required or Optional |
---|---|---|---|---|
Controls the strides the weights tensor is moved when computing convolution |
s64 |
A s64 list containing positive values |
Required |
|
Controls number of zeros to be add to the front/top/left of spatial dimensions |
s64 |
A s64 list containing non-negative values |
Required |
|
Controls number of zeros to be add to the back/bottom/right of spatial dimensions |
s64 |
A s64 list containing non-negative values |
Required |
|
Controls the amount of stretching the kernel before convolution ( visualization link ) |
s64 |
A s64 list containing positive values (>1 means dilated convolution) |
Required |
|
Controls how the padding is calculated |
string |
|
Optional |
|
Controls how input channels and output channels are divided into |
s64 |
A positive s64 value, |
Optional |
|
Controls how to interpret the shape of |
string |
|
Optional |
|
Controls how to interpret the shape of |
string |
|
Optional |
Execution arguments¶
The inputs and outputs must be provided according to below index order when constructing an operation.
Inputs¶
Index |
Argument Name |
Required or Optional |
---|---|---|
0 |
|
Required |
1 |
|
Required |
2 |
|
Optional |
Note
The shape of \(\weights\) is \((out\_channels, in\_channels / groups, spatial\_shape)\) for OIX
format or \((spatial\_shape, in\_channels / groups, out\_channels)\) for XIO
format. Both \(in\_channels\) and \(out\_channels\) must be divisible by groups attribute.
Outputs¶
Index |
Argument Name |
Required or Optional |
---|---|---|
0 |
|
Required |
Supported data types¶
Convolution operation supports the following data type combinations.
Src |
Weights |
Bias |
Dst |
---|---|---|---|
f32 |
f32 |
f32 |
f32 |
bf16 |
bf16 |
bf16 |
bf16 |
f16 |
f16 |
f16 |
f16 |