为什么 nvcc 无法使用 boost::spirit 编译 CUDA 文件?

发布于 2024-12-15 16:03:47 字数 458 浏览 4 评论 0原文

我正在尝试将 CUDA 集成到使用 boost::spirit 的现有应用程序中。

隔离问题,我发现以下代码无法与 nvcc 进行编译:

main.cu:

#include <boost/spirit/include/qi.hpp>
int main(){
    exit(0);
}

Compiling with nvcc -o cudaTest main.cu 我得到了很多可以在此处看到错误。

但是,如果我将文件名更改为 main.cpp,并使用 nvcc 再次编译,它就可以工作。这里发生了什么以及我该如何解决它?

I'm trying to integrate CUDA to an existing aplication wich uses boost::spirit.

Isolating the problem, I've found out that the following code does not copile with nvcc:

main.cu:

#include <boost/spirit/include/qi.hpp>
int main(){
    exit(0);
}

Compiling with nvcc -o cudaTest main.cu I get a lot of errors that can be seen here.

But if I change the filename to main.cpp, and compile again using nvcc, it works. What is happening here and how can I fix it?

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

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

发布评论

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

评论(1

暮凉 2024-12-22 16:03:47

nvcc 有时在编译复杂的模板代码(例如 Boost 中的代码)时会遇到问题,即使该代码仅在 __host__ 函数中使用。

当文件的扩展名是 .cpp 时,nvcc 本身不执行解析,而是将代码转发到主机编译器,这就是为什么您会根据文件扩展名观察到不同的行为。

如果可能,尝试将依赖于 Boost 的代码隔离到不需要由 nvcc 解析的 .cpp 文件中。

我还要确保尝试使用最新的 CUDA 附带的 nvcc 4.1nvcc 的模板支持随着每个版本的发布而改进。

nvcc sometimes has trouble compiling complex template code such as is found in Boost, even if the code is only used in __host__ functions.

When a file's extension is .cpp, nvcc performs no parsing itself and instead forwards the code to the host compiler, which is why you observe different behavior depending on the file extension.

If possible, try to quarantine code which depends on Boost into .cpp files which needn't be parsed by nvcc.

I'd also make sure to try the nvcc which ships with the recent CUDA 4.1. nvcc's template support improves with each release.

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