Skip to content

Preserve device contexts when duplicate init fails - #176

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
fallintoplace:fix/preserve-device-contexts-on-duplicate-init
Jun 17, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
fallintoplace:fix/preserve-device-contexts-on-duplicate-init

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

Summary

  • keep init_device_contexts from clearing the thread-local device map while checking for duplicate initialization
  • add a regression test showing duplicate init continues to fail after the first duplicate error

Why

ctx.devices.replace(None).is_none() used the duplicate-init predicate itself to replace the existing map with None. That made the first duplicate call return Context already initialized, but it also dropped the initialized state, so a later call could initialize again.

Validation

  • cargo fmt --check
  • git diff --check
  • cargo test -p cuda-async duplicate_init_preserves_existing_device_contexts (blocked locally: CUDA toolkit headers are not installed; cuda-bindings could not find cuda.h under /usr/local/cuda)

@nihalpasham nihalpasham added bug Something isn't working host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async) labels Jun 17, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

LGTM 👍🏾

  • The old check wiped the live device map even on the error path; the fix restores it.

Reviewer note, verified: the added duplicate-init test passes and genuinely fails on the old code.

@nihalpasham
nihalpasham merged commit 3384414 into NVIDIA:main Jun 17, 2026
24 checks passed
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants