views:

105

answers:

1

I'm trying to use cmake to simplify distributing my OpenCL program. I have a kernel file which includes several headers and other source files, and I want to have a single self contained executable.

My plan is to have cmake run the C preprocessor on the kernel source, turning the cl file and its includes into a single unit which is easier to work with.

I can use add_custom_command to do it by calling gcc/clang with -E, but then I don't get the flags to include the right directories to find the various header files in the command, and I don't see an easy way to find all current include directories to use in the custom call to the compiler.

Is there a way to run only the C preprocessor on a file with the current cmake environment?

A: 

I would suggest a different approach.

  1. Build your kernel into a binary (example for ATI Stream: http://developer.amd.com/support/KnowledgeBase/Lists/KnowledgeBase/DispForm.aspx?ID=115 )

  2. Compile this binary data into your program (as a char[] blob) and load it when your program starts.

With cmake and custom targets this should be quite simple.

tauran
There is a small problem with that approach: since opencl binaries are implementation (and device specific for AMD cpu and gpu) you are locking yourself to the configuration you compiled this for (possibly even to the environment you built it with, since there is no guarantee the format won't change over time). So you are loosing the ability to run your compiled program on different harwareconfigurations (unless you include a binary for each possible device).
Grizzly
As OpenCL is for highly optimized calculations and the implementations and drivers (AMD/nVidia) continually improve as do the gpu devices, you would have to think about an update mechanism any way. Additionally OpenCL (AMD) provides the possibility to build the kernel for all known devices.
tauran