Repository navigation
Conversation
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.
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.
[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
SummaryEnables Warp graph capture for Newton physics steps on the CPU.
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 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.
| 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") |
There was a problem hiding this comment.
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!
|
run-ci |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
|
run-ci |
maxkra15
left a comment
There was a problem hiding this comment.
CPU capture/replay and recapture match eager stepping exactly with pinned Newton. Current-head CI is green.
# 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.
Description
On
device="cpu", the Newton backend never captures the physics step. The gate inNewtonBackend.init_solverrequiresdevice.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_cudacondition. The step is now captured on any device whenuse_cuda_graphis set (the default) and the solver'ssupports_captureholds.capture_graphgets a CPU branch that useswp.ScopedCapture(device=...), because the CPU has no streams;relaxedis CUDA-only.Warp's CPU capture does not replay torch operations, host reads (
.numpy()),wp.Mesh.refit, nestedcapture_launchcalls, 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 throughsupports_capture: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.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. Settinguse_cuda_graph=Falseturns 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_*_callbackdocstrings now point toNewtonCfg.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
mainat 8a9e6eb. The setup ispresets=newton_mjwarpwith seeded zero actions. Each run does 20 warmup env steps, then times 100 env steps (50 for Anymal-D), with awp.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, thenenv.stepin a loop), roughly:Eager is the same command with capture disabled on the CPU.
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
Validation
Eager and captured CPU trajectories were compared step by step through
NewtonBackend, with resets and decimation changes:Tests are kept minimal:
test_backends_with_different_solvers_step_side_by_sidenow 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.captures=False, so its tests keep stepping without capture on the CPU.isaaclab_newton/test/physics/test_coupler.py: the MPM stub intest_mpm_grid_controls_coupled_cuda_graph_supportgets a model on a CUDA device, becauseMPMSolver.supports_capturenow reads the solver's device.isaaclab_newtonandisaaclab_contribtest file was run in its own process with theisaacsimandtetrahedralizationextras: all 53 files pass. That includes the Kit-based reset, fabric-sync, deformable and manual-coupling tests. After merging main (which moved the coupler intoisaaclab_newtonand removedCoupledMJWarpVBDSolver), the manager, solver, coupler, coupler-runtime, MPM and deformable tests pass again.uv run isaaclab --format,git diff --checkand the changelog gate pass.Limitations
collide_interval > 1replay the collision cadence frozen at capture time, on both CUDA and CPU. This is unchanged by this PR._WarpLaunchCachestill skips launch reuse on the CPU. It could cut uncaptured launch cost and is a separate follow-up.Checklist
pre-commitchecks withuv run isaaclab --formatsource/<pkg>/changelog.d/for every touched packageCONTRIBUTORS.md