Skip to content

Fix unchecked CUDA calls in noexcept functions - #1244

Merged
cliffburdick merged 10 commits into
NVIDIA:mainfrom
lennartvoelz:fix/unchecked_cuda_calls
Sep 18, 2026
Merged

cliffburdick merged 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

Comment thread include/matx/transforms/cgsolve.h
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

@lennartvoelz

Copy link
Copy Markdown
Contributor Author

Hi @cliffburdick, could you let me know which test is failing? I made sure no tests failed locally because of my changes, but some didn't run from the beginning because of the Jetson architecture, so it could be one of these cases I could not verify

@cliffburdick

Copy link
Copy Markdown
Collaborator

Hi @cliffburdick, could you let me know which test is failing? I made sure no tests failed locally because of my changes, but some didn't run from the beginning because of the Jetson architecture, so it could be one of these cases I could not verify

Hi @lennartvoelz, nothing is failing. It's just a DNS issue. I'll review and merge when ready.

@cliffburdick

Copy link
Copy Markdown
Collaborator

Hi @cliffburdick, could you let me know which test is failing? I made sure no tests failed locally because of my changes, but some didn't run from the beginning because of the Jetson architecture, so it could be one of these cases I could not verify

@lennartvoelz there is one unresolved comment from greptile.

@lennartvoelz

lennartvoelz commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

@lennartvoelz there is one unresolved comment from greptile.

Hi @cliffburdick, I think the comment is stale. Should be fixed with the latest commit and the introduced resource guard 31c0b3c

@cliffburdick

Copy link
Copy Markdown
Collaborator

/build

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 93.388%lennartvoelz:fix/unchecked_cuda_calls into NVIDIA:main. No base build found for NVIDIA:main.

@cliffburdick
cliffburdick merged commit bee23e5 into NVIDIA:main Sep 18, 2026
2 checks passed
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

3 participants