Skip to content

Commit 8302994

Browse files
gonidelisfbusato
andauthored
Fix CCCL_THROW in dlpack_to_mdspan (#7363) (#7233)
Co-authored-by: Federico Busato <50413820+fbusato@users.noreply.github.com>
1 parent 7fae9c7 commit 8302994

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

thrust/thrust/detail/allocator/temporary_allocator.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <thrust/memory.h>
3434
#include <thrust/system/detail/bad_alloc.h>
3535

36+
#include <cuda/std/__exception/exception_macros.h>
3637
#include <cuda/std/__memory/allocator_traits.h>
3738
#include <cuda/std/__utility/pair.h>
3839
#include <cuda/std/cassert>
@@ -99,7 +100,21 @@ class temporary_allocator : public thrust::detail::tagged_allocator<T, System, t
99100

100101
_CCCL_HOST_DEVICE void deallocate(pointer p, size_type n) noexcept
101102
{
102-
return thrust::return_temporary_buffer(system(), p, n);
103+
_CCCL_TRY
104+
{
105+
thrust::return_temporary_buffer(system(), p, n);
106+
}
107+
_CCCL_CATCH_ALL
108+
{
109+
_CCCL_ASSERT(false, "Exception thrown in deallocate");
110+
// Swallow all exceptions to maintain noexcept contract per C++ allocator requirements.
111+
// Deallocate must be noexcept to be safe in destructors and during exception unwinding.
112+
// Clear CUDA error state and leak the memory rather than propagating exception.
113+
// Memory is leaked, but this matches standard allocator behavior when deallocation fails.
114+
#if _CCCL_CUDA_COMPILATION()
115+
NV_IF_TARGET(NV_IS_HOST, cudaGetLastError();)
116+
#endif // _CCCL_CUDA_COMPILATION()
117+
}
103118
}
104119

105120
_CCCL_HOST_DEVICE inline System& system()

0 commit comments

Comments
 (0)