成员“已经被声明为”与CUDA和Eigen的误差 [英] Member "has already been declared" error with CUDA and Eigen

查看:1175
本文介绍了成员“已经被声明为”与CUDA和Eigen的误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是一个CUDA和Nsight的初学者,想利用线性代数运算(例如CUBLAS)伟大的GPU性能。我有很多自定义代码,在 Eigen 的帮助下编写是很多矩阵乘法运算,所以我想让我的代码不变,只是做GPU上的操作。

I'm just a beginner with CUDA and Nsight and want to utilize great GPU performance with linear algebra operations (e.g. CUBLAS). I've got a lots of custom code written with the help of Eigen and there are lots of matrix multiplication operations, so I wanted to have my code unchanged, just do those operations on GPU.

我已经创建了一个示例项目与Visual Studio Nsight和它工作正常,但当我添加

I've created a sample project with Visual Studio Nsight and it worked fine, but when I add

#include <Eigen/Dense>

行,我遇到以下错误

1>------ Build started: Project: MatrixPerformanceCompare, Configuration: Debug Win32 ------
1>  Compiling CUDA source file kernel.cu...
1>  
1>  C:\CUDA\Progs\VS\SampleProject\MatrixPerformanceCompare>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin"  -Ic:\CUDA\Progs\VS\SampleProject\MatrixPerformanceCompare\include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\kernel.cu.obj "C:\CUDA\Progs\VS\SampleProject\MatrixPerformanceCompare\kernel.cu" 
1>c:\cuda\progs\vs\sampleproject\matrixperformancecompare\include\eigen\src/Core/Block.h(102): error : "operator=" has already been declared in the current scope
1>c:\cuda\progs\vs\sampleproject\matrixperformancecompare\include\eigen\src/Core/Ref.h(122): error : "operator=" has already been declared in the current scope
1>c:\cuda\progs\vs\sampleproject\matrixperformancecompare\include\eigen\src/Core/products/Parallelizer.h(20): warning : variable "m_maxThreads" was set but never used
1>c:\cuda\progs\vs\sampleproject\matrixperformancecompare\include\eigen\src/Geometry/RotationBase.h(76): error : function template "Eigen::operator*(const Eigen::EigenBase<OtherDerived> &, const Eigen::Quaternion<_Scalar, _Options> &)" has already been defined
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 5.5.targets(592,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin"  -Ic:\CUDA\Progs\VS\SampleProject\MatrixPerformanceCompare\include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\kernel.cu.obj "C:\CUDA\Progs\VS\SampleProject\MatrixPerformanceCompare\kernel.cu"" exited with code 2.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

我知道这是一个与定义守卫连接的错误,简单c ++项目的代码用相同的Eigen源编译精细。
你能帮我吗?

I know that this is a error connected with the define guards, but those in Eigen seems OK, and in simple c++ project the code with the same Eigen source compiles fine. Could you help me?

推荐答案

CUDA前端解析器对于C ++代码不能解析极其复杂的主机模板定义在所有情况下。它的工作是查看一个 .cu 文件中的代码,并尝试分割出必须由GPU工具链编译的代码,该代码应该传递给主机编译器。将Boost和QT头文件导入 .cu 文件时,会发生失败。我会下注Eigen模板导致同样的问题。

The CUDA front end parser for C++ code is not capable of parsing extremely complex host template definitions correctly in all situations. It's job is to look through code in a .cu file and try and split out code which must be compiled by the GPU toolchain from code which should pass through to the host compiler. It is known to fail when importing Boost and QT headers into .cu files. I'll wager the Eigen templates are causing the same problem.

我知道的唯一解决方案是重构代码,以分离出主机代码依赖于模板添加到具有 .cc 扩展名的其他文件。 CUDA前端从不会在 .cc 文件中看到任何代码,问题消失。在实践中,这种类型的代码分割并不是真正的问题,因为主机模板代码实际上不能在CUDA GPU代码内使用,在最坏的情况下,你可能需要一个小的封装函数或额外的抽象级别来保持你的GPU和主机代码分开。

The only solution I am aware of is to refactor your code to separate out the host code that relies on the templates to a different file with a .cc extension. The CUDA front end never sees any code in a .cc file and the problem disappears. In practice, this sort of code splitting isn't really a problem because the host template code can't actually be used inside CUDA GPU code anyway, and at worst you might require a small wrapper function or additional level of abstraction to keep your GPU and host code separate.

这篇关于成员“已经被声明为”与CUDA和Eigen的误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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