kumasento / polymer

Bridging polyhedral analysis tools to the MLIR framework
MIT License
99 stars 21 forks source link

No Pluto optimization in matrix multiplication example #119

Closed malixian closed 2 years ago

malixian commented 2 years ago

I build the polymer with impact branch, and try to optimize matmul.mlir. But I find there is no difference between output mlir and input mlir. The command I used is polymer-opt -pluto-opt ../matmul.mlir. And the output mlir is:

module  {
  func @matmul() {
    %0 = alloc() : memref<64x64xf32>
    %1 = alloc() : memref<64x64xf32>
    %2 = alloc() : memref<64x64xf32>
    affine.for %arg0 = 0 to 64 {
      affine.for %arg1 = 0 to 64 {
        affine.for %arg2 = 0 to 64 {
          %3 = affine.load %0[%arg0, %arg2] : memref<64x64xf32>
          %4 = affine.load %1[%arg2, %arg1] : memref<64x64xf32>
          %5 = mulf %3, %4 : f32
          %6 = affine.load %2[%arg0, %arg1] : memref<64x64xf32>
          %7 = addf %5, %6 : f32
          affine.store %7, %2[%arg0, %arg1] : memref<64x64xf32>
        }
      }
    }
    return
  }
}

When I try to build this project with main branch and use the command ./scripts/build-with-polygeist.sh, I get a compile error:

configure: error: clang header file not found checking for pet/Makefile... no configure: error: configure in pet/ failed tools/mlir/tools/polymer/CMakeFiles/pluto.dir/build.make:124: recipe for target 'tools/mlir/tools/polymer/pluto/src/pluto-stamp/pluto-configure' failed make[3]: [tools/mlir/tools/polymer/pluto/src/pluto-stamp/pluto-configure] Error 1 CMakeFiles/Makefile2:109388: recipe for target 'tools/mlir/tools/polymer/CMakeFiles/pluto.dir/all' failed make[2]: [tools/mlir/tools/polymer/CMakeFiles/pluto.dir/all] Error 2 CMakeFiles/Makefile2:110540: recipe for target 'tools/mlir/tools/polymer/test/CMakeFiles/check-polymer.dir/rule' failed make[1]: [tools/mlir/tools/polymer/test/CMakeFiles/check-polymer.dir/rule] Error 2 Makefile:27063: recipe for target 'check-polymer' failed make: [check-polymer] Error 2

Is there any solutions to solve these problems above? Thanks.

kumasento commented 2 years ago

Hi there, you may need to add -reg2mem -extract-scop-stmt before -pluto-opt, sorry for the confusion. Let me know if you need any further help.

On Mon, 29 Nov 2021 at 05:17, malixian @.***> wrote:

I build the polymer with impact branch, and try to optimize matmul.mlir. But I find there is no difference between output mlir and input mlir. The command I used is polymer-opt -pluto-opt ../matmul.mlir. And the output mlir is:

module { func @matmul() { %0 = alloc() : memref<64x64xf32> %1 = alloc() : memref<64x64xf32> %2 = alloc() : memref<64x64xf32> affine.for %arg0 = 0 to 64 { affine.for %arg1 = 0 to 64 { affine.for %arg2 = 0 to 64 { %3 = affine.load %0[%arg0, %arg2] : memref<64x64xf32> %4 = affine.load %1[%arg2, %arg1] : memref<64x64xf32> %5 = mulf %3, %4 : f32 %6 = affine.load %2[%arg0, %arg1] : memref<64x64xf32> %7 = addf %5, %6 : f32 affine.store %7, %2[%arg0, %arg1] : memref<64x64xf32> } } } return } }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kumasento/polymer/issues/119, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACC42R7EU7FVZALV6YUVNWTUOMEFRANCNFSM5I6HTAHQ .

-- Ruizhe Zhao https://kumasento.github.io

malixian commented 2 years ago

Thank you for your reply @kumasento . When I run the command ./polymer-opt -reg2mem -extract-scop-stmt -pluto-opt matmul.mlir, there occurs a core dump. Error log is:

polymer-opt: /home/mlx/repos/MLIR-repos/polymer/llvm/mlir/lib/Analysis/AffineStructures.cpp:3050: void getIndependentConstraints(const mlir::FlatAffineConstraints &, unsigned int, unsigned int, SmallVectorImpl &, SmallVectorImpl &): Assertion `pos < cst.getNumIds() && "invalid start position"' failed.

kumasento commented 2 years ago

Interesting. Thanks for reporting this.

Would you mind trying out the main branch? Or check out any example under test/ to see if it can run on your end?

Also, you may want to check .github/workflows/buildAndTest.yml to see how polymer can be built with the main branch, which is different from impact.

On Tue, 30 Nov 2021 at 01:11, malixian @.***> wrote:

Thank you for your reply @kumasento https://github.com/kumasento . When I run the command ./polymer-opt -reg2mem -extract-scop-stmt -pluto-opt matmul.mlir, there occurs a core dump. Error log is:

polymer-opt: /home/mlx/repos/MLIR-repos/polymer/llvm/mlir/lib/Analysis/AffineStructures.cpp:3050: void getIndependentConstraints(const mlir::FlatAffineConstraints &, unsigned int, unsigned int, SmallVectorImpl &, SmallVectorImpl &): Assertion `pos < cst.getNumIds() && "invalid start position"' failed.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/kumasento/polymer/issues/119#issuecomment-982186592, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACC42R6F5UTIL2RNXEMJFELUOQQCPANCNFSM5I6HTAHQ .

-- Ruizhe Zhao https://kumasento.github.io

malixian commented 2 years ago

Thanks, I will try it.