clcc - an NVIDIA OpenCL command line compiler

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)

I tried to compile but did not get any result file, just got " no error"

What was the command you used?
What OS are you using?
What driver version do you have?

Wow, very interesting and nice to debug OpenCL programs without going through the ComputeCache.

I’d really like to see the source code to this. Strangely enough, it compiles a kernel of mine fine which hangs when using clBuildProgram, which I documented here: http://forums.nvidia.com/index.php?showtopic=193736

Me too. As a side note, the chosen name of “clcc” is already taken by http://clcc.sourceforge.net/

I finally tracked down the only version of the source I still have access to.

I have put it up on GitHub: https://github.com/ljbade/clcc

This version worked on Windows when I wrote it (back in December 2010) with the then current NVIDIA drivers.

I did test this code on Linux without any problems too but it might have needed a little tweaking and I can’t find the source code from when I compiled it on Linux.

The files include both Visual Studio 2008 for Windows build, and a Code Blocks project for Linux build.

If you get it working OK with current drivers for Linux please send me any changes and a Makefile if you created one and I will add it to git.

I will have a go at testing it on a spare Linux PC next week as well as on Windows to see if it needs fixing.

Hmm that sucks… Well if anyone can think of a better name!

How about “cloc” (openCL Offline Compiler)?

Is “-cl-nv-arch sm_XX” still supported by toolkits 4.1/4.2?
I can’t get it to work.

Finally these forums are back!

A few updates about CLCC - The github now includes a Linux build script thanks to a contributor and a bug fix for Linux.

I haven’t tested it for a while as I have been using AMD cards for the past year so tell me if it does not work - preferably via GitHub issues page.

And if anyone has fixes/tweaks/new features be sure to submit your code to me.