llvm / llvm/Polygeist

CUDA program to LLVM

Open
#439 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
624
Forks
170
PR merge metrics
No merged PRs in 30d

Description

Hi, I was trying to convert the official CUDA Sample [vectorAdd program](https://github.com/NVIDIA/cuda-samples/blob/master/Samples/0_Introduction/vectorAdd/vectorAdd.cu) to mlir and llvm using Polygeist. The Polygeist was built using these commands:

**LLVM-PROJECT BUILD**
`cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="clang;mlir;lld" \
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi" \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX" \
-DMLIR_ENABLE_CUDA_RUNNER=ON \
-DMLIR_ENABLE_EXECUTION_ENGINE=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
-DCMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES=/usr/local/cuda/include \
-DCLANG_LINKER_WRAPPER_ENABLED=OFF`

`ninja`

**POLYGEIST BUILD**
`cmake -G Ninja .. \
-DMLIR_DIR=$PWD/../llvm-project/build/lib/cmake/mlir \
-DCLANG_DIR=$PWD/../llvm-project/build/lib/cmake/clang \
-DPOLYGEIST_ENABLE_CUDA=1 \
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_RTTI=ON \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES=/usr/local/cuda/include`

`ninja`

The program converts to mlir without any errors using:
`./cgeist --immediate -cuda-path=/usr/local/cuda -I/usr/local/cuda/include -I/usr/lib/gcc/x86_64-linux-gnu/11/include --resource-dir=/local/Polygeist/llvm-project/build/lib/clang/18 -I/local/cuda-samples/Common --cuda-gpu-arch=sm_86 vectorAdd.cu`
The ouput is [MLIR_trace.txt](https://github.com/user-attachments/files/20614908/MLIR_trace.txt)

But when I directly try to convert the using:
`./cgeist -cuda-path=/usr/local/cuda -I/usr/local/cuda/include -I/usr/lib/gcc/x86_64-linux-gnu/11/include --resource-dir=/local/Polygeist/llvm-project/build/lib/clang/18 -I/local/cuda-samples/Common --cuda-gpu-arch=sm_86 vectorAdd.cu`
The ouput is [LLVM_trace.txt](https://github.com/user-attachments/files/20614894/LLVM_trace.txt)

Are there any steps that I am missing? What can be the issue? Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the cgeist commands in the issue and compare the attached MLIR_trace.txt and LLVM_trace.txt outputs. Read the CUDA vectorAdd.cu sample and Polygeist's direct conversion entry point to determine why immediate conversion succeeds while direct conversion does not. Done means identifying the missing step or reproducible cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.