Why does nvcc preprocess with gcc and compiles with a different compiler?

Hi, we would like understand the architecture of the nvcc compilation workflow in more detail.

For context, we are engineers working on Fedora Linux and we are curious about the current flow of nvcc compilation, especially the part “The CUDA Compilation Trajectory” from your manual: 1. Introduction — NVIDIA CUDA Compiler Driver 12.4 documentation

We don’t understand why two different compilers are involved in the process.

Concrete snippet:
gcc -D__NV_NO_HOST_COMPILER_CHECK=1 -D__CUDA_ARCH_LIST__=520 -D__NV_LEGACY_LAUNCH -E -x c++ -D__CUDACC__ -D__NVCC__ “-I/usr/local/cuda/bin/…/targets/x86_64-linux/include” -D__CUDACC_VER_MAJOR__=12 -D__CUDACC_VER_MINOR__=4 -D__CUDACC_VER_BUILD__=99 -D__CUDA_API_VER_MAJOR__=12 -D__CUDA_API_VER_MINOR__=4 -D__NVCC_DIAG_PRAGMA_SUPPORT__=1 -include “cuda_runtime.h” -m64 “CMakeCUDACompilerId.cu” -o “tmp/CMakeCUDACompilerId.cpp4.ii”

cudafe++ --c++17 --gnu_version=140001 --display_error_number --orig_src_file_name “CMakeCUDACompilerId.cu” --orig_src_path_name “/home/fedora/python-torch/pytorch-6a89a753b1556fe8558582c452fdba083f6ec01a/build/CMakeFiles/3.28.2/CompilerIdCUDA/CMakeCUDACompilerId.cu” --allow_managed --m64 --parse_templates --gen_c_file_name “tmp/CMakeCUDACompilerId.cudafe1.cpp” --stub_file_name “CMakeCUDACompilerId.cudafe1.stub.c” --gen_module_id_file --module_id_file_name “tmp/CMakeCUDACompilerId.module_id” “tmp/CMakeCUDACompilerId.cpp4.ii”

Our concern is that using 2 different compilers requires them to align in features and extensions - gcc preprocessing can result in code that cudafe++ cannot compile. In other words, cudafe++ has to support every extension of gcc.

Our final goal is to compile cuda-accelerated pytorch: since Fedora 40 has gcc 14 and the latest cuda (12.4.1) only supports gcc 13, we are investigating what is the root cause.

We look forward to your answer, thank you.

I think my answer is over here: nvcc preprocessing - #8 by njuffa