how to compile CUDA to llvm IR?

2019-02-15 08:02发布

问题:

I've been trying for three days to compile a CUDA kernel into llvm IR and I couldn't do it. I've changed langoptions.cpp and added CUDA=1; in the constructor , but still the clang give me Error messages for cuda syntax (like _synchthreads() call). I've done the following:

  1. downloaded llvm (including clang) modified langoptions.cpp (CUDA=1; in the constructor), and installed it.
  2. installed CUDA toolkit 4.1 and CUDA SDK.
  3. compiled a CUDA example using clang using:

    clang -I${CUDA_HOME}/include -I${CUDA_SDK_INC}
    ~/workspace/cuda_example/mis_kernel.cu -S -emit-llvm -o
    ~/workspace/cuda_example/a.ll
    

and as I said it doesn't work.

回答1:

clang –x=CUDA in the public LLVM trunk is something experimental done outside of NVIDIA; you should contact the llvm-dev alias with questions.

NVCC doesn't support emitting LLVM IR.