简体   繁体   English

在CUDA C项目中使用C ++

[英]Using C++ in a CUDA C project

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. 我正在CUDA C中实现排序和流压缩算法。但是,我刚刚发现,自己以良好的性能实现这些算法并不是那么简单。 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++). 鉴于我正在使用矩阵,因此无法使用CUDPP,因此,尽管我避免使用CUDPP,但我将不得不使用推力库(我对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. 我一直在用C进行编程,我真的只想使用C ++来解决问题,所以基本上我想知道我是否可以在C中拥有大部分代码,然后再拥有少量C ++代码(我想我会必须使用“外部”功能),但我想确定在CUDA中是否可行。

Thanks in advance. 提前致谢。

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). 即使您可能认为所编译的任何.cu文件中的主机端代码都是C,但无论如何,它都是使用C ++编译器进行编译的(大多数CUDA内部都依赖于C ++功能进行编译)。 So you are actually working in C++ now without realizing it. 因此,您实际上正在使用C ++进行工作,而没有意识到。

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. 我们一直使用它来将一些CUDA函数包装到C ++类中(这是REAL的补充),然后将其与JNI包装在一起,以用于Java。 If we can do it, you can do it! 如果我们能做到,那你就可以做到! Have at it! 加油!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM