Dear LLVM-Developers and Vinod Grover,
we are trying to extend the cling C++ interpreter () with CUDA functionality for Nvidia GPUs. I already developed a prototype based on OrcJIT and am seeking for feedback. I am currently a stuck with a runtime issue, on which my interpreter prototype fails to execute kernels with a CUDA runtime error.
=== How to use the prototype
This application interprets cuda runtime code. The program needs the whole cuda-program (.cu-file) and its pre-compiled device code (as fatbin) as an input:
command: cuda-interpreter [source].cu [kernels].fatbin
I also implemented an alternative mode, which is generating an object file. The object file can be linked (ld) to an exectuable. This mode is just implemented to check if the LLVM module generation works as expected. Activate it by changing the define INTERPRET from 1 to 0 .
The prototype is based on the clang example in
I also pushed the source code to github with the install instructions and examples: The device code generation can be performed with either clang’s CUDA frontend or NVCC to ptx. Here is the workflow in five stages:
- generating ptx device code (a kind of nvidia assembler)
- translate ptx to sass (machine code of ptx)
- generate a fatbinray (a kind of wrapper for the device code)
- generate host code object file (use fatbinary as input)
- link to executable
(The exact commands are stored in the commands.txt in the github repo)
The interpreter replaces the 4th and 5th step. It interprets the host code with pre-compiled device code as fatbinary. The fatbinary (Step 1 to 3) will be generated with the clang compiler and the nvidia tools ptxas and fatbinary.
=== Test Cases and Issues
You find the test sources on GitHub in the directory “example_prog”.
Run the tests with cuda-interpeter and the two arguments as above:
 path to the source code in “example_prog”
- note: even for host-only code, use the file-ending .cu
 path to the runtime .fatbin
- note: needs the file ending .fatbin
- a fatbin file is necessary, but if the program doesn’t need a kernel, the content of the file will ignore
Note: As a prototype, the input is just static and barely checked yet.
hello.cu: simple c++ hello world program with cmath library call sqrt() → works without problems
pthread_test.cu: c++ program, which starts a second thread → works without problems
fat_memory.cu: use cuda library and allocate about 191 MB of VRAM. After the allocation, the program waits for 3 seconds, so you can check the memory usage with the nvidia-smi → works without problems
runtime.cu: combine cuda library with a simple cuda kernel → Generating an object file, which can be linked (see 5th call in commands above → ld …) to a working executable.
The last example has the following issues: Running the executable works fine. Interpreting the code instead does not work. The Cuda Runtime returns the error 8 (cudaErrorInvalidDeviceFunction) , the kernel failed.
Do you have any idea how to proceed?