Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using #include to load OpenCL code

I've seen this done long ago with hlsl/glsl shader code -- using an #include on the source code file that pastes the code into a char* so that no file IO happens at runtime.

If I were to represent it as pseudo-code, it would look a little like this:

#define CLSourceToString(filename) " #include "filename" "
const char* kernel = CLSourceToString("kernel.cl");

Now of course that #define isn't going to work because it'll just try to use those quotation marks to start strings.

like image 637
Adam Avatar asked Sep 12 '09 16:09

Adam


People also ask

What Is the mean of using?

1 : to put into action or service : avail oneself of : employ. 2 : to expend or consume by putting to use —often used with up. 3 : stand sense 1d the house could use a coat of paint. 4 : to consume or take (liquor, drugs, etc.) regularly.

What is the synonym of using?

The words employ and utilize are common synonyms of use. While all three words mean "to put into service especially to attain an end," use implies availing oneself of something as a means or instrument to an end. willing to use any means to achieve her ends.

What is the verb of using?

verb (used with object), used, us·ing. to employ for some purpose; put into service; make use of: to use a knife. to avail oneself of; apply to one's own purposes: to use the facilities. to expend or consume in use: We have used the money provided.

What Is the act of using something?

noun. the act of employing, using, or putting into service: the use of tools. the state of being employed or used. an instance or way of employing or using something: proper use of the tool; the painter's use of color. a way of being employed or used; a purpose for which something is used: He was of temporary use.


2 Answers

See the bullet physics engines use of OpenCL for how to do this to a kernel.

In C++ / C source

#define MSTRINGIFY(A) #A
char* stringifiedSourceCL = 
#include "VectorAddKernels.cl"

In the OpenCL source

MSTRINGIFY(
   __kernel void VectorAdd(__global float8* c)
   {
    // snipped out OpenCL code...
    return;
   }
);
like image 170
grrussel Avatar answered Oct 21 '22 05:10

grrussel


According to this, it's not possible, but you can use xxd -i to archieve the same effect.

like image 32
sepp2k Avatar answered Oct 21 '22 04:10

sepp2k