Skip to content

trunk/69465889df3652d30e76a251b59eb87ad25f261b

@yuweih205 yuweih205 tagged this 08 Sep 18:56
Fixes #195824

`AllocationRef::~AllocationRef` calls `C10_CUDA_CHECK` / `C10_CUDA_DRIVER_CHECK`, which throw. A destructor is implicitly noexcept, so when cleanup fails — typically because the CUDA context is already broken after an unrelated failure — the process dies with `std::terminate` and the original error is masked.

Switch the cleanup to the `_WARN` macro variants (already used elsewhere in this file) and wrap the remaining throw points (`CUDAGuard` construction, `DriverAPI::get`) in try/catch. Cleanup failures now warn and leak the allocation, which is acceptable since the process is tearing down anyway.

Repro on stock torch (2.9.1, single H200, world_size=1): allocate a symmetric-memory tensor, trigger a device-side assert, then drop the tensor — teardown aborts with `terminate called after throwing an instance of 'c10::AcceleratorError'` from the symmetric-memory free path, replacing the original `device-side assert triggered` error. gcc also flags the old pattern directly: `warning: 'throw' will always call 'terminate' [-Wterminate]`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/196003
Approved by: https://github.com/Skylion007, https://github.com/kapilsh
Assets 2
Loading