Hi
I’m pretty sure it’s a NVCC bug because the error is in the translated code from nvcc. And without Cuda there is no problem.
This C++ code :
struct CParams { int n; }; __device__ constexpr CParams cparams0={5}; template<const CParams &cparams> __global__ void f() { int t=cparams.n; } int main() { f< cparams0 ><<<1,32>>>(); return 0; }
Generate this compilation message :
make all Building file: ../main.cu Invoking: NVCC Compiler /usr/local/cuda-11/bin/nvcc --device-debug --debug -gencode arch=compute_86,code=sm_86 -gencode arch=compute_86,code=compute_86 -ccbin g++ -c -o "main.o" "../main.cu" ../main.cu(10): warning: variable "t" was declared but never referenced In file included from tmpxft_0000266a_00000000-6_main.cudafe1.stub.c:1: /tmp/tmpxft_0000266a_00000000-6_main.cudafe1.stub.c:14:68: error: ‘__shadow_var’ was not declared in this scope 14 | template<> __specialization_static void __wrapper__device_stub_f<(&__shadow_var(cparams0,::cparams0))>(void){__device_stub__Z1fIL_ZN57_INTERNAL_39_tmpxft_0000266a_00000000_7_main_cpp1_ii_main8cparams0EEEvv();} | ^~~~~~~~~~~~ /tmp/tmpxft_0000266a_00000000-6_main.cudafe1.stub.c:14:41: error: template-id ‘__wrapper__device_stub_f<<expression error> >’ for ‘void __wrapper__device_stub_f()’ does not match any template declaration 14 | template<> __specialization_static void __wrapper__device_stub_f<(&__shadow_var(cparams0,::cparams0))>(void){__device_stub__Z1fIL_ZN57_INTERNAL_39_tmpxft_0000266a_00000000_7_main_cpp1_ii_main8cparams0EEEvv();} | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../main.cu:8:47: note: candidate is: ‘template<const CParams& cparams> void __wrapper__device_stub_f()’ 8 | template<const CParams &cparams> __global__ void f()
Versions:
nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2021 NVIDIA Corporation Built on Mon_Oct_11_21:27:02_PDT_2021 Cuda compilation tools, release 11.4, V11.4.152 Build cuda_11.4.r11.4/compiler.30521435_0 gcc --version gcc (Debian 10.2.1-6) 10.2.1 20210110