Skip to content

Improve manager and direct task hot paths - #6492

Closed
kellyguo11 wants to merge 1 commit into
isaac-sim:developfrom
kellyguo11:kellyg/perf-managers-direct-core
Closed

kellyguo11 wants to merge 1 commit into
isaac-sim:developfrom
kellyguo11:kellyg/perf-managers-direct-core

Conversation

@kellyguo11

Copy link
Copy Markdown
Contributor

Description

Improves the training hot paths that are shared by manager-based tasks and the selected direct core tasks.

This PR:

  • caches ActionManager action dimensions instead of rebuilding them every step
  • avoids unconditional observation term clones when concatenated terms do not need in-place post-processing
  • keeps a regression test that mutating returned observation outputs does not mutate source tensors
  • removes avoidable action clones in core direct tasks
  • simplifies Cartpole direct observation, reward, and termination tensor work

Fixes #

Benchmark impact

Runtime throughput from the exploration benchmark set:

Task Baseline FPS Optimized FPS Delta
Isaac-Cartpole-Direct 326,798.82 349,495.25 +6.95%
Isaac-Ant 248,768.20 253,743.87 +2.00%
Isaac-Velocity-Flat-UnitreeGo2 218,373.12 223,769.76 +2.47%
Isaac-Open-Drawer-Franka 129,490.49 132,211.63 +2.10%
Isaac-Ant-Direct 456,616.43 456,017.78 -0.13%

Short RSL-RL throughput checks:

Task Baseline total FPS Optimized total FPS Delta
Isaac-Cartpole-Direct, 10 iters 139,522.60 139,602.60 +0.06%
Isaac-Ant, 50 iters 145,352.32 147,341.06 +1.37%
Isaac-Velocity-Flat-UnitreeGo2, 150 iters 106,937.88 109,667.20 +2.55%

Convergence sanity: the Cartpole direct 10-iteration run preserved the same max reward, last reward, max episode length, and last episode length. The Go2 150-iteration reward curve stayed in the same learning regime, but the final seed-42 reward was slightly below baseline, so longer multi-seed validation is still recommended before treating convergence neutrality as final.

Type of change

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

Screenshots

Not applicable.

Validation

  • ./isaaclab.sh -p -m pytest source/isaaclab/test/managers/test_observation_manager.py
  • ./isaaclab.sh -f

Checklist

  • 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, or documentation is not required for this internal performance cleanup
  • 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
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Jul 13, 2026
StafaH added a commit to StafaH/IsaacLab that referenced this pull request Sep 28, 2026
Cache ActionManager term dimensions, which are fixed after term
construction but were recomputed on every action step. Keep Cartpole direct
joint indices on the device so observations, rewards, terminations, resets,
and effort writes no longer upload host lists each step, and drop redundant
action copies in the Cartpole and Reorient direct tasks. The locomotion
task keeps its copy because its reset zeroes the stored actions in place.
@StafaH

StafaH commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Closing in favor of #8039 which includes still relevant fixes from this PR

@StafaH StafaH closed this Sep 28, 2026
ooctipus added a commit that referenced this pull request Sep 28, 2026
# Description

Part 4 of the camera performance series. Based on the latest `develop`,
including #8084 and #8087. Supersedes #7495.

Profiling the camera and direct tasks found host-device synchronizations
in every step: the CPU blocked on the GPU, then ran Python code while
the GPU sat idle. This PR removes them from termination tracking, the
Lift rewards and success monitoring, marker validation, camera updates,
and the Cartpole and Pendulum direct tasks. It also incorporates the
hot-path fixes from #6492 (by @kellyguo11) that still apply to current
`develop`.

- `torch.where` replaces `nonzero` in the termination manager and
replaces boolean-mask writes in the Lift progress rewards.
- `SuccessMonitor` updates no longer synchronize. They rank outcomes
with fixed-size scatters instead of `unique_consecutive`,
`repeat_interleave`, and boolean masks. Masked or overflowing outcomes
go to an internal scratch row. A new `valid` argument lets the Lift
reset hook pass a mask instead of filtering.
- `SuccessMonitor.get_mean_success_rate()` returns a 0-d tensor, so
logging it does not synchronize. The Cartpole direct and Pendulum MARL
success rates are logged as tensors for the same reason. Call `.item()`
where a Python float is needed.
- Cartpole direct and Pendulum MARL store their joint indices as device
tensors. Observations, rewards, terminations, resets, and effort writes
no longer upload host lists each step.
- Marker index validation runs only when a backend consumes the IDs, and
once per ID tensor.
- Cameras with `update_period == 0` skip the outdated-mask readback.
- Zero-width uniform `add` noise returns its input.
- `object_point_cloud_b` defaults to `visualize=False`. Drawing 262k
markers every step cost a sync, and with RTX the markers appeared in
camera images. The Kuka rendering test already disabled them for that
reason.
- `ActionManager` caches its term dimensions, which are fixed after
construction but were recomputed on every action step (from #6492).
- The Cartpole and Reorient direct tasks drop redundant action copies
(from #6492).

With #8087, managers finalize scene-entity selections to device tensors.
`object_ee_distance` therefore indexes with `asset_cfg.body_ids`
directly, and this PR's earlier cached device-ID helper was removed.
After #8087 it would have iterated the finalized tensor to build its
cache key, reading indices back from the device.

### Changes from #6492

Each #6492 change was checked against current `develop`:

| #6492 change | Decision |
| --- | --- |
| Skip observation-term clones | Not taken: `develop` already provides
this through #8038. |
| Cabinet direct `actions.clone()` | Not taken: the line no longer
exists. |
| `ActionManager` caches term dimensions | **Taken.** |
| Cartpole direct index cleanup | **Taken and extended.** #6492 fixed 1
of the 9 synchronizations caused by host-list joint indexing. Storing
the joint indices as device tensors removes all 9. |
| Drop `actions.clone()` in the Cartpole and Reorient direct tasks |
**Taken.** Neither task modifies the stored actions in place. |
| Drop `actions.clone()` in the Locomotion direct task | **Not taken.**
Its reset zeroes `self.actions` in place, which would zero the policy's
own action tensor, e.g. the one held in RL rollout storage. |

### Investigated and dropped: Newton sensor-graph flag cache

An earlier revision cached the Newton sensor graph's task flags and
skipped the upload when they were unchanged, on the premise that each
upload synchronized the stream. That premise does not hold for the
current Warp (1.17), so the change was reverted and `develop`'s per-call
upload is kept:

- Warp uploads the flags with a single `cudaMemcpyAsync` from pageable
memory, which CUDA stages on the host without waiting for the stream.
- Behind about 455 ms of Warp kernels queued on the same stream, ten
uploads return in 0.07–0.13 ms.
- An Nsight Systems trace of the Kuka camera task shows each flag
upload's `cudaMemcpyAsync` returning in 5.9 µs on average, 35.6 µs at
most.
- End to end (Kuka camera task, 256 environments), `develop`'s upload,
the cache, and device-side flag writes measured 12.53, 12.50, and 12.47
ms per step. That spread is within run-to-run noise (12.45–12.58 ms).

## Series

1. #8036: Read camera outputs through `ProxyArray.torch` (bug fix)
(base: develop)
2. #8037: Fused normalization for strided camera images (base: #8036)
3. #8038: Skip redundant observation copies (base: #8037)
4. #8039: Remove per-step host synchronizations (base: develop)
5. #8040: Newton `render_batch` in one sensor-graph launch (base:
develop)
6. #8041: RSL-RL cuDNN benchmark, mixed precision and compile settings
(base: develop)
7. #8042: Kuka Allegro camera tasks on the shared image observation
(base: #8038)

The series is split from #7440, which remains the combined reference
branch.

## Type of change

- Bug fix (non-breaking change which fixes an issue)
- Changes to `SuccessMonitor`: `get_mean_success_rate()` returns a 0-d
tensor instead of a float, and `success_update()` gains a `valid`
argument. The changelog includes migration guidance.

## Performance

RTX PRO 6000 Blackwell Workstation Edition (driver 595.91.07); PyTorch
2.12.0+cu130; Warp 1.17.0; Newton 1.6.0; GPU otherwise idle. `develop`
at `10fdf81d9` compared with this PR (`b2727a0f2`; later commits only
trim comments and revert the Newton change above), with the same
`uv.lock`. Runtime benchmark (`isaaclab benchmark runtime`),
Newton/MJWarp, seed 42, no visualizer. Three fresh processes per
revision, run in alternating order. Figures are the mean step time
across processes.

| Workload | `develop` | This PR | Change |
| --- | ---: | ---: | ---: |
| `Isaac-Lift-KukaAllegro-Camera`, 256 envs,
`presets=duo_camera,rgb128`, Newton renderer (500 steps) | 14.44 ms |
12.62 ms | **−12.6%** (+14.4% throughput) |
| `Isaac-Cartpole-Direct`, 4096 envs (2,000 steps) | 1.674 ms | 1.441 ms
| **−13.9%** (+16.2% throughput) |
| `Isaac-Pendulum-MARL-Direct`, 4096 envs (2,000 steps) | 2.144 ms |
1.862 ms | **−13.2%** (+15.2% throughput) |

Per-process step times (`develop` → PR):
- Camera: `14.44, 14.48, 14.40` → `12.67, 12.63, 12.57` ms.
- Cartpole: `1.680, 1.685, 1.657` → `1.446, 1.438, 1.439` ms.
- Pendulum: `2.137, 2.158, 2.137` → `1.827, 1.863, 1.895` ms.

Host synchronizations per `env.step()`, attributed to call sites with
PyTorch sync-debug mode over 170 steps (4096 envs):

| Task | `develop` | This PR | Remaining |
| --- | ---: | ---: | --- |
| `Isaac-Lift-KukaAllegro-Camera` (`presets=cube`, Newton renderer) |
21.3 | 4.2 | step reset and command-resample `nonzero`; curriculum,
command-metric, and termination logging reads |
| `Isaac-Cartpole-Direct` | 10.3 | 1.0 | step reset `nonzero` |
| `Isaac-Pendulum-MARL-Direct` | 10.0 | 1.0 | step reset `nonzero` |

PyTorch labels sync-debug mode a prototype that does not detect every
synchronization, and it does not see synchronizations issued by Warp, so
these counts are lower bounds.

Reproduce with:

```bash
uv run --frozen isaaclab benchmark runtime \
  --task Isaac-Lift-KukaAllegro-Camera --num_envs 256 --num_steps 500 \
  --warmup_steps 100 --seed 42 --device cuda:0 --visualizer none \
  --output_path /tmp/pr8039 physics=newton_mjwarp renderer=newton_renderer presets=duo_camera,rgb128
```

### Not addressed

- **Step reset and command resampling:** both still call `nonzero` once
per step. Both convert a mask into variable-length environment IDs, and
the reset and command pipelines consume those IDs throughout. Removing
these synchronizations means moving those pipelines to masks or padded
IDs, which is out of scope here.
- **Warp-side synchronizations:** the Nsight trace above also records
many `cudaStreamSynchronize` calls outside the flag uploads, which
PyTorch's sync-debug mode cannot attribute. Their sources are not yet
identified.

## Validation

- Cartpole direct produces bit-identical observation and reward
checksums to `develop` after 150 seeded steps, including resets.
- Pendulum MARL is not run-to-run deterministic on MJWarp. Its
observations and rewards were instead compared on identical state
against `develop`'s host-index formulas for 150 steps, with a maximum
difference of 0.0. Reorient direct is also non-deterministic; its change
only removes a copy of an action tensor that is never modified in place.
- `test_circular_buffer.py`, `test_noise.py`, `test_curriculum.py`, the
manager tests (including `test_event_manager.py`,
`test_reward_manager.py`, `test_termination_manager.py`, and
`test_scene_entity_cfg.py`), `test_lift_env_cfg.py`,
`test_sensor_base.py`, `test_visualization_markers.py`, and
`test_kit_visualizer_scene_partitioning.py` pass.
- `test_rendering_lift_kuka_homo_kitless.py` passes for the Newton
renderer and legacy OVRTX cases. The two `ovstage` OVRTX cases fail
identically on `develop`.
- `uv run --frozen isaaclab -f` passes, including changelog checks.

## Release backport

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

---------

Co-authored-by: Octi Zhang <[email protected]>
isaaclab-bot Bot pushed a commit that referenced this pull request Sep 28, 2026
# Description

Part 4 of the camera performance series. Based on the latest `develop`,
including #8084 and #8087. Supersedes #7495.

Profiling the camera and direct tasks found host-device synchronizations
in every step: the CPU blocked on the GPU, then ran Python code while
the GPU sat idle. This PR removes them from termination tracking, the
Lift rewards and success monitoring, marker validation, camera updates,
and the Cartpole and Pendulum direct tasks. It also incorporates the
hot-path fixes from #6492 (by @kellyguo11) that still apply to current
`develop`.

- `torch.where` replaces `nonzero` in the termination manager and
replaces boolean-mask writes in the Lift progress rewards.
- `SuccessMonitor` updates no longer synchronize. They rank outcomes
with fixed-size scatters instead of `unique_consecutive`,
`repeat_interleave`, and boolean masks. Masked or overflowing outcomes
go to an internal scratch row. A new `valid` argument lets the Lift
reset hook pass a mask instead of filtering.
- `SuccessMonitor.get_mean_success_rate()` returns a 0-d tensor, so
logging it does not synchronize. The Cartpole direct and Pendulum MARL
success rates are logged as tensors for the same reason. Call `.item()`
where a Python float is needed.
- Cartpole direct and Pendulum MARL store their joint indices as device
tensors. Observations, rewards, terminations, resets, and effort writes
no longer upload host lists each step.
- Marker index validation runs only when a backend consumes the IDs, and
once per ID tensor.
- Cameras with `update_period == 0` skip the outdated-mask readback.
- Zero-width uniform `add` noise returns its input.
- `object_point_cloud_b` defaults to `visualize=False`. Drawing 262k
markers every step cost a sync, and with RTX the markers appeared in
camera images. The Kuka rendering test already disabled them for that
reason.
- `ActionManager` caches its term dimensions, which are fixed after
construction but were recomputed on every action step (from #6492).
- The Cartpole and Reorient direct tasks drop redundant action copies
(from #6492).

With #8087, managers finalize scene-entity selections to device tensors.
`object_ee_distance` therefore indexes with `asset_cfg.body_ids`
directly, and this PR's earlier cached device-ID helper was removed.
After #8087 it would have iterated the finalized tensor to build its
cache key, reading indices back from the device.

### Changes from #6492

Each #6492 change was checked against current `develop`:

| #6492 change | Decision |
| --- | --- |
| Skip observation-term clones | Not taken: `develop` already provides
this through #8038. |
| Cabinet direct `actions.clone()` | Not taken: the line no longer
exists. |
| `ActionManager` caches term dimensions | **Taken.** |
| Cartpole direct index cleanup | **Taken and extended.** #6492 fixed 1
of the 9 synchronizations caused by host-list joint indexing. Storing
the joint indices as device tensors removes all 9. |
| Drop `actions.clone()` in the Cartpole and Reorient direct tasks |
**Taken.** Neither task modifies the stored actions in place. |
| Drop `actions.clone()` in the Locomotion direct task | **Not taken.**
Its reset zeroes `self.actions` in place, which would zero the policy's
own action tensor, e.g. the one held in RL rollout storage. |

### Investigated and dropped: Newton sensor-graph flag cache

An earlier revision cached the Newton sensor graph's task flags and
skipped the upload when they were unchanged, on the premise that each
upload synchronized the stream. That premise does not hold for the
current Warp (1.17), so the change was reverted and `develop`'s per-call
upload is kept:

- Warp uploads the flags with a single `cudaMemcpyAsync` from pageable
memory, which CUDA stages on the host without waiting for the stream.
- Behind about 455 ms of Warp kernels queued on the same stream, ten
uploads return in 0.07–0.13 ms.
- An Nsight Systems trace of the Kuka camera task shows each flag
upload's `cudaMemcpyAsync` returning in 5.9 µs on average, 35.6 µs at
most.
- End to end (Kuka camera task, 256 environments), `develop`'s upload,
the cache, and device-side flag writes measured 12.53, 12.50, and 12.47
ms per step. That spread is within run-to-run noise (12.45–12.58 ms).

## Series

1. #8036: Read camera outputs through `ProxyArray.torch` (bug fix)
(base: develop)
2. #8037: Fused normalization for strided camera images (base: #8036)
3. #8038: Skip redundant observation copies (base: #8037)
4. #8039: Remove per-step host synchronizations (base: develop)
5. #8040: Newton `render_batch` in one sensor-graph launch (base:
develop)
6. #8041: RSL-RL cuDNN benchmark, mixed precision and compile settings
(base: develop)
7. #8042: Kuka Allegro camera tasks on the shared image observation
(base: #8038)

The series is split from #7440, which remains the combined reference
branch.

## Type of change

- Bug fix (non-breaking change which fixes an issue)
- Changes to `SuccessMonitor`: `get_mean_success_rate()` returns a 0-d
tensor instead of a float, and `success_update()` gains a `valid`
argument. The changelog includes migration guidance.

## Performance

RTX PRO 6000 Blackwell Workstation Edition (driver 595.91.07); PyTorch
2.12.0+cu130; Warp 1.17.0; Newton 1.6.0; GPU otherwise idle. `develop`
at `10fdf81d9` compared with this PR (`b2727a0f2`; later commits only
trim comments and revert the Newton change above), with the same
`uv.lock`. Runtime benchmark (`isaaclab benchmark runtime`),
Newton/MJWarp, seed 42, no visualizer. Three fresh processes per
revision, run in alternating order. Figures are the mean step time
across processes.

| Workload | `develop` | This PR | Change |
| --- | ---: | ---: | ---: |
| `Isaac-Lift-KukaAllegro-Camera`, 256 envs,
`presets=duo_camera,rgb128`, Newton renderer (500 steps) | 14.44 ms |
12.62 ms | **−12.6%** (+14.4% throughput) |
| `Isaac-Cartpole-Direct`, 4096 envs (2,000 steps) | 1.674 ms | 1.441 ms
| **−13.9%** (+16.2% throughput) |
| `Isaac-Pendulum-MARL-Direct`, 4096 envs (2,000 steps) | 2.144 ms |
1.862 ms | **−13.2%** (+15.2% throughput) |

Per-process step times (`develop` → PR):
- Camera: `14.44, 14.48, 14.40` → `12.67, 12.63, 12.57` ms.
- Cartpole: `1.680, 1.685, 1.657` → `1.446, 1.438, 1.439` ms.
- Pendulum: `2.137, 2.158, 2.137` → `1.827, 1.863, 1.895` ms.

Host synchronizations per `env.step()`, attributed to call sites with
PyTorch sync-debug mode over 170 steps (4096 envs):

| Task | `develop` | This PR | Remaining |
| --- | ---: | ---: | --- |
| `Isaac-Lift-KukaAllegro-Camera` (`presets=cube`, Newton renderer) |
21.3 | 4.2 | step reset and command-resample `nonzero`; curriculum,
command-metric, and termination logging reads |
| `Isaac-Cartpole-Direct` | 10.3 | 1.0 | step reset `nonzero` |
| `Isaac-Pendulum-MARL-Direct` | 10.0 | 1.0 | step reset `nonzero` |

PyTorch labels sync-debug mode a prototype that does not detect every
synchronization, and it does not see synchronizations issued by Warp, so
these counts are lower bounds.

Reproduce with:

```bash
uv run --frozen isaaclab benchmark runtime \
  --task Isaac-Lift-KukaAllegro-Camera --num_envs 256 --num_steps 500 \
  --warmup_steps 100 --seed 42 --device cuda:0 --visualizer none \
  --output_path /tmp/pr8039 physics=newton_mjwarp renderer=newton_renderer presets=duo_camera,rgb128
```

### Not addressed

- **Step reset and command resampling:** both still call `nonzero` once
per step. Both convert a mask into variable-length environment IDs, and
the reset and command pipelines consume those IDs throughout. Removing
these synchronizations means moving those pipelines to masks or padded
IDs, which is out of scope here.
- **Warp-side synchronizations:** the Nsight trace above also records
many `cudaStreamSynchronize` calls outside the flag uploads, which
PyTorch's sync-debug mode cannot attribute. Their sources are not yet
identified.

## Validation

- Cartpole direct produces bit-identical observation and reward
checksums to `develop` after 150 seeded steps, including resets.
- Pendulum MARL is not run-to-run deterministic on MJWarp. Its
observations and rewards were instead compared on identical state
against `develop`'s host-index formulas for 150 steps, with a maximum
difference of 0.0. Reorient direct is also non-deterministic; its change
only removes a copy of an action tensor that is never modified in place.
- `test_circular_buffer.py`, `test_noise.py`, `test_curriculum.py`, the
manager tests (including `test_event_manager.py`,
`test_reward_manager.py`, `test_termination_manager.py`, and
`test_scene_entity_cfg.py`), `test_lift_env_cfg.py`,
`test_sensor_base.py`, `test_visualization_markers.py`, and
`test_kit_visualizer_scene_partitioning.py` pass.
- `test_rendering_lift_kuka_homo_kitless.py` passes for the Newton
renderer and legacy OVRTX cases. The two `ovstage` OVRTX cases fail
identically on `develop`.
- `uv run --frozen isaaclab -f` passes, including changelog checks.

## Release backport

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

---------

Co-authored-by: Octi Zhang <[email protected]>

(cherry picked from commit 60bc09f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants