Skip to content

Optimize Newton Ant direct stepping - #6509

Closed
AntoineRichard wants to merge 1 commit into
isaac-sim:developfrom
AntoineRichard:antoiner/optimize-ant-direct
Closed

AntoineRichard wants to merge 1 commit into
isaac-sim:developfrom
AntoineRichard:antoiner/optimize-ant-direct

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

Summary

This Draft PR shows the code changes required to let Isaac-Ant-Direct benefit from Newton zero-copy state access instead of spending most of the step in task orchestration.

  • Fuse stable Ant intermediate values, terminations, rewards, and observations into one Warp post-step kernel.
  • Keep reset selection on the GPU with a guarded device-mask reset hook.
  • Stage persistent effort targets once per environment step instead of once per physics substep.
  • Remove repeated all-joint index uploads, duplicate reset work, and redundant state copies/writes.
  • Skip inactive Newton instantaneous-wrench buffer clears.
  • Preserve the original Torch path for PhysX and unsupported Newton configurations.

This is a fresh PR based directly on develop. It does not modify or depend on #6474.

Performance

RTX 5090, 4,096 environments, Newton/MJWarp, 100 warm-up steps, 1,000 measured steps, pre-generated seeded actions, with one device synchronization before and after the complete measured window:

Seed Control Optimized Reduction Speedup
42 3.308513 ms 1.359872 ms 58.898% 2.433x
43 3.047741 ms 1.361723 ms 55.320% 2.238x
44 3.012498 ms 1.364235 ms 54.714% 2.208x
Mean 3.122917 ms 1.361944 ms 56.311% paired mean 2.293x aggregate

Aggregate throughput improves from 1.312M to 3.007M env-steps/s. The optimized stable task reaches the same throughput class as the 2.98M env-steps/s experimental Warp/mask upper-bound task without substituting its different semantics.

Same-mode Nsight traces show:

  • task post-processing launches: 55 per step to 1 per step;
  • non-graph kernel launches: 2,000 to 1,160 over 20 steps;
  • reset compaction kernels: eliminated;
  • per-step cudaStreamSynchronize: 40 calls / 11.536 ms to zero;
  • inactive wrench clears: 14 per step to zero.

Semantic guards

  • The fused post-step runs only on Newton with compute_final_obs=False.
  • PhysX retains its pull-on-demand state path.
  • Mask reset requires stateless ImplicitActuator instances, no Newton actuator adapter, no events or noise, and no reset rerendering.
  • Active wrench composers are cleared with the reset mask; inactive composers launch no work.
  • Live joint-limit views preserve runtime limit updates.
  • Stable XYZW quaternion math, termination, reward, observation layout, timeout boundary, potential bookkeeping, and terminal outputs are retained.

Type of change

  • Bug fix / performance optimization (non-breaking)
  • New feature
  • Breaking change
  • Documentation update

Screenshots

Not applicable; this is a headless simulation performance change.

Validation

  • 18 passed across focused CPU/CUDA regression tests.
  • Regression tests were confirmed to fail without the relevant fixes.
  • Live PhysX Ant fallback smoke test passed.
  • Three 4,096-environment Newton device-complete repetitions passed.
  • ./isaaclab.sh -p tools/changelog/cli.py check develop passed.
  • ./isaaclab.sh -f passed after the final commit.

Checklist

  • I have read and understood the contribution guidelines.
  • I have run the pre-commit checks with ./isaaclab.sh -f.
  • Documentation changes are not required for this internal guarded optimization; the benchmark contract and results are included above.
  • No new warnings were identified; focused tests report existing deprecation warnings.
  • I have added tests that prove the fixes are effective.
  • I have added one changelog fragment for each touched package.
  • Antoine Richard is already listed in CONTRIBUTORS.md.

Fuse Ant task post-processing and keep reset selection on the device for the default Newton configuration. Remove redundant action, reset, joint-index, and inactive wrench work so direct stepping can benefit from Newton zero-copy state access.
@AntoineRichard

Copy link
Copy Markdown
Collaborator Author

Superseded by the focused Draft PRs #6510, #6511, and #6512. The fused Ant post-step and device-mask implementation are intentionally deferred and are not included in those PRs. Benchmark PR #6474 remains untouched.

AntoineRichard added a commit that referenced this pull request Jul 15, 2026
# Description

Skips resetting inactive instantaneous-wrench composers in the Newton,
PhysX, and OVPhysX articulation write paths.

