Skip to content

Commit 5cdc178

Browse files
Cache flat wrench-buffer view in _create_buffers
Previously write_data_to_sim rebuilt the (N, 9) zero-copy reshape of self._wrench_buf on every step. The view aliases a fixed allocation whose shape never changes, so build it once at buffer creation and reuse the cached view in the hot path. Addresses Antoine's PR #5426 review comment on rigid_object.py:188.
1 parent d74e904 commit 5cdc178

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

  • source/isaaclab_ovphysx/isaaclab_ovphysx/assets/rigid_object

source/isaaclab_ovphysx/isaaclab_ovphysx/assets/rigid_object/rigid_object.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,9 @@ def write_data_to_sim(self) -> None:
178178
outputs=[self._wrench_buf],
179179
device=self._device,
180180
)
181-
# Reshape (N, 1, 9) → (N, 9) zero-copy for the binding write.
182-
flat_view = wp.array(
183-
ptr=self._wrench_buf.ptr,
184-
shape=(self._num_instances, 9),
185-
dtype=wp.float32,
186-
device=self._device,
187-
copy=False,
188-
)
189181
binding = self._get_binding(TT.RIGID_BODY_WRENCH)
190182
if binding is not None:
191-
binding.write(flat_view)
183+
binding.write(self._wrench_buf_flat)
192184
inst.reset()
193185

194186
def update(self, dt: float) -> None:
@@ -1101,7 +1093,16 @@ def _create_buffers(self) -> None:
11011093
self._ALL_TRUE_BODY_MASK = wp.array(np.ones(B, dtype=bool), dtype=wp.bool, device=device)
11021094

11031095
# external wrench composer
1096+
# The kernel writes into the (N, 1, 9) view; the binding consumes the (N, 9)
1097+
# view -- both alias the same allocation, so we cache the flat reshape once.
11041098
self._wrench_buf = wp.zeros((N, 1, 9), dtype=wp.float32, device=device)
1099+
self._wrench_buf_flat = wp.array(
1100+
ptr=self._wrench_buf.ptr,
1101+
shape=(N, 9),
1102+
dtype=wp.float32,
1103+
device=device,
1104+
copy=False,
1105+
)
11051106
self._instantaneous_wrench_composer = WrenchComposer(self)
11061107
self._permanent_wrench_composer = WrenchComposer(self)
11071108

0 commit comments

Comments
 (0)