Why Does Nvcc Fails to Compile a Cuda File with Boost::Spirit

Why does nvcc fails to compile a CUDA file with boost::spirit?

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.

Why does the typedefed struct fail to compile with NVCC?

To summarize the comments into an answer so that this question falls off the unanswered queue for the CUDA tag.

This:

typedef struct {
long long int mem_0;
} Tuple1;

defines a type containing an unnamed structure. There is no definition of struct Tuple1.

This, on the other hand, defines such a structure:

struct Tuple1 {
long long int mem_0;
};

and this defines a type containing such a named structure:

typedef struct Tuple1 {
long long int mem_0;
} Tuple1_t;

Any of the latter two would be compatible with your other code.

ATL on CUDA occurs compilation error

The CUDA C++ front end is known to fail on very complex template declarations (at least boost, eigen, QT have been reported here to fail to compile when included into a .cu file).

The only solution is to quarantine the ATL code into .cpp files and not include those headers into .cu files. nvcc will not attempt to send code within .cpp files through the CUDA C++ parser and there will be no errors. You might need to provide wrapper functions in your .cu file(s) to link the ATL containing code to the CUDA code, depending on your application design.

If you have a real usage case for using ATL inside a .cu file, I would suggest contacting NVIDIA developer support and raising a bug report/feature request.

Why does this OpenMP code compile with g++, but fail with nvcc?

There is evidently a defect in CUDA 11.2 as far as this code example goes.

The problem appears to be resolved in CUDA 11.4 and later.

The solution is to upgrade the CUDA install to CUDA 11.4 or later.

Cuda with Boost

Dan, I have written a CUDA code using boost::program_options in the past, and looked back to it to see how I dealt with your problem. There are certainly some quirks in the nvcc compile chain. I believe you can generally deal with this if you've decomposed your classes appropriately, and realize that often NVCC can't handle C++ code/headers, but your C++ compiler can handle the CUDA-related headers just fine.

I essentially have main.cpp which includes my program_options header, and the parsing stuff dictating what to do with the options. The program_options header then includes the CUDA-related headers/class prototypes. The important part (as I think you've seen) is to just not have the CUDA code and accompanying headers include that options header. Pass your objects to an options function and have that fill in relevant info. Something like an ugly version of a Strategy Pattern. Concatenated:

main.cpp:
#include "myprogramoptionsparser.hpp"
(...)
CudaObject* MyCudaObj = new CudaObject;
GetCommandLineOptions(argc,argv,MyCudaObj);

myprogramoptionsparser.hpp:
#include <boost/program_options.hpp>
#include "CudaObject.hpp"

void GetCommandLineOptions(int argc,char **argv,CudaObject* obj){
(do stuff to cuda object) }

CudaObject.hpp:
(do not include myprogramoptionsparser.hpp)

CudaObject.cu:
#include "CudaObject.hpp"

It can be a bit annoying, but the nvcc compiler seems to be getting better at handling more C++ code. This has worked fine for me in VC2008/2010, and linux/g++.

Compiling Eigen library with nvcc (CUDA)

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.

nvcc unknown option -no_pie

Having done an update, I assume is to the latest stable (v4.1), so according to

NVIDIA CUDA Toolkit v4.1 Production Release Notes for Windows, Linux, and Mac OS X, CUDA Toolkit Known Issues, *MAC 10.*7:

The host linker on Mac OS 10.7 generates position-independent executables by default. As CUDA does not support position-independent executable currently, the linker must generate position-dependent executable by passing in the -no_pie option. If nvcc is being used to link the application, this option will be passed to the linker by default. To override the default behavior, the -Xlinker -pie option can be passed to nvcc.



Related Topics



Leave a reply



Submit