Boost logo

Boost :

Subject: Re: [boost] [compute] kernels as strings impairs readability and maintainability
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-12-25 06:19:14


On Thu, Dec 25, 2014 at 1:58 PM, Antony Polukhin <antoshkka_at_[hidden]> wrote:
>
> There is a possible hack for that case! You'll need two helper header files
> `import.pp` and `end_import.pp`. Something like the following could work
> (not tested).

[snip]

> That's it. Now if you need that kernel as a string, you just write the
> following:
>
> #define IMPORT_AS variable_name
> #include "import.pp"
> #include "kernel.cl"
> #include "end_import.pp"

I think raw string literals could make it cleaner:

#define BEGIN_CL "opencl(
#define END_CL )opencl"

const char cl_program[] =
#include "kernel.cl"

// In kernel.cl:

BEGIN_CL

<code here>

END_CL

I wonder how debugging goes in OpenCL though. If the kernel does not
compile or is not working, you probably get pointers to the kernel
string, not the C++ source. Is there a convenient way to translate
between the two?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk