[BUG]: `__cccl_allocation_stream` invokes cuda-driver UB
- 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
Something else
### Component
libcu++
### Describe the bug
I noticed that `cuda::__cccl_allocation_stream` holds a static-lifetime `cuda::stream`
```
inline ::cuda::stream_ref __cccl_allocation_stream()
{
static ::cuda::stream __stream{device_ref{0}};
return __stream;
}
```
The dtor (and hence `cuStreamDestroy`) will run below main. But, [quoth the documentation](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#initialization)
> The CUDA interfaces use global state that is initialized during host program initiation and destroyed during host program termination. The CUDA runtime and driver cannot detect if this state is invalid, so using any of these interfaces (implicitly or explicitly) during program initiation or termination after main) **will result in undefined behavior.**
oops.
### How to Reproduce
n/a
### Expected behavior
No UB.
### Reproduction link
_No response_
### Operating System
_No response_
### nvidia-smi output
_No response_
### NVCC version
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.