how do I invoke the OpenCL compiler

rather simple question:

In Linux/Ubuntu 10.04 LTS,
Having installed NVIDIA’s CUDA sdk, (CUDA is operational)
Having installed the necessary libs so that the OpenCL examples are building ok using make,
how do I invoke the OpenCL compiler on a specific source file?

You call clBuildProgram within your source-code.

Code cannot be compiled off-line, as you will never know what devices the code might run on.

I did not make myself clear:
How do I compile the host code (not the device code, which is dynamically compiled with clBuildProgram).
Initially I thought the host code is compiled by gcc, but since OpenCL has some language constructs that are not part of the C language, … it should be something else.

gcc works fine to compile the host code. As for the language constructs of OpenCL, that are not part of C, you just have to include the OpenCL library ("#include <CL/cl.h>").

Check the demo programs in your Nvidia SDK, they probably also use gcc.

Thanks,

This one compiles:

g++ -L/usr/local/cuda/lib64 -lOpenCL -I/usr/local/cuda/include -I/home/onto/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc -I/home/onto/NVIDIA_GPU_Computing_SDK/shared/inc oclVectorAdd.cpp

but does not link, due to these:
oclVectorAdd.cpp:(.text+0x33): undefined reference to shrCheckCmdLineFlag' oclVectorAdd.cpp:(.text+0x51): undefined reference toshrSetLogFileName’
oclVectorAdd.cpp:(.text+0x70): undefined reference to shrLog' oclVectorAdd.cpp:(.text+0x91): undefined reference toshrRoundUp’
oclVectorAdd.cpp:(.text+0xef): undefined reference to shrLog' oclVectorAdd.cpp:(.text+0xfe): undefined reference toshrLog’
oclVectorAdd.cpp:(.text+0x17e): undefined reference to shrFillArray' oclVectorAdd.cpp:(.text+0x195): undefined reference toshrFillArray’
oclVectorAdd.cpp:(.text+0x1be): undefined reference to `shrLog’

Any idea which is the missing library ?

[quote=“stenlee”]

I did not make myself clear:
How do I compile the host code (not the device code, which is dynamically compiled with clBuildProgram).
Initially I thought the host code is compiled by gcc, but since OpenCL has some language constructs that are not part of the C language, … it should be something else.[/quote]

Oh right, well that isn’t the opencl compiler. It’s just a C++ compiler.

The C (acutally it seems you mean C++, which is a totally different language) code doesn’t include any opencl-specific constructs, just library calls like any other code.

You just run ‘make’ for the examples. Some of them them use more than one file or some library functions common within the examples and you can’t compile the source files one by one without too much hassles.

There’s a certain library that is missing:

[b]

shrutil_x86_64

[/b]

I’ve been able to short-circuit the problem, by adding
~/NVIDIA_GPU_Computing_SDK/shared/obj/x86_64/release/shrUtils.cpp.o
to the linker command line, but obviously that is not the right way to go.

I couldn’t figure out where do I get this lib from?

That’s just stuff that nvidia puts in its SDK examples, for code that is shared by all of them (things like parsing the command line and selecting a gpu). It has nothing to do with OpenCL.