[CMake] Converting a OpenCL program into a C++ header?

Daniel Blezek Blezek.Daniel at mayo.edu
Tue Jun 15 17:56:48 EDT 2010


Hi Stefan,

  Yes, I¹ve done this sort of thing with Lua (which is built as part of our
code), but I¹d prefer to do this with CMake to avoid the extra headache of
maintaining my code.  I suspect it¹s just a few lines (but knowing the right
few lines is the key).

Thanks,
-dan


On 6/15/10 4:33 PM, "Stefan Buschmann" <s_buschmann at gmx.de> wrote:

> Am 15.06.2010 23:13, schrieb Daniel Blezek:
>>  Converting a OpenCL program into a C++ header? Hi,
>>  
>>   We would like to convert an OpenCL program written in a separate file to a
>> C++ header (essentially a long string).
>>  
>> For example, if my OpenCL program is in the file Square.cl
>>  
>> __kernel square(
>>    __global float* input,
>>    __global float* output,
>>    const unsigned int count)
>> {               
>>    int i = get_global_id(0);
>>    if(i < count)
>>        output[i] = input[i] * input[i];
>> }               
>>  
>> I¹d like to turn it into something like this in Square.h:
>>  
>> const char *KernelSource = "\n" \
>> "__kernel square(                                                       \n" \
>> "   __global float* input,                                              \n" \
>> "   __global float* output,                                             \n" \
>> "   const unsigned int count)                                           \n" \
>> "{                                                                      \n" \
>> "   int i = get_global_id(0);                                           \n" \
>> "   if(i < count)                                                       \n" \
>> "       output[i] = input[i] * input[i];                                \n" \
>> "}                                                                      \n" \
>> "\n";
>>  
>> So that my OpenCL code can be directly compiled into my executable.  This is
>> also useful for OpenGL shaders.
>>  
>> The question: is this something that CMake could do?  If so, any examples
>> where to begin looking?
>>  
> You could write a little application that reads in the source file and
> generates the header file just as in your example. Then you could use CMake to
> execute that application e.g. using add_custom_command() before building your
> executables that include the generated header files. You could even build the
> tool itself as a dependency first.
> 
> Hope that helps...
> 
> Stefan
> 
> 
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

-- 
Daniel Blezek, PhD
Medical Imaging Informatics Innovation Center

P 127 or (77) 8 8886
T 507 538 8886
E blezek.daniel at mayo.edu

Mayo Clinic
200 First St. S.W.
Harwick SL-44
Rochester, MN 55905
mayoclinic.org


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100615/c3fe193f/attachment.htm>


More information about the CMake mailing list