Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/source/concepts/physics-backends/ovphysx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,38 @@ some property tensors are CPU-only. :class:`~isaaclab_ov.sim.views.OvPhysxView`
validates these requirements and can reinterpret supported flat scalar layouts
as structured Warp values, but it does not move data between CPU and GPU.

On a CUDA simulation, :class:`~isaaclab_ov.sim.views.OvPhysxView` replays OvPhysX
session reads and writes captured into CUDA graphs instead of blocking
``TensorBinding`` calls:

- **Reads** (``read_into``, ``get_attribute`` with ``out``): poses, velocities,
accelerations, joint state, Jacobians, mass matrices and deformable nodes.
- **Writes** (``set_attribute`` from a Warp array, whole or by ``mask``): joint
targets, actuation forces, rigid-body poses and velocities, and whole wrench
writes. The next simulation step waits for them.
- **Still** ``TensorBinding``: articulation root and joint state, masked wrenches,
writes by ``indices`` or from host data, properties, and CPU simulations.

The assets follow these rules; code that drives a view directly follows them too:

- Pass destination, source and mask buffers kept across calls, since each
captures once; masks are Warp ``bool`` arrays on the simulation device.
- Make session calls and the view's ``TensorBinding`` calls on one stream, the
current Warp stream at the first replay; another stream raises ``RuntimeError``.
- Keep a view's prims in one ``UsdPhysics.Scene``; otherwise the first session
call raises ``ValueError``.
- After writing joint or root state, set
``sim.backend_manager.kinematics_dirty = True`` before ``sim.forward()``.
- Make structural edits on the USD stage before the first ``sim.reset()``:
OvPhysX does not report edits made through the native handle.

To record session calls into its own CUDA graph, a caller runs each once outside
the capture, then replays the graph on the session's stream, or on a stream that
first waits for it and that it synchronizes before the next step, closing a view
or a centre-of-mass write. It calls ``sim.forward()`` on that stream before the
replay after a state write, and captures the graph again after closing a view or
writing a centre of mass.

Use ``try_binding_for`` when a tensor type might not apply to the selected
prims. Reacquire raw bindings and convenience views after reset paths that
rebuild the stage or runtime, or after teardown. Destroy raw bindings and close
Expand Down
Empty file.
21 changes: 0 additions & 21 deletions source/isaaclab_newton/isaaclab_newton/assets/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,27 +722,6 @@ def set_body_link_velocity_to_sim(
body_acc_w[env_id, body_id] = wp.spatial_vectorf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)


@wp.kernel
def set_body_link_pose_to_sim_mask(
data: wp.array2d(dtype=wp.transformf),
env_mask: wp.array(dtype=wp.bool),
body_mask: wp.array(dtype=wp.bool),
body_link_pose_w: wp.array2d(dtype=wp.transformf),
):
"""Write masked body link pose data to simulation buffers.

Args:
data: Input array of body link poses. Shape is (num_envs, num_bodies).
env_mask: Environments to write. Shape is (num_envs,).
body_mask: Bodies to write. Shape is (num_bodies,).
body_link_pose_w: Output array where body link poses are written. Shape is (num_envs, num_bodies).
"""
env_id, body_id = wp.tid()
if not env_mask[env_id] or not body_mask[body_id]:
return
body_link_pose_w[env_id, body_id] = data[env_id, body_id]


@wp.kernel
def set_body_com_pose_to_sim_mask(
data: wp.array2d(dtype=wp.transformf),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def write_body_link_pose_to_sim_mask(
body_mask = self._resolve_body_mask(body_mask, body_ids)
self.assert_shape_and_dtype_mask(body_poses, (env_mask, body_mask), wp.transformf, "body_poses")
wp.launch(
shared_kernels.set_body_link_pose_to_sim_mask,
memory.make_masked_copy(wp.transformf, 2),
dim=(env_mask.shape[0], body_mask.shape[0]),
inputs=[body_poses, env_mask, body_mask],
outputs=[self.data._sim_bind_body_link_pose_w],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Fixed :class:`~isaaclab_ov.assets.RigidObjectCollection` with seven bodies, or six for velocities, reading its fused
bindings as the instance-major layout of the test mock, which mis-sized its data and wrote and read state at the wrong
rows: the layout now comes from the rank of the pose binding.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* Changed :meth:`~isaaclab_ov.sim.views.OvPhysxView.read_into` and
:meth:`~isaaclab_ov.sim.views.OvPhysxView.get_attribute` with ``out`` on a CUDA simulation to replay captured ovphysx
session reads of simulation state instead of blocking ``TensorBinding`` reads. Pass a destination kept across calls:
each captures once. Values are unchanged up to float32 rounding. A Jacobian or mass matrix read through the view no
longer refreshes the kinematics: call :meth:`~isaaclab_ov.physics.OvPhysxManager.update_kinematics` first, as
:class:`~isaaclab_ov.assets.ArticulationData` does.
* **Breaking:** Changed session reads and writes to raise ``ValueError`` for a view whose prims belong to several
``UsdPhysics.Scene`` prims.
Empty file.
15 changes: 15 additions & 0 deletions source/isaaclab_ov/changelog.d/ovphysx-session-writes.changed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* Changed :meth:`~isaaclab_ov.sim.views.OvPhysxView.set_attribute` on a CUDA simulation to replay captured ovphysx
session writes of joint targets, actuation forces, rigid-body poses and velocities, and whole wrench writes, from a
Warp array, whole or by ``mask``, as an actuator's ``set_*_index`` command without ``env_ids`` does. The call returns
before the GPU write, which the next step waits for. Pass source and mask buffers kept across calls. Other writes keep
the ``TensorBinding`` write.
* Changed :meth:`~isaaclab_ov.physics.OvPhysxManager.update_kinematics` on a CUDA simulation to refresh over one held
query instead of creating one and waiting on every call.
* Changed the masked pose and velocity writers of :class:`~isaaclab_ov.assets.RigidObjectCollection` to write only the
selected (environment, body) entries, without converting the masks to indices on the host.
* **Breaking:** Changed session writes by ``mask`` to raise ``ValueError`` for a mask that is not a contiguous Warp
``bool`` array on the simulation device.
* **Breaking:** Changed session reads and writes to raise ``RuntimeError`` on a stream other than the one the first
session call used.
* **Breaking:** Changed the mask writers and setters of :class:`~isaaclab_ov.assets.RigidObjectCollection` to raise
``ValueError`` for a mask whose length is not the environment or body count.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ def stage_user_command(
target_backend = articulation._get_backend_ordered_joint_buffer(user_buffer, backend_buffer)
if env_mask is not None:
articulation._root_view.set_attribute(tensor_type, target_backend, mask=env_mask)
elif env_ids is not None:
elif env_ids is not None and env_ids is not articulation._ALL_INDICES:
articulation._root_view.set_attribute(
tensor_type, target_backend, indices=articulation._get_sim_env_ids(env_ids)
)
else:
# Every environment, as an action term's per-step target write without env_ids (they resolve to
# _ALL_INDICES): a whole write, which a CUDA simulation commits through its captured session write.
articulation._root_view.set_attribute(tensor_type, target_backend)

def submit_commands(self, collection: ActuatorCollection) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4112,18 +4112,11 @@ def _process_tendons(self) -> None:
self._num_spatial_tendons = self._root_view.spatial_tendon_count

if self._num_fixed_tendons > 0 or self._num_spatial_tendons > 0:
stage_usda = self._backend_manager._stage_usda
if stage_usda is not None:
stage = self._backend_manager.backend.usd_stage
if stage is not None:
try:
from pxr import Sdf, Usd

from isaaclab.sim.utils.queries import get_all_matching_child_prims

layer = Sdf.Layer.CreateAnonymous("isaaclab_ov.usda")
if not layer.ImportFromString(stage_usda):
raise RuntimeError("Failed to import the serialized OVPhysX stage.")
stage = Usd.Stage.Open(layer)

articulation_root_path = getattr(self, "_articulation_root_path", None)
if articulation_root_path is None:
joint_prims = stage.Traverse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ def body_com_jacobian_w(self) -> ProxyArray:
shape = (self._num_instances, body_count, 6, self._num_joints + self._num_base_dofs)
self._body_com_jacobian_w.data = ProxyArray(wp.empty(shape, wp.float32, self.device))
if self._body_com_jacobian_w.timestamp < self._sim_timestamp:
self._backend_manager.update_kinematics() # computed from the link poses, as body_link_pose_w refreshes
has_body_ordering = self.has_body_ordering
has_joint_ordering = self.has_joint_ordering
if has_body_ordering or has_joint_ordering:
Expand Down Expand Up @@ -1125,6 +1126,7 @@ def mass_matrix(self) -> ProxyArray:
shape = self._view.binding_for(TT.MASS_MATRIX).shape
self._mass_matrix.data = ProxyArray(wp.empty(shape, wp.float32, self.device))
if self._mass_matrix.timestamp < self._sim_timestamp:
self._backend_manager.update_kinematics() # computed from the link poses, as body_link_pose_w refreshes
if self.has_joint_ordering:
if self._mass_matrix_backend is None:
self._mass_matrix_backend = wp.empty_like(self._mass_matrix.data.warp)
Expand Down
73 changes: 73 additions & 0 deletions source/isaaclab_ov/isaaclab_ov/assets/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,79 @@ def set_root_link_velocity_to_sim_mask(
body_acc_w[i, j] = wp.spatial_vectorf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)


@wp.kernel
def set_body_com_pose_to_sim_mask(
data: wp.array2d(dtype=wp.transformf),
body_com_pose_b: wp.array2d(dtype=wp.transformf),
env_mask: wp.array(dtype=wp.bool),
body_mask: wp.array(dtype=wp.bool),
body_com_pose_w: wp.array2d(dtype=wp.transformf),
body_link_pose_w: wp.array2d(dtype=wp.transformf),
):
"""Mask-scatter body COM poses into the cache and derive the corresponding link poses."""
env_id, body_id = wp.tid()
if env_mask[env_id] and body_mask[body_id]:
body_com_pose_w[env_id, body_id] = data[env_id, body_id]
body_link_pose_w[env_id, body_id] = get_com_pose_in_link_frame_func(
data[env_id, body_id], body_com_pose_b[env_id, body_id]
)


@wp.kernel
def set_body_com_velocity_to_sim_mask(
data: wp.array2d(dtype=wp.spatial_vectorf),
env_mask: wp.array(dtype=wp.bool),
body_mask: wp.array(dtype=wp.bool),
body_com_velocity_w: wp.array2d(dtype=wp.spatial_vectorf),
body_acc_w: wp.array2d(dtype=wp.spatial_vectorf),
):
"""Mask-scatter body COM velocities into the cache and zero the body accelerations."""
env_id, body_id = wp.tid()
if env_mask[env_id] and body_mask[body_id]:
body_com_velocity_w[env_id, body_id] = data[env_id, body_id]
body_acc_w[env_id, body_id] = wp.spatial_vectorf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)


@wp.kernel
def set_body_link_velocity_to_sim_mask(
data: wp.array2d(dtype=wp.spatial_vectorf),
body_com_pose_b: wp.array2d(dtype=wp.transformf),
body_link_pose_w: wp.array2d(dtype=wp.transformf),
env_mask: wp.array(dtype=wp.bool),
body_mask: wp.array(dtype=wp.bool),
body_link_velocity_w: wp.array2d(dtype=wp.spatial_vectorf),
body_com_velocity_w: wp.array2d(dtype=wp.spatial_vectorf),
body_acc_w: wp.array2d(dtype=wp.spatial_vectorf),
):
"""Mask-scatter body link velocities into the cache, derive the COM velocities and zero the accelerations."""
env_id, body_id = wp.tid()
if env_mask[env_id] and body_mask[body_id]:
body_link_velocity_w[env_id, body_id] = data[env_id, body_id]
body_com_velocity_w[env_id, body_id] = get_link_velocity_in_com_frame_func(
data[env_id, body_id], body_link_pose_w[env_id, body_id], body_com_pose_b[env_id, body_id]
)
body_acc_w[env_id, body_id] = wp.spatial_vectorf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)


@wp.kernel
def reshape_data_to_view_mask(
data: wp.array2d(dtype=Any),
env_mask: wp.array(dtype=wp.bool),
body_mask: wp.array(dtype=wp.bool),
view_data: wp.array(dtype=Any),
view_mask: wp.array(dtype=wp.bool),
):
"""Mask variant of ``RigidObjectCollection.reshape_data_to_view_2d``: copy the selected (env, body) entries of the
instance-major ``data`` to their body-major view rows ``view_id = body_id * num_envs + env_id``, and mark those rows
in ``view_mask``; the other rows are unmarked."""
env_id, body_id = wp.tid()
view_id = body_id * data.shape[0] + env_id
selected = env_mask[env_id] and body_mask[body_id]
view_mask[view_id] = selected
if selected:
view_data[view_id] = data[env_id, body_id]


"""
Articulation-only kernels (used by isaaclab_ov.assets.articulation).
"""
Expand Down
Loading
Loading