Imbeding OpenCL code

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

Moderators: Dade, coordinators

Imbeding OpenCL code

Postby helloworld922 » Wed Nov 23, 2011 3:26 pm

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
#endif
std::string kernel(   
#include "kernel.cl"
);

// alternative string creation
std::string kernel2 =
#include "kernel.cl"
;



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


Just a thought.
helloworld922
 
Posts: 57
Joined: Sat Jul 10, 2010 12:21 pm

Re: Imbeding OpenCL code

Postby jeanphi » Fri Nov 25, 2011 12:55 am

Hi,

Interesting trick.

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


Return to Organization & Optimization

Who is online

Users browsing this forum: No registered users and 1 guest