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 [url="http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html"]OpenCL 1.0/1.1 clBuildProgram options[/url] , the NVIDIA extended ones from [url="http://developer.download.nvidia.com/compute/cuda/3_2_prod/toolkit/docs/OpenCL_Extensions/cl_nv_compiler_options.txt"]cl_nv_compiler_options[/url], 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.

[s]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.[/s]
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 - [attachment=19283:clcc.zip]
Linux x86 Release 1[attachment=19329:clcc.tar.gz]
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 - [attachment=19283:clcc.zip]

Linux x86 Release 1[attachment=19329:clcc.tar.gz]
Attachments

clcc.tar.gz

clcc.zip

#1
Posted 12/24/2010 09:06 AM   
I tried to compile but did not get any result file, just got " no error"
I tried to compile but did not get any result file, just got " no error"

#2
Posted 01/11/2011 01:44 PM   
What was the command you used?
What OS are you using?
What driver version do you have?
What was the command you used?

What OS are you using?

What driver version do you have?

#3
Posted 01/12/2011 09:55 AM   
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
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

#4
Posted 02/21/2011 03:10 PM   
[quote name='heipei' date='21 February 2011 - 05:10 PM' timestamp='1298301026' post='1196727']
I'd really like to see the source code to this.
[/quote]
Me too. As a side note, the chosen name of "clcc" is already taken by http://clcc.sourceforge.net/
[quote name='heipei' date='21 February 2011 - 05:10 PM' timestamp='1298301026' post='1196727']

I'd really like to see the source code to this.



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

#5
Posted 08/13/2011 09:19 PM   
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.

[quote name='eyebex' date='14 August 2011 - 09:19 AM' timestamp='1313270366' post='1278988']
Me too. As a side note, the chosen name of "clcc" is already taken by http://clcc.sourceforge.net/
[/quote]

Hmm that sucks.. Well if anyone can think of a better name!
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.

[quote name='eyebex' date='14 August 2011 - 09:19 AM' timestamp='1313270366' post='1278988']

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





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

#6
Posted 03/25/2012 06:50 AM   
[quote name='ljbadenz' date='25 March 2012 - 07:50 AM' timestamp='1332658232' post='1387564']
Hmm that sucks.. Well if anyone can think of a better name!
[/quote]
How about "cloc" (openCL Offline Compiler)?
[quote name='ljbadenz' date='25 March 2012 - 07:50 AM' timestamp='1332658232' post='1387564']

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



How about "cloc" (openCL Offline Compiler)?

#7
Posted 03/25/2012 09:34 AM   
Is "-cl-nv-arch sm_XX" still supported by toolkits 4.1/4.2?
I can't get it to work.
Is "-cl-nv-arch sm_XX" still supported by toolkits 4.1/4.2?

I can't get it to work.

#8
Posted 04/29/2012 11:15 AM   
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.
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.

#9
Posted 11/01/2012 05:25 PM   
Scroll To Top