llvm / Polygeist

C/C++ frontend for MLIR. Also features polyhedral optimizations, parallel optimizations, and more!
https://polygeist.llvm.org
Other
478 stars 113 forks source link

How to run PolyBench/C benchmarks with polyhedral pluto optimization using Polygeist? #385

Open arun-thmn opened 8 months ago

arun-thmn commented 8 months ago

Hi,

I'm trying to run PolyBench/C benchmarks with polyhedral pluto optimization using Polygeist, but I cannot succeed. I used the earlier script at https://github.com/wsmoses/Polygeist-Script/blob/main/polybench-c-4.2.1-beta/run.sh as reference.

I used the options as below and not able to proceed with polymer-opt: clang -c -O3 ./utilities/polybench.c -o ./utilities/polybench.o -DEXTRALARGE_DATASET -DPOLYBENCH_TIME

clang -I ./utilities/ ./linear-algebra/blas/syr2k/syr2k.c -E -DEXTRALARGE_DATASET -DPOLYBENCH_TIME > ./syr2k.c

cgeist ./syr2k.c -S -o ./syr2k.mlir

polymer-opt -allow-unregistered-dialect -reg2mem -insert-redundant-load -extract-scop-stmt -canonicalize -pluto-opt="dump-clast-after-pluto=syr2k.cloog" -canonicalize ./syr2k.mlir

The error from 'polymer-opt': ./syr2k.mlir:10:73: error: invalid memref element type llvm.mlir.global external @stderr() {addr_space = 0 : i32} : memref<?x!llvm.struct<(....)>>

It would be helpful, if some guide me with right set of options.

Thanks Arun T

wsmoses commented 8 months ago

How did you build polymer and polygeist. We actually recently merged polymer into the polygeist repo directly so it may be helpful to build the latest main

On Thu, Feb 1, 2024, 5:55 PM arun-thmn @.***> wrote:

Hi,

I'm trying to run PolyBench/C benchmarks with polyhedral pluto optimization using Polygeist, but I cannot succeed. I used the earlier script at https://github.com/wsmoses/Polygeist-Script/blob/main/polybench-c-4.2.1-beta/run.sh as reference.

I used the options as below and not able to proceed with polymer-opt: clang -c -O3 ./utilities/polybench.c -o ./utilities/polybench.o -DEXTRALARGE_DATASET -DPOLYBENCH_TIME

clang -I ./utilities/ ./linear-algebra/blas/syr2k/syr2k.c -E -DEXTRALARGE_DATASET -DPOLYBENCH_TIME > ./syr2k.c

cgeist ./syr2k.c -S -o ./syr2k.mlir

polymer-opt -allow-unregistered-dialect -reg2mem -insert-redundant-load -extract-scop-stmt -canonicalize -pluto-opt="dump-clast-after-pluto=syr2k.cloog" -canonicalize ./syr2k.mlir

The error from 'polymer-opt': ./syr2k.mlir:10:73: error: invalid memref element type llvm.mlir.global external @stderr https://github.com/stderr() {addr_space = 0 : i32} : memref<?x!llvm.struct<(....)>>

It would be helpful, if some guide me with right set of options.

Thanks Arun T

— Reply to this email directly, view it on GitHub https://github.com/llvm/Polygeist/issues/385, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJTUXAIVE4VXXAJHOY6CKDYRPCHLAVCNFSM6AAAAABCVH62I2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGEYTEOJXHA2DCMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

arun-thmn commented 8 months ago

Hi, I did a recent clone from main a week back and did followed the instructions to built Polygeist and Polymer with '-DPOLYGEIST_ENABLE_POLYMER=1' Thanks

benroywillis commented 7 months ago

Following up on this issue with a study that arrived here independently.

I built Polygeist as an external project in llvm (option 2 from the docs) on Ubuntu 22.04 LTS with gcc 11.4.0 and the following configuration:

~$: cmake -G Ninja ../llvm-project/llvm/ -DLLVM_ENABLE_PROJECTS="mlir;clang;openmp" -DLLVM_EXTERNAL_PROJECTS="polygeist" -DLLVM_EXTERNAL_POLYGEIST_SOURCE_DIR=../ -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_ENABLE_ASSERTIONS=ON -DPOLYGEIST_ENABLE_POLYMER=1 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$(POLYGEIST_INSTALL)

when compiling the polybench gemm app with the following commands:

$(POLYGEIST_INSTALL)bin/cgeist -march=native -I $(POLYGEIST_INSTALL)lib/clang/18/omp/ -I /home/ben/Builds/PolygeistScripts/polybench-c-4.2.1-beta/utilities/ -D POLYBENCH_TIME -D POLYBENCH_NO_FLUSH_CACHE -D EXTRALARGE_DATASET -S gemm.c -o gemm.polymer.in.mlir $(POLYGEIST_INSTALL)bin/polymer-opt -reg2mem -insert-redundant-load -extract-scop-stmt -canonicalize -pluto-opt=dump-clast-after-pluto=gemm.polymer.cloog -canonicalize gemm.polymer.in.mlir > gemm.polymer.out.mlir

polymer-opt fails with: gemm.polymer.in.mlir:9:73: error: invalid memref element type llvm.mlir.global external @stderr() {addr_space = 0 : i32} : memref<?x!llvm.struct<(i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i64, i16, i8, array<1 x i8>, ptr, i64, ptr, ptr, ptr, ptr, i64, i32, array<20 x i8>)>>

Is there a workaround for this? If not, is this in the pipeline of things to fix?

pal-stdr commented 1 week ago

Hello @wsmoses First let me give you thanks for the polygeist. A great piece of work indeed.

OS: Ubuntu 20.04LTS Polygeist built with: -DPOLYGEIST_ENABLE_POLYMER=1

However, I have exactly same error for polymer-opt.

polymer-opt -allow-unregistered-dialect -reg2mem -insert-redundant-load -extract-scop-stmt -canonicalize -pluto-opt=dump-clast-after-pluto=/path/to/polygeist-polybench-benchmark-script/polybench-c-4.2.1-beta/linear-algebra/blas/gemm/gemm.c.cloog -canonicalize /path/to/gemm/gemm.c.cgeist.in.mlir > /path/to/gemm/gemm.c.polymer.out.mlir

# Output
/path/to/gemm/gemm.c.cgeist.in.mlir :9:73: error: invalid memref element type
  llvm.mlir.global external @stderr() {addr_space = 0 : i32} : memref<?x!llvm.struct<(i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i64, i16, i8, array<1 x i8>, ptr, i64, ptr, ptr, ptr, ptr, i64, i32, array<20 x i8>)>>

And this is how I build the polygeist

cmake   \
    -G Ninja    \
    -S ../  \
    -B .    \
    -DCMAKE_BUILD_TYPE=Debug      \
    -DCMAKE_INSTALL_PREFIX=../polygeist-installation  \
    -DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm  \
    -DCLANG_DIR=$LLVM_BUILD_DIR/lib/cmake/clang \
    -DMLIR_DIR=$LLVM_BUILD_DIR/lib/cmake/mlir   \
    -DLLVM_EXTERNAL_LIT=$LLVM_BUILD_DIR/bin/llvm-lit \
    -DPOLYGEIST_ENABLE_CUDA=1   \
    -DCMAKE_CUDA_COMPILER=$CUDA_NVCC_PATH    \
    -DPOLYGEIST_ENABLE_POLYMER=1    \
    -DPOLYGEIST_POLYMER_ENABLE_PLUTO=1  \
    -DLLVM_USE_LINKER=lld

@arun-thmn & @benroywillis Did you guys found any solution?

Thanks in advance!