From c21c5003952f3f54afbafd70208160969bc2523f Mon Sep 17 00:00:00 2001 From: EllisLambda Date: Mon, 30 Oct 2023 14:29:18 +0800 Subject: [PATCH] [midend] Canonicalize dynamic rank detection. --- .../MatMulOptimization/BatchMatMulOptimize.cpp | 5 ++--- .../Conversion/MatMulOptimization/CMakeLists.txt | 2 +- .../MatMulParallelVectorization.cpp | 5 ++--- .../BuiltinTransposeVectorization.cpp | 13 +++++++------ .../Conversion/TransposeOptimization/CMakeLists.txt | 2 +- tools/buddy-opt/CMakeLists.txt | 2 +- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/midend/lib/Conversion/MatMulOptimization/BatchMatMulOptimize.cpp b/midend/lib/Conversion/MatMulOptimization/BatchMatMulOptimize.cpp index b23c0b5f4b..f86435abbd 100644 --- a/midend/lib/Conversion/MatMulOptimization/BatchMatMulOptimize.cpp +++ b/midend/lib/Conversion/MatMulOptimization/BatchMatMulOptimize.cpp @@ -1,5 +1,4 @@ -//===- BatchMatMulOptimize.cpp -//-------------------------------------------------===// +//===- BatchMatMulOptimize.cpp --------------------------------------------===// // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -145,7 +144,7 @@ class BatchMatMulOptimizePattern : public ConversionPattern { Value loopVarColOfB = ivRange.front(); // Compile time branch detection. - if (C.getType().cast().getDimSize(2) < 0 or + if (C.getType().cast().isDynamicDim(2) or C.getType().cast().getDimSize(2) % affineVectorSize != 0) { diff --git a/midend/lib/Conversion/MatMulOptimization/CMakeLists.txt b/midend/lib/Conversion/MatMulOptimization/CMakeLists.txt index c8695e600d..8e726863eb 100644 --- a/midend/lib/Conversion/MatMulOptimization/CMakeLists.txt +++ b/midend/lib/Conversion/MatMulOptimization/CMakeLists.txt @@ -13,4 +13,4 @@ add_mlir_library(BatchMatMulOptimization add_mlir_library(MatMulParallelVectorization MatMulParallelVectorization.cpp -) \ No newline at end of file +) diff --git a/midend/lib/Conversion/MatMulOptimization/MatMulParallelVectorization.cpp b/midend/lib/Conversion/MatMulOptimization/MatMulParallelVectorization.cpp index 97a55c889b..90cbae7d21 100644 --- a/midend/lib/Conversion/MatMulOptimization/MatMulParallelVectorization.cpp +++ b/midend/lib/Conversion/MatMulOptimization/MatMulParallelVectorization.cpp @@ -1,5 +1,4 @@ -//===- MatMulParallelVectorization.cpp -//-------------------------------------------------===// +//===- MatMulParallelVectorization.cpp ------------------------------------===// // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -141,7 +140,7 @@ class MatMulParallelVectorizationPattern : public ConversionPattern { ArrayRef{aRow, bRow}, false, 3, true); // Compile time branch detection. - if (C.getType().cast().getDimSize(1) < 0 or + if (C.getType().cast().isDynamicDim(1) or C.getType().cast().getDimSize(1) % affineVectorSize != 0) { // Depending on the position, use either full vectors or tail vectors. diff --git a/midend/lib/Conversion/TransposeOptimization/BuiltinTransposeVectorization.cpp b/midend/lib/Conversion/TransposeOptimization/BuiltinTransposeVectorization.cpp index 1496b2fbd4..0cb8761a72 100644 --- a/midend/lib/Conversion/TransposeOptimization/BuiltinTransposeVectorization.cpp +++ b/midend/lib/Conversion/TransposeOptimization/BuiltinTransposeVectorization.cpp @@ -1,5 +1,4 @@ -//===- BuiltinTransposeVectorization.cpp -//-------------------------------------------------===// +//===- BuiltinTransposeVectorization.cpp ----------------------------------===// // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -205,7 +204,7 @@ class TransposeOptimizationPattern : public ConversionPattern { }); // Compile time branch detection. - if (A.getType().cast().getDimSize(0) < 0 or + if (A.getType().cast().isDynamicDim(0) or A.getType().cast().getDimSize(0) % affineVectorSize != 0) { // Depending on the position, use either full vectors or tail @@ -265,7 +264,7 @@ class TransposeOptimizationPattern : public ConversionPattern { parallelColLoop.getRegion().push_back(loopBody); rewriter.setInsertionPointAfter(parallelColLoop); - if (A.getType().cast().getDimSize(1) < 0 or + if (A.getType().cast().isDynamicDim(1) or A.getType().cast().getDimSize(1) % affineVectorSize != 0) { affine::AffineIfOp branchingColUnaligned = @@ -325,7 +324,7 @@ class TransposeOptimizationPattern : public ConversionPattern { }); }); - if (A.getType().cast().getDimSize(0) < 0 or + if (A.getType().cast().isDynamicDim(0) or A.getType().cast().getDimSize(0) % affineVectorSize != 0) { affine::AffineIfOp branchingRowColUnaligned = @@ -413,7 +412,9 @@ class TransposeOptimizationPass public: MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TransposeOptimizationPass) StringRef getArgument() const final { return "transpose-optimize"; } - StringRef getDescription() const final { return "Transpose Optimization only for rank 2 tensor."; } + StringRef getDescription() const final { + return "Transpose Optimization only for rank 2 tensor."; + } TransposeOptimizationPass() = default; TransposeOptimizationPass(const TransposeOptimizationPass &) {} explicit TransposeOptimizationPass(int64_t affineVectorSizeParam) { diff --git a/midend/lib/Conversion/TransposeOptimization/CMakeLists.txt b/midend/lib/Conversion/TransposeOptimization/CMakeLists.txt index 3054d74abf..70d5ca7fca 100644 --- a/midend/lib/Conversion/TransposeOptimization/CMakeLists.txt +++ b/midend/lib/Conversion/TransposeOptimization/CMakeLists.txt @@ -2,4 +2,4 @@ add_mlir_library(TransposeOptimization BuiltinTransposeVectorization.cpp LINK_LIBS PUBLIC BuddyUtils -) \ No newline at end of file +) diff --git a/tools/buddy-opt/CMakeLists.txt b/tools/buddy-opt/CMakeLists.txt index d4622e1d22..27b628720d 100644 --- a/tools/buddy-opt/CMakeLists.txt +++ b/tools/buddy-opt/CMakeLists.txt @@ -29,4 +29,4 @@ target_link_libraries(buddy-opt BuddyGemmini LowerGemminiPass LowerLinalgToGemminiPass - ) \ No newline at end of file +)