使用 nvcc (CUDA) 编译 Eigen 库 [英] Compiling Eigen library with nvcc (CUDA)

查看:79
本文介绍了使用 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 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