CUDA 11.6.0 with gcc 11.2.1 fails to process system headers included by <functional>

subj; When I try to build any trivial program that includes <functional> nvcc fails:

$ cat >test.cu <<EOF
#include <functional>
int main(void) { }
EOF
$ nvcc test.cu
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11/bits/std_function.h:435:145: ошибка: packs параметров не расширены с «...»:
  435 |         function(_Functor&& __f)
      |                                                                                                                                                 ^
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11/bits/std_function.h:435:145: замечание:         «_ArgTypes»
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11/bits/std_function.h:530:146: ошибка: packs параметров не расширены с «...»:
  530 |         operator=(_Functor&& __f)
      |                                                                                                                                                  ^
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11/bits/std_function.h:530:146: замечание:         «_ArgTypes»

Though it works fine with gcc-10.3.0:

$ nvcc --compiler-bindir "/usr/x86_64-pc-linux-gnu/gcc-bin/10.3.0" test.cu

My Cuda and gcc versions:

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:16:03_PST_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/11.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-11.2.1_p20220115/work/gcc-11-20220115/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/11.2.1 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.1 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.1/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.1/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/11.2.1/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --disable-libunwind-exceptions --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 11.2.1_p20220115 p4' --disable-esp --enable-libstdcxx-time --with-build-config=bootstrap-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --disable-libada --disable-cet --disable-systemtap --disable-valgrind-annotations --disable-vtable-verify --disable-libvtv --with-zstd --enable-lto --with-isl --disable-isl-version-check --enable-default-pie --enable-default-ssp
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.1 20220115 (Gentoo 11.2.1_p20220115 p4)

nvcc -v output:

$ nvcc -v test.cu
#$ _NVVM_BRANCH_=nvvm
#$ _SPACE_=
#$ _CUDART_=cudart
#$ _HERE_=/opt/cuda/bin
#$ _THERE_=/opt/cuda/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_DIR_=targets/x86_64-linux
#$ TOP=/opt/cuda/bin/..
#$ NVVMIR_LIBRARY_DIR=/opt/cuda/bin/../nvvm/libdevice
#$ LD_LIBRARY_PATH=/opt/cuda/bin/../lib:
#$ PATH=/opt/cuda/bin/../nvvm/bin:/opt/cuda/bin:/home/alexander/perl5/bin:/usr/trinity/14/games:/home/alexander/.cargo/bin:~/.cargo/bin:/usr/i486-pc-linux-gnu/gcc-bin/4.3.2:/usr/lib/llvm/8/bin:/usr/tqt3/bin:/usr/trinity/14/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/lib/llvm/13/bin:/usr/lib/llvm/12/bin:/usr/lib/llvm/11/bin:/usr/lib/llvm/10/bin:/usr/lib/llvm/9/bin:/opt/nvidia-cg-toolkit/bin:/usr/games/bin:/opt/cuda/bin:/usr/lib64/opencascade/bin
#$ INCLUDES="-I/opt/cuda/bin/../targets/x86_64-linux/include"
#$ LIBRARIES=  "-L/opt/cuda/bin/../targets/x86_64-linux/lib/stubs" "-L/opt/cuda/bin/../targets/x86_64-linux/lib"
#$ CUDAFE_FLAGS=
#$ PTXAS_FLAGS=
#$ gcc -D__CUDA_ARCH__=520 -D__CUDA_ARCH_LIST__=520 -E -x c++  -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__  "-I/opt/cuda/bin/../targets/x86_64-linux/include"    -D__CUDACC_VER_MAJOR__=11 -D__CUDACC_VER_MINOR__=6 -D__CUDACC_VER_BUILD__=55 -D__CUDA_API_VER_MAJOR__=11 -D__CUDA_API_VER_MINOR__=6 -D__NVCC_DIAG_PRAGMA_SUPPORT__=1 -include "cuda_runtime.h" -m64 "test.cu" -o "/tmp/tmpxft_00007fce_00000000-9_test.cpp1.ii"
#$ cicc --c++17 --gnu_version=110201 --display_error_number --orig_src_file_name "test.cu" --orig_src_path_name "/tmp/test.cu" --allow_managed   -arch compute_52 -m64 --no-version-ident -ftz=0 -prec_div=1 -prec_sqrt=1 -fmad=1 --include_file_name "tmpxft_00007fce_00000000-3_test.fatbin.c" -tused --gen_module_id_file --module_id_file_name "/tmp/tmpxft_00007fce_00000000-4_test.module_id" --gen_c_file_name "/tmp/tmpxft_00007fce_00000000-6_test.cudafe1.c" --stub_file_name "/tmp/tmpxft_00007fce_00000000-6_test.cudafe1.stub.c" --gen_device_file_name "/tmp/tmpxft_00007fce_00000000-6_test.cudafe1.gpu"  "/tmp/tmpxft_00007fce_00000000-9_test.cpp1.ii" -o "/tmp/tmpxft_00007fce_00000000-6_test.ptx"
#$ ptxas -arch=sm_52 -m64  "/tmp/tmpxft_00007fce_00000000-6_test.ptx"  -o "/tmp/tmpxft_00007fce_00000000-10_test.sm_52.cubin"
#$ fatbinary -64 --cicc-cmdline="-ftz=0 -prec_div=1 -prec_sqrt=1 -fmad=1 " "--image3=kind=elf,sm=52,file=/tmp/tmpxft_00007fce_00000000-10_test.sm_52.cubin" "--image3=kind=ptx,sm=52,file=/tmp/tmpxft_00007fce_00000000-6_test.ptx" --embedded-fatbin="/tmp/tmpxft_00007fce_00000000-3_test.fatbin.c"
#$ rm /tmp/tmpxft_00007fce_00000000-3_test.fatbin
#$ gcc -D__CUDA_ARCH_LIST__=520 -E -x c++ -D__CUDACC__ -D__NVCC__  "-I/opt/cuda/bin/../targets/x86_64-linux/include"    -D__CUDACC_VER_MAJOR__=11 -D__CUDACC_VER_MINOR__=6 -D__CUDACC_VER_BUILD__=55 -D__CUDA_API_VER_MAJOR__=11 -D__CUDA_API_VER_MINOR__=6 -D__NVCC_DIAG_PRAGMA_SUPPORT__=1 -include "cuda_runtime.h" -m64 "test.cu" -o "/tmp/tmpxft_00007fce_00000000-5_test.cpp4.ii"
#$ cudafe++ --c++17 --gnu_version=110201 --display_error_number --orig_src_file_name "test.cu" --orig_src_path_name "/tmp/test.cu" --allow_managed  --m64 --parse_templates --gen_c_file_name "/tmp/tmpxft_00007fce_00000000-6_test.cudafe1.cpp" --stub_file_name "tmpxft_00007fce_00000000-6_test.cudafe1.stub.c" --module_id_file_name "/tmp/tmpxft_00007fce_00000000-4_test.module_id" "/tmp/tmpxft_00007fce_00000000-5_test.cpp4.ii"
#$ gcc -D__CUDA_ARCH__=520 -D__CUDA_ARCH_LIST__=520 -c -x c++  -DCUDA_DOUBLE_MATH_FUNCTIONS "-I/opt/cuda/bin/../targets/x86_64-linux/include"   -m64 "/tmp/tmpxft_00007fce_00000000-6_test.cudafe1.cpp" -o "/tmp/tmpxft_00007fce_00000000-11_test.o"
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11/bits/std_function.h:435:145: error: parameter packs not expanded with '...':
  435 |         function(_Functor&& __f)
      |                                                                                                                                                 ^
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11/bits/std_function.h:435:145: note:         '_ArgTypes'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11/bits/std_function.h:530:146: error: parameter packs not expanded with '...':
  530 |         operator=(_Functor&& __f)
      |                                                                                                                                                  ^
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/g++-v11/bits/std_function.h:530:146: note:         '_ArgTypes'
# --error 0x1 --
2 Likes

CUDA 11.6.1 samples have build issues with gcc 11.2.0 on Ubuntu 21.10, while building fine with gcc 10.3.0. Can be simply solved by adding #include <limits> in these two files:
cuda-samples/Samples/5_Domain_Specific/simpleVulkan/VulkanBaseApp.cpp
cuda-samples/Samples/5_Domain_Specific/simpleVulkanMMAP/VulkanBaseApp.cpp
After this change all samples are built correctly.

1 Like

Seeing the same issue with std_function.h with CUDA 11.5 and gcc 11.2.0 on Ubuntu 22.04 Jammy Jellyfish, but downgrading gcc for my project is not really an option unfortunately. Any other kind of workaround available?

2 Likes

Looks like the problem is fixed in cuda-11.6.2

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.