morph
morph

Reputation: 305

Tell NVCC to NOT preprocess host code to avoid BOOST_COMPILER redefinition

I have a .cu-file that contains both host and device code:

// device code
__global__ void
myKernel() { ... }

// host code
#include <boost/thread/mutex.hpp>

boost::mutex myMutex;

int main() { ... }

As you see I do an include of boost's mutex-functionality. When I compile the file I get an error because of the following warning:

warning C4005: 'BOOST_COMPILER': Macro-Redefinition c:\boost\include\boost-1_49_0\boost\config\compiler\visualc.hpp

So I assume that nvcc handles all the preprocessing for both device- and host-code. Am I right and if yes, how can I avoid that and pass also the preprocessing to cl.exe (MSVC 2010, Win7)?

I already tried to put the host-code in a seperate hpp/cpp-file and include this file in the cu-file - same problem. In the host code I define a surface-reference that will be used in the device code. So this is the reason I need an include in the cu-file and the host-code to be known by the device-code respectively.

Upvotes: 2

Views: 931

Answers (1)

talonmies
talonmies

Reputation: 72349

This is a known limitation of nvcc (technically cudafe, I think). nvcc uses file extension to determine whether a given source file should be processed for device code or passed to the CUDA preprocessors and then device compiler. That compilation trajectory can't correctly parse some of the very complex declarations that boost contains, and the compile fails.

The solution is to not import boost headers inside a .cu file. Put your host boost code in a .cc file, device code and kernel launches in a separate .cu file and make some thin wrappers to access the kernel calls from the .cc file. You can still pass all the source to nvcc to compile, but separating the boost imports from the device code eliminates the problem of the front end choking on the boost declarations.

Upvotes: 2

Related Questions