Fix unchecked CUDA calls in noexcept functions - #1244
Conversation
… in noexcept contexts Adds MATX_CUDA_CHECK_NOEXCEPT: - checks the error state against cudaSuccess - on failure, logs the error - logging is guarded by try/catch, to allow safe usage in noexcept contexts (logging with std::format could throw)
# Conflicts: # include/matx/core/allocator.h
Covers print.h, pybind.h, and tensor.h's prefetch helpers.
Covers cuda_executor_common.h's timing/profiling calls and distributed.h's device-guard and stream-cleanup destructors.
…forms/ Covers base_operator.h's copy/event-record paths and the solver transforms (cgsolve, chol, eig, fft, inverse, lu, qr, solve, svd).
Greptile SummaryThe PR adds checked CUDA-call handling, including non-throwing diagnostics for noexcept contexts, and converts the temporary stream and event lifetimes in iterative solver paths to RAII.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported exception-path resource leak is addressed by transferring each successfully created CUDA handle into RAII ownership before subsequent throwing operations. Important Files Changed
Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/unchecked_c..." | Re-trigger Greptile |
| @@ -75,8 +75,8 @@ namespace matx | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
Exceptions leak CUDA resources
When event creation or a later checked CUDA operation fails after the temporary stream or event has been created, MATX_CUDA_CHECK throws before the manual cleanup at the end of the function, causing callers that recover from the exception to leak CUDA resources. The same raw-handle lifetime pattern occurs in svdbpi_impl.
Knowledge Base Used:
The newly-added MATX_CUDA_CHECK calls in cgsolve_impl and svdbpi_impl can now throw between creating their temporary d2h stream/event and the end-of-function cleanup that used to destroy them, leaking both on any such throw. Replace the manual create/destroy with detail::CudaStreamGuard/CudaEventGuard (core/resource_guard.h), a shared unique_ptr-based RAII guard for opaque CUDA handles, so cleanup runs on any exception path.
|
/build |
Fixes #1241
Adds MATX_CUDA_CHECK_NOEXCEPT:
Wraps bare CUDA API calls in either MATX_CUDA_CHECK or MATX_CUDA_CHECK_NOEXCEPT