conv2d_backprop_input
Description
Computes 2D deconvolution of the float16 type with the given 5HD out_backprop and FracZ weight.
The shape of the out_backprop tensor is 5HD, that is, (N, C1, H, W, C0). The shape of the weight tensor is FracZ, that is, (C1*KH*KW, Cout//C0_out, C0_out, C0).
Prototype
conv2d_backprop_input(filters, out_backprop, filter_sizes, input_sizes, para_dict)
Parameters
- filters: a FracZ tensor of type float16, for the weight.
- out_backprop: backprop of the 2D convolution. Currently, the float16 type is supported.
- filter_size: weight matrix size.
- input_sizes: size of the input matrix.
- para_dict: a dictionary for the key-value pairs, including the following keys:
- strides: a list of the strides along the H and W directions of the feature map.
- padding: a list for the padding lines along the H and W directions of the feature map.
- dilations: a list of the dilations along the H and W directions of the filter.
- res_dtype: output data type. Defaults to float16.
- offset_x: compensation for the input matrix during quantization.
- offset_w: compensation for the weight during quantization. This key is not supported currently and must be set to None.
- kernel_name: operator name.
- group_dict: a dictionary for conv2d_backprop_input group convolution arguments, including:
1. w_shape_nchw, weight shape with the NCHW format.
2. groups, argument for group convolution.
3. c0_size, which is tbe_platform.C0_SIZE. Defaults to 16.
4. c0_size_k, which is tbe_platform.CUBE_MKN[filter_dtype]['mac'][1]. The value is 16 if filter_dtype is float16.
The computation formula is as follows.
_lcm(param1, param2): calculates the least common multiple.
ceil(param1, param2): calculates param1/param2 and rounds up the result.
dx_c_ori = w_shape_nchw[1]
dy_c_ori = w_shape_nchw[0] // groups
filter_batch_ori = w_shape_nchw[0] // groups
filter_c_ori = w_shape_nchw[1]
dx_c_extend = _lcm(dx_c_ori, c0_size) // dx_c_ori
dy_c_extend = _lcm(dy_c_ori, c0_size_k) // dy_c_ori
multiple_extend = min(_lcm(dx_c_extend, dy_c_extend), groups)
dx_c1_extend = ceil(multiple_extend * dx_c_ori, c0_size)
dy_c1_extend = ceil(multiple_extend * dy_c_ori, c0_size_k)
group_dict = {
"g_extend": g_extend,
"multiple_extend": multiple_extend,
"groups": groups,
"dx_c1_extend": dx_c1_extend,
"dy_c1_extend": dy_c1_extend,
"dx_c_ori": dx_c_ori,
"dy_c_ori": dy_c_ori,
"filter_batch_ori": filter_batch_ori,
"filter_c_ori": filter_c_ori,
"filter_ori_format": "NCHW"
}
Returns
res_tensor: result tensor.
Restrictions
This API cannot be used in conjunction with other TBE DSL APIs.
Applicability
Example
from tbe import tvm
from tbe import dsl
from tbe.dsl.compute import cube_util
out_backprop_shape = (1, 1, 7, 7, 16)
out_backprop_dtype = "float16"
filter_frac = (1, 1, 16, 16)
filter_dtype = "float16"
filter_sizes = (16, 16, 1, 1)
input_sizes = (1, 16, 7, 7)
out_backprop = tvm.placeholder(out_backprop_shape, name="out_backprop", dtype=out_backprop_dtype)
filters = tvm.placeholder(filter_frac, name="filters", dtype=filter_dtype)
strides = [1, 1]
padding = [0, 0, 0, 0]
dilations = [1, 1, 1, 1]
res_dtype = "float32"
offset_x = 0
offset_w = None
kernel_name = "conv2d_backprop_input_dx_1_1_7_7_16_dy_1_1_7_7_16_dw_16_16_1_1_s_1_1_p_SAME"
group_dict = {
"groups": 1,
"g_extend": 1,
"multiple_extend": 1,
"dx_c1_extend": (input_sizes[1] + 16 - 1)// 16,
"dy_c1_extend": out_backprop_shape [1],
"dx_c_ori": input_sizes[1],
"dy_c_ori": filter_sizes[0],
"filter_batch_ori": filter_sizes[0],
"filter_c_ori": filter_sizes[1],
"filter_ori_format": "NCHW"
}
para_dict = {
"strides": strides,
"padding": padding,
"dilations": dilations,
"res_dtype": res_dtype,
"offset_x": offset_x,
"offset_w": offset_w,
"kernel_name": kernel_name,
"group_dict": group_dict
}
input_backprop = dsl.conv2d_backprop_input(
filters=filters,
out_backprop=out_backprop,
filter_sizes=filter_sizes,
input_sizes=input_sizes,
para_dict=para_dict
)