Ada*_*dam 6 c c++ opencl c-preprocessor
我很久以前就用hlsl/glsl着色器代码看到了这一点 - 使用#include源代码文件将代码粘贴到一个代码中,char*以便在运行时不会发生文件IO.
如果我将它表示为伪代码,它看起来有点像这样:
#define CLSourceToString(filename) " #include "filename" "
const char* kernel = CLSourceToString("kernel.cl");
Run Code Online (Sandbox Code Playgroud)
现在当然#define不会起作用,因为它只会尝试使用这些引号来启动字符串.
grr*_*sel 12
有关如何对内核执行此操作,请参阅子弹物理引擎对OpenCL的使用.
在C++/C源代码中
#define MSTRINGIFY(A) #A
char* stringifiedSourceCL =
#include "VectorAddKernels.cl"
Run Code Online (Sandbox Code Playgroud)
在OpenCL源代码中
MSTRINGIFY(
__kernel void VectorAdd(__global float8* c)
{
// snipped out OpenCL code...
return;
}
);
Run Code Online (Sandbox Code Playgroud)