使用 C++在 CUDA C 项目中
我正在 CUDA C 中实现排序和流压缩算法。但是我刚刚发现自己实现这些算法并具有良好的性能并不是那么简单。鉴于我正在处理矩阵,我无法使用 CUDPP,因此,尽管我在避免使用它,但我将不得不使用推力库(我对 C++ 一无所知)。
我一直在用 C 编程,我真的只是想使用 C++ 来工作,所以基本上我想知道我是否可以用 C 语言编写大部分代码,然后使用少量的 C++ 代码(我猜我会的)必须使用“外部”函数)但我想确定它在 CUDA 中是否可行。
提前致谢。
I am implementing a sort and stream compaction algorithms in CUDA C. However I have just figured that it is not that simple to implement those algorithms by myself with good performance. Given that I am working with matrices I cannot use CUDPP, so, although I was avoiding it, I will have to work with thrust library(I know nothing of C++).
I have been programing in C, and I really just want to use C++ to work with thrust, so basically I want to know if I can have most of my code in C and then have little bits of C++ code(I am guessing I will have to use the "external" function) but I wanted to be sure if it's feasible in CUDA.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在主机代码方面,thrust 的集成很简单。即使您可能认为您编译的任何 .cu 文件中的主机端代码都是 C,但无论如何它都是使用 C++ 编译器进行编译的(大多数 CUDA 内部依赖于 C++ 功能来编译)。所以你现在实际上正在使用 C++ 工作而没有意识到。
On the host code side, thrust is simple to integrate. Even though you might think that your host side code in any .cu file you compile is C, it is compiled using a C++ compiler anyway (most of CUDA internally relies on C++ features to compile). So you are actually working in C++ now without realizing it.
是的,可能会使您的构建过程复杂化,但其他方面工作正常。我们一直使用它来将一些 CUDA 函数包装到 C++ 类中(这是真正的亮点),然后用 JNI 包装以在 Java 中使用。如果我们能做到,您也能做到!努力吧!
Yes, might complicate your build process but otherwise works fine. We use it all the time to wrap up some CUDA functions into C++ class which (and this is the REAL kicker) are then wrapped up with JNI for use in Java. If we can do it, you can do it! Have at it!