Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthrough
ChangesStream-aware GPU D2D Memcpy with Meta Dispatch
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
source/op/pt/comm.cc (1)
167-181:⚠️ Potential issue | 🟠 MajorGuard self-send copy with
nsend > 0to avoid UB from uninitializedsend_g1.
send_g1is only initialized whennsend != 0(Line 150), but the self-send copy branch (Lines 176-181) executes unconditionally. Whennsend == 0, readingsend_g1as a function argument is undefined behavior.Proposed fix
- if (recv_g1_tensor.is_cuda()) { - gpu_memcpy_d2d_current_stream(recv_g1, send_g1, - (std::size_t)nsend * tensor_size); - } else { - memcpy(recv_g1, send_g1, - (unsigned long)nsend * tensor_size * sizeof(FPTYPE)); - } + if (nsend > 0) { + if (recv_g1_tensor.is_cuda()) { + gpu_memcpy_d2d_current_stream( + recv_g1, send_g1, (std::size_t)nsend * tensor_size); + } else { + memcpy(recv_g1, send_g1, + (unsigned long)nsend * tensor_size * sizeof(FPTYPE)); + } + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@source/op/pt/comm.cc` around lines 167 - 181, The self-send copy branch containing the gpu_memcpy_d2d_current_stream and memcpy calls for recv_g1_tensor execution is not guarded against the case where nsend equals zero, but send_g1 is only initialized when nsend is non-zero. Add a condition checking nsend > 0 to wrap the entire self-send copy branch (the conditional block checking recv_g1_tensor.is_cuda()) to prevent reading the uninitialized send_g1 pointer when nsend is zero, which would result in undefined behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@source/op/pt/comm.cc`:
- Around line 167-181: The self-send copy branch containing the
gpu_memcpy_d2d_current_stream and memcpy calls for recv_g1_tensor execution is
not guarded against the case where nsend equals zero, but send_g1 is only
initialized when nsend is non-zero. Add a condition checking nsend > 0 to wrap
the entire self-send copy branch (the conditional block checking
recv_g1_tensor.is_cuda()) to prevent reading the uninitialized send_g1 pointer
when nsend is zero, which would result in undefined behavior.
ff9fea3 to
06f8748
Compare
06f8748 to
4f0d7a2
Compare
4f0d7a2 to
77387c2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5563 +/- ##
==========================================
+ Coverage 82.15% 82.18% +0.03%
==========================================
Files 898 898
Lines 103306 103584 +278
Branches 4410 4432 +22
==========================================
+ Hits 84867 85130 +263
+ Misses 17065 17059 -6
- Partials 1374 1395 +21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
35e40b5 to
b097f65
Compare
Register Meta kernels for the pt_expt border communication wrappers so shape inference can run without dispatching the real CPU/CUDA implementation. Also move local CUDA/HIP device-to-device self copies onto the current PyTorch stream instead of using synchronous cudaMemcpy/hipMemcpy. Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
b097f65 to
248c36e
Compare
Summary
deepmd_export::border_opandborder_op_backwardso output metadata is available without running the real implementationgpuMemcpyAsyncin DeepMD's CUDA/HIP device abstraction and use it for local self-send device-to-device copies on PyTorch's current streamborder_opreturnsg1metadata; backward returnsgrad_g1metadata) and why the copy still uses PyTorch's current streamMotivation / notes
The pt_expt border communication wrappers already have Python fake impls, but the C++ op registrations did not provide a Meta dispatch implementation. PyTorch documents that a FakeTensor kernel (also called a meta kernel) is required for custom operators to work with compile/export/FX, and
opcheckverifies that the fake/meta kernel returns the same metadata (sizes/strides/dtype/device/etc.) as the real op:For these wrappers, metadata is input-derived:
border_op(..., g1, ...) -> Tensorreturns a cloned export output with the same metadata asg1border_op_backward(..., grad_g1, ...) -> Tensorreturns a cloned export output with the same metadata asgrad_g1So the Meta kernels can use
torch::empty_like(...)and avoid touchingdata_ptr(), MPI, or CUDA/HIP runtime state during shape-only dispatch.For CUDA/HIP local self-send copies, this PR now exposes
gpuMemcpyAsyncingpu_cuda.h/gpu_rocm.hand uses that abstraction incomm.cc. The stream is still obtained from PyTorch's current CUDA/HIP stream because this is a PyTorch custom op; enqueueing work on the default stream would risk incorrect ordering or unintended synchronization with neighbouring PyTorch ops.This does not try to make the MPI send/recv/barrier path asynchronous; those remain host-side synchronization points by nature.
Tests
git diff --check HEAD~1..HEADA local build/test was not run in this environment because PyTorch is not installed for the active Python interpreter.
Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
Summary by CodeRabbit
Bug Fixes
New Features
deepmd_exportborder forward/backward operations to support export/AOT workflows without real communication.Chores
gpuMemcpyAsyncaliases for both CUDA and HIP backends.