Newton and PhysX previously cleared all seven composer buffers on every
physics substep even when no instantaneous wrench had been applied.
Nsight attributed fourteen 442,368-byte clears per Ant environment step
to this work on Newton. OVPhysX already avoids resets when neither
composer is active; its guard removes the remaining redundant reset when
only permanent wrenches are active.

The active check preserves the existing reset after every applied
instantaneous wrench. An inactive composer is already fully reset:
construction and full reset both zero its five input and two output
buffers, while every supported add or set operation marks it active.

This is one focused slice of superseded Draft PR #6509 and is
independent of benchmark PR #6474.

## Type of change

- Bug fix (non-breaking performance fix)

## Validation

- ./isaaclab.sh -p tools/changelog/cli.py check develop
- ./isaaclab.sh -f before commit
- ./isaaclab.sh -f after commit and before push
- The Newton source change was exercised by the original focused
CPU/CUDA validation before the PR split; new test files are
intentionally omitted from this slice.

## Checklist

- [x] I have read and understood the contribution guidelines
- [x] I have run the pre-commit checks with ./isaaclab.sh --format
- [x] Documentation changes are not required
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment for every touched package
- [x] My name already exists in CONTRIBUTORS.md
AntoineRichard added a commit that referenced this pull request Jul 15, 2026
# Description

Adds a protected DirectRLEnv reset hook that preserves the existing
indexed reset behavior by default while allowing backend-native task
implementations to complete reset processing from a device mask without
materializing dynamic reset indices on the host.

CUDA torch.nonzero compaction requires determining a dynamic output size
and can synchronize the stream. The hook isolates that policy decision
without changing existing DirectRLEnv task semantics.

ManagerBasedRLEnv is intentionally not included. Its scene, event,
recorder, curriculum, observation, action, reward, command, and
termination reset contracts currently require compact environment IDs,
so adding the same hook there would not yet provide a
synchronization-free path.

This is one focused slice of superseded Draft PR #6509 and is
independent of benchmark PR #6474.

## Type of change

- New feature (non-breaking protected extension point)

## Validation

- ./isaaclab.sh -p tools/changelog/cli.py check develop
- ./isaaclab.sh -f before commit
- ./isaaclab.sh -f after commit and before push
- The source change was exercised by the original focused CPU/CUDA
validation before the PR split; new test files are intentionally omitted
from this slice.

## Checklist

- [x] I have read and understood the contribution guidelines
- [x] I have run the pre-commit checks with ./isaaclab.sh --format
- [x] Documentation changes are not required for this protected hook
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment for the touched package
- [x] My name already exists in CONTRIBUTORS.md
matthewtrepte pushed a commit to matthewtrepte/IsaacLab that referenced this pull request Aug 4, 2026
# Description

Skips resetting inactive instantaneous-wrench composers in the Newton,
PhysX, and OVPhysX articulation write paths.

Newton and PhysX previously cleared all seven composer buffers on every
physics substep even when no instantaneous wrench had been applied.
Nsight attributed fourteen 442,368-byte clears per Ant environment step
to this work on Newton. OVPhysX already avoids resets when neither
composer is active; its guard removes the remaining redundant reset when
only permanent wrenches are active.

The active check preserves the existing reset after every applied
instantaneous wrench. An inactive composer is already fully reset:
construction and full reset both zero its five input and two output
buffers, while every supported add or set operation marks it active.

This is one focused slice of superseded Draft PR isaac-sim#6509 and is
independent of benchmark PR isaac-sim#6474.

## Type of change

- Bug fix (non-breaking performance fix)

## Validation

- ./isaaclab.sh -p tools/changelog/cli.py check develop
- ./isaaclab.sh -f before commit
- ./isaaclab.sh -f after commit and before push
- The Newton source change was exercised by the original focused
CPU/CUDA validation before the PR split; new test files are
intentionally omitted from this slice.

## Checklist

- [x] I have read and understood the contribution guidelines
- [x] I have run the pre-commit checks with ./isaaclab.sh --format
- [x] Documentation changes are not required
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment for every touched package
- [x] My name already exists in CONTRIBUTORS.md
matthewtrepte pushed a commit to matthewtrepte/IsaacLab that referenced this pull request Aug 4, 2026
# Description

Adds a protected DirectRLEnv reset hook that preserves the existing
indexed reset behavior by default while allowing backend-native task
implementations to complete reset processing from a device mask without
materializing dynamic reset indices on the host.

CUDA torch.nonzero compaction requires determining a dynamic output size
and can synchronize the stream. The hook isolates that policy decision
without changing existing DirectRLEnv task semantics.

ManagerBasedRLEnv is intentionally not included. Its scene, event,
recorder, curriculum, observation, action, reward, command, and
termination reset contracts currently require compact environment IDs,
so adding the same hook there would not yet provide a
synchronization-free path.

This is one focused slice of superseded Draft PR isaac-sim#6509 and is
independent of benchmark PR isaac-sim#6474.

## Type of change

- New feature (non-breaking protected extension point)

## Validation

- ./isaaclab.sh -p tools/changelog/cli.py check develop
- ./isaaclab.sh -f before commit
- ./isaaclab.sh -f after commit and before push
- The source change was exercised by the original focused CPU/CUDA
validation before the PR split; new test files are intentionally omitted
from this slice.

## Checklist

- [x] I have read and understood the contribution guidelines
- [x] I have run the pre-commit checks with ./isaaclab.sh --format
- [x] Documentation changes are not required for this protected hook
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment for the touched package
- [x] My name already exists in CONTRIBUTORS.md
AntoineRichard added a commit that referenced this pull request Sep 8, 2026
# Description

Reduces common Direct Locomotion task overhead used by Ant and Humanoid
without introducing the experimental Ant post-step path.

The change:

- stages effort targets once per environment step because articulation
command buffers persist across decimation substeps;
- uses the cached all-joint target path instead of repeatedly uploading
joint indices;
- keeps scalar zero assignments on-device;
- removes a duplicate articulation reset already performed by the scene
reset;
- removes redundant clones after advanced indexing; and
- uses the common fused joint-state writer provided by PhysX, Newton,
and Isaac Lab OV.

The isolated device scalar change improved the Ant host-return
measurement from 3.433 ms to 3.231 ms. The remaining changes remove
repeated launches, index transfers, copies, and reset writes; the larger
fused post-step and device-mask work is deliberately excluded.

This is one focused slice of superseded Draft PR #6509 and is
independent of benchmark PR #6474.

## Type of change

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

## Release backport

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

## Screenshots

Not applicable.

## Validation

- `uv run python tools/changelog/cli.py check develop`
- `uv run --frozen isaaclab -f`
- `uv run --frozen --extra test python -m pytest
source/isaaclab_tasks/test/core/test_environments_newton.py -k 'Direct
and (Ant or Humanoid)' -q` (`2 passed`)
- Verified the fused writer interface on PhysX, Newton, and Isaac Lab
OV.
- The source change was exercised by the original focused CPU/CUDA
validation before the PR split; new test files are intentionally omitted
from this slice.

## Checklist

Docker and GPU tests run on demand. Push the commits you want tested,
then
comment `run-ci` on the pull request.

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation (not
required for this internal performance fix)
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] 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)
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
isaaclab-bot Bot pushed a commit that referenced this pull request Sep 8, 2026
# Description

Reduces common Direct Locomotion task overhead used by Ant and Humanoid
without introducing the experimental Ant post-step path.

The change:

- stages effort targets once per environment step because articulation
command buffers persist across decimation substeps;
- uses the cached all-joint target path instead of repeatedly uploading
joint indices;
- keeps scalar zero assignments on-device;
- removes a duplicate articulation reset already performed by the scene
reset;
- removes redundant clones after advanced indexing; and
- uses the common fused joint-state writer provided by PhysX, Newton,
and Isaac Lab OV.

The isolated device scalar change improved the Ant host-return
measurement from 3.433 ms to 3.231 ms. The remaining changes remove
repeated launches, index transfers, copies, and reset writes; the larger
fused post-step and device-mask work is deliberately excluded.

This is one focused slice of superseded Draft PR #6509 and is
independent of benchmark PR #6474.

## Type of change

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

## Release backport

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

## Screenshots

Not applicable.

## Validation

- `uv run python tools/changelog/cli.py check develop`
- `uv run --frozen isaaclab -f`
- `uv run --frozen --extra test python -m pytest
source/isaaclab_tasks/test/core/test_environments_newton.py -k 'Direct
and (Ant or Humanoid)' -q` (`2 passed`)
- Verified the fused writer interface on PhysX, Newton, and Isaac Lab
OV.
- The source change was exercised by the original focused CPU/CUDA
validation before the PR split; new test files are intentionally omitted
from this slice.

## Checklist

Docker and GPU tests run on demand. Push the commits you want tested,
then
comment `run-ci` on the pull request.

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation (not
required for this internal performance fix)
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] 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)
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

(cherry picked from commit 25fad3e)
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.

1 participant