diff --git a/docs/BuildOnLinuxOSX.md b/docs/BuildOnLinuxOSX.md index f2bf7858ae..21fbc37e0c 100644 --- a/docs/BuildOnLinuxOSX.md +++ b/docs/BuildOnLinuxOSX.md @@ -15,7 +15,7 @@ Firstly, install MLIR (as a part of LLVM-Project): ``` bash git clone -n https://github.com/llvm/llvm-project.git # Check out a specific branch that is known to work with ONNX-MLIR. -cd llvm-project && git checkout e86910337f98e57f5b9253f7d80d5b916eb1d97e && cd .. +cd llvm-project && git checkout b270525f730be6e7196667925f5a9bfa153262e9 && cd .. ``` [same-as-file]: <> (utils/build-mlir.sh) diff --git a/docs/BuildOnWindows.md b/docs/BuildOnWindows.md index 2f10915561..13e2a002ec 100644 --- a/docs/BuildOnWindows.md +++ b/docs/BuildOnWindows.md @@ -52,7 +52,7 @@ Install MLIR (as a part of LLVM-Project): ```shell git clone -n https://github.com/llvm/llvm-project.git # Check out a specific branch that is known to work with ONNX-MLIR. -cd llvm-project && git checkout e86910337f98e57f5b9253f7d80d5b916eb1d97e && cd .. +cd llvm-project && git checkout b270525f730be6e7196667925f5a9bfa153262e9 && cd .. ``` [same-as-file]: <> (utils/build-mlir.cmd) diff --git a/src/Conversion/KrnlToLLVM/ConvertKrnlToLLVM.cpp b/src/Conversion/KrnlToLLVM/ConvertKrnlToLLVM.cpp index d33abe5918..950eb65236 100644 --- a/src/Conversion/KrnlToLLVM/ConvertKrnlToLLVM.cpp +++ b/src/Conversion/KrnlToLLVM/ConvertKrnlToLLVM.cpp @@ -193,12 +193,23 @@ void populateAffineAndKrnlToLLVMConversion(RewritePatternSet &patterns, // They run it in two steps, and add additional lowerings. vector::populateVectorToVectorCanonicalizationPatterns(patterns); + vector::populateVectorBitCastLoweringPatterns(patterns); vector::populateVectorBroadcastLoweringPatterns(patterns); vector::populateVectorContractLoweringPatterns( patterns, vector::VectorTransformsOptions()); + vector::populateVectorMaskOpLoweringPatterns(patterns); + vector::populateVectorShapeCastLoweringPatterns(patterns); + vector::populateVectorInterleaveLoweringPatterns(patterns); vector::populateVectorTransposeLoweringPatterns( patterns, vector::VectorTransformsOptions()); - vector::populateVectorShapeCastLoweringPatterns(patterns); + // Vector transfer ops with rank > 1 should be lowered with VectorToSCF. + vector::populateVectorTransferLoweringPatterns( + patterns, /*maxTransferRank=*/1); + vector::populateVectorMaskMaterializationPatterns( + patterns, /*force32BitVectorIndices*/ false); + vector::populateVectorInsertExtractStridedSliceTransforms(patterns); + vector::populateVectorStepLoweringPatterns(patterns); + vector::populateVectorRankReducingFMAPattern(patterns); populateAffineToStdConversionPatterns(patterns); populateSCFToControlFlowConversionPatterns(patterns); diff --git a/src/Conversion/ONNXToTOSA/Math/Conv2D.cpp b/src/Conversion/ONNXToTOSA/Math/Conv2D.cpp index dc35d39099..3bede485b3 100644 --- a/src/Conversion/ONNXToTOSA/Math/Conv2D.cpp +++ b/src/Conversion/ONNXToTOSA/Math/Conv2D.cpp @@ -41,7 +41,7 @@ Value createConvInGroups(PatternRewriter &rewriter, Operation *op, const llvm::ArrayRef weightShape, Value &newInput, Value &newWeight, Value &bias, const int64_t groups, DenseI64ArrayAttr &pads, DenseI64ArrayAttr &strides, - DenseI64ArrayAttr &dilations) { + DenseI64ArrayAttr &dilations, TypeAttr &accType) { // Set up constants outside of loop const int64_t sizeOfSliceInput = weightShape[1]; const int64_t sizeOfSliceKernel = weightShape[0] / groups; @@ -72,7 +72,7 @@ Value createConvInGroups(PatternRewriter &rewriter, Operation *op, mlir::cast(resultType).getElementType()); Value tempConv2D = tosa::CreateOpAndInfer(rewriter, op->getLoc(), newConvOutputType, newSliceInput, newSliceWeight, - newSliceBias, pads, strides, dilations); + newSliceBias, pads, strides, dilations, accType); // Add value to vector sliceValues.push_back(tempConv2D); } @@ -147,6 +147,10 @@ class ONNXConvOpLoweringToTOSA : public ConversionPattern { DenseI64ArrayAttr newPads = rewriter.getDenseI64ArrayAttr({pads[0], pads[2], pads[1], pads[3]}); + Type convType = + (resultType.isF16()) ? rewriter.getF16Type() : rewriter.getF32Type(); + TypeAttr accType = mlir::TypeAttr::get(convType); + // Handle group parameter by creating multiple convs const int64_t group = adaptor.getGroup(); Value conv2D = NULL; @@ -157,11 +161,11 @@ class ONNXConvOpLoweringToTOSA : public ConversionPattern { conv2D = tosa::CreateOpAndInfer(rewriter, convOp->getLoc(), newConvOutputType, newInput, newWeight, bias, - newPads, strides, dilations); + newPads, strides, dilations, accType); } else { conv2D = createConvInGroups(rewriter, convOp, tosaBuilder, resultType, weightShape, newInput, newWeight, bias, group, newPads, strides, - dilations); + dilations, accType); } // Convert output [N,OH,OW,OC] -> [N,OC,OH,OW] diff --git a/src/Conversion/ONNXToTOSA/ONNXToTOSALegalizeUtils.cpp b/src/Conversion/ONNXToTOSA/ONNXToTOSALegalizeUtils.cpp index 984c60b5b2..321a2b35e2 100644 --- a/src/Conversion/ONNXToTOSA/ONNXToTOSALegalizeUtils.cpp +++ b/src/Conversion/ONNXToTOSA/ONNXToTOSALegalizeUtils.cpp @@ -48,7 +48,7 @@ Value buildOnnxToTosaPaddingConstOp(mlir::PatternRewriter &rewriter, // Create a new pad vec in the right format // ONNX : [b1, b2, b3, b4, e1, e2, e3, e4] - // TOSA :[[b1, e1], [b2, e2], [b3, e3], [b4, e4]] + // TOSA :[b1, e1, b2, e2, b3, e3, b4, e4] // Adds any initial or last vals, not included in onnxPads. llvm::SmallVector tosaPads{initialVals}; @@ -59,11 +59,9 @@ Value buildOnnxToTosaPaddingConstOp(mlir::PatternRewriter &rewriter, tosaPads.push_back(onnxPads[i + dimSize]); } tosaPads.insert(tosaPads.end(), lastVals.begin(), lastVals.end()); - - // TOSA format groups dimensions by 2. - const unsigned int numberOfDims = tosaPads.size() / 2; TosaBuilder tosaBuilder(rewriter, loc); - return tosaBuilder.getConst(tosaPads, {numberOfDims, 2}); + return tosaBuilder.getConst( + tosaPads, {static_cast(tosaPads.size())}); } } // namespace tosa diff --git a/test/mlir/conversion/krnl_to_llvm/krnl_math_function_lowering.mlir b/test/mlir/conversion/krnl_to_llvm/krnl_math_function_lowering.mlir index d739869098..4293e3352d 100644 --- a/test/mlir/conversion/krnl_to_llvm/krnl_math_function_lowering.mlir +++ b/test/mlir/conversion/krnl_to_llvm/krnl_math_function_lowering.mlir @@ -16,9 +16,7 @@ func.func @test_krnl_erf_lowering(%arg0: memref<10x10xf32>) -> memref<10x10xf32> // CHECK-LABEL: test_krnl_erf_lowering // CHECK: [[MEMREF_IN:%.+]] = llvm.insertvalue %arg6, {{.*}}[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[BUILTIN_CAST_0:%.+]] = builtin.unrealized_conversion_cast [[MEMREF_IN]] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> to memref<10x10xf32> -// CHECK: [[BUILTIN_CAST_1:%.+]] = builtin.unrealized_conversion_cast [[BUILTIN_CAST_0]] : memref<10x10xf32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[DATA:%.+]] = llvm.extractvalue [[BUILTIN_CAST_1]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> +// CHECK: [[DATA:%.+]] = llvm.extractvalue [[MEMREF_IN]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> // CHECK: [[DATA_IN:%.+]] = llvm.getelementptr [[DATA]]{{.*}} : (!llvm.ptr, i64) -> !llvm.ptr, f32 // CHECK: [[SCALAR_IN:%.+]] = llvm.load [[DATA_IN]] : !llvm.ptr // CHECK: [[ERF_RES:%.+]] = llvm.call @erff([[SCALAR_IN]]) : (f32) -> f32 @@ -41,9 +39,7 @@ func.func @test_krnl_acos_lowering(%arg0: memref<10x10xf32>) -> memref<10x10xf32 // CHECK-LABEL: test_krnl_acos_lowering // CHECK: [[MEMREF_IN:%.+]] = llvm.insertvalue %arg6, {{.*}}[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[BUILTIN_CAST_0:%.+]] = builtin.unrealized_conversion_cast [[MEMREF_IN]] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> to memref<10x10xf32> -// CHECK: [[BUILTIN_CAST_1:%.+]] = builtin.unrealized_conversion_cast [[BUILTIN_CAST_0]] : memref<10x10xf32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[DATA:%.+]] = llvm.extractvalue [[BUILTIN_CAST_1]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> +// CHECK: [[DATA:%.+]] = llvm.extractvalue [[MEMREF_IN]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> // CHECK: [[DATA_IN:%.+]] = llvm.getelementptr [[DATA]]{{.*}} : (!llvm.ptr, i64) -> !llvm.ptr, f32 // CHECK: [[SCALAR_IN:%.+]] = llvm.load [[DATA_IN]] : !llvm.ptr // CHECK: [[ACOS_RES:%.+]] = llvm.call @acosf([[SCALAR_IN]]) : (f32) -> f32 @@ -66,9 +62,7 @@ func.func @test_krnl_acosh_lowering(%arg0: memref<10x10xf32>) -> memref<10x10xf3 // CHECK-LABEL: test_krnl_acosh_lowering // CHECK: [[MEMREF_IN:%.+]] = llvm.insertvalue %arg6, {{.*}}[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[BUILTIN_CAST_0:%.+]] = builtin.unrealized_conversion_cast [[MEMREF_IN]] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> to memref<10x10xf32> -// CHECK: [[BUILTIN_CAST_1:%.+]] = builtin.unrealized_conversion_cast [[BUILTIN_CAST_0]] : memref<10x10xf32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[DATA:%.+]] = llvm.extractvalue [[BUILTIN_CAST_1]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> +// CHECK: [[DATA:%.+]] = llvm.extractvalue [[MEMREF_IN]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> // CHECK: [[DATA_IN:%.+]] = llvm.getelementptr [[DATA]]{{.*}} : (!llvm.ptr, i64) -> !llvm.ptr, f32 // CHECK: [[SCALAR_IN:%.+]] = llvm.load [[DATA_IN]] : !llvm.ptr // CHECK: [[ACOS_RES:%.+]] = llvm.call @acoshf([[SCALAR_IN]]) : (f32) -> f32 @@ -91,9 +85,7 @@ func.func @test_krnl_asin_lowering(%arg0: memref<10x10xf32>) -> memref<10x10xf32 // CHECK-LABEL: test_krnl_asin_lowering // CHECK: [[MEMREF_IN:%.+]] = llvm.insertvalue %arg6, {{.*}}[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[BUILTIN_CAST_0:%.+]] = builtin.unrealized_conversion_cast [[MEMREF_IN]] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> to memref<10x10xf32> -// CHECK: [[BUILTIN_CAST_1:%.+]] = builtin.unrealized_conversion_cast [[BUILTIN_CAST_0]] : memref<10x10xf32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[DATA:%.+]] = llvm.extractvalue [[BUILTIN_CAST_1]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> +// CHECK: [[DATA:%.+]] = llvm.extractvalue [[MEMREF_IN]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> // CHECK: [[DATA_IN:%.+]] = llvm.getelementptr [[DATA]]{{.*}} : (!llvm.ptr, i64) -> !llvm.ptr, f32 // CHECK: [[SCALAR_IN:%.+]] = llvm.load [[DATA_IN]] : !llvm.ptr // CHECK: [[ACOS_RES:%.+]] = llvm.call @asinf([[SCALAR_IN]]) : (f32) -> f32 @@ -116,9 +108,7 @@ func.func @test_krnl_asinh_lowering(%arg0: memref<10x10xf32>) -> memref<10x10xf3 // CHECK-LABEL: test_krnl_asinh_lowering // CHECK: [[MEMREF_IN:%.+]] = llvm.insertvalue %arg6, {{.*}}[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[BUILTIN_CAST_0:%.+]] = builtin.unrealized_conversion_cast [[MEMREF_IN]] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> to memref<10x10xf32> -// CHECK: [[BUILTIN_CAST_1:%.+]] = builtin.unrealized_conversion_cast [[BUILTIN_CAST_0]] : memref<10x10xf32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[DATA:%.+]] = llvm.extractvalue [[BUILTIN_CAST_1]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> +// CHECK: [[DATA:%.+]] = llvm.extractvalue [[MEMREF_IN]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> // CHECK: [[DATA_IN:%.+]] = llvm.getelementptr [[DATA]]{{.*}} : (!llvm.ptr, i64) -> !llvm.ptr, f32 // CHECK: [[SCALAR_IN:%.+]] = llvm.load [[DATA_IN]] : !llvm.ptr // CHECK: [[ACOS_RES:%.+]] = llvm.call @asinhf([[SCALAR_IN]]) : (f32) -> f32 @@ -141,9 +131,7 @@ func.func @test_krnl_atan_lowering(%arg0: memref<10x10xf32>) -> memref<10x10xf32 // CHECK-LABEL: test_krnl_atan_lowering // CHECK: [[MEMREF_IN:%.+]] = llvm.insertvalue %arg6, {{.*}}[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[BUILTIN_CAST_0:%.+]] = builtin.unrealized_conversion_cast [[MEMREF_IN]] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> to memref<10x10xf32> -// CHECK: [[BUILTIN_CAST_1:%.+]] = builtin.unrealized_conversion_cast [[BUILTIN_CAST_0]] : memref<10x10xf32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[DATA:%.+]] = llvm.extractvalue [[BUILTIN_CAST_1]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> +// CHECK: [[DATA:%.+]] = llvm.extractvalue [[MEMREF_IN]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> // CHECK: [[DATA_IN:%.+]] = llvm.getelementptr [[DATA]]{{.*}} : (!llvm.ptr, i64) -> !llvm.ptr, f32 // CHECK: [[SCALAR_IN:%.+]] = llvm.load [[DATA_IN]] : !llvm.ptr // CHECK: [[ACOS_RES:%.+]] = llvm.call @atanf([[SCALAR_IN]]) : (f32) -> f32 @@ -165,9 +153,7 @@ func.func @test_krnl_atanh_lowering(%arg0: memref<10x10xf32>) -> memref<10x10xf3 // CHECK-LABEL: test_krnl_atanh_lowering // CHECK: [[MEMREF_IN:%.+]] = llvm.insertvalue %arg6, {{.*}}[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[BUILTIN_CAST_0:%.+]] = builtin.unrealized_conversion_cast [[MEMREF_IN]] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> to memref<10x10xf32> -// CHECK: [[BUILTIN_CAST_1:%.+]] = builtin.unrealized_conversion_cast [[BUILTIN_CAST_0]] : memref<10x10xf32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[DATA:%.+]] = llvm.extractvalue [[BUILTIN_CAST_1]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> +// CHECK: [[DATA:%.+]] = llvm.extractvalue [[MEMREF_IN]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> // CHECK: [[DATA_IN:%.+]] = llvm.getelementptr [[DATA]]{{.*}} : (!llvm.ptr, i64) -> !llvm.ptr, f32 // CHECK: [[SCALAR_IN:%.+]] = llvm.load [[DATA_IN]] : !llvm.ptr // CHECK: [[ACOS_RES:%.+]] = llvm.call @atanhf([[SCALAR_IN]]) : (f32) -> f32 @@ -189,12 +175,9 @@ func.func @test_krnl_tan_lowering(%arg0: memref<10x10xf32>) -> memref<10x10xf32> // CHECK-LABEL: test_krnl_tan_lowering // CHECK: [[MEMREF_IN:%.+]] = llvm.insertvalue %arg6, {{.*}}[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[BUILTIN_CAST_0:%.+]] = builtin.unrealized_conversion_cast [[MEMREF_IN]] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> to memref<10x10xf32> -// CHECK: [[BUILTIN_CAST_1:%.+]] = builtin.unrealized_conversion_cast [[BUILTIN_CAST_0]] : memref<10x10xf32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> -// CHECK: [[DATA:%.+]] = llvm.extractvalue [[BUILTIN_CAST_1]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> +// CHECK: [[DATA:%.+]] = llvm.extractvalue [[MEMREF_IN]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> // CHECK: [[DATA_IN:%.+]] = llvm.getelementptr [[DATA]]{{.*}} : (!llvm.ptr, i64) -> !llvm.ptr, f32 // CHECK: [[SCALAR_IN:%.+]] = llvm.load [[DATA_IN]] : !llvm.ptr // CHECK: [[ACOS_RES:%.+]] = llvm.call @tanf([[SCALAR_IN]]) : (f32) -> f32 // CHECK: [[DATA_OUT:%.+]] = llvm.getelementptr {{.*}} : (!llvm.ptr, i64) -> !llvm.ptr, f32 // CHECK: llvm.store [[ACOS_RES]], [[DATA_OUT]] : f32, !llvm.ptr - diff --git a/test/mlir/conversion/onnx_to_tosa/Math/Conv.mlir b/test/mlir/conversion/onnx_to_tosa/Math/Conv.mlir index a772d6b4a0..0437de4625 100644 --- a/test/mlir/conversion/onnx_to_tosa/Math/Conv.mlir +++ b/test/mlir/conversion/onnx_to_tosa/Math/Conv.mlir @@ -11,7 +11,7 @@ func.func @test_onnx_conv2d_stride_13(%arg0: tensor<5x3x256x256xf32>, %arg1 : te // CHECK: %[[VAL_3:.*]] = "tosa.const"() <{value = dense<[0, 2, 3, 1]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: %[[VAL_4:.*]] = tosa.transpose %[[VAL_0]], %[[VAL_3]] : (tensor<5x3x256x256xf32>, tensor<4xi32>) -> tensor<5x256x256x3xf32> // CHECK: %[[VAL_5:.*]] = tosa.transpose %[[VAL_1]], %[[VAL_3]] : (tensor<2x3x64x64xf32>, tensor<4xi32>) -> tensor<2x64x64x3xf32> -// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_4]], %[[VAL_5]], %[[VAL_2]] {dilation = array, pad = array, stride = array} : (tensor<5x256x256x3xf32>, tensor<2x64x64x3xf32>, tensor<2xf32>) -> tensor<5x15x15x2xf32> +// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_4]], %[[VAL_5]], %[[VAL_2]] {acc_type = f32, dilation = array, pad = array, stride = array} : (tensor<5x256x256x3xf32>, tensor<2x64x64x3xf32>, tensor<2xf32>) -> tensor<5x15x15x2xf32> // CHECK: %[[VAL_7:.*]] = "tosa.const"() <{value = dense<[0, 3, 1, 2]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: %[[VAL_8:.*]] = tosa.transpose %[[VAL_6]], %[[VAL_7]] : (tensor<5x15x15x2xf32>, tensor<4xi32>) -> tensor<5x2x15x15xf32> // CHECK: return %[[VAL_8]] : tensor<5x2x15x15xf32> @@ -29,7 +29,7 @@ func.func @test_onnx_conv2d_novalue(%arg0: tensor<5x3x256x256xf32>, %arg1 : tens // CHECK: %[[VAL_3:.*]] = tosa.transpose %[[VAL_0]], %[[VAL_2]] : (tensor<5x3x256x256xf32>, tensor<4xi32>) -> tensor<5x256x256x3xf32> // CHECK: %[[VAL_4:.*]] = tosa.transpose %[[VAL_1]], %[[VAL_2]] : (tensor<2x3x64x64xf32>, tensor<4xi32>) -> tensor<2x64x64x3xf32> // CHECK: %[[VAL_5:.*]] = "tosa.const"() <{value = dense<0.000000e+00> : tensor<2xf32>}> : () -> tensor<2xf32> -// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_3]], %[[VAL_4]], %[[VAL_5]] {dilation = array, pad = array, stride = array} : (tensor<5x256x256x3xf32>, tensor<2x64x64x3xf32>, tensor<2xf32>) -> tensor<5x197x199x2xf32> +// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_3]], %[[VAL_4]], %[[VAL_5]] {acc_type = f32, dilation = array, pad = array, stride = array} : (tensor<5x256x256x3xf32>, tensor<2x64x64x3xf32>, tensor<2xf32>) -> tensor<5x197x199x2xf32> // CHECK: %[[VAL_7:.*]] = "tosa.const"() <{value = dense<[0, 3, 1, 2]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: %[[VAL_8:.*]] = tosa.transpose %[[VAL_6]], %[[VAL_7]] : (tensor<5x197x199x2xf32>, tensor<4xi32>) -> tensor<5x2x197x199xf32> // CHECK: return %[[VAL_8]] : tensor<5x2x197x199xf32> @@ -47,7 +47,7 @@ func.func @test_onnx_conv2d_no_dilation_pad(%arg0: tensor<5x3x256x256xf32>, %arg // CHECK: %[[VAL_3:.*]] = tosa.transpose %[[VAL_0]], %[[VAL_2]] : (tensor<5x3x256x256xf32>, tensor<4xi32>) -> tensor<5x256x256x3xf32> // CHECK: %[[VAL_4:.*]] = tosa.transpose %[[VAL_1]], %[[VAL_2]] : (tensor<7x3x64x64xf32>, tensor<4xi32>) -> tensor<7x64x64x3xf32> // CHECK: %[[VAL_5:.*]] = "tosa.const"() <{value = dense<0.000000e+00> : tensor<7xf32>}> : () -> tensor<7xf32> -// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_3]], %[[VAL_4]], %[[VAL_5]] {dilation = array, pad = array, stride = array} : (tensor<5x256x256x3xf32>, tensor<7x64x64x3xf32>, tensor<7xf32>) -> tensor<5x15x15x7xf32> +// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_3]], %[[VAL_4]], %[[VAL_5]] {acc_type = f32, dilation = array, pad = array, stride = array} : (tensor<5x256x256x3xf32>, tensor<7x64x64x3xf32>, tensor<7xf32>) -> tensor<5x15x15x7xf32> // CHECK: %[[VAL_7:.*]] = "tosa.const"() <{value = dense<[0, 3, 1, 2]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: %[[VAL_8:.*]] = tosa.transpose %[[VAL_6]], %[[VAL_7]] : (tensor<5x15x15x7xf32>, tensor<4xi32>) -> tensor<5x7x15x15xf32> // CHECK: return %[[VAL_8]] : tensor<5x7x15x15xf32> @@ -65,7 +65,7 @@ func.func @test_onnx_conv2d_no_dilation_pad_stride(%arg0: tensor<5x3x256x260xf32 // CHECK: %[[VAL_3:.*]] = tosa.transpose %[[VAL_0]], %[[VAL_2]] : (tensor<5x3x256x260xf32>, tensor<4xi32>) -> tensor<5x256x260x3xf32> // CHECK: %[[VAL_4:.*]] = tosa.transpose %[[VAL_1]], %[[VAL_2]] : (tensor<2x3x60x64xf32>, tensor<4xi32>) -> tensor<2x60x64x3xf32> // CHECK: %[[VAL_5:.*]] = "tosa.const"() <{value = dense<0.000000e+00> : tensor<2xf32>}> : () -> tensor<2xf32> -// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_3]], %[[VAL_4]], %[[VAL_5]] {dilation = array, pad = array, stride = array} : (tensor<5x256x260x3xf32>, tensor<2x60x64x3xf32>, tensor<2xf32>) -> tensor<5x197x197x2xf32> +// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_3]], %[[VAL_4]], %[[VAL_5]] {acc_type = f32, dilation = array, pad = array, stride = array} : (tensor<5x256x260x3xf32>, tensor<2x60x64x3xf32>, tensor<2xf32>) -> tensor<5x197x197x2xf32> // CHECK: %[[VAL_7:.*]] = "tosa.const"() <{value = dense<[0, 3, 1, 2]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: %[[VAL_8:.*]] = tosa.transpose %[[VAL_6]], %[[VAL_7]] : (tensor<5x197x197x2xf32>, tensor<4xi32>) -> tensor<5x2x197x197xf32> // CHECK: return %[[VAL_8]] : tensor<5x2x197x197xf32> @@ -85,19 +85,19 @@ func.func @test_onnx_conv2d_group(%arg0: tensor<5x64x256x256xf32>, %arg1 : tenso // CHECK: %[[VAL_6:.*]] = tosa.slice %[[VAL_4]] {size = array, start = array} : (tensor<5x256x256x64xf32>) -> tensor<5x256x256x16xf32> // CHECK: %[[VAL_7:.*]] = tosa.slice %[[VAL_5]] {size = array, start = array} : (tensor<12x45x45x16xf32>) -> tensor<3x45x45x16xf32> // CHECK: %[[VAL_8:.*]] = tosa.slice %[[VAL_2]] {size = array, start = array} : (tensor<12xf32>) -> tensor<3xf32> -// CHECK: %[[VAL_9:.*]] = tosa.conv2d %[[VAL_6]], %[[VAL_7]], %[[VAL_8]] {dilation = array, pad = array, stride = array} : (tensor<5x256x256x16xf32>, tensor<3x45x45x16xf32>, tensor<3xf32>) -> tensor<5x17x17x3xf32> +// CHECK: %[[VAL_9:.*]] = tosa.conv2d %[[VAL_6]], %[[VAL_7]], %[[VAL_8]] {acc_type = f32, dilation = array, pad = array, stride = array} : (tensor<5x256x256x16xf32>, tensor<3x45x45x16xf32>, tensor<3xf32>) -> tensor<5x17x17x3xf32> // CHECK: %[[VAL_10:.*]] = tosa.slice %[[VAL_4]] {size = array, start = array} : (tensor<5x256x256x64xf32>) -> tensor<5x256x256x16xf32> // CHECK: %[[VAL_11:.*]] = tosa.slice %[[VAL_5]] {size = array, start = array} : (tensor<12x45x45x16xf32>) -> tensor<3x45x45x16xf32> // CHECK: %[[VAL_12:.*]] = tosa.slice %[[VAL_2]] {size = array, start = array} : (tensor<12xf32>) -> tensor<3xf32> -// CHECK: %[[VAL_13:.*]] = tosa.conv2d %[[VAL_10]], %[[VAL_11]], %[[VAL_12]] {dilation = array, pad = array, stride = array} : (tensor<5x256x256x16xf32>, tensor<3x45x45x16xf32>, tensor<3xf32>) -> tensor<5x17x17x3xf32> +// CHECK: %[[VAL_13:.*]] = tosa.conv2d %[[VAL_10]], %[[VAL_11]], %[[VAL_12]] {acc_type = f32, dilation = array, pad = array, stride = array} : (tensor<5x256x256x16xf32>, tensor<3x45x45x16xf32>, tensor<3xf32>) -> tensor<5x17x17x3xf32> // CHECK: %[[VAL_14:.*]] = tosa.slice %[[VAL_4]] {size = array, start = array} : (tensor<5x256x256x64xf32>) -> tensor<5x256x256x16xf32> // CHECK: %[[VAL_15:.*]] = tosa.slice %[[VAL_5]] {size = array, start = array} : (tensor<12x45x45x16xf32>) -> tensor<3x45x45x16xf32> // CHECK: %[[VAL_16:.*]] = tosa.slice %[[VAL_2]] {size = array, start = array} : (tensor<12xf32>) -> tensor<3xf32> -// CHECK: %[[VAL_17:.*]] = tosa.conv2d %[[VAL_14]], %[[VAL_15]], %[[VAL_16]] {dilation = array, pad = array, stride = array} : (tensor<5x256x256x16xf32>, tensor<3x45x45x16xf32>, tensor<3xf32>) -> tensor<5x17x17x3xf32> +// CHECK: %[[VAL_17:.*]] = tosa.conv2d %[[VAL_14]], %[[VAL_15]], %[[VAL_16]] {acc_type = f32, dilation = array, pad = array, stride = array} : (tensor<5x256x256x16xf32>, tensor<3x45x45x16xf32>, tensor<3xf32>) -> tensor<5x17x17x3xf32> // CHECK: %[[VAL_18:.*]] = tosa.slice %[[VAL_4]] {size = array, start = array} : (tensor<5x256x256x64xf32>) -> tensor<5x256x256x16xf32> // CHECK: %[[VAL_19:.*]] = tosa.slice %[[VAL_5]] {size = array, start = array} : (tensor<12x45x45x16xf32>) -> tensor<3x45x45x16xf32> // CHECK: %[[VAL_20:.*]] = tosa.slice %[[VAL_2]] {size = array, start = array} : (tensor<12xf32>) -> tensor<3xf32> -// CHECK: %[[VAL_21:.*]] = tosa.conv2d %[[VAL_18]], %[[VAL_19]], %[[VAL_20]] {dilation = array, pad = array, stride = array} : (tensor<5x256x256x16xf32>, tensor<3x45x45x16xf32>, tensor<3xf32>) -> tensor<5x17x17x3xf32> +// CHECK: %[[VAL_21:.*]] = tosa.conv2d %[[VAL_18]], %[[VAL_19]], %[[VAL_20]] {acc_type = f32, dilation = array, pad = array, stride = array} : (tensor<5x256x256x16xf32>, tensor<3x45x45x16xf32>, tensor<3xf32>) -> tensor<5x17x17x3xf32> // CHECK: %[[VAL_22:.*]] = tosa.concat %[[VAL_9]], %[[VAL_13]], %[[VAL_17]], %[[VAL_21]] {axis = 3 : i32} : (tensor<5x17x17x3xf32>, tensor<5x17x17x3xf32>, tensor<5x17x17x3xf32>, tensor<5x17x17x3xf32>) -> tensor<5x17x17x12xf32> // CHECK: %[[VAL_23:.*]] = "tosa.const"() <{value = dense<[0, 3, 1, 2]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: %[[VAL_24:.*]] = tosa.transpose %[[VAL_22]], %[[VAL_23]] : (tensor<5x17x17x12xf32>, tensor<4xi32>) -> tensor<5x12x17x17xf32> @@ -115,7 +115,7 @@ func.func @test_onnx_conv2d_autopad(%arg0: tensor<5x3x125x256xf32>, %arg1 : tens // CHECK: %[[VAL_3:.*]] = "tosa.const"() <{value = dense<[0, 2, 3, 1]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: %[[VAL_4:.*]] = tosa.transpose %[[VAL_0]], %[[VAL_3]] : (tensor<5x3x125x256xf32>, tensor<4xi32>) -> tensor<5x125x256x3xf32> // CHECK: %[[VAL_5:.*]] = tosa.transpose %[[VAL_1]], %[[VAL_3]] : (tensor<2x3x64x64xf32>, tensor<4xi32>) -> tensor<2x64x64x3xf32> -// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_4]], %[[VAL_5]], %[[VAL_2]] {dilation = array, pad = array, stride = array} : (tensor<5x125x256x3xf32>, tensor<2x64x64x3xf32>, tensor<2xf32>) -> tensor<5x125x256x2xf32> +// CHECK: %[[VAL_6:.*]] = tosa.conv2d %[[VAL_4]], %[[VAL_5]], %[[VAL_2]] {acc_type = f32, dilation = array, pad = array, stride = array} : (tensor<5x125x256x3xf32>, tensor<2x64x64x3xf32>, tensor<2xf32>) -> tensor<5x125x256x2xf32> // CHECK: %[[VAL_7:.*]] = "tosa.const"() <{value = dense<[0, 3, 1, 2]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: %[[VAL_8:.*]] = tosa.transpose %[[VAL_6]], %[[VAL_7]] : (tensor<5x125x256x2xf32>, tensor<4xi32>) -> tensor<5x2x125x256xf32> // CHECK: return %[[VAL_8]] : tensor<5x2x125x256xf32> diff --git a/test/mlir/conversion/onnx_to_tosa/NN/AveragePool.mlir b/test/mlir/conversion/onnx_to_tosa/NN/AveragePool.mlir index 8ebeaa30c6..8d9d426494 100644 --- a/test/mlir/conversion/onnx_to_tosa/NN/AveragePool.mlir +++ b/test/mlir/conversion/onnx_to_tosa/NN/AveragePool.mlir @@ -141,10 +141,10 @@ func.func @test_averagepool_pad_with_count_include_pad(%arg0 : tensor<5x5x32x32x } // CHECK-LABEL: func.func @test_averagepool_pad_with_count_include_pad // CHECK-SAME: ([[PARAM_0_:%.+]]: tensor<5x5x32x32xf32>) -> tensor<5x5x32x32xf32> { -// CHECK-DAG: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[0, 0], [0, 0], [1, 1], [1, 1]{{.}}> : tensor<4x2xi64>}> : () -> tensor<4x2xi64> +// CHECK-DAG: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<[0, 0, 0, 0, 1, 1, 1, 1]> : tensor<8xi64>}> : () -> tensor<8xi64> // CHECK-DAG: [[VAR_1_:%.+]] = "tosa.const"() <{value = dense<0.000000e+00> : tensor}> : () -> tensor // CHECK-NOT: separator of consecutive DAGs -// CHECK-DAG: [[VAR_2_:%.+]] = tosa.pad [[PARAM_0_]], [[VAR_0_]], [[VAR_1_]] : (tensor<5x5x32x32xf32>, tensor<4x2xi64>, tensor) -> tensor<5x5x34x34xf32> +// CHECK-DAG: [[VAR_2_:%.+]] = tosa.pad [[PARAM_0_]], [[VAR_0_]], [[VAR_1_]] : (tensor<5x5x32x32xf32>, tensor<8xi64>, tensor) -> tensor<5x5x34x34xf32> // CHECK-DAG: [[VAR_3_:%.+]] = "tosa.const"() <{value = dense<[0, 2, 3, 1]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: [[VAR_4_:%.+]] = tosa.transpose [[VAR_2_]], [[VAR_3_]] : (tensor<5x5x34x34xf32>, tensor<4xi32>) -> tensor<5x34x34x5xf32> // CHECK-DAG: [[VAR_5_:%.+]] = tosa.avg_pool2d [[VAR_4_]] {acc_type = f32, kernel = array, pad = array, stride = array} : (tensor<5x34x34x5xf32>) -> tensor<5x32x32x5xf32> @@ -162,10 +162,10 @@ func.func @test_averagepool_pad_nonunif_with_count_include_pad(%arg0 : tensor<5x } // CHECK-LABEL: func.func @test_averagepool_pad_nonunif_with_count_include_pad // CHECK-SAME: ([[PARAM_0_:%.+]]: tensor<5x5x32x32xf32>) -> tensor<5x5x30x34xf32> { -// CHECK-DAG: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[0, 0], [0, 0], [0, 2], [1, 3]{{.}}> : tensor<4x2xi64>}> : () -> tensor<4x2xi64> +// CHECK-DAG: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<[0, 0, 0, 0, 0, 2, 1, 3]> : tensor<8xi64>}> : () -> tensor<8xi64> // CHECK-DAG: [[VAR_1_:%.+]] = "tosa.const"() <{value = dense<0.000000e+00> : tensor}> : () -> tensor // CHECK-NOT: separator of consecutive DAGs -// CHECK-DAG: [[VAR_2_:%.+]] = tosa.pad [[PARAM_0_]], [[VAR_0_]], [[VAR_1_]] : (tensor<5x5x32x32xf32>, tensor<4x2xi64>, tensor) -> tensor<5x5x34x36xf32> +// CHECK-DAG: [[VAR_2_:%.+]] = tosa.pad [[PARAM_0_]], [[VAR_0_]], [[VAR_1_]] : (tensor<5x5x32x32xf32>, tensor<8xi64>, tensor) -> tensor<5x5x34x36xf32> // CHECK-DAG: [[VAR_3_:%.+]] = "tosa.const"() <{value = dense<[0, 2, 3, 1]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: [[VAR_4_:%.+]] = tosa.transpose [[VAR_2_]], [[VAR_3_]] : (tensor<5x5x34x36xf32>, tensor<4xi32>) -> tensor<5x34x36x5xf32> // CHECK-DAG: [[VAR_5_:%.+]] = tosa.avg_pool2d [[VAR_4_]] {acc_type = f32, kernel = array, pad = array, stride = array} : (tensor<5x34x36x5xf32>) -> tensor<5x30x34x5xf32> @@ -183,10 +183,10 @@ func.func @test_averagepool_strides_nonunifpad_ceil_with_count_include_pad(%arg0 } // CHECK-LABEL: func.func @test_averagepool_strides_nonunifpad_ceil_with_count_include_pad // CHECK-SAME: ([[PARAM_0_:%.+]]: tensor<5x5x30x32xf32>) -> tensor<5x5x16x17xf32> { -// CHECK-DAG: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<{{.}}[0, 0], [0, 0], [1, 0], [2, 0]{{.}}> : tensor<4x2xi64>}> : () -> tensor<4x2xi64> +// CHECK-DAG: [[VAR_0_:%.+]] = "tosa.const"() <{value = dense<[0, 0, 0, 0, 1, 0, 2, 0]> : tensor<8xi64>}> : () -> tensor<8xi64> // CHECK-DAG: [[VAR_1_:%.+]] = "tosa.const"() <{value = dense<0.000000e+00> : tensor}> : () -> tensor // CHECK-NOT: separator of consecutive DAGs -// CHECK-DAG: [[VAR_2_:%.+]] = tosa.pad [[PARAM_0_]], [[VAR_0_]], [[VAR_1_]] : (tensor<5x5x30x32xf32>, tensor<4x2xi64>, tensor) -> tensor<5x5x31x34xf32> +// CHECK-DAG: [[VAR_2_:%.+]] = tosa.pad [[PARAM_0_]], [[VAR_0_]], [[VAR_1_]] : (tensor<5x5x30x32xf32>, tensor<8xi64>, tensor) -> tensor<5x5x31x34xf32> // CHECK-DAG: [[VAR_3_:%.+]] = "tosa.const"() <{value = dense<[0, 2, 3, 1]> : tensor<4xi32>}> : () -> tensor<4xi32> // CHECK: [[VAR_4_:%.+]] = tosa.transpose [[VAR_2_]], [[VAR_3_]] : (tensor<5x5x31x34xf32>, tensor<4xi32>) -> tensor<5x31x34x5xf32> // CHECK-DAG: [[VAR_5_:%.+]] = tosa.avg_pool2d [[VAR_4_]] {acc_type = f32, kernel = array, pad = array, stride = array} : (tensor<5x31x34x5xf32>) -> tensor<5x16x17x5xf32> diff --git a/third_party/stablehlo b/third_party/stablehlo index 8c7946c8c9..459e481b77 160000 --- a/third_party/stablehlo +++ b/third_party/stablehlo @@ -1 +1 @@ -Subproject commit 8c7946c8c94182d238600fb0775a5ba594a43bd7 +Subproject commit 459e481b77f8537aae3f8e8e8ad9550721afe202 diff --git a/utils/clone-mlir.sh b/utils/clone-mlir.sh index 303761b48f..804dff5fda 100644 --- a/utils/clone-mlir.sh +++ b/utils/clone-mlir.sh @@ -1,3 +1,3 @@ git clone -n https://github.com/llvm/llvm-project.git # Check out a specific branch that is known to work with ONNX-MLIR. -cd llvm-project && git checkout e86910337f98e57f5b9253f7d80d5b916eb1d97e && cd .. +cd llvm-project && git checkout b270525f730be6e7196667925f5a9bfa153262e9 && cd ..