forked from OSchip/llvm-project
[mlir][tosa] Fix depthwise_conv2D strides/dilation and name
Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D107997
This commit is contained in:
parent
2ff7ca98a9
commit
ba0997ca09
|
@ -988,8 +988,8 @@ structured_op: !LinalgStructuredOpConfig
|
|||
scalar_arg: KZp
|
||||
--- !LinalgOpConfig
|
||||
metadata: !LinalgOpMetadata
|
||||
name: depthwise_conv2D_nchw
|
||||
cpp_class_name: DepthwiseConv2DNchwOp
|
||||
name: depthwise_conv2D_nhwc
|
||||
cpp_class_name: DepthwiseConv2DNhwcOp
|
||||
doc: |-
|
||||
Performs depth-wise 2-D convolution.
|
||||
|
||||
|
@ -1070,8 +1070,8 @@ structured_op: !LinalgStructuredOpConfig
|
|||
scalar_arg: K
|
||||
--- !LinalgOpConfig
|
||||
metadata: !LinalgOpMetadata
|
||||
name: depthwise_conv2D_nchw_q
|
||||
cpp_class_name: DepthwiseConv2DNchwQOp
|
||||
name: depthwise_conv2D_nhwc_q
|
||||
cpp_class_name: DepthwiseConv2DNhwcQOp
|
||||
doc: |-
|
||||
Performs depth-wise 2-D convolution.
|
||||
|
||||
|
|
|
@ -1066,18 +1066,18 @@ public:
|
|||
Value conv;
|
||||
if (!isQuantized) {
|
||||
conv = rewriter
|
||||
.create<linalg::DepthwiseConv2DNchwOp>(
|
||||
.create<linalg::DepthwiseConv2DNhwcOp>(
|
||||
loc, linalgConvTy, ValueRange{input, weight},
|
||||
ValueRange{biasReshape}, dilationAttr, strideAttr)
|
||||
ValueRange{biasReshape}, strideAttr, dilationAttr)
|
||||
.getResult(0);
|
||||
} else {
|
||||
auto iZpVal = rewriter.create<ConstantOp>(loc, iZp);
|
||||
auto kZpVal = rewriter.create<ConstantOp>(loc, kZp);
|
||||
conv =
|
||||
rewriter
|
||||
.create<linalg::DepthwiseConv2DNchwQOp>(
|
||||
.create<linalg::DepthwiseConv2DNhwcQOp>(
|
||||
loc, linalgConvTy, ValueRange{input, weight, iZpVal, kZpVal},
|
||||
ValueRange{biasReshape}, dilationAttr, strideAttr)
|
||||
ValueRange{biasReshape}, strideAttr, dilationAttr)
|
||||
.getResult(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ def conv_2d_nhwc_hwcf_q(
|
|||
]) - cast(U, IZp)) * (cast(U, K[D.kh, D.kw, D.c, D.f]) - cast(U, KZp))
|
||||
|
||||
@linalg_structured_op
|
||||
def depthwise_conv2D_nchw(
|
||||
def depthwise_conv2D_nhwc(
|
||||
I=TensorDef(T1, S.N, S.IH, S.IW, S.IC),
|
||||
K=TensorDef(T2, S.KH, S.KW, S.IC, S.CM),
|
||||
O=TensorDef(U, S.N, S.OH, S.OW, S.IC, S.CM, output=True),
|
||||
|
@ -233,7 +233,7 @@ def depthwise_conv2D_nchw(
|
|||
D.ic]) * cast(U, K[D.kh, D.kw, D.ic, D.cm])
|
||||
|
||||
@linalg_structured_op
|
||||
def depthwise_conv2D_nchw_q(
|
||||
def depthwise_conv2D_nhwc_q(
|
||||
I=TensorDef(T1, S.N, S.IH, S.IW, S.IC),
|
||||
K=TensorDef(T2, S.KH, S.KW, S.IC, S.CM),
|
||||
IZp=ScalarDef(I32),
|
||||
|
|
|
@ -1225,7 +1225,7 @@ func @depthwise_conv(%arg0 : tensor<1x7x5x3xf32>, %arg1 : tensor<3x1x3x11xf32>,
|
|||
// CHECK: linalg.yield %arg3 : f32
|
||||
// CHECK: } -> tensor<1x5x5x33xf32>
|
||||
// CHECK: [[DBIAS:%.+]] = linalg.tensor_expand_shape [[BIAS]] {{\[}}[0], [1], [2], [3, 4]]
|
||||
// CHECK: [[DEPTH:%.+]] = linalg.depthwise_conv2D_nchw {dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%arg0, %arg1 : tensor<1x7x5x3xf32>, tensor<3x1x3x11xf32>) outs([[DBIAS]] : tensor<1x5x5x3x11xf32>)
|
||||
// CHECK: [[DEPTH:%.+]] = linalg.depthwise_conv2D_nhwc {dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%arg0, %arg1 : tensor<1x7x5x3xf32>, tensor<3x1x3x11xf32>) outs([[DBIAS]] : tensor<1x5x5x3x11xf32>)
|
||||
// CHECK: linalg.tensor_collapse_shape %3 {{\[}}[0], [1], [2], [3, 4]]
|
||||
%2 = "tosa.depthwise_conv2d"(%arg0, %arg1, %arg2) { pad = [0, 0, 0, 0], stride = [1, 1], dilation = [1, 1] } : (tensor<1x7x5x3xf32>, tensor<3x1x3x11xf32>, tensor<33xf32>) -> (tensor<1x5x5x33xf32>)
|
||||
return
|
||||
|
@ -1236,6 +1236,25 @@ func @depthwise_conv(%arg0 : tensor<1x7x5x3xf32>, %arg1 : tensor<3x1x3x11xf32>,
|
|||
// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1, d2, d3) -> (d3)>
|
||||
// CHECK: #[[$MAP1:.*]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>
|
||||
|
||||
// CHECK-LABEL: @depthwise_conv_strides
|
||||
func @depthwise_conv_strides(%arg0 : tensor<1x11x9x3xf32>, %arg1 : tensor<3x1x3x11xf32>, %arg2 : tensor<33xf32>) -> () {
|
||||
// CHECK: [[INIT:%.+]] = linalg.init_tensor [1, 5, 5, 33]
|
||||
// CHECK: [[BIAS:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%arg2 : tensor<33xf32>) outs([[INIT]] : tensor<1x5x5x33xf32>) {
|
||||
// CHECK: ^bb0(%arg3: f32, %arg4: f32): // no predecessors
|
||||
// CHECK: linalg.yield %arg3 : f32
|
||||
// CHECK: } -> tensor<1x5x5x33xf32>
|
||||
// CHECK: [[DBIAS:%.+]] = linalg.tensor_expand_shape [[BIAS]] {{\[}}[0], [1], [2], [3, 4]]
|
||||
// CHECK: [[DEPTH:%.+]] = linalg.depthwise_conv2D_nhwc {dilations = dense<1> : tensor<2xi64>, strides = dense<2> : tensor<2xi64>} ins(%arg0, %arg1 : tensor<1x11x9x3xf32>, tensor<3x1x3x11xf32>) outs([[DBIAS]] : tensor<1x5x5x3x11xf32>)
|
||||
// CHECK: linalg.tensor_collapse_shape %3 {{\[}}[0], [1], [2], [3, 4]]
|
||||
%2 = "tosa.depthwise_conv2d"(%arg0, %arg1, %arg2) { pad = [0, 0, 0, 0], stride = [2, 2], dilation = [1, 1] } : (tensor<1x11x9x3xf32>, tensor<3x1x3x11xf32>, tensor<33xf32>) -> (tensor<1x5x5x33xf32>)
|
||||
return
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1, d2, d3) -> (d3)>
|
||||
// CHECK: #[[$MAP1:.*]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>
|
||||
|
||||
// CHECK-LABEL: @depthwise_conv_quant
|
||||
func @depthwise_conv_quant(%arg0 : tensor<1x12x12x4xi8>, %arg1 : tensor<3x3x4x128xi8>, %arg2 : tensor<512xi32>) -> () {
|
||||
// CHECK: [[INIT:%.+]] = linalg.init_tensor [1, 10, 10, 512]
|
||||
|
@ -1246,7 +1265,7 @@ func @depthwise_conv_quant(%arg0 : tensor<1x12x12x4xi8>, %arg1 : tensor<3x3x4x12
|
|||
// CHECK: [[DBIAS:%.+]] = linalg.tensor_expand_shape [[BIAS]] {{\[}}[0], [1], [2], [3, 4]]
|
||||
// CHECK: %[[C128:.+]] = constant -128
|
||||
// CHECK: %[[C42:.+]] = constant 42
|
||||
// CHECK: [[DEPTH:%.+]] = linalg.depthwise_conv2D_nchw_q {dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%arg0, %arg1, %[[C128]], %[[C42]] : tensor<1x12x12x4xi8>, tensor<3x3x4x128xi8>, i32, i32) outs([[DBIAS]] : tensor<1x10x10x4x128xi32>)
|
||||
// CHECK: [[DEPTH:%.+]] = linalg.depthwise_conv2D_nhwc_q {dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%arg0, %arg1, %[[C128]], %[[C42]] : tensor<1x12x12x4xi8>, tensor<3x3x4x128xi8>, i32, i32) outs([[DBIAS]] : tensor<1x10x10x4x128xi32>)
|
||||
// CHECK: linalg.tensor_collapse_shape %3 {{\[}}[0], [1], [2], [3, 4]]
|
||||
%0 = "tosa.depthwise_conv2d"(%arg0, %arg1, %arg2) {pad = [0, 0, 0, 0], quantization_info = {input_zp = -128 : i32, weight_zp = 42 : i32}, stride = [1, 1], dilation = [1, 1] } : (tensor<1x12x12x4xi8>, tensor<3x3x4x128xi8>, tensor<512xi32>) -> tensor<1x10x10x512xi32>
|
||||
return
|
||||
|
@ -1254,6 +1273,27 @@ func @depthwise_conv_quant(%arg0 : tensor<1x12x12x4xi8>, %arg1 : tensor<3x3x4x12
|
|||
|
||||
// -----
|
||||
|
||||
// CHECK: #[[$MAP0:.*]] = affine_map<(d0, d1, d2, d3) -> (d3)>
|
||||
// CHECK: #[[$MAP1:.*]] = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>
|
||||
|
||||
// CHECK-LABEL: @depthwise_conv_quant_dilations
|
||||
func @depthwise_conv_quant_dilations(%arg0 : tensor<1x14x14x4xi8>, %arg1 : tensor<3x3x4x128xi8>, %arg2 : tensor<512xi32>) -> () {
|
||||
// CHECK: [[INIT:%.+]] = linalg.init_tensor [1, 10, 10, 512]
|
||||
// CHECK: [[BIAS:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]]], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%arg2 : tensor<512xi32>) outs([[INIT]] : tensor<1x10x10x512xi32>) {
|
||||
// CHECK: ^bb0(%arg3: i32, %arg4: i32): // no predecessors
|
||||
// CHECK: linalg.yield %arg3 : i32
|
||||
// CHECK: } -> tensor<1x10x10x512xi32>
|
||||
// CHECK: [[DBIAS:%.+]] = linalg.tensor_expand_shape [[BIAS]] {{\[}}[0], [1], [2], [3, 4]]
|
||||
// CHECK: %[[C128:.+]] = constant -128
|
||||
// CHECK: %[[C42:.+]] = constant 42
|
||||
// CHECK: [[DEPTH:%.+]] = linalg.depthwise_conv2D_nhwc_q {dilations = dense<2> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%arg0, %arg1, %[[C128]], %[[C42]] : tensor<1x14x14x4xi8>, tensor<3x3x4x128xi8>, i32, i32) outs([[DBIAS]] : tensor<1x10x10x4x128xi32>)
|
||||
// CHECK: linalg.tensor_collapse_shape %3 {{\[}}[0], [1], [2], [3, 4]]
|
||||
%0 = "tosa.depthwise_conv2d"(%arg0, %arg1, %arg2) {pad = [0, 0, 0, 0], quantization_info = {input_zp = -128 : i32, weight_zp = 42 : i32}, stride = [1, 1], dilation = [2, 2] } : (tensor<1x14x14x4xi8>, tensor<3x3x4x128xi8>, tensor<512xi32>) -> tensor<1x10x10x512xi32>
|
||||
return
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// CHECK-LABEL: @transpose_conv
|
||||
func @transpose_conv(%arg0 : tensor<1x12x12x2xf32>, %arg1 : tensor<4x3x3x2xf32>, %arg2 : tensor<4xf32>) -> () {
|
||||
// CHECK: linalg.pad_tensor %arg0 low[0, 2, 2, 0] high[0, 2, 2, 0]
|
||||
|
|
Loading…
Reference in New Issue