Compiling Eigen library with nvcc (CUDA)

前端 未结 3 1772
长发绾君心
长发绾君心 2020-12-17 02:45

I tried to compile following program (main.cu) with the nvcc (CUDA 5.0 RC):

#include 
#include 

int main( int argc, char**         


        
相关标签:
3条回答
  • 2020-12-17 03:23

    Starting with Eigen 3.3, nvcc (7.5) succeeds in passing Eigen code to cl (MSVC 2013) (almost?) correctly. For example, the following code produces only 11 warnings:

    #include <Eigen/Core>
    #include <iostream>
    
    int main()
    {
        std::cout << "Hello Eigen\t";
        std::cout << EIGEN_WORLD_VERSION << "." << EIGEN_MAJOR_VERSION << "." << EIGEN_MINOR_VERSION << "\n";
        std::cout << "Hello nvcc\t";
        std::cout << __CUDACC_VER_MAJOR__ << "." << __CUDACC_VER_MINOR__ << "." << __CUDACC_VER_BUILD__ << "\n";
        return 0;
    }
    

    Output as expected (Eigen 3.3rc1):

    Hello Eigen 3.2.94
    Hello nvcc 7.5.17

    But a long list of warnings (see post history if you actually want to see them).

    Update:

    Unfortunately, using CUDA 8.0 & VS2015 (with both Eigen 3.2.9 & Eigen 3.3rc1) results in compilation errors again:

    "operator=" has already been declared in the current scope eigen\src\Core\Block.h 111
    "operator=" has already been declared in the current scope eigen\src\Core\Ref.h 89

    So close...

    Update 2:

    This has been fixed in commit 59db051 and is available by either using the development branch or waiting for v3.3 (or 3.3rc2) to actually come out.

    0 讨论(0)
  • 2020-12-17 03:32

    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.

    0 讨论(0)
  • 2020-12-17 03:35

    It looks like one of the core contributors to Eigen is porting it to be compatible with CUDA. The idea would be to call it from kernel code.

    0 讨论(0)
提交回复
热议问题