Fix DLPack P2P Cross-Device Transfer (cu130)#180
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes cu130 cross-device DLPack transfer failures by introducing a cached CUDA P2P capability check and adding a CPU-staging fallback in the comfy_kitchen DLPack wrapper when direct peer access is unavailable.
Changes:
- Bump project version to
2.6.1. - Add
p2p_registry.pyto cachecudaDeviceCanAccessPeerresults. - Update the comfy_kitchen
_wrap_for_dlpackpatch to use a P2P-aware CPU-staging fallback for cross-device transfers.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
pyproject.toml |
Version bump to 2.6.1 for the cu130 DLPack transfer fix release. |
p2p_registry.py |
New cached P2P-access registry using cudaDeviceCanAccessPeer via ctypes. |
__init__.py |
Patches comfy_kitchen DLPack wrapping to stage through CPU when P2P is unavailable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+434
to
+436
| return wrap_for_dlpack(staged_tensor, *args[1:], **kwargs) | ||
| else: | ||
| return wrap_for_dlpack(staged_tensor, **kwargs) |
Comment on lines
+16
to
+21
| def _get_libcudart(): | ||
| """Load libcudart.so once and cache the handle.""" | ||
| global _libcudart | ||
| if _libcudart is None: | ||
| _libcudart = ctypes.CDLL("libcudart.so") | ||
| return _libcudart |
Comment on lines
+36
to
+41
| def _raw_can_access_peer(device_a: int, device_b: int) -> bool: | ||
| """Call cudaDeviceCanAccessPeer via ctypes. Returns True if P2P is available.""" | ||
| lib = _get_libcudart() | ||
| can_access = ctypes.c_int(0) | ||
| result = lib.cudaDeviceCanAccessPeer(ctypes.byref(can_access), device_a, device_b) | ||
| if result != 0: |
| return d is not None and d.type == "cuda" and d.index is not None | ||
|
|
||
| if _valid_cuda(tensor_device) and _valid_cuda(exec_device): | ||
| if tensor_device.index != exec_device.index and not p2p_registry.can_access_peer(tensor_device.index, exec_device.index): |
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.
Fixes #167 and #177 by adding a proper device guard and P2P registry for DLPack staging.
Changes:
2.6.1p2p_registry.pycache forcudaDeviceCanAccessPeer_patch_comfy_kitchen_dlpack_device_guardwhencuda:xtocuda:ylacks direct PCIe/NVLink P2P access.