Repository navigation
Fix OVPhysX CPU-only property writes racing their pinned-host staging copies - #7486
Conversation
OVPhysX keeps joint and body properties on the host, so the isaaclab_ov assets stage GPU-resident data, environment indices, and masks into pinned host buffers before calling the CPU-only setters. Warp performs that device-to-host copy asynchronously on the device stream, so a busy stream let the setters consume stale buffer contents. Affected environments could silently receive zero joint properties during initialization, which made seeded Isaac-Ant-Direct runs on ovphysx non-reproducible. Synchronize the device stream after every device-to-pinned-host staging copy in Articulation, RigidObject, and RigidObjectCollection, matching the pattern already used by the generic staging helpers, and add a regression test that keeps the device stream busy ahead of the writes.
|
run-ci |
Greptile SummaryThis PR prevents OVPhysX CPU-only property setters from reading pinned-host staging buffers before asynchronous GPU-to-host copies complete.
Confidence Score: 5/5The PR appears safe to merge, with synchronization consistently placed between asynchronous pinned-host staging copies and their CPU consumers. The changed paths follow the repository’s existing staging pattern, and the regression test exercises both indexed and masked writes while prior GPU work delays the copies. Important Files Changed
Sequence DiagramsequenceDiagram
participant GPU as GPU device stream
participant Host as Pinned host buffer
participant Setter as OVPhysX CPU setter
GPU->>Host: Asynchronous wp.copy
GPU-->>Host: Copy completes
Note over GPU,Host: wp.synchronize_stream waits here
Host->>Setter: Read staged properties / indices / masks
Setter->>Setter: Apply property values
Reviews (1): Last reviewed commit: "Wait for pinned-host staging before OVPh..." | Re-trigger Greptile |
There was a problem hiding this comment.
Isaac Lab Review Bot
The CUDA-side race fix is correctly targeted, but the new synchronization calls introduce a concrete regression for supported CPU-device OVPhysX configurations: initialization now attempts to synchronize a CUDA-only stream on all three asset types.
- Design and architecture: Placing fences directly after device-to-pinned-host copies is appropriate for CUDA staging and matches existing synchronization patterns. However, applying those fences unconditionally in device-agnostic initialization and setter paths breaks the CPU backend, where host-to-host copies are already synchronous.
- API: Public setter signatures and selector semantics remain unchanged. Runtime compatibility does not: Articulation, RigidObject, and RigidObjectCollection can now fail during initialization when OvPhysxManager resolves the simulation device to CPU.
- Implementation: The added wp.synchronize_stream calls correctly order CUDA copies before CPU consumers, but Warp stream synchronization requires a CUDA device. The unconditional calls in each _create_buffers path therefore abort CPU-device initialization, with the corresponding setter, index, and mask helpers carrying the same defect. Guard synchronization based on the copy source being CUDA; the regression test currently covers only cuda:0.
Significant concerns. Posted 3 actionable findings inline.
Automated review; human maintainers own approval decisions.
AntoineRichard
left a comment
There was a problem hiding this comment.
Thanks Marco LGTM!
|
Backported to |
… copies (#7486) OVPhysX keeps joint and body properties on the host, so the isaaclab_ov assets stage GPU-resident data, environment indices, and masks into pinned host buffers before calling the CPU-only setters. Warp performs that device-to-host copy asynchronously on the device stream, so a busy stream let the setters consume stale buffer contents. Affected environments could silently receive zero joint properties during initialization, which made seeded Isaac-Ant-Direct runs on ovphysx non-reproducible. Synchronize the device stream after every device-to-pinned-host staging copy in Articulation, RigidObject, and RigidObjectCollection, matching the pattern already used by the generic staging helpers, and add a regression test that keeps the device stream busy ahead of the writes. (cherry picked from commit 7e7c590)
Description
OVPhysX keeps joint and body properties (stiffness, damping, limits, armature, friction, mass, center of mass, inertia) on the host even when the simulation runs on the GPU, so the
isaaclab_ovassets stage the GPU-resident caches, environment indices, and masks into pinned host buffers withwp.copyand then call the CPU-onlyset_attribute. Warp issues a device-to-host copy into pinned memory asynchronously on the device stream, so whenever that stream still has work queued ahead of the copy, the setter consumed whatever the pinned buffer held before the copy landed: zeros on first use, or the values of the previous write.For
Isaac-Ant-Directonphysics=ovphysxthis hit the actuator setup writes during initialization. In a fraction of fresh processes some environments received all-zero joint properties, their first physics step diverged, and repeated seeded training runs stopped being reproducible. The race is timing dependent, which is why short validation series could pass while longer ones did not.Two helpers already had the right pattern (
ArticulationData._binding_write/_stage_to_pinned_cpuandRigidObjectCollection._env_body_ids_to_view_idsfence withwp.synchronize_streamright after the copy); the preallocated-buffer paths did not. This change makes every device-to-pinned-host staging copy consumed by CPU code wait for the device stream before the setter runs:Articulation:_push_joint_property(all joint property writers),set_masses_*,_set_coms,set_inertias_*,_get_cpu_env_ids,_get_cpu_env_mask, and the one-time_cpu_env_ids_allfill.RigidObject: the same mass, center of mass, inertia, index, and mask sites.RigidObjectCollection: the mass, center of mass, and inertia staging copies and the one-time_cpu_all_view_idsfill.Host-to-device copies followed by kernels on the same stream are already stream ordered and are left untouched.
Performance
Measured on an RTX A6000 with
Isaac-Ant-Direct, 4096 environments,physics=ovphysx, 300 random-action steps per run:The wait is bounded by the copy itself because the CPU-only setter cannot start before the data is on the host anyway; the setter's per-DOF PhysX calls dominate the write cost by roughly two orders of magnitude. Steady-state training is unaffected because these writers only run at initialization and during reset-time randomization.
Test
test_cpu_only_property_writes_wait_for_pinned_host_stagingwarms up the writers, queues a long kernel on the device stream ahead of each write, and checks the values read back from OVPhysX. It fails on the previous code (the two selected environments keep their old stiffness) and passes with this change.Type of change
Release backport
developThe defect also affects the current release branch with
ovphysx; maintainers may want to tick the backport box.Checklist
Docker and GPU tests run on demand. Push the commits you want tested, then
comment
run-cion the pull request.pre-commitchecks with./isaaclab.sh --formatsource/<pkg>/changelog.d/for every touched package (do not editCHANGELOG.rstor bumpextension.toml— CI handles that)CONTRIBUTORS.mdor my name already exists there