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
std::string kernel(   
#include ""

// alternative string creation
std::string kernel2 =
#include ""
Code: Select all
#ifndef ocl_code
#define ocl_code(code) #code
kernel void doIt()

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

Re: Imbeding OpenCL code

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


Interesting trick.

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