如何构建大型 OpenCL 内核?
我曾在几个项目中使用 OpenCL,但总是将内核编写为一个(有时相当大)函数。现在我正在开发一个更复杂的项目,并且希望跨多个内核共享功能。
但我能找到的示例都将内核显示为单个文件(很少甚至调用辅助函数)。似乎应该可以使用多个文件 - clCreateProgramWithSource()
接受多个字符串(并组合它们,我认为) - 尽管 pyopencl 的 Program()
仅需要一个字符串来源。
所以我想听听有这方面经验的人的意见:
- 是否存在与多个源文件相关的问题?
- pyopencl 简单连接文件的最佳解决方法是?
- 有什么方法可以编译函数库(而不是在每个内核中传递库源代码,即使不是全部都使用)?
- 如果每次都需要传入库源,未使用的函数是否会被丢弃(无开销)?
- 还有其他最佳实践/建议吗?
谢谢。
I have worked with OpenCL on a couple of projects, but have always written the kernel as one (sometimes rather large) function. Now I am working on a more complex project and would like to share functions across several kernels.
But the examples I can find all show the kernel as a single file (very few even call secondary functions). It seems like it should be possible to use multiple files - clCreateProgramWithSource()
accepts multiple strings (and combines them, I assume) - although pyopencl's Program()
takes only a single source.
So I would like to hear from anyone with experience doing this:
- Are there any problems associated with multiple source files?
- Is the best workaround for pyopencl to simply concatenate files?
- Is there any way to compile a library of functions (instead of passing in the library source with each kernel, even if not all are used)?
- If it's necessary to pass in the library source every time, are unused functions discarded (no overhead)?
- Any other best practices/suggestions?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为 OpenCL 有程序中多个源文件的概念 - 程序是一个编译单元。但是,您可以使用 #include 并在编译时引入标头或其他 .cl 文件。
OpenCL 程序中可以有多个内核 - 因此,在一次编译后,您可以调用已编译的一组内核中的任何一个。
任何未使用的代码(函数或静态已知无法访问的任何代码)都可以假定在编译期间被消除,但编译时间成本较小。
I don't think OpenCL has a concept of multiple source files in a program - a program is one compilation unit. You can, however, use #include and pull in headers or other .cl files at compile time.
You can have multiple kernels in an OpenCL program - so, after one compilation, you can invoke any of the set of kernels compiled.
Any code not used - functions, or anything statically known to be unreachable - can be assumed to be eliminated during compilation, at some minor cost to compile time.
在 OpenCL 1.2 中,您将不同的目标文件链接在一起。
In OpenCL 1.2 you link different object files together.