【问题标题】:Error while Compiling Eigen library v3.3.4 with VS2017 + nvcc (CUDA 9.0)使用 VS2017 + nvcc (CUDA 9.0) 编译 Eigen 库 v3.3.4 时出错
【发布时间】:2018-01-19 12:41:25
【问题描述】:

我尝试编译以下代码,同时使用 Eigen 和 cuda,但出现错误。

    #include "cuda_runtime.h"
    #include "device_launch_parameters.h"
    #include <stdio.h>
    #include <iostream>
    #include <Eigen/Dense>
    #include <Eigen/IterativeLinearSolvers>

    __global__ void printWithCUDA()
    {
        if (threadIdx.x == 0)
        {
            printf(" Printed with thread %d \n", threadIdx.x);
        }
    }

    int main()
    {
        // Eigen Operation
        Eigen::Matrix3d eigenA;
        eigenA << 1, 2, 3,
           4, 5, 6,
           7, 8, 9;

        Eigen::Matrix3d eigenB;
        eigenB << -1, -2, -3,
           -4, -5, -6,
           -7, -8, -9;

        Eigen::MatrixXd eigenC = eigenA * eigenB;
        std::cout << " \n Eigen Matrix " << std::endl;
        std::cout << eigenC;

        // CUDA Operation
        printWithCUDA <<< 1, 32 >>>();
        if (cudaPeekAtLastError() != cudaSuccess)
        {
            fprintf(stderr, "addWithCuda failed!");
            return 1;
        }

        return 0;
    }

使用 VS 2017、Eigen v3.3.4 和 CUDA 9.0,我收到以下错误

eigen\src/Core/util/Macros.h(402): 致命错误 C1017: 无效的整数常量表达式

Macros.h(402): fatal error C1017

在我的原始项目中,Eigen 代码在 .h 文件中与 cuda 代码分开,但错误是相同的。

PS:效果不错

  1. 如果我评论特征部分,或者
  2. 我在没有 nvcc 的 VS 2017 的完全 cpp 项目中使用 Eigen

这是特定于 VS2017 + CUDA 9.0 + Eigen v3.3.4 的吗?因为根据Compiling Eigen library with nvcc (CUDA) : update2 它适用于其他版本。

谢谢

更新1:

感谢 Avi Ginsburg,我已经下载了最新版本的 dev 分支。使用该版本,我不再收到此错误。 但是,我还有其他不明白的错误:我刚刚用The unstable source code from the development branch这里的那个替换了最新的稳定版本 完整的错误在图片中可用Error_Compil 但看起来像这样

1>kernel.cu 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(614): 错误 C2244: 'Eigen::JacobiSVD::allocate': 无法将函数定义与现有声明 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(613):注意:见“Eigen::JacobiSVD::allocate”的声明 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(614):注意:定义 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(614): 注意:'void Eigen::JacobiSVD::allocate(::Eigen::SVDBase>: :Index,Eigen::SVDBase::Index,unsigned int)' 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(614):注意:现有声明 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(614): 注意:'void Eigen::JacobiSVD::allocate(Eigen::SVDBase::Index, Eigen::SVDBase::Index,unsigned int)'

【问题讨论】:

    标签: cuda visual-studio-2017 eigen nvcc


    【解决方案1】:

    显然,__CUDACC_VER__ 在 CUDA 9.0 中不再支持,因此 __CUDACC_VER__ &gt;= 80000 不再是有效的比较。我不确定它的定义是什么(我假设#define __CUDACC_VER__ "" 会导致此错误),因为我没有在这台计算机上安装 CUDA。试试 Eigen 的 dev 分支,他们可能会修复它。如果不是,则应改为检查__CUDACC_VER_MAJOR____CUDACC_VER_MINOR__。如果你得到它的工作,你可以提交一个建议的修复。

    更新

    Eigen 开发人员已经在 dev 分支中修复了它(不确定何时)。他们绕过了这个问题:

    // Starting with CUDA 9 the composite __CUDACC_VER__ is not available.
    #if defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 9)
    #define EIGEN_CUDACC_VER  ((__CUDACC_VER_MAJOR__ * 10000) + (__CUDACC_VER_MINOR__ * 100))
    #elif defined(__CUDACC_VER__)
    #define EIGEN_CUDACC_VER __CUDACC_VER__
    #else
    #define EIGEN_CUDACC_VER 0
    #endif
    

    Eigen/Core 中并将Macros.h 行替换为(EIGEN_CUDACC_VER &gt;= 80000)

    【讨论】:

      猜你喜欢
      • 2012-09-29
      • 2018-03-09
      • 2023-03-27
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多