Reject cross-device streams in acquireExternalStream - #235
Merged
scal444 merged 1 commit intoJul 27, 2026
Conversation
acquireExternalStream validated a caller-supplied stream handle with cudaStreamQuery, which reports whether the stream is live, not which device owns it. CUDA permits querying a stream that belongs to another device in the same process, so a foreign stream returned cudaSuccess and was accepted. The cross-device rejection the function advertises was therefore never actually happening. Resolve the stream's owning device and compare it against the current device. cudaStreamGetDevice does this directly but requires CUDA 12.8, above our supported floor, so below that fall back to probing with an event: an event and the stream it is recorded into must share a CUDA context, so recording an event created on the current device fails with cudaErrorInvalidResourceHandle when the stream belongs to another device. The driver API (cuStreamGetCtx) was avoided deliberately: it changes signature in CUDA 13 and would add a libcuda link dependency. DeviceTest.AcquireExternalStreamWrongDevice covers this but only runs with 2+ GPUs, which is why it went unnoticed until it failed in multi-GPU CI.
Contributor
|
| Filename | Overview |
|---|---|
| src/utils/device.cpp | Adds compatible cross-device stream ownership validation without exposing a concrete correctness regression. |
| tests/test_fmcs_primitives.cu | Updates local includes to the repository-root-relative convention supported by the target’s include configuration. |
Reviews (1): Last reviewed commit: "Reject cross-device streams in acquireEx..." | Re-trigger Greptile
evasnow1992
approved these changes
Jul 27, 2026
evasnow1992
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for fixing the test failure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
acquireExternalStream validated a caller-supplied stream handle with cudaStreamQuery, which reports whether the stream is live, not which device owns it. CUDA permits querying a stream that belongs to another device in the same process, so a foreign stream returned cudaSuccess and was accepted. The cross-device rejection the function advertises was therefore never actually happening.
Resolve the stream's owning device and compare it against the current device. cudaStreamGetDevice does this directly but requires CUDA 12.8, above our supported floor, so below that fall back to probing with an event: an event and the stream it is recorded into must share a CUDA context, so recording an event created on the current device fails with cudaErrorInvalidResourceHandle when the stream belongs to another device.
The driver API (cuStreamGetCtx) was avoided deliberately: it changes signature in CUDA 13 and would add a libcuda link dependency.
DeviceTest.AcquireExternalStreamWrongDevice covers this but only runs with 2+ GPUs, which is why it went unnoticed until it failed in multi-GPU CI.