使用#include装载OpenCL代码
问题描述:
很久以前,我已经看到了这样做,使用hlsl / glsl着色器代码 - 在源代码文件中使用 #include
将代码粘贴到 char *
,以便在运行时不会发生文件IO。
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");
当然, #define
isn'
答
See the bullet physics engines use of OpenCL for how to do this to a kernel.
在C ++ / C源中
In C++ / C source
#define MSTRINGIFY(A) #A
char* stringifiedSourceCL =
#include "VectorAddKernels.cl"
/ p>
In the OpenCL source
MSTRINGIFY(
__kernel void VectorAdd(__global float8* c)
{
// snipped out OpenCL code...
return;
}
);