Compiling Eigen library with nvcc (CUDA)(使用 nvcc (CUDA) 编译 Eigen 库)
问题描述
我尝试使用 nvcc (CUDA 5.0 RC) 编译以下程序 (main.cu):
I tried to compile following program (main.cu) with the nvcc (CUDA 5.0 RC):
#include <Eigen/Core>
#include <iostream>
int main( int argc, char** argv )
{
std::cout << "Pure CUDA" << std::endl;
}
不幸的是,我收到一堆警告和错误,我只能使用 nvcc 而不是 Microsoft 编译来解释.
Unfortunately, I get a bunch of warnings and errors I can only explain using nvcc instead of the Microsoft compile.
这个假设正确吗?有没有办法用 nvcc 编译 Eigen?(我实际上不想将 Eigen 矩阵转移到 GPU,只是访问它们的成员)?
Is this assumption right? Is there any way to compile Eigen with nvcc? (I actually don´t want to transfer Eigen matrices to the GPU, just access their members)?
如果使用 nvcc 编译 Eigen 不起作用,是否有关于分离主机和设备代码的巧妙方法的不错的指南/教程?
If it should not work to compile Eigen with nvcc, is there a nice guide/tutorial about clever ways to seperate host and device code?
我正在使用 CUDA 5.0 RC、Visual Studio 2008、Eigen 3.0.5.为了编译我使用的 .cu 文件,CUDA 中包含的规则文件,以及 CMake 生成的自定义构建步骤.使用 CUDA 规则文件,我的构建目标是计算能力 3.0.
I am using CUDA 5.0 RC, Visual Studio 2008, Eigen 3.0.5. To compile the .cu file I used both, the rules file included in CUDA, aswell as the custom build step produced by CMake. Using the CUDA rule file, I targeted the build at compute capability 3.0.
感谢您的建议.
PS:如果我用宿主编译器编译相同的代码,它会完美运行.
PS: If I compile the same code with the host compiler it works perfectly.
推荐答案
NVCC 调用正常的主机编译器,但在它完成一些预处理之前,因此 NVCC 可能正在努力正确解析 Eigen 代码(特别是如果它使用C++11 的特性,但这不太可能,因为你说 VS2008 有效).
NVCC invokes the normal host compiler but not before it has done some preprocessing, so it's likely that NVCC is struggling to parse the Eigen code correctly (especially if it uses C++11 features, but that's unlikely since you say VS2008 works).
我通常建议将设备代码和包装器分离到 .cu
文件中,并将应用程序的其余部分留在普通 .c
/.cpp
文件由主机编译器直接处理.请参阅 this answer 了解有关使用 VS2008 进行此设置的一些提示.
I usually advise separating the device code and wrappers into the .cu
files and leaving the rest of your application in normal .c
/.cpp
files to be handled by the host compiler directly. See this answer for some tips on getting this set up with VS2008.
这篇关于使用 nvcc (CUDA) 编译 Eigen 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 nvcc (CUDA) 编译 Eigen 库


基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30