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?

2
  • does nvcc assume it's C code if the extension isn't .cpp, and C++ if it is perhaps?
    – Flexo
    Nov 15, 2011 at 15:24
  • @awoodland: That's extremely unlikely because the errors are about template arguments.
    – Bill Lynch
    Nov 15, 2011 at 15:49

1 Answer 1

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.

6
  • 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, 2011 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, 2011 at 16:12
  • 1
    @Vik: you might investigate whether you can apply the pimpl pattern to workaround the problem with your class definition: en.wikipedia.org/wiki/Pimpl Nov 15, 2011 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, 2011 at 13:43
  • 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 for my test setup. Sep 28, 2016 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.