Compiling CUDA with clang

醉酒当歌 提交于 2019-12-17 20:43:08

问题


I am new to LLVM. I heard that clang supports CUDA. How do I compile CUDA using clang? Do I have to make some config changes or include any specific header files? I couldn't find any information on this on the web. Is it possible at all?

Right now when I try to compile a dummy cuda program with clang as

clang -I /usr/local/cuda/include filename.cu 

I get the following error

 unknown type name '__global__'

 __global__ void nothing(int *A)

any help is appreciated! btw i am running it in a mac.


回答1:


2016-05-01 Update: clang now supports CUDA. See @rivanvx' answer.

The CUDA compiler is based on LLVM. Clang, though also based on LLVM, does not support CUDA.




回答2:


Thanks to contributions from Google and others, Clang now supports building CUDA. Command line parameters are slightly different from nvcc, though. According to the official documentation, assuming your file is named axpy.cu, the basic usage is:

$ clang++ axpy.cu -o axpy --cuda-gpu-arch=<GPU arch>  \
    -L<CUDA install path>/<lib64 or lib>              \
    -lcudart_static -ldl -lrt -pthread

Note that using Clang for compiling CUDA still requires that you have the proprietary CUDA runtime from the NVIDIA CUDA toolkit installed.



来源:https://stackoverflow.com/questions/12099684/compiling-cuda-with-clang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!