我可以从 C++ 调用 CUDA 运行时函数吗?代码不是由 nvcc 编译的?
有什么方法可以调用 CUDA 运行时函数调用,例如
cudaMemcpy(...);
在使用常规 C++ 编译器编译的 .cpp 文件中?
Is there any way I can call CUDA runtime function calls such as
cudaMemcpy(...);
in a .cpp file, compiled with a regular C++ compiler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:这里有一个示例,但不再找到,但大多数该示例的内容复制如下。
调用者 C(但可以是 C++)
被调用者 (CUDA)
EDIT: There was an example here but it's not longer found, but most of the example was copied below.
The caller C (but could be C++)
The Callee (CUDA)
与@PreetSangha(提供了一个非常有用的答案)类似,我在将其作为
extern ...
运行时遇到了一些问题,所以我只想添加对我有用的解决方案(包括模板化函数调用) )。这是我的示例的代码(完整的 CUDA 代码被排除,因为它已经在 @PreetSangha 的示例中),并且应该给出其工作原理的主要想法。它被编译并确认可以在Linux机器上运行。我还没有在 Windows 上尝试过,但应该类似。在我的场景中,我想尝试
int
、float
和double
,但可以添加更多模板。Similarly to @PreetSangha (who provided a very useful answer), I had some issues when running it as
extern ...
so I would just like to add the solution which worked for me (including templated function calls).This is the code for my example (the full CUDA code is excluded because it is already in @PreetSangha's example) and is supposed to give a main idea on how it works. It was compiled and confirmed to run on a linux machine. I haven't tried it on windows yet but should be similar. In my scenario I wanted to try
int
,float
anddouble
but more templates could be added.您可以
用于编译或
you can use
for compile or