I am trying to convert a CUDA program (.cu) that does vector addition. I was able to lower the CUDA (.cu) to llvm (.ll) and then to llvm-mlir using clang and mlir-translate. But I need to lower it to mlir with other dialects like linalg or gpu etc. Is there any way of doing so? Thanks!
PS: I tried Polygiest but was not able to figure out.
Since ClangIR also has a CU → CIR → Core Dialects pipeline, you could try playing with that and see what you can get (note sure anyone has tested that yet though).
Also @wsmoses@chelini for Polygeist, it should support CUDA. It would have been more helpful if you specifically explained what you tried and what the problem was.
Got it working. Had to set the environment variable as export CPLUS_INCLUDE_PATH=Exp/Polygeist/llvm-project/build/lib/clang/18/include and then ran Exp/Polygeist/build/bin/cgeist test2.cu --cuda-gpu-arch=sm_86 --cuda-path=/usr/local/cuda --nocudalib -I/usr/local/cuda/include -I/usr/lib/gcc/x86_64-linux-gnu/11/include --immediate
The IR consists of llvm, arith, scf, gpu etc. dialects though.
I was going to say --nocudainc looks suspicious, you don’t want to remove CUDA definitions from consideration. You may also need to pass --resource-dir to cgeist explicitly by first querying it from clang --print-resource-dir using the clang you built.
Ran with the modified flags, it generates the same code with or without the --nocudalib, I added the --resource-dir. Also, Polegeist dialect op also appears.
nocudalib disables linking with libdevice, so it will not have any effect on compilation itself. The original compilation string had nocudainc, which disables inclusion of system-level CUDA headers leading to undeclared symbol errors.