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.
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.
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.
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.
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.
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;
}
);
According to this, it's not possible, but you can use xxd -i
to archieve the same effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With