I am compiling a C++ library with CUDA kernels inside on Ubuntu 20.04.
My GCC compiler version which I use is GCC 9.3 (I think that is the standard version for Ubuntu 20.04).
I am using CUDA Toolkit 11.3
When I am compiling the ‘.cu’ files (with the CUDA kernels) with NVCC, I get the following error:
“error: argument list for class template “std::pair” is missing”.
The error occurs in file ‘/usr/include/c++/9/bits/stl_pair.h’.
I don’t know whether the error comes from the host (GCC) or device (NVCC) compiler.
I googled a bit, and according to the link  this error indicates that the GCC and Toolkit version are NOT compatible.
So I am wondering whether GCC 9.3 and Toolkit 11.3 are compatible on Ubuntu 20.04 or not .
Side note: I get also warnings because I am including the CUDA header files ‘device_functions.h’ and ‘math_functions.h’, but I think that is not related to the issue.
The CUDA toolchain automatically includes CUDA-specific header files when compiling .cu files, so manual inclusion of CUDA-specific header files should not be necessary and should in fact be avoided. That has been true since the very beginning of CUDA. The rationale for the auto-inclusion was that the hurdle when moving from plain C/C++ to CUDA should be as low as possible.
Inclusion of cuda_runtime.h is necessary when accessing CUDA APIs from regular C++ code, of course.
Updating from CUDA Toolkit 11.3 to 11.5 did not solve the issue. Will investigate a bit deeper the issue. Where are all the output log files produced by the different components of NVCC (host compiler, device compiler, ptxas) ? I want to check them.
As usual, excellent support here by NVIDIA (Robert) and others (njuffa etc.), thanks ! That’s one thing I like on CUDA.
I have added the --verbose option already, thanks for pointing out the additional ‘keep’ option.
Is there some explanation which log file belongs to which component ?
Specifically, where goes the log output of the host compiler code, and where goes the log output of the device compiler code to ?
For that, if it were me, I would have to parse the verbose output. For example, if you say “device compiler” my best guess is you are referring to ptxas (converts PTX to SASS). In that case, I would look through the verbose output for a command line that begins with ptxas ... That command line should show all the input and output file names used by that command. I don’t know of an a-priori decoder ring and such a decoder ring would probably be harder to parse anyway, given all the temp file naming conventions used.
Below is the output of the respective NVCC step where the error occurs.
I have a file ‘Arithmetic.cu’ which is processed by NVCC.
I compile only for Compute capability 8.0 (machine code).
The strange thing is that even when I delete everything in Arithmetic.cu (so the file is completely empty), I get the error below… Any ideas by someone ? I am wondering also what the ‘cicc’ component actually is. I also am not sure whether I should change the ‘–c++17’ compiler flag in the call of ‘cc’ compiler to ‘–c++14’ (so that it matches with the flag in ‘cicc’ call) or remove it ? Any help or suggestions are appreciated.
So it seems that NVCC does NOT like when GCC does not use its default C++ standard.
One advice from me to the NVCC compiler team would be to check for this, and trigger a better error message … That would be really great also for other people… It was kinda difficult for me to find the root cause for this error.
You should never do that with nvcc. (By the way this is the first time in this thread where you have actually indicated the command you are using, from what I can see.)
If you want to specify an alternate c++ standard, do so with the appropriate switch from the nvcc command line. This keeps the host compiler and the components provided by the NVIDIA toolchain in sync.
For older versions of nvcc that may not support a particular standard (e.g. -std=c++17) the solutions are:
upgrade to a newer version of nvcc (or)
segregate the host code sections that depend on the newer c++ standard not yet explicitly supported by nvcc into their own .cpp files and compile those directly with the host compiler. Use wrapper functions as needed to tie functionality together.
Many thanks. I forget about the -Xcompiler=-std=c++17 switch because it is added automatically in our workflow. We have a custom CMAKE workflow where each GCC compiler flag <gcc_flag> is automatically propagated to NVCC (host) compiler flag ‘-Xcompiler=<gcc_flag>’ That is useful to keep them in sync for flags like eg. -Wno-narrowing or -fpic etc. But I should skip this propagating for the ‘-std=XYZ’ flags.
I am not sure whether this requirements of keeping both compilers ‘in sync’ (with respect to C++ standard) is mentioned in the NVCC documentation. Or I suppose I overread it.
I suppose the situation is the same on Windows with Visual Studio (2017, 2019), or ?
I don’t know that it is stated anywhere. If you feel the docs could be improved you can always file a bug.
I believe so.
FWIW I have filed an internal bug with a suggestion to make an addition to this section of the nvcc manual to clarify that that is the only correct method to select the dialect of the host compiler from the nvcc command line. I cannot say if it will be incorporated or when. I won’t be able to respond to further questions about the status of that bug.