## Imbeding OpenCL code

Discussion related to the organization of the source code, repository and code-level/compiler optimization.

### Imbeding OpenCL code

I've noticed that LuxRays currently has two versions of each opencl code file:
one is a .cl file with the raw opencl code, and the other is a cpp file which looks like someone took the opencl code and turned it into a string. Now I would imagine that there might be some utility you're using to do this for you, but I recently found a method that Bullet Physics uses to imbed the opencl code into the executable:

The basic idea is to define a preprocessor macro which returns the string's contents, then inside your opencl source file surround everything with that macro.

Something like this:
cpp code file:
Code: Select all
#ifndef ocl_code#define ocl_code(code) #code#endifstd::string kernel(   #include "kernel.cl");// alternative string creationstd::string kernel2 = #include "kernel.cl";

kernel.cl:
Code: Select all
#ifndef ocl_code#define ocl_code(code) #code#endifocl_code(kernel void doIt(){})

Just a thought.
helloworld922

Posts: 57
Joined: Sat Jul 10, 2010 12:21 pm

### Re: Imbeding OpenCL code

Hi,

Interesting trick.

Jeanphi
jeanphi

Posts: 7943
Joined: Mon Jan 14, 2008 7:21 am