Tell NVCC to NOT preprocess host code to avoid BOOST_COMPILER redefinition

主宰稳场 提交于 2019-12-11 03:28:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11540962/tell-nvcc-to-not-preprocess-host-code-to-avoid-boost-compiler-redefinition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!