Skip to content

fix(examples): standardize explicit resource cleanup - #1711

Merged
cpcloud merged 4 commits into
NVIDIA:mainfrom
cpcloud:issue-1676-resource-cleanup
Mar 4, 2026
Merged

fix(examples): standardize explicit resource cleanup#1711
cpcloud merged 4 commits into
NVIDIA:mainfrom
cpcloud:issue-1676-resource-cleanup

Conversation

@cpcloud

@cpcloudcpcloud commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes#1676.

  • apply deterministic cleanup in cuda_core examples using try/finally so streams, buffers, and graph resources are always released
  • extend cuda_bindings/examples/common/common.pyKernelHelper with explicit lifetime management (close, context-manager support) and deterministic NVRTC program teardown
  • update bindings examples to explicitly close helper-owned modules and clean up missed resources (including missing stream/event teardown in simpleCudaGraphs_test.py)
  • align example behavior with issue Examples: Standardize resource cleanup #1676 guidance to avoid relying on process-exit cleanup

Test plan

  • pixi run --manifest-path cuda_core -e cu13 python -m compileall <all touched example/helper files>
  • pixi run --manifest-path cuda_core -e cu13 pytest cuda_core/tests/example_tests/test_basic_examples.py -q

Made with Cursor

@copy-pr-bot

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@cpcloud

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@github-actions

This comment has been minimized.

@cpcloud

Copy link
Copy Markdown
ContributorAuthor

/ok to test

1 similar comment
@cpcloud

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@cpcloud
cpcloud requested a review from rparolinMarch 4, 2026 10:51
Ensure cuda.core and cuda.bindings examples deterministically release streams, buffers, and loaded modules so examples remain safe when copied into long-running programs.
Made-with: Cursor
Accept pre-commit auto-fixes from the nix run to keep the cleanup PR fully hook-clean.
Made-with: Cursor
Replace manual KernelHelper close calls with context-managed usage so modules are unloaded consistently even on early exits and cleanup stays centralized.
Made-with: Cursor
@cpcloud
cpcloudforce-pushed the issue-1676-resource-cleanup branch from 8800c46 to 3865524CompareMarch 4, 2026 11:09
@cpcloud

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboommdboom left a comment

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.

Approved, modulo fixing whatever is causing the tests to fail.

Not something for this PR, because it's clear this PR is trying to only make changes to cuda_bindings/examples. This PR definitely highlights places where cuda.core objects /should/ have context managers, and I will probably create a new issue to identify those and implement them (and then update these examples accordingly at that point).

Move CUBIN/PTX extraction back into the successful compile path in KernelHelper so example tests do not crash with UnboundLocalError when compilation succeeds.
Made-with: Cursor
@cpcloud

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@cpcloud
cpcloud enabled auto-merge (squash) March 4, 2026 17:42
@cpcloud
cpcloud merged commit 7848bc3 into NVIDIA:mainMar 4, 2026
86 checks passed
@github-actions

Copy link
Copy Markdown
Doc Preview CI
Preview removed because the pull request was closed or merged.

@leofangleofang added this to the cuda.core v0.7.0 milestone Apr 7, 2026
Sign up for freeto 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.

Examples: Standardize resource cleanup

3 participants

@cpcloud@mdboom@leofang