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

查看:312
本文介绍了使用nvcc(CUDA)编译特征库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用nvcc(CUDA 5.0 RC)编译以下程序(main.cu):

  #include< ; Eigen / Core> 
#include< iostream>

int main(int argc,char ** argv)
{
std :: cout< Pure CUDA< std :: endl;不幸的是,我收到了一些警告和错误,我只能解释使用nvcc而不是Microsoft编译。



这个假设是正确的吗?
有什么方法用nvcc编译Eigen吗? (我实际上不想传递Eigen矩阵到GPU,只是访问他们的成员)?



如果它不应该使用nvcc编译Eigen,



我使用的是CUDA 5.0 RC,Visual Studio 2008,Eigen 3.0.5。为了编译.cu文件,我使用了CUDA中包含的规则文件,以及CMake生成的自定义构建步骤。使用CUDA规则文件,我以计算能力3.0为目标。



感谢您的建议。



如果我编译相同的代码与主机编译器它工作完美。

解决方案

NVCC调用正常的主机编译器,它已经做了一些预处理,所以很可能是NVCC正在努力正确解析Eigen代码(特别是如果它使用C ++ 11功能,但这不太可能,因为你说VS2008工作)。



我通常建议将设备代码和包装器分成 .cu 文件,并将您的应用程序的其余部分保留在正常 .c / .cpp 文件直接由主机编译器处理。有关使用VS2008进行此设置的一些提示,请参见此答案


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;
}

Unfortunately, I get a bunch of warnings and errors I can only explain using nvcc instead of the Microsoft compile.

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)?

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?

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.

Thanks for your advice.

PS: If I compile the same code with the host compiler it works perfectly.

解决方案

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).

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)编译特征库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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