Skip to content

Reserve CUDA graph memory when the simulation context is created - #8539

Merged
kellyguo11 merged 3 commits into
isaac-sim:developfrom
egolubev-nvda:egolubev/reserve-cuda-graph-memory
Oct 14, 2026
Merged

kellyguo11 merged 3 commits into
isaac-sim:developfrom
egolubev-nvda:egolubev/reserve-cuda-graph-memory

Conversation

@egolubev-nvda

@egolubev-nvda egolubev-nvda commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

On Windows, the first CUDA graph capture after the renderer's first frame can stall for many minutes. This PR applies the workaround from @shi-eric's analysis in #8342: record one tiny allocation in a CUDA graph when SimulationContext is created, so the CUDA driver reserves graph memory before anything can block its placement.

Fixes #8342. Supersedes #8528.

Root cause (summary of #8342)

  • The first allocation recorded in a CUDA graph makes the driver reserve a large virtual-address range for graph memory (96 GiB on our machine).
  • Cubric allocates managed memory, which creates a 52 GiB managed-memory window. The driver places the graph-memory range directly above that window.
  • When a rendered frame already occupies those addresses, the driver retries placement 2 MiB higher each time, at about 0.8 s of kernel CPU per attempt. The GPU stays idle; getting past the blocked range takes about 15 minutes.
  • Capture Newton CUDA graphs without advancing simulation #8058 moved Newton's first capture to the first physics step, after the first frame. MuJoCo-Warp allocates temporaries on every step, so the capture contains allocations.

Change

  • isaaclab.utils.device.reserve_cuda_graph_memory(device): records one wp.empty(1) inside wp.ScopedCapture, once per CUDA device. It skips non-CUDA devices, devices with the Warp memory pool disabled, and devices that are already capturing. A failure is logged as a warning and never blocks startup.
  • SimulationContext.__init__ calls it right after selecting the device, before physics backends and renderers are created. Every entry point (environments, benchmarks, tests) goes through this path.
  • Runs on all platforms; on platforms without the driver issue the extra capture is harmless.

Measurements

Windows 11, RTX 6000 Ada, driver 596.72, Isaac-Lift-KukaAllegro-Camera, 1024 envs, newton_mjwarp, capture watchdog 8–15 s:

Setup develop This PR
OVRTX (kitless), presets=newton_mjwarp,ovrtx,single_camera,simple_shading_full_mdl64 about 70% of runs stalled 0 / 10
Kit with Isaac Sim RTX, presets=newton_mjwarp,isaacsim_rtx,single_camera 7 / 8 stalled 0 / 8

The Kit result means this stall is not limited to OVRTX: Kit with Newton physics hits it too.

Other checks with the same workaround (applied at gym.make, physics-only task, 8192 envs):

  • A graph-memory trim right before Newton's capture does not release the early reservation (0 / 8 stalls).
  • Physics step, full environment step and peak GPU memory are within noise of develop.

Limits

  • Under Kit, Kit's renderer starts before SimulationContext, so the reservation cannot precede it. It still precedes Cubric's managed memory and the next rendered frame, which was enough in the measurements above.
  • OvPhysX imports ovstage in _prepare_stage_creation, before this call. OvPhysX with OVRTX was not measured.
  • Linux, L40, and long training runs were not tested here.
  • Kit with PhysX physics was not tested.

Type of change

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

Release backport

  • Backport this pull request to the active release branch after it merges into develop

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format (ruff check and format on the changed files)
  • 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
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

On Windows, the first allocation recorded in a CUDA graph after the
renderer's first frame can stall the CUDA driver for minutes while it
places the graph-memory address range. Record one tiny allocation in a
graph right after selecting the device, before physics backends and
renderers are created, so later captures reuse the early reservation.

Fixes isaac-sim#8342.
@egolubev-nvda

Copy link
Copy Markdown
Contributor 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 Oct 13, 2026
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Adds CUDA graph memory reservation to simulation startup.

The PR appears safe to merge, with a non-blocking improvement to let failed reservations be retried.

Findings

  1. P2 Failed attempts block later retries ▶

Summary

Adds a small CUDA graph capture when SimulationContext selects its device, before physics initialization and renderer creation.

  • Simulation setup reserves CUDA graph memory before physics starts.

Acknowledged limits: egolubev-nvda states that Kit’s renderer starts earlier and that OvPhysX with OVRTX was not measured.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Select Torch and Warp device] --> B{CUDA, memory pool enabled, not capturing, not cached?}
    B -->|No| E[Initialize physics]
    B -->|Yes| C[Cache device alias]
    C --> D[Capture one small allocation]
    D -->|Success| E
    D -->|Failure: log warning| E
    E --> F[Create render context]
Loading

Reviews (1) · Last reviewed commit: "Reserve CUDA graph memory when the simul..." · Reviewed by Greptile

or warp_device.alias in _GRAPH_MEMORY_RESERVED_DEVICES
):
return
_GRAPH_MEMORY_RESERVED_DEVICES.add(warp_device.alias)

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 Failed attempts block later retries

reserve_cuda_graph_memory marks the device as reserved before the capture succeeds. If capture fails, every later call for that device returns without trying again, including after a new SimulationContext is created. Add the alias only after a successful capture, or remove it on failure, and test that a failed attempt can be retried.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 71079fc: the device is marked as reserved only after the capture succeeds, so a failed attempt is retried by the next call. The device test now covers a failure followed by a successful retry.

@egolubev-nvda

Copy link
Copy Markdown
Contributor Author

Results of local tests
image

@StafaH StafaH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's minimize the additional test coverage, and also leave a #TODO to remove this after the bug is fixed

Mark a device as reserved only after the capture succeeds, so a failed
attempt is retried by the next simulation context. Reduce the new device
tests to one, and add a TODO to remove the workaround once the CUDA
driver bug is fixed.
@egolubev-nvda

Copy link
Copy Markdown
Contributor Author

@StafaH Thanks. Done in 71079fc: added a TODO at the call site to remove the workaround once the CUDA driver bug is fixed, and reduced the new tests to one device test plus the ordering test (the earlier skip-case and real-CUDA tests are removed). The commit also marks a device as reserved only after a successful capture, per the Greptile comment.

@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: Style consistency (1), Test quality (2). Other reviewed categories look good.

  • PR description: The stall-rate evidence covers hardware, backend, workload, environment count, samples, and results; add exact baseline and candidate revisions, the reproduction command, and warmup procedure.
  • Design and architecture: Architecture looks good.
  • Scope and over-engineering: No over-engineering issues.
  • API: API changes look good.
  • Compatibility and deprecation: No breaking changes identified.
  • Implementation: Implementation looks good.
  • Style consistency: The utils.device module docstring excludes graph-memory reservation, leaving its documented scope stale; broaden it to cover both device selection and CUDA graph reservation.
  • Test quality: The added tests duplicate SimulationContext construction setup and never assert wp.empty; share the harness and verify the allocation call.

Minor fixes needed. Posted 3 inline findings.

Automated review; human maintainers own approval decisions.

wp.set_device(warp_device)


def reserve_cuda_graph_memory(device: str) -> None:

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.

🟡 Warning · Style Consistency — Module docstring excludes graph reservation

The module documents itself as "Internal utilities for selecting compute devices", which no longer covers this graph-memory reservation. Update the module docstring to cover both responsibilities.

physics_manager.initialize.side_effect = lambda sim: order.append("physics_initialize")
physics_cfg = SimpleNamespace(class_type=physics_manager, dt=0.01)
settings = {}
monkeypatch.setattr(context_module, "_resolve_physics_cfg", lambda cfg, use_isaac_sim: physics_cfg)

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.

🟡 Warning · Test Quality — Duplicated SimulationContext construction setup

These monkeypatch lines repeat verbatim the harness in test_visualizer_construction_precedes_initialization_and_happens_once, so future __init__ changes must be mirrored twice. Extract the shared construction setup into one fixture or helper.



def test_reserve_cuda_graph_memory_captures_once_and_retries_after_failure(monkeypatch):
"""One allocation is recorded per device; a failed attempt is retried by the next call."""

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.

🟡 Warning · Test Quality — Test docstring claims unverified allocation

The mocked wp.empty is never recorded or asserted, so deleting the production allocation leaves this test green despite the "one allocation is recorded" claim. Assert the allocation or narrow the docstring to capture count and…

@nvsekkin

Copy link
Copy Markdown
Collaborator

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 Oct 13, 2026
@nvsekkin

Copy link
Copy Markdown
Collaborator

@egolubev-nvda to @StafaH's point - the new tests only are for a temporary workaround. Could you drop the tests in the PR. I can re-trigger the pipeline after

@egolubev-nvda

Copy link
Copy Markdown
Contributor Author

@nvsekkin Done in 6c5257d: the new tests are removed, so the PR now only changes \device.py, \simulation_context.py\ (call plus TODO) and the changelog fragment. Ready for the pipeline when you get a chance.

@nvsekkin

Copy link
Copy Markdown
Collaborator

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 Oct 14, 2026
@kellyguo11
kellyguo11 merged commit c647410 into isaac-sim:develop Oct 14, 2026
59 checks passed
kellyguo11 pushed a commit that referenced this pull request Oct 14, 2026
Backports #8539 to `release/3.0.0`.

The original cherry-pick conflicted. An NVIDIA inference model proposed
this resolution, and deterministic validation confirmed that it changes
no paths outside the original PR. Because conflict resolution cannot be
certified as an exact patch replay, this PR is intentionally a draft and
requires release-maintainer review.

| Field | Commit |
|---|---|
| Original merged change | `c647410de088139054199f41bb71b451602a5fe7` |
| Release base used | `34ba08a104f370fa22d6136bb4e64a1190096c5a` |
| Proposed backport | `ae4599d5cd4d2ce592459ffe3cf5b978af18ec1d` |

Co-authored-by: Evgenii Golubev <[email protected]>
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.

[Bug Report] Windows: Newton CUDA graph capture hangs in a Warp allocation (regression from #8058, not fixed by #8316)

4 participants