4

I'm trying to integrate CUDA to an existing aplication wich uses boost::spirit.

Isolating the problem, I've found out that the following code does not copile with nvcc:

main.cu:

#include <boost/spirit/include/qi.hpp>
int main(){
    exit(0);
}

Compiling with nvcc -o cudaTest main.cu I get a lot of errors that can be seen here.

But if I change the filename to main.cpp, and compile again using nvcc, it works. What is happening here and how can I fix it?

Vik
  • 133
  • 2
  • 10

1 Answers1

5

nvcc sometimes has trouble compiling complex template code such as is found in Boost, even if the code is only used in __host__ functions.

When a file's extension is .cpp, nvcc performs no parsing itself and instead forwards the code to the host compiler, which is why you observe different behavior depending on the file extension.

If possible, try to quarantine code which depends on Boost into .cpp files which needn't be parsed by nvcc.

I'd also make sure to try the nvcc which ships with the recent CUDA 4.1. nvcc's template support improves with each release.

Jared Hoberock
  • 11,118
  • 3
  • 40
  • 76
  • 1
    The way I usually solve this is by having my controlling code in a pure `.cpp` file that I process with my standard compiler, and it calls specific functions that are separately implemented in the `.cu` files. That works pretty well. – Kerrek SB Nov 15 '11 at 15:50
  • I usually isolate the CUDA code like _Kerrek SB_ said, but the problem is that now I need to use some Class definitions that are in a `.h` file, witch includes boost spirit, and I can't figure out how to hide spirit from `nvcc` since this class uses it. _Jared Hoberock_ I'm using the CUDA 4.0 compilation tools. Don't know if ugrading to 4.1 will solve it but I'll try when everything else doesn't works. – Vik Nov 15 '11 at 16:12
  • 1
    @Vik: you might investigate whether you can apply the pimpl pattern to workaround the problem with your class definition: http://en.wikipedia.org/wiki/Pimpl – Jared Hoberock Nov 15 '11 at 21:41
  • @JaredHoberock, this workaround solves my problem, thanks. But this looks like a nvcc bug. Hope it get fixed to save time for other people. – Vik Nov 16 '11 at 13:43
  • I have the same problem with boost and a similar problem with #include (the Eigen Linear Algebra Library). Apparently, the template support in their parser is still not on par with msvc. – masterxilo Jun 27 '16 at 13:17
  • 1
    @masterxilo Try using Eigen 3.3 (currently rc1). It still generates a lot of warnings, but at least it compiles (the few things I have tested, at least). See [this](http://stackoverflow.com/questions/12802560/compiling-eigen-library-with-nvcc-cuda/39745481#39745481) for my test setup. – Avi Ginsburg Sep 28 '16 at 11:18