mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #2722] [Bug] [TE] cudaEventRecord: invalid resource handle when NVLink/MNNVL transfer targets a non-current GPU #710
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#710
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @staryxchen on GitHub (Jul 2, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/2722
Originally assigned to: @xiangui33423 on GitHub.
Repro
Reported by @n-WN in the discussion on #2691:
The failure is specific to the case where the buffer's device differs from the calling thread's current CUDA device.
Root cause (from reading the code)
NVLinkTransport::startTransfer(nvlink_transport.cpp:225-233, mirrored inMnnvlTransport::startTransferatmnnvl_transport.cpp:265-272):submitTransferTaskscorrectly resolves the buffer's device (say device 1) and callsgetStreamFromPool(stream, 1).CUDAStreamPool::DevicePool::acquire(cuda_stream_pool.cpp:70-82) doescudaSetDevice(1)→cudaStreamCreateWithFlags→cudaSetDevice(currentDevice)to restore the caller's device. So the stream lives on device 1, but the caller is back on device 0.cudaErrorInvalidResourceHandle.Fix direction
Either:
cudaSetDevice(target_device)guard, restoring the caller's device afterward. Localized change in eachstartTransfer.startTransfercall (event, memcpy, event record, restore).Both need to know the batch's target device — which is already computed in
submitTransferTasksand can be plumbed tostartTransfervia theSubBatch.Same fix applies to both
NVLinkTransportandMnnvlTransport.Not related to
Orthogonal to #2620 / #2691. #2691 only changes where the device id comes from (registration-time
BufferDesc.locationvs. submit-timecudaPointerGetAttributes); in this repro the old path already resolves the right device id. The mismatch is between event device and stream device, not in device inference.Community fix welcome — happy to review.
@github-actions[bot] commented on GitHub (Jul 2, 2026):
Thanks for opening this issue, @staryxchen!
151037142A maintainer will triage this when possible. To help us respond faster, please include:
Useful links: Documentation · Contributing guide
@xiangui33423 commented on GitHub (Jul 3, 2026):
Hi, I'd like to take this issue.
I understand the root cause as an event/stream device mismatch: the stream is created on the resolved target GPU, but the event is created on the caller's current CUDA device. I'll try to plumb the target device into
startTransfer, guard event creation/recording with the correct CUDA device, restore the previous device afterward, and apply the fix to both NVLink and MNNVL.Could you assign this to me?
@staryxchen commented on GitHub (Jul 3, 2026):
OK, I've assigned this issue to you. Before you submit a PR, please make sure to verify on your local machine that the code compiles successfully and that the issue has been resolved. Thanks for your contribution in advance.
@xiangui33423 commented on GitHub (Jul 3, 2026):
Thanks for assigning this to me. I'll verify the build locally and test the reported NVLink/MNNVL cross-GPU case before submitting the PR.
@n-WN commented on GitHub (Jul 6, 2026):
Field verification of #2754 on the original multi-GPU CUDA-enabled repro host: the exact command that failed deterministically before (
tebench --seg_type=VRAM --local_gpu_id=1 --target_gpu_id=0 --xport_type=nvlink) now runs clean on latest main (f1f5e40) — nocudaEventRecord: invalid resource handle, cross-GPU reads sustain 140→372 GB/s from 256 KB to 4 MB blocks (vs. ~1.3 TB/s for the same-GPU path, consistent with NVLink vs. HBM). Thanks @xiangui33423 for the fix and @staryxchen for the fast triage.