Skip to content

InnocentBug/thrust_mangling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thrust Name Resolution Bug Report

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.

Quick Reproduction Steps

The bug has been confirmed with the following setup:

  • Compiler: g++ version g++ (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

Additional Notes

  • 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.

Bug Reproduction

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> >&)'

Workaround for the Bug

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
./main

Expected Output

You should see an output similar to this:

std::vector 11
thrust::vector 11

Bug Resolution and Future Improvements

It 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.

About

Demonstration of name resolution bug with Thrust and GCC

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors