CUDA without nvcc
It is possible to compile CUDA programs for running on the GPU without using nvcc. This is what I'm doing in a project:
- Install the CUDA Toolkit
- Install a compiler capable of generating PTX assembly. I used clang 22.1, with the NVPTX target
- Compile your sources into LLVM bitcode, using
target
nvptx64-nvidia-cuda - Use llvm-link and opt to link all bitcode files. Optionally,
also merge
libdevicefrom the CUDA SDK - Generate ptx assembly code using llc
- Optionally, assemble the ptx into machine code using ptxas from the CUDA SDK
The resulting binary can be run on the GPU using the CUDA Driver API, and works fine with cuda-gdb, ncu, etc
An example program, including Makefile and host code, can be downloaded below.
Why do this instead of just using nvcc? One reason is that you can
compile your sources as C++ for OpenCL, which the NVIDIA drivers don't
support (actually the main reason I did all this). Another big reason
is that there is no need to add the __device
and/or __host function qualifiers to all functions in the
program, so there is less clutter in the source code.
| User: guest, password: guest (info) | |||
| cudatest.tar.xz [SIG] | example code | 3 KB | 2026-Jun-09 |