Skip to content

Commit 0d8a804

Browse files
committed
rename the attribute to tosa.local_bound and deal with tosa.transpose_conv2d
1 parent 6a5fb62 commit 0d8a804

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

mlir/lib/Conversion/TosaToLinalg/TosaToLinalgNamed.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ class ConvConverter : public OpConversionPattern<TosaConvOp> {
415415
ValueRange{broadcastBias}, strideAttr, dilationAttr);
416416

417417
if (localBound)
418-
conv->setAttr("local_bound", rewriter.getBoolAttr(true));
418+
conv->setAttr("tosa.local_bound", rewriter.getBoolAttr(true));
419419

420420
rewriter.replaceOp(op, conv->getResult(0));
421421
return success();
@@ -427,7 +427,7 @@ class ConvConverter : public OpConversionPattern<TosaConvOp> {
427427
Value convVal = conv.getResult(0);
428428

429429
if (localBound)
430-
conv->setAttr("local_bound", rewriter.getBoolAttr(true));
430+
conv->setAttr("tosa.local_bound", rewriter.getBoolAttr(true));
431431

432432
// We may need to truncate back to the result type if the accumulator was
433433
// wider than the result.
@@ -569,7 +569,7 @@ class DepthwiseConvConverter
569569
Value convVal = conv.getResult(0);
570570

571571
if (localBound)
572-
conv->setAttr("local_bound", rewriter.getBoolAttr(true));
572+
conv->setAttr("tosa.local_bound", rewriter.getBoolAttr(true));
573573

574574
// We may need to truncate back to the result type if the accumulator was
575575
// wider than the result.
@@ -614,7 +614,7 @@ class DepthwiseConvConverter
614614
ValueRange{zeroTensor}, strideAttr, dilationAttr);
615615

616616
if (localBound)
617-
conv->setAttr("local_bound", rewriter.getBoolAttr(true));
617+
conv->setAttr("tosa.local_bound", rewriter.getBoolAttr(true));
618618

619619
SmallVector<ReassociationExprs, 4> reassociationMap;
620620
createDepthwiseConvCollapseMap(resultRank, reassociationMap, rewriter);

mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeTransposeConv.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ class TransposeConvNonStridedConverter
6969
auto reverse2 = rewriter.create<tosa::ReverseOp>(
7070
loc, weightTy, reverse1, /* axis = */ rewriter.getI32IntegerAttr(2));
7171

72+
bool localBound = false;
73+
if (auto localBoundAttr = op->getAttrOfType<BoolAttr>("local_bound"))
74+
localBound = localBoundAttr.getValue();
7275
Value conv2d = rewriter.create<tosa::Conv2DOp>(
7376
loc, resultTy, input, reverse2, bias, op.getInputZp(), op.getWeightZp(),
7477
rewriter.getDenseI64ArrayAttr(convPad),
7578
rewriter.getDenseI64ArrayAttr(stride),
7679
rewriter.getDenseI64ArrayAttr({1, 1}),
77-
/* acc_type = */ op.getAccType());
80+
/* acc_type = */ op.getAccType(), localBound);
7881

7982
rewriter.replaceOp(op, conv2d);
8083
return success();
@@ -238,13 +241,16 @@ class TransposeConvStridedConverter
238241
}
239242

240243
// Perform the convolution using the zero bias.
244+
bool localBound = false;
245+
if (auto localBoundAttr = op->getAttrOfType<BoolAttr>("local_bound"))
246+
localBound = localBoundAttr.getValue();
241247
Value conv2d = CreateOpAndInferShape<tosa::Conv2DOp>(
242248
rewriter, loc, UnrankedTensorType::get(resultETy), input,
243249
weight, zeroBias, inputZp.value(), weightZp.value(),
244250
/*pad=*/rewriter.getDenseI64ArrayAttr({0, 0, 0, 0}),
245251
/*stride=*/rewriter.getDenseI64ArrayAttr({1, 1}),
246252
/*dilation=*/rewriter.getDenseI64ArrayAttr({1, 1}),
247-
/* acc_type = */ op.getAccType())
253+
/* acc_type = */ op.getAccType(), localBound)
248254
.getResult();
249255

250256
// Factor the resulting width / height.

mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-named.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ func.func @max_pool2d_nan_ignore(%arg0: tensor<1x6x34x62xf32>) -> (tensor<1x4x32
10521052
func.func @conv2d_local_bound_true(%input: tensor<1x49x42x27xf32>, %weights: tensor<28x3x3x27xf32>, %bias: tensor<1xf32>) -> () {
10531053
%input_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>
10541054
%weight_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>
1055-
// CHECK: linalg.conv_2d_nhwc_fhwc {dilations = dense<[2, 1]> : tensor<2xi64>, local_bound = true, strides = dense<1> : tensor<2xi64>}
1055+
// CHECK: linalg.conv_2d_nhwc_fhwc {dilations = dense<[2, 1]> : tensor<2xi64>, tosa.local_bound = true, strides = dense<1> : tensor<2xi64>}
10561056
%0 = tosa.conv2d %input, %weights, %bias, %input_zp, %weight_zp {acc_type = f32, local_bound = true, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>, dilation = array<i64: 2, 1>} : (tensor<1x49x42x27xf32>, tensor<28x3x3x27xf32>, tensor<1xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x45x40x28xf32>
10571057
return
10581058
}
@@ -1074,7 +1074,7 @@ func.func @conv2d_local_bound_false(%input: tensor<1x49x42x27xf32>, %weights: te
10741074
func.func @conv3d_local_bound_true(%input: tensor<1x49x48x47x27xf32>, %weights: tensor<28x3x4x5x27xf32>, %bias: tensor<1xf32>) -> () {
10751075
%input_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>
10761076
%weight_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>
1077-
// CHECK: linalg.conv_3d_ndhwc_dhwcf {dilations = dense<1> : tensor<3xi64>, local_bound = true, strides = dense<1> : tensor<3xi64>}
1077+
// CHECK: linalg.conv_3d_ndhwc_dhwcf {dilations = dense<1> : tensor<3xi64>, tosa.local_bound = true, strides = dense<1> : tensor<3xi64>}
10781078
%0 = tosa.conv3d %input, %weights, %bias, %input_zp, %weight_zp {acc_type = f32, local_bound = true, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 1, 1, 1>, dilation = array<i64: 1, 1, 1>} : (tensor<1x49x48x47x27xf32>, tensor<28x3x4x5x27xf32>, tensor<1xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x47x45x43x28xf32>
10791079
return
10801080
}
@@ -1096,7 +1096,7 @@ func.func @conv3d_local_bound_false(%input: tensor<1x49x48x47x27xf32>, %weights:
10961096
func.func @depthwise_conv_local_bound_true(%arg0 : tensor<1x7x5x3xf32>, %arg1 : tensor<3x1x3x11xf32>, %arg2 : tensor<1xf32>) -> () {
10971097
%input_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>
10981098
%weight_zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>
1099-
// CHECK: linalg.depthwise_conv_2d_nhwc_hwcm {dilations = dense<1> : tensor<2xi64>, local_bound = true, strides = dense<1> : tensor<2xi64>}
1099+
// CHECK: linalg.depthwise_conv_2d_nhwc_hwcm {dilations = dense<1> : tensor<2xi64>, tosa.local_bound = true, strides = dense<1> : tensor<2xi64>}
11001100
%2 = tosa.depthwise_conv2d %arg0, %arg1, %arg2, %input_zp, %weight_zp {acc_type = f32, local_bound = true, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>, dilation = array<i64: 1, 1> } : (tensor<1x7x5x3xf32>, tensor<3x1x3x11xf32>, tensor<1xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x5x5x33xf32>
11011101
return
11021102
}

mlir/test/Dialect/Tosa/tosa-decompose-transpose-conv.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,25 @@ func.func @transpose_conv2d_strided_overpad(%arg0 : tensor<1x16x1x1xi8>, %arg1 :
181181
(tensor<1x16x1x1xi8>, tensor<1x2x1x1xi8>, tensor<1xi32>, tensor<1xi8>, tensor<1xi8>) -> tensor<1x19x2x1xi32>
182182
"func.return" (%2) : (tensor<1x19x2x1xi32>) -> ()
183183
}
184+
185+
// -----
186+
187+
// CHECK-LABEL: @transpose_conv2d_with_local_bound
188+
func.func @transpose_conv2d_with_local_bound(%arg0: tensor<2x16x14x3xf32>, %arg1: tensor<5x3x6x3xf32>, %arg2: tensor<5xf32>) -> tensor<2x18x19x5xf32> {
189+
// CHECK: tosa.conv2d [[ANY:.*]] local_bound = true
190+
%zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>
191+
%0 = tosa.transpose_conv2d %arg0, %arg1, %arg2, %zp, %zp {acc_type = f32, local_bound = true, out_pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} : (tensor<2x16x14x3xf32>, tensor<5x3x6x3xf32>, tensor<5xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<2x18x19x5xf32>
192+
return %0 : tensor<2x18x19x5xf32>
193+
}
194+
195+
// -----
196+
197+
// CHECK-LABEL: @transpose_conv2d_strided_with_local_bound
198+
199+
func.func @transpose_conv2d_strided_with_local_bound(%arg0: tensor<2x17x15x3xf32>, %arg1: tensor<5x3x5x3xf32>, %arg2: tensor<5xf32>) -> tensor<2x?x?x5xf32> {
200+
// CHECK: tosa.conv2d [[ANY:.*]] local_bound = true
201+
%zp = "tosa.const"() <{values = dense<0.0> : tensor<1xf32>}> : () -> tensor<1xf32>
202+
%0 = tosa.transpose_conv2d %arg0, %arg1, %arg2, %zp, %zp {acc_type = f32, local_bound = true, out_pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 2, 3>} : (tensor<2x17x15x3xf32>, tensor<5x3x5x3xf32>, tensor<5xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<2x35x47x5xf32>
203+
%1 = tensor.cast %0 : tensor<2x35x47x5xf32> to tensor<2x?x?x5xf32>
204+
return %1 : tensor<2x?x?x5xf32>
205+
}

0 commit comments

Comments
 (0)