Skip to content

Fix OVPhysX CPU-only property writes racing their pinned-host staging copies - #7486

Merged
marcodiiga merged 1 commit into
isaac-sim:developfrom
marcodiiga:fix/malesiani/ovphysx_pinned_host_staging_sync
Sep 2, 2026
Merged

marcodiiga merged 1 commit into
isaac-sim:developfrom
marcodiiga:fix/malesiani/ovphysx_pinned_host_staging_sync

Conversation

@marcodiiga

@marcodiiga marcodiiga commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

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_ov assets stage the GPU-resident caches, environment indices, and masks into pinned host buffers with wp.copy and then call the CPU-only set_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-Direct on physics=ovphysx this 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_cpu and RigidObjectCollection._env_body_ids_to_view_ids fence with wp.synchronize_stream right 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_all fill.
  • 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_ids fill.

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:

Scenario Fence calls in the step loop Fence cost CPU setter cost Step time
Ant steady state (no property writes after init) 0 0 0 8.7 ms/step, unchanged
Initialization (6 actuator property writes) n/a 0.10 to 0.15 ms total 53 to 66 ms total one-time
Stiffness and damping rewritten for 256 envs every step 600 about 19 us median per write, 11 to 13 ms total 546 to 584 ms total 11.7 to 11.9 ms/step before, 12.0 to 12.2 ms/step after (two runs each, within run-to-run noise)
Stiffness and damping rewritten for all 4096 envs every step 600 11 ms total 7.8 to 8.9 s total 42 to 47 ms/step both ways

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_staging warms 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

  • Bug fix (non-breaking change which fixes an issue)

Release backport

  • Backport this pull request to the active release branch after it merges into develop

The 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-ci on the pull request.

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump extension.toml — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

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.
@marcodiiga

Copy link
Copy Markdown
Collaborator Author

run-ci

@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Sep 2, 2026
@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Sep 2, 2026
@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR prevents OVPhysX CPU-only property setters from reading pinned-host staging buffers before asynchronous GPU-to-host copies complete.

  • Adds stream synchronization for joint and rigid-body property, environment-index, and mask staging across Articulation, RigidObject, and RigidObjectCollection.
  • Adds a CUDA regression test that queues work ahead of property writes and verifies indexed and masked values through the OVPhysX bindings.
  • Adds the required isaaclab_ov changelog fragment.

Confidence Score: 5/5

The 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

Filename Overview
source/isaaclab_ov/isaaclab_ov/assets/articulation/articulation.py Fences device-to-pinned-host property, index, and mask copies before immediate CPU binding consumption.
source/isaaclab_ov/isaaclab_ov/assets/rigid_object/rigid_object.py Adds equivalent synchronization to rigid-body mass, center-of-mass, inertia, index, and mask staging.
source/isaaclab_ov/isaaclab_ov/assets/rigid_object_collection/rigid_object_collection.py Synchronizes collection property and one-time view-index staging before CPU-side use.
source/isaaclab_ov/test/assets/test_articulation.py Adds a CUDA regression test covering busy-stream indexed and masked CPU-only property writes.
source/isaaclab_ov/changelog.d/fix-malesiani-ovphysx_pinned_host_staging_sync.rst Documents the stale pinned-host staging race and affected property writers.

Sequence Diagram

sequenceDiagram
    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
Loading

Reviews (1): Last reviewed commit: "Wait for pinned-host staging before OVPh..." | Re-trigger Greptile

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AntoineRichard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Marco LGTM!

@marcodiiga
marcodiiga merged commit 7e7c590 into isaac-sim:develop Sep 2, 2026
48 of 49 checks passed
@isaaclab-bot

isaaclab-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Backported to release/3.0.0 as 340cfb5.

isaaclab-bot Bot pushed a commit that referenced this pull request Sep 2, 2026
… 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants