【问题标题】:Member "has already been declared" error with CUDA and EigenCUDA 和 Eigen 的成员“已被声明”错误
【发布时间】:2014-02-08 13:57:19
【问题描述】:

我只是 CUDA 和 Nsight 的初学者,希望通过线性代数运算(例如 CUBLAS)利用出色的 GPU 性能。我在Eigen 的帮助下编写了很多自定义代码,并且有很多矩阵乘法运算,所以我希望我的代码保持不变,只需在 GPU 上执行这些运算即可。

我用 Visual Studio Nsight 创建了一个示例项目,它运行良好,但是当我添加时

#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 ==========

我知道这是与定义保护有关的错误,但 Eigen 中的那些似乎还可以,并且在简单的 c++ 项目中,具有相同 Eigen 源的代码编译得很好。 你能帮帮我吗?

【问题讨论】:

    标签: c++ visual-studio-2010 cuda eigen nsight


    【解决方案1】:

    C++ 代码的 CUDA 前端解析器无法在所有情况下正确解析极其复杂的主机模板定义。它的工作是查看.cu 文件中的代码,并尝试将必须由GPU 工具链编译的代码与应该传递给主机编译器的代码分开。已知将 Boost 和 QT 标头导入.cu 文件时会失败。我敢打赌 Eigen 模板会导致同样的问题。

    我知道的唯一解决方案是重构您的代码,将依赖模板的主机代码分离到具有.cc 扩展名的不同文件中。 CUDA 前端永远不会在.cc 文件中看到任何代码,问题就消失了。在实践中,这种代码拆分并不是真正的问题,因为主机模板代码实际上不能在 CUDA GPU 代码中使用,最坏的情况是您可能需要一个小的包装函数或额外的抽象级别来保持您的 GPU和宿主代码分开。

    【讨论】:

    • 谢谢,这就是解决方案!我刚刚将 source.cc 文件添加到我的项目中,并将 Eigen 代码移到了那里。同样在开始时,我将 main 函数留在 .cu 文件中并且它没有编译,但是当我将 main 也移动到 .cc 文件时 - 它就像一个魅力
    • 上帝,这就是解决方案。我在这上面花了几个小时!
    猜你喜欢
    • 1970-01-01
    • 2013-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    • 2015-01-18
    相关资源
    最近更新 更多