Skip to content

Capture the Newton physics step on CPU with Warp graph capture - #8959

Merged
maxkra15 merged 6 commits into
isaac-sim:mainfrom
AntoineRichard:antoiner/feat/newton-cpu-graph-capture
Nov 11, 2026
Merged

maxkra15 merged 6 commits into
isaac-sim:mainfrom
AntoineRichard:antoiner/feat/newton-cpu-graph-capture

Conversation

@AntoineRichard

@AntoineRichard AntoineRichard commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

On device="cpu", the Newton backend never captures the physics step. The gate in NewtonBackend.init_solver requires device.is_cuda, so every step launches each Warp kernel from Python, at about 6–11 µs per launch. Warp has supported CPU graph capture since 1.13 (main pins 1.17.0). It records kernel launches and memory operations and replays them natively.

This PR drops the is_cuda condition. The step is now captured on any device when use_cuda_graph is set (the default) and the solver's supports_capture holds. capture_graph gets a CPU branch that uses wp.ScopedCapture(device=...), because the CPU has no streams; relaxed is CUDA-only.

Warp's CPU capture does not replay torch operations, host reads (.numpy()), wp.Mesh.refit, nested capture_launch calls, or copies between non-contiguous arrays. Inside a capture, these either run once and never replay, with no error, or raise. Solvers whose CPU step hits one of these now opt out through supports_capture:

  • MPM: stays uncaptured on the CPU. Its rheology loop reads the residual on the host, and sparse grids rebuild through wp.Volume.rebuild, which CPU capture doesn't record. Captured runs drift from the first replay on a fixed grid and crash on a rebuildable sparse grid; CUDA capture of the same scenes is bit-for-bit identical.
  • Kamino P-ADMM with an iterative linear solver (CR, CG, or sparse dynamics, which forces CR): stays uncaptured on the CPU. The solver copies between non-contiguous arrays, which CPU capture rejects with an error on the first captured step. DVI, and P-ADMM with a direct solver, are captured.

Everything else is captured on the CPU: MJWarp (not with use_mujoco_cpu), XPBD, Featherstone, VBD, and the coupler, which captures only when every entry does. Setting use_cuda_graph=False turns capture off on the CPU.

Callback contract. On the CPU, a torch op or host read in a step callback runs only once, with no error. The register_*_callback docstrings now point to NewtonCfg.use_cuda_graph, which says callbacks may only do Warp work. An audit of every in-repo step callback, actuator path (Newton actuators, BAM, delay, neural drives) and sensor update found only Warp work.

No new dependencies and no new public API.

Performance

Workstation: i9-14900K, Linux, Python 3.12, Warp 1.17.0, Newton 1.8.0.dev0 (rev 42f7def1), MuJoCo Warp 3.15.0, measured on main at 8a9e6eb. The setup is presets=newton_mjwarp with seeded zero actions. Each run does 20 warmup env steps, then times 100 env steps (50 for Anymal-D), with a wp.synchronize() before each timer read. The table shows ms per env step, eager vs. captured. Every row produced the same observation checksum both ways. Each row is one zero-action run of a small timing script (gym.make, then env.step in a loop), roughly:

uv run python bench_env.py --task Isaac-Cartpole-Direct --num_envs 256 --device cpu presets=newton_mjwarp

Eager is the same command with capture disabled on the CPU.

Task Envs Eager Captured Speedup
Cartpole-Direct 1 4.18 0.33 12.7×
Cartpole-Direct 256 5.44 1.32 4.1×
Cartpole-Direct 4096 19.6 16.5 1.19×
Ant-Direct 1 4.93 0.57 8.7×
Ant-Direct 64 9.04 4.04 2.2×
Ant-Direct 1024 61.9 56.8 1.09×
Velocity-Flat-AnymalD 1 16.9 2.9 5.8×
Velocity-Flat-AnymalD 256 297 274 1.08×

The gain shrinks as env count grows. Capture removes launch overhead, but Warp CPU kernels still run serially on one thread, so at high env counts kernel execution dominates.

Type of change

  • New feature (non-breaking change which adds functionality)

Validation

Eager and captured CPU trajectories were compared step by step through NewtonBackend, with resets and decimation changes:

  • Bit-for-bit identical:
    • MJWarp tasks: Cartpole, Ant, Anymal-D, Reach-Franka, Humanoid, Allegro, G1, Go2 rough, MicroDuck BAM, and Anymal-D with an LSTM actuator.
    • XPBD and Featherstone.
    • VBD: rigid scenes, cloth with and without self-contact, tet meshes, and an Isaac Lab cable scene.
    • Kamino: DVI, and P-ADMM with a direct linear solver.
    • Coupler: proxy and ADMM configurations, MJWarp+VBD, gb300-like cable.
  • Not identical, so these now opt out: MPM and Kamino P-ADMM with an iterative linear solver.

Tests are kept minimal:

  • test_backends_with_different_solvers_step_side_by_side now also runs backend capture and outer capture on the CPU. Eager stays CUDA-only, because the capture cases already step their CPU reference backends eagerly.
  • The recording-solver fixture defaults to captures=False, so its tests keep stepping without capture on the CPU.
  • isaaclab_newton/test/physics/test_coupler.py: the MPM stub in test_mpm_grid_controls_coupled_cuda_graph_support gets a model on a CUDA device, because MPMSolver.supports_capture now reads the solver's device.
  • Every isaaclab_newton and isaaclab_contrib test file was run in its own process with the isaacsim and tetrahedralization extras: all 53 files pass. That includes the Kit-based reset, fabric-sync, deformable and manual-coupling tests. After merging main (which moved the coupler into isaaclab_newton and removed CoupledMJWarpVBDSolver), the manager, solver, coupler, coupler-runtime, MPM and deformable tests pass again.
  • uv run isaaclab --format, git diff --check and the changelog gate pass.

Limitations

  • Only the physics step is captured on the CPU. The BVH refit, ray caster, Warp renderer and frame transformer graphs stay CUDA-only.
  • Coupler proxies with collide_interval > 1 replay the collision cadence frozen at capture time, on both CUDA and CPU. This is unchanged by this PR.
  • _WarpLaunchCache still skips launch reuse on the CPU. It could cut uncaptured launch cost and is a separate follow-up.

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package
  • My name already exists in CONTRIBUTORS.md

Warp's CPU graph capture records kernel launches and memory operations
and replays them natively, removing per-launch Python overhead. The
Newton backend only captured on CUDA, so every CPU step launched each
kernel from Python.

Capture the step on the CPU for solvers that opt in through the new
NewtonSolver.cpu_capture flag: MJWarp (without use_mujoco_cpu), XPBD and
Featherstone. Other solvers keep stepping eagerly on the CPU.
capture_graph gains a CPU branch, since the CPU has no streams.

Document that step callbacks must issue only Warp work, because CPU
capture does not replay torch operations or host reads.
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Nov 6, 2026
Drop NewtonSolver.cpu_capture: the Newton step is now captured on any
device when use_cuda_graph is set and the solver's supports_capture
holds. Solvers whose CPU step Warp's CPU capture cannot replay opt out
there instead:

- MPM reads its rheology residual on the host and rebuilds sparse grids
  through Volume.rebuild, so it stays eager on the CPU.
- Kamino P-ADMM with an iterative linear solver copies strided views,
  which CPU capture rejects, so it stays eager on the CPU.
- CoupledMJWarpVBDSolver now captures only when both sub-solvers
  support capture.

VBD, XPBD, Featherstone, MJWarp and the coupler replay bit for bit on
the CPU and are captured.
@AntoineRichard
AntoineRichard marked this pull request as ready for review November 6, 2026 18:32
@AntoineRichard
AntoineRichard requested a review from a team November 6, 2026 18:32
@greptile-apps

greptile-apps Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR changes execution across CPU-based Newton physics steps.

The PR appears safe to merge, with a non-blocking gap in tests for the new solver-specific capture rules.

Findings

  1. P2 Capture rules lack direct tests ▶

Summary

Enables Warp graph capture for Newton physics steps on the CPU.

  • Newton replays supported physics steps from graphs on the CPU.
  • Coupled MJWarp and VBD steps follow both solvers' capture limits.

The new solver-specific capture rules need focused regression tests. No blocking behavior defect was established.

Acknowledgment: AntoineRichard explicitly identifies frozen collision cadence for coupler proxies with collide_interval > 1 as an existing limitation outside this change.

Reviews (1) · Last reviewed commit: "Gate CPU capture through supports_captur..." · Reviewed by Greptile

MPMSolver.supports_capture now reads the solver's device, so the stub needs a model on a CUDA device to keep testing grid support.
Comment on lines +85 to +88
config = solver._config
if solver.model.device.is_cuda or config.dynamics_solver != "padmm":
return True
return not config.sparse_dynamics and config.dynamics.linear_solver_type in ("LLTB", "LLTBRCM", "LLTS")

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.

P2 Capture rules lack direct tests

The expanded replay test covers only MJWarp and Featherstone. It does not check the new CPU exclusions in KaminoSolver.supports_capture and MPMSolver.supports_capture, or the sub-solver checks in CoupledMJWarpVBDSolver.supports_capture. These guards could regress while the suite still passes, allowing unsupported CPU work to be captured.

Add focused tests for accepted and rejected configurations, including CUDA behavior. The existing MPM test checks only mpm_supports_graph_capture, not the new device check.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@AntoineRichard

Copy link
Copy Markdown
Collaborator Author

run-ci

@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 Nov 6, 2026

@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

Needs attention: Compatibility and deprecation (1), Style consistency (2), Test quality (1). Other reviewed categories look good.

  • PR description: The body matches the diff, but classify the default CPU semantic change as breaking and add the benchmark command, warmup, measured-step count, and software environment needed to reproduce the table.
  • Design and architecture: Architecture looks good.
  • Scope and over-engineering: No over-engineering issues.
  • API: API changes look good.
  • Compatibility and deprecation: Breaking changes: the existing use_cuda_graph default now captures CPU callbacks and external solvers, silently changing replay behavior without an opt-in transition, targeted warning, or deprecation coverage.
  • Implementation: Implementation looks good.
  • Style consistency: CPU support leaves a CUDA-named timer key, and the added MPM docstring breaks the adjacent one-line-summary pattern; use device-neutral naming and separate the rationale paragraph.
  • Test quality: The expanded device matrix adds a redundant CPU eager row already exercised by eager reference backends in both CPU capture cases; restrict eager execution to CUDA.

Significant concerns. Posted 4 inline findings.

Automated review; human maintainers own approval decisions.

…oiner/feat/newton-cpu-graph-capture

# Conflicts:
#	source/isaaclab_contrib/isaaclab_contrib/custom_coupling/coupled_mjwarp_vbd_solver.py
#	source/isaaclab_newton/isaaclab_newton/physics/kamino_solver.py
#	source/isaaclab_newton/isaaclab_newton/physics/mpm_solver.py
#	source/isaaclab_newton/isaaclab_newton/physics/newton_backend.py
#	source/isaaclab_newton/isaaclab_newton/physics/newton_solver.py
…e row

Rename the graph capture timer to newton_graph_capture now that it also times CPU captures, and keep the eager row of the side-by-side backend test on CUDA only: the CPU capture rows already step their reference backends eagerly.

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

The current-head CPU Featherstone capture/replay/recapture probe matches eager stepping bit-for-bit. CI fails during Cartpole process startup creating Carb shared memory; this does not demonstrate a CPU capture regression. Rerun that failed benchmark on a clean worker before approval.

…oiner/feat/newton-cpu-graph-capture

# Conflicts:
#	source/isaaclab_contrib/isaaclab_contrib/custom_coupling/coupled_mjwarp_vbd_solver.py
@AntoineRichard

Copy link
Copy Markdown
Collaborator Author

run-ci

@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 Nov 9, 2026

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

CPU capture/replay and recapture match eager stepping exactly with pinned Newton. Current-head CI is green.

@maxkra15
maxkra15 merged commit 5571528 into isaac-sim:main Nov 11, 2026
67 of 91 checks passed
r-schmitt pushed a commit that referenced this pull request Nov 12, 2026
# Description

After #8959 enabled Newton CPU graph capture, actuator target writes
could fail with `AttributeError: 'Tensor' object has no attribute
'ptr'`. Warp's CPU capture expects array metadata when recording the
Torch values and selectors passed to these kernels.

Convert Torch arguments to zero-copy `wp.from_torch` views at the
indexed and masked target-setter launch boundaries. This preserves
storage, dtype, strides, and selector order, so graph replay observes
in-place command updates. Existing dispatch and backend staging remain
unchanged.

Extends the two existing setter tests with CPU capture/replay checks for
updated values, selections, and untouched entries.

## Validation

- All six extended setter cases reproduce the original error before the
fix; all **23 actuator tests pass** afterward.
- Real Cartpole CPU capture/replay: **20 steps** with changing actions,
correct targets, and finite outputs.
- Full formatting/lint, changelog, and diff checks passed.
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.

5 participants