GeorgT GeorgT - 10 months ago 312
C++ Question

Compiling Eigen library with nvcc (CUDA)

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

#include <Eigen/Core>
#include <iostream>

int main( int argc, char** argv )
std::cout << "Pure CUDA" << std::endl;

Unfortunately, I get a bunch of warnings and errors I can only explain using nvcc instead of the Microsoft compile.

Is this assumption right?
Is there any way to compile Eigen with nvcc? (I actually donĀ“t want to transfer Eigen matrices to the GPU, just access their members)?

If it should not work to compile Eigen with nvcc, is there a nice guide/tutorial about clever ways to seperate host and device code?

I am using CUDA 5.0 RC, Visual Studio 2008, Eigen 3.0.5. To compile the .cu file I used both, the rules file included in CUDA, aswell as the custom build step produced by CMake. Using the CUDA rule file, I targeted the build at compute capability 3.0.

Thanks for your advice.

PS: If I compile the same code with the host compiler it works perfectly.

Tom Tom
Answer Source

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.