forked from OSchip/llvm-project
[mlir][tosa] Do not fold transpose with quantized types
For such cases, the type of the constant DenseElementsAttr is different from the transpose op return type. Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D110446
This commit is contained in:
parent
d5f2013004
commit
b45476c94c
|
@ -165,6 +165,12 @@ struct ConstantTransposeOptimization
|
|||
|
||||
LogicalResult matchAndRewrite(tosa::TransposeOp op,
|
||||
PatternRewriter &rewriter) const override {
|
||||
auto outputType = op.getType().cast<ShapedType>();
|
||||
ArrayRef<int64_t> outputShape = outputType.getShape();
|
||||
// TOSA supports quantized types.
|
||||
if (!outputType.getElementType().isIntOrIndexOrFloat())
|
||||
return failure();
|
||||
|
||||
DenseElementsAttr inputValues;
|
||||
if (!matchPattern(op.input1(), m_Constant(&inputValues)))
|
||||
return failure();
|
||||
|
@ -184,9 +190,6 @@ struct ConstantTransposeOptimization
|
|||
ArrayRef<int64_t> inputShape = inputType.getShape();
|
||||
int64_t numElements = inputType.getNumElements();
|
||||
|
||||
auto outputType = op.getType().cast<ShapedType>();
|
||||
ArrayRef<int64_t> outputShape = outputType.getShape();
|
||||
|
||||
SmallVector<Attribute, 4> outputValues;
|
||||
outputValues.resize(numElements);
|
||||
|
||||
|
|
|
@ -314,3 +314,14 @@ func @transpose_nofold_multi_users() -> (tensor<3x2xf32>, tensor<2x3xf32>) {
|
|||
%1 = "tosa.transpose"(%input, %perms) : (tensor<2x3xf32>, tensor<2xi32>) -> tensor<3x2xf32>
|
||||
return %1, %input : tensor<3x2xf32>, tensor<2x3xf32>
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// CHECK-LABEL: @transpose_nofold_quantized_types
|
||||
func @transpose_nofold_quantized_types() -> tensor<1x1x16x1x!quant.uniform<i8<-127:127>:f32:3, {1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,2.100000e+00,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01}>> {
|
||||
%perms = "tosa.const"() {value = dense<[1, 2, 3, 0]> : tensor<4xi32>} : () -> tensor<4xi32>
|
||||
%input = "tosa.const"() {value = dense<[[[[-127, 127, 127, -127, -127, -127, -127, -127, -127, 127, 127, 127, 127, 127, -127, 127]]]]> : tensor<1x1x1x16xi8>} : () -> tensor<1x1x1x16xi8>
|
||||
// CHECK: tosa.transpose
|
||||
%0 = "tosa.transpose"(%input, %perms) : (tensor<1x1x1x16xi8>, tensor<4xi32>) -> tensor<1x1x16x1x!quant.uniform<i8<-127:127>:f32:3, {1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,2.100000e+00,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01}>>
|
||||
return %0: tensor<1x1x16x1x!quant.uniform<i8<-127:127>:f32:3, {1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,2.100000e+00,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01,1.000000e-01}>>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue