Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arun-thmn opened this issue Feb 1, 2024 · 6 comments

Comments

@arun-thmn
Copy link

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
Copy link
Member

wsmoses commented Feb 1, 2024 via email

@arun-thmn
Copy link
Author

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
Copy link

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
Copy link

pal-stdr commented Oct 7, 2024

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!

@vincentloechner
Copy link

vincentloechner commented Feb 13, 2025

Hi all,
This is still not solved. Latest version of polygeist, compiled on Ubuntu 20.04 with -DPOLYGEIST_ENABLE_POLYMER=1.

$ 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 ./syr2k.mlir
./syr2k.mlir:10: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>)>>
                                                                        ^

It seems that the !llvm.struct from stderr (coming from the stdio.h include) is not handled by polymer-opt.

@keryell
Copy link
Contributor

keryell commented Feb 19, 2025

I am not using Polygeist but I am interested by struct support with MLIR standard dialects and curious about whether using !llvm.struct as used in Polygeist is usable while waiting for a good solution.
I thought that Polygeist was adding a MemRefElementTypeInterface to def LLVMStructType : LLVMType<"LLVMStruct", "struct", [ in https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td to explain that !llvm.struct are allowed inside memref<>.
But it looks like Polygeist does not use a patched version of MLIR.
Looking at https://github.com/llvm/Polygeist/blob/main/tools/polygeist-opt/polygeist-opt.cpp it looks like there is some cleverness to inject dynamically some new interfaces to a few LLVMIR dialect instructions, while registering them too.
By comparing to https://github.com/llvm/Polygeist/blob/main/tools/polymer/tools/polymer-opt/polymer-opt.cc it looks like all this boilerplate code is lacking.
@vincentloechner could you try copy-pasting most of the

class MemRefInsider
[...]
template <typename T>
struct PtrElementModel
[...]
registry.insert...
[...]
registry.addExtension...

After that, you should not use the dubious -allow-unregistered-dialect anymore.
This boiler plate code seems also duplicated in https://github.com/llvm/Polygeist/blob/main/tools/cgeist/driver.cc
I guess all this boilerplate code should be in a Polygeist library to be called by all the tools using Polygeist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants