Skip to content

Fix unchecked CUDA calls in noexcept functions - #1244

Open
lennartvoelz wants to merge 10 commits into
NVIDIA:mainfrom
lennartvoelz:fix/unchecked_cuda_calls
Open

Fix unchecked CUDA calls in noexcept functions#1244
lennartvoelz wants to merge 10 commits into
NVIDIA:mainfrom
lennartvoelz:fix/unchecked_cuda_calls

Conversation

@lennartvoelz

Copy link
Copy Markdown
Contributor

Fixes #1241

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)

Wraps bare CUDA API calls in either MATX_CUDA_CHECK or MATX_CUDA_CHECK_NOEXCEPT

… 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)
@copy-pr-bot

copy-pr-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

# 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).
@lennartvoelz
lennartvoelz marked this pull request as ready for review August 28, 2026 10:09
@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The 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.

  • Adds MATX_CUDA_CHECK_NOEXCEPT for destructors and other noexcept functions.
  • Wraps previously unchecked CUDA runtime calls with the appropriate checking macro.
  • Introduces CUDA stream and event guards so successfully created handles are released during exception unwinding.
  • Updates cgsolve_impl and svdbpi_impl to use the new guards.

Confidence Score: 5/5

The 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

Filename Overview
include/matx/core/error.h Adds a non-throwing CUDA error-check macro whose logging is protected against exceptions.
include/matx/core/resource_guard.h Adds unique-pointer-based CUDA stream and event ownership with noexcept deleters.
include/matx/transforms/cgsolve.h Transfers each successfully created convergence stream and event into RAII ownership before later checked operations can throw.
include/matx/transforms/svd/svd_cuda.h Applies the same exception-safe ownership pattern to block-power-iteration SVD resources.

Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/unchecked_c..." | Re-trigger Greptile

@@ -75,8 +75,8 @@ namespace matx


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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:

lennartvoelz and others added 2 commits August 28, 2026 13:40
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.
@cliffburdick

Copy link
Copy Markdown
Collaborator

/build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Unchecked CUDA calls in noexcept functions cause sticky errors to leak into unrelated downstream paths

2 participants