CUDA 和 STL 向量

发布于 2024-09-14 08:53:46 字数 368 浏览 3 评论 0原文

刚刚了解到许多 cpp 功能(包括 stl 矢量类)在 cu 文件中不起作用。即使在主机代码中使用它们也是如此。

由于我必须使用使用 STL 的 C++ 类,因此我无法编译调用内核的 CU 文件。 (我没有在 CU 文件中使用任何 STL 功能,但我认为 include 是问题所在。)

我尝试使用 cmake 来构建它,

cuda_add_executable(
Blah
Blah.cu
BlahKernel.cu
HostCodeWithVector.cpp
)

但这显然不起作用。现在出现的问题是,是否可以使用 gcc 而不是 nvcc 构建 HostCodeWithVector.cpp 并以某种方式链接它..?

Having just learned that many cpp features (including the stl vector class) do not work in cu files. Even when using them in the host code.

Since I have to use a C++ class which uses STL I cannot compile my CU file which invokes the kernel. (I don't use any STL features in the CU file, but I think the include is the problem.)

I tried to build this by using cmake with

cuda_add_executable(
Blah
Blah.cu
BlahKernel.cu
HostCodeWithVector.cpp
)

which obviously doesn't work. The question now arises if it's possible to build HostCodeWithVector.cpp with gcc instead of nvcc and the link it somehow..?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末 2024-09-21 08:53:46

由于 __host__ 正是在您的 CPU 上运行的内容,因此您可以使用任何编译器(MSVC、gcc)编译此部分,然后与 nvcc 结果链接。因此,您应该只在 CU 文件中保留 GPU 互操作,其他所有内容都放入 CPP 中。

since __host__ is just what runs on your CPU you can compile this part using any compiler (MSVC, gcc) and then link with nvcc result. So you should just leave only GPU interop in CU files, everything else put into CPP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文