使用#include加载OpenCL代码

发布于 2024-08-04 18:28:19 字数 348 浏览 2 评论 0原文

我很久以前就看到过使用 hlsl/glsl 着色器代码完成此操作 - 在源代码文件上使用 #include 将代码粘贴到 char* 中,这样就不会文件 IO 发生在运行时。

如果我将它表示为伪代码,它看起来有点像这样:

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

现在当然,#define 不起作用,因为它只是尝试使用这些引号来启动字符串。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诺曦 2024-08-11 18:28:19

请参阅 OpenCL 的子弹物理引擎使用 如何内核

在 C++ / C 源代码中

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

在 OpenCL 源代码中

MSTRINGIFY(
   __kernel void VectorAdd(__global float8* c)
   {
    // snipped out OpenCL code...
    return;
   }
);

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;
   }
);
穿越时光隧道 2024-08-11 18:28:19

根据 ,这是不可能的,但您可以使用 xxd -i 来达到相同的效果。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文