我可以嵌入 C++ OpenCL 内核中的类?
是否有可能在 OpenCL 内核中使用自定义的 C++ 类? 它应该像这样工作:
#include "element.cpp"
__kernel void do_something(__global element* input, __global element* output);
{
int index = get_global_id(0);
output[index] = input[index].update(index);
}
这很有趣,因为您可以指定之后必须在 element::update(int no) 中完成的工作。
我没有让它发挥作用。这是 OpenCL 编译器告诉我的:
未知类型名称“类”
在 CUDA 中这是有效的。如果 OpenCL 内核中的对象方法不起作用,还有其他想法吗?
感谢您提前的提示!
is there a possibility to use self-defined C++ - classes in an OpenCL kernel?
It should work like this:
#include "element.cpp"
__kernel void do_something(__global element* input, __global element* output);
{
int index = get_global_id(0);
output[index] = input[index].update(index);
}
This is interesting, because you can specify the work that must be done in element::update(int no) afterwards.
I did not get it to work. This is what the OpenCL-Compiler tells me:
unknown type name 'class'
In CUDA this works. Are there any other ideas, if the approach with objects in the OpenCL kernel does not work?
Thanks for your hints in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信 OpenCL 遵循 C99 语言规范而不是 C++。 OpenCL 的 C++ 版本规范正在进行中。我相信AMD APP已经实现了OpenCL的C++版本。回到你的问题,我认为最好有一个结构体作为 C++ 和 C 之间的接口。C++ 版本应该是 C 实现的包装器,如果你迫切需要这样做的话。
编辑:我无法将其放在评论中,因此将其放在这里。 AMD 围绕 OpenCL 的 C++ 库包括 静态 C++库 和 螺栓。
I believe OpenCL follows C99 language specification and not C++. The specifications for C++ version of OpenCL is going on. I believe AMD APP has implemented the C++ version of OpenCL. Coming back to your question, I think it's best to have a struct as the interface between C++ and C. The C++ version should be a wrapper around the C implementation, IF you direly need to do so.
EDIT: I couldn't place this in comments, hence putting it here. AMD's C++ libraries around OpenCL include a static C++ library and Bolt.
不可以。OpenCL 语言扩展了C99,因此不支持C++ 关键字和功能,例如“class”。
如果您要应用的代码既是 C++ 又是 OpenCL,即在两者的公共子集中,您可以
根据需要在 OpenCL 或 C++ 中拥有类似的东西并调用它,例如,
假设该元素是一个结构体,而不是具有非C 类型。
一般来说,OpenCL 的输入和输出必须是简单的结构或数组,而不是类。
No. The OpenCL language extends C99, and therefore does not have support for C++ keywords and features, e.g. "class".
If your code to apply is both C++ and OpenCL i.e. in the common subset of both, you could have something similar to
and invoke that in either OpenCL or C++, as desired e.g.
provided that element is a struct, and not with fields of non-C types.
In general, the inputs and outputs to OpenCL must be simple structs or arrays, not classes.
不,其他人告诉您 OpenCL 基于 C99,因此您可以使用类似的结构
No, others as they tell you OpenCL is based in C99 therefore you can use structs like