0

I tried to compile the following code where I use Eigen and cuda at the same time and I get an error.

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

With VS 2017, Eigen v3.3.4 and CUDA 9.0, I get the following error

eigen\src/Core/util/Macros.h(402): fatal error C1017: invalid integer constant expression

Macros.h(402): fatal error C1017

In my original project, the Eigen code is separated in a .h file from cuda code but the error is the same.

PS: it works well

  1. if I comment the eigen part, or
  2. I use Eigen in a fully cpp project with VS 2017 without nvcc

Is this specific to VS2017 + CUDA 9.0 + Eigen v3.3.4 ? Because according to Compiling Eigen library with nvcc (CUDA) : update2 it worked for other verions.

Thanks

Update1:

Thanks Avi Ginsburg, I have downloaded the latest version of dev branch. With that version, I don't get this error anymore. However, I have other errors that I don't understand: I have just replaced the latest stable release version with the one here The unstable source code from the development branch The full error is available in the image here Error_Compil but it looks like this

1>kernel.cu 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(614): error C2244: 'Eigen::JacobiSVD::allocate': unable to match function definition to an existing declaration 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(613): note: see declaration of 'Eigen::JacobiSVD::allocate' 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(614): note: definition 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(614): note: '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): note: existing declarations 1>g:\librray_quant\issues_lib\eigen_nvcc\eigen_nvcc\3rdparties\dev_branch\eigen\src/SVD/JacobiSVD.h(614): note: 'void Eigen::JacobiSVD::allocate(Eigen::SVDBase::Index,Eigen::SVDBase::Index,unsigned int)'

RyoSahiba
  • 1
  • 3

1 Answers1

1

Apparently, __CUDACC_VER__ is no longer supported in CUDA 9.0, and therefore __CUDACC_VER__ >= 80000 is no longer a valid comparison. I'm not sure what it is defined to be (I assume #define __CUDACC_VER__ "" to cause this error), as I do not have CUDA installed on this computer. Try the dev branch of Eigen, they might have a fix for it. If not, the check should be for __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__ instead. You can submit a proposed fix if you get it working.

Update

The Eigen devs already fixed it in the dev branch (not sure when). They bypassed the issue with:

// 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

in Eigen/Core and replaced the Macros.h line with (EIGEN_CUDACC_VER >= 80000).

Community
  • 1
  • 1
Avi Ginsburg
  • 10,323
  • 3
  • 29
  • 56