NVIDIA / NVIDIA/cccl

[BUG]: CUDA Thrust object shared between .cu and .cpp files

Open
#2,737 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
486
Avg merge
2d 6h
Merged PRs (30d)
295

Description

### Is this a duplicate?

- [x] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this bug and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)

### Type of Bug

Compile-time Error

### Component

Thrust

### Describe the bug

It looks like recent changes to Thrust were made to tag the host_vector class name with the compile time CUDA architecture. This creates an issue (undefined reference) when linking shared objects compiled with nvcc or not (.cu vs .cpp files) that use Thrust objects, even host-only ones like host_vector.

Compiling everything with nvcc is probably in our case is not an option, some of the files need moc (ie Qt).

### How to Reproduce

To reproduce on Ubuntu 20.04.6 LTS with Cuda 12.6:
Main.cpp:

[include](https://forums.developer.nvidia.com/tag/include)
[include](https://forums.developer.nvidia.com/tag/include)

bool cudaFunc(thrust::host_vector &vec);
int main()
{
thrust::host_vector vec;
cudaFunc(vec);
}

cudaFunc.cu:

[include](https://forums.developer.nvidia.com/tag/include)
[include](https://forums.developer.nvidia.com/tag/include)
bool cudaFunc(thrust::host_vector &vec)
{
return true;
}

Compile with:

/usr/local/cuda/bin/nvcc -c cudaFunc.cu
g++ -I /usr/local/cuda/include -L /usr/local/cuda/targets/x86_64-linux/lib main.cpp cudaFunc.o -lcudart -ldl

will produce the error:

/usr/bin/ld: /tmp/cc5fFAJC.o: in function main:
main.cpp:(.text+0x30): undefined reference to cudaFunc(thrust::THRUST_200500___CUDA_ARCH_LIST___NS::host_vector&)

This will link fine on Ubuntu 20 with Cuda 12.3.

### Expected behavior

No link error.

### Reproduction link

_No response_

### Operating System

_No response_

### nvidia-smi output

_No response_

### NVCC version

nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Sep_12_02:18:05_PDT_2024
Cuda compilation tools, release 12.6, V12.6.77
Build cuda_12.6.r12.6/compiler.34841621_0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.