This report highlights an issue where Thrust names are not correctly resolved when compiling with g++. For a detailed explanation, please refer to my blog post.
The bug has been confirmed with the following setup:
- Compiler:
g++versiong++ (Debian 12.2.0-14) 12.2.0 - CUDAToolKit: Version 12.8
- nvcc: Version
Cuda compilation tools, release 12.8, V12.8.61 Build cuda_12.8.r12.8/compiler.35404655_0 - GPU: NVIDIA RTX 2080 Super
Reproducibility may vary with different setups. To reproduce the issue, compile the relevant files as follows:
nvcc -std=c++17 -x cu -c nvcc.cu -o nvcc.cu.o
g++ -isystem /usr/local/cuda-12.8/include -std=c++17 -c gcc.cpp -o gcc.cpp.o
g++ -std=c++17 main.cpp nvcc.cu.o gcc.cpp.o -L /usr/local/cuda-12/lib64/ -lcudart -o main- Include Path Adjustment: You may need to adjust the include path for the installed CUDA libraries.
- Deprecation Warning: You might encounter a warning about a deprecated compute architecture.
If you successfully reproduce the bug, you should see a line similar to this:
gcc.cpp:(.text+0x5d): undefined reference to `bar(thrust::THRUST_200700___CUDA_ARCH_LIST___NS::host_vector<int, std::allocator<int> >&)'To circumvent the issue, you can compile the C++ code that calls Thrust using nvcc as well. This approach resolves the problem.
nvcc -std=c++17 -x cu -c gcc.cpp -o gcc.cpp.o
g++ -std=c++17 main.cpp nvcc.cu.o gcc.cpp.o -L /usr/local/cuda-12/lib64/ -lcudart -o main
./mainYou should see an output similar to this:
std::vector 11
thrust::vector 11It is likely that g++ will not be able to resolve CUDA_ARCH_LIST.
Ideally, in such cases, the compilation should terminate with a clear and meaningful error message.
This would eliminate the need for manual object source investigations and name demangling, making the debugging process more straightforward.