I was having problems with the NVIDIA compiler crashing on my code. As I was poking around trying to figure out what was causing the crash, I figured out the shared library interface to the NVIDIA OpenCL clang/llvm compiler.
I created a little program that uses this compiler (bundled with the drivers) to do command line compiling of code.
I hope this will be useful to people who want to integrate a OpenCL C to PTX compiler into their build chain. You might be able to run ptxas on the resulting PTX file to get cubin, but I have not yet investigated if clCreateProgramWithBinary will accept cubin.
The other useful feature is that you can control the compiler options to select a different target CUDA Compute Level (sm_XX) than the card currently installed. You can even run the compiler without needing a GPU installed at all - just extract needed nvcompiler.dll/nvcompiler32.dll/libnvidia-compiler.so file from the latest driver installer. I imagine this will be useful for automated/dedicated build machines that likely lack a GPU.
The format of the command is this:
clcc [“build-options”] input.cl output.cl
“build-options” - a quoted string containing the build options to pass to the NVIDIA compiler (equivalent to clBuildProgram’s options string).
It accepts all the OpenCL 1.0/1.1 clBuildProgram options , the NVIDIA extended ones from cl_nv_compiler_options, and these hidden extras:
-cl-nv-arch sm_XX - selects the target CUDA Compute Level architecture to compile for (sm_10 for 1.0, sm_11 for 1.1, sm_12 for 1.2, sm_13 for 1.3 and sm_20 for 2.0 (Fermi))
–cl-nv-cstd=CLX.X - selects the target OpenCL C language version (CL1.0 or CL1.1)
(there may be others)
input.cl - the source OpenCL C file
output.ptx - the destination PTX file
Currently I only support one input per PTX file, but the API supports multiple inputs so I may add that feature.
Also I only have a Windows binary, but I have tested the program on Linux and it works the same as Windows so I will release a Linux binary next week.
EDIT: I have now attached a Linux build
Try it out, test it, use it etc. and give me feedback, bugs, suggestions etc.
Windows x86 Release 1 -
clcc.zip (4.21 KB)
Linux x86 Release 1
clcc.tar.gz (3.04 KB)