NVIDIA / cccl

CUDA Core Compute Libraries
Other
990 stars 120 forks source link

[BUG]: Fail to build a project with object that are template instantiate of thrust::complex. #1876

Open YoniSp opened 4 weeks ago

YoniSp commented 4 weeks ago

Is this a duplicate?

Type of Bug

Compile-time Error

Component

Thrust

Describe the bug

Fail to build a project with object that are template instantiate of thrust::complex.

[yehonatans@srv12 build]$ cmake ..
-- The CXX compiler identification is GNU 11.4.1
-- The CUDA compiler identification is NVIDIA 12.5.40
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Found CUDAToolkit: /usr/local/cuda/include (found version "12.5.40") 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Configuring done (8.4s)
-- Generating done (0.1s)
-- Build files have been written to: /home/Yehonatans/CLionProjects/CudaTemplateInstansiation/build
[yehonatans@srv12 build]$ make
[ 25%] Building CXX object CMakeFiles/CudaTemplateInstansiation.dir/main.cpp.o
[ 50%] Building CUDA object CMakeFiles/CudaTemplateInstansiation.dir/tt.cu.o
[ 75%] Linking CUDA device code CMakeFiles/CudaTemplateInstansiation.dir/cmake_device_link.o
[100%] Linking CXX executable CudaTemplateInstansiation
/bin/ld: CMakeFiles/CudaTemplateInstansiation.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x8a): undefined reference to `void funca<thrust::THRUST_200400___CUDA_ARCH_LIST___NS::complex<float> >(thrust::THRUST_200400___CUDA_ARCH_LIST___NS::complex<float>)'
/bin/ld: main.cpp:(.text+0xd0): undefined reference to `tt<thrust::THRUST_200400___CUDA_ARCH_LIST___NS::complex<float> >::func(thrust::THRUST_200400___CUDA_ARCH_LIST___NS::complex<float>)'

How to Reproduce

Build the c++ project without success with Cuda 12.4 or above proj.zip

Expected behavior

The build process will fail

Reproduction link

No response

Operating System

Rocky Linux 9 and 8

nvidia-smi output

No response

NVCC version

nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2024 NVIDIA Corporation Built on Wed_Apr_17_19:19:55_PDT_2024 Cuda compilation tools, release 12.5, V12.5.40 Build cuda_12.5.r12.5/compiler.34177558_0

jrhemstad commented 4 weeks ago

I suspect what is happening here is trying to use thrust::complex across two object files compiled with and without nvcc.

Unfortunately, a recent-ish change means this is no longer supported because thrust types do not have a consistent ABI between TUs compiled with and without nvcc. See: https://github.com/NVIDIA/cccl?tab=readme-ov-file#application-binary-interface-abi

image

Luckily, it should be a pretty easy fix to replace #include <thrust/complex.h> and thrust::complex with #include <cuda/std/complex> and cuda::std::complex.

Let us know if that works for you!

YoniSp commented 3 weeks ago

If I am using cuda::std::complex, is there a guarantee that the ABI will not be different when using it on c++ and cu files in the same project?

jrhemstad commented 3 weeks ago

If I am using cuda::std::complex, is there a guarantee that the ABI will not be different when using it on c++ and cu files in the same project?

Yes. All cuda:: types have a consistent ABI between c++ and cu files.