Fix external contact cache lifetime under CUDA graphs - #3768
Conversation
Allocate the external-contact mapping before the first solver step so a CUDA graph cannot retain a captured temporary allocation. Extend the fast-path buffer regression test to cover the mapping itself.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthrough
ChangesMuJoCo contact cache lifecycle
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Description
SolverMuJoCoalready creates the contact fast-path generation and count buffers before the first step, but the thread-to-contact map was still created lazily in_convert_contacts_to_mjwarp(). When the first step was captured in a CUDA graph, the solver kept a pointer to that captured allocation after capture ended.This allocates the map after model conversion, when
mjw_data.naconmaxis known. The allocation is limited to the GPU path with external Newton contacts. The existing capacity check remains in place in case the MJWarp data capacity changes later.The fast-path buffer test now covers the map's type, size, device, and initial contents.
Closes #3767.
Checklist
CHANGELOG.mdhas been updated (if user-facing change)Test plan
The eight external-contact MuJoCo solver tests pass. I also ran the reproduction from #3767 directly:
main: prints the cache pointer, then exits with code 139 oncache.numpy()I verified the regression test separately with the source change removed; it fails because
_contact_tid_to_cidisNone.Bug fix
Steps to reproduce:
SolverMuJoCowithuse_mujoco_contacts=Falseon CUDA.wp.ScopedCapture.solver._contact_tid_to_cidafter capture.Minimal reproduction:
Summary by CodeRabbit