Skip to content

Fix newton_gl visualizer CUDA illegal access with --device cpu - #7658

Merged
kellyguo11 merged 3 commits into
isaac-sim:developfrom
matthewtrepte:mtrepte/newton-gl-cpu-device-illegal-access
Sep 9, 2026
Merged

kellyguo11 merged 3 commits into
isaac-sim:developfrom
matthewtrepte:mtrepte/newton-gl-cpu-device-illegal-access

Conversation

@matthewtrepte

@matthewtrepte matthewtrepte commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the CUDA illegal-memory access when a CPU simulation uses the newton_gl visualizer on a machine with CUDA present.

uv run --extra all python scripts/environments/zero_agent.py \
  --task IsaacContrib-Stack-Cube-UR10-Short-Suction-IK-Rel \
  --visualizer newton_gl physics=isaacsim_physx \
  --device cpu --num_envs 16

Root cause

Several allocations implicitly used Warp's process-global default device. Warp defaults to cuda:0 when CUDA is available, even when the simulation, its published scene data, or the consuming viewer is on CPU. This mixed CPU pointers with CUDA mappings and render buffers.

Changes

  • SimulationContext selects the configured PyTorch and Warp process device before constructing physics, rendering, or visualization backends.
  • SceneDataProvider derives transform allocations and launches from the transform publication and geometry mappings from the points publication. Matching formats retain the zero-copy passthrough.
  • Newton marker meshes and instances allocate on viewer.device; registration remains owned and cached by each viewer.
  • Rebuilding a Newton shadow model invalidates its prior body mapping at the same lifecycle boundary.
  • Removes device ownership from PhysicsManager, per-frame device guessing from the Newton mapping cache, redundant tests, and unrelated uv.lock changes.

The resulting PR is +31 net production lines versus +68 before this cleanup, and +112 total lines versus +369.

Validation

  • Exact reported workflow, bounded with --max_steps 5: exited successfully with no CUDA illegal-access errors.
  • Affected scene-data, marker, Newton visualization-state, and Newton adapter suites: 117 passed.
  • SimulationContext device-ordering cases on CPU and cuda:0: 2 passed; the assertion runs inside PhysxManager.initialize, proving selection happens before backend setup.
  • Focused Ruff lint and format hooks: passed.

Release backport

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

physics=isaacsim_physx --device cpu combined with the newton_gl
visualizer crashed with a repeating Warp CUDA error 700 (illegal
memory access) on any machine that also has a CUDA device present.
The root cause: SceneDataProvider (used to shadow-copy PhysX
transforms for Newton-native visualizers) and
NewtonVisualizationMarkers both allocated internal Warp arrays
without an explicit device=, so they landed on Warp's process-global
default device (cuda:0 whenever CUDA is present) instead of the
configured CPU device, mismatching the CPU-resident sim data.

- SceneDataProvider (get_transforms, init_output, create_mapping,
  create_geometry_mapping, get_points) now derives its device from
  the sim backend and threads it through every internal allocation.
- NewtonVisualizationMarkers.render/_ensure_mesh_registered now
  allocate marker/mesh arrays on the inferred marker device; mesh
  registration is cached per (viewer, mesh, device) so a mesh
  registered before any marker state exists (falls back to "cpu")
  is re-registered once the real device is known.
- PhysicsManager.initialize now syncs Warp's process-global default
  device for CPU runs too (previously only the CUDA branch did),
  fixing the same bug class everywhere else in the codebase that
  omits an explicit device=.
- NewtonManager.update_visualization_state now also invalidates its
  cached shadow-body index mapping on a device change, not just a
  body-count change.

Reproduced the exact bug report (zero_agent.py --visualizer newton_gl
physics=isaacsim_physx --device cpu) and confirmed each fix with a
regression test that reproduces a real crash without it and passes
with it.
@matthewtrepte
matthewtrepte requested a review from a team September 9, 2026 00:15
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Sep 9, 2026
@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no concrete behavioral, security, or repository-rule issue remains.

Summary

  • Synchronizes Warp’s process-global default for CPU simulations.
  • Derives scene-data conversion buffers and launches from backend devices.
  • Allocates Newton marker and mesh data on the inferred marker device.
  • Invalidates cached shadow-body mappings after simulation-device changes.
  • Adds CPU/CUDA mismatch and mesh re-registration regression tests.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Simulation configuration] --> B[PhysicsManager.initialize]
    B --> C[Set Warp default device]
    A --> D[SceneData backend arrays]
    D --> E[SceneDataProvider infers backend device]
    E --> F[Allocate mappings and outputs]
    E --> G[Launch conversion kernels]
    A --> H[Marker state tensors]
    H --> I[Infer marker device]
    I --> J[Allocate mesh and instance arrays]
    I --> K[Cache registration by viewer, mesh, and device]
    A --> L[Newton visualization state]
    L --> M{Cached mapping device matches?}
    M -- No --> N[Rebuild mapping]
    M -- Yes --> O[Reuse mapping]
    N --> G
    O --> G
Loading

@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

The explicit Warp-device propagation is consistent across SceneDataProvider and Newton marker paths, but NewtonManager’s mapping-cache invalidation compares a normalized Warp device name with the raw configured device string, causing needless cache rebuilds when aliases such as cuda are used.

  • Design and architecture: Deriving allocation and launch devices from backend arrays provides a coherent defense against Warp’s process-global default. The remaining inconsistency is that the visualization mapping is allocated using scene_data_provider.device but validated against PhysicsManager._device rather than the same normalized device source.
  • API: The private _ensure_mesh_registered(..., device) signature is updated consistently at its call sites and tests. The additive SceneDataProvider.device property and package changelog fragments are appropriately integrated.
  • Implementation: Normalize the configured device before comparison, or compare the cached mapping directly with scene_data_provider.device. Otherwise a configured cuda alias compares unequal to the mapping’s ordinal-qualified cuda:0 device and forces path resolution and mapping creation on every visualization update.

Minor fixes needed. Posted 1 actionable finding inline.

Automated review; human maintainers own approval decisions.

# kernel on scene_data_provider.device, which must match this mapping's own device.
if cls._scene_data_mapping is not None and (
cls._scene_data_mapping.shape[0] != cls._model.body_count
or str(cls._scene_data_mapping.device) != str(PhysicsManager._device)

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 · Implementation — Device comparison ignores 'cuda' alias normalization

The mapping is allocated via scene_data_provider.device, whose string form is always ordinal-qualified (cuda:0), but invalidation compares it to the raw configured string PhysicsManager._device, which may be cuda. In that case the comparison never matches, so _scene_data_mapping is discarded and _resolve_scene_data_body_paths plus create_mapping re-run on every visualization update. Compare normalized devices, e.g. str(scene_data_provider.device) or str(wp.get_device(PhysicsManager._device)).

matthewtrepte and others added 2 commits September 9, 2026 00:28
PhysicsManager._device can be the unqualified "cuda" (a documented,
valid --device value distinct from "cuda:N"), but a Warp array's own
.device always reports ordinal-qualified ("cuda:0"). Comparing the
raw strings meant this pair would always mismatch under --device
cuda, discarding and rebuilding the cached shadow-body mapping on
every single visualization update instead of reusing it. Compare
resolved wp.Device objects instead.

Addresses isaaclab-review-bot feedback on PR isaac-sim#7658.
@kellyguo11

Copy link
Copy Markdown
Contributor

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 Sep 9, 2026
@kellyguo11
kellyguo11 merged commit aea146a into isaac-sim:develop Sep 9, 2026
83 of 84 checks passed
@isaaclab-bot

isaaclab-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Backported to release/3.0.0 as 772533d.

isaaclab-bot Bot pushed a commit that referenced this pull request Sep 9, 2026
## Summary

Fixes the CUDA illegal-memory access when a CPU simulation uses the
`newton_gl` visualizer on a machine with CUDA present.

```bash
uv run --extra all python scripts/environments/zero_agent.py \
  --task IsaacContrib-Stack-Cube-UR10-Short-Suction-IK-Rel \
  --visualizer newton_gl physics=isaacsim_physx \
  --device cpu --num_envs 16
```

## Root cause

Several allocations implicitly used Warp's process-global default
device. Warp defaults to `cuda:0` when CUDA is available, even when the
simulation, its published scene data, or the consuming viewer is on CPU.
This mixed CPU pointers with CUDA mappings and render buffers.

## Changes

- `SimulationContext` selects the configured PyTorch and Warp process
device before constructing physics, rendering, or visualization
backends.
- `SceneDataProvider` derives transform allocations and launches from
the transform publication and geometry mappings from the points
publication. Matching formats retain the zero-copy passthrough.
- Newton marker meshes and instances allocate on `viewer.device`;
registration remains owned and cached by each viewer.
- Rebuilding a Newton shadow model invalidates its prior body mapping at
the same lifecycle boundary.
- Removes device ownership from `PhysicsManager`, per-frame device
guessing from the Newton mapping cache, redundant tests, and unrelated
`uv.lock` changes.

The resulting PR is +31 net production lines versus +68 before this
cleanup, and +112 total lines versus +369.

## Validation

- Exact reported workflow, bounded with `--max_steps 5`: exited
successfully with no CUDA illegal-access errors.
- Affected scene-data, marker, Newton visualization-state, and Newton
adapter suites: **117 passed**.
- `SimulationContext` device-ordering cases on CPU and `cuda:0`: **2
passed**; the assertion runs inside `PhysxManager.initialize`, proving
selection happens before backend setup.
- Focused Ruff lint and format hooks: passed.

## 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 aea146a)
kellyguo11 pushed a commit that referenced this pull request Oct 9, 2026
# Description

cuRobo's quad-mesh triangulation (`curobo/util/usd_helper.py`) creates
its Warp arrays on CUDA but calls `wp.launch()` without a device, so the
kernel runs on Warp's default device. Since #7658, `SimulationContext`
sets the Warp default
device to the sim device, so `--device cpu` runs execute the
CPU-compiled kernel against CUDA pointers.

Fix: wrap the planner's `get_obstacles_from_stage()` call in
`wp.ScopedDevice(f"cuda:{cuda_device}")` so cuRobo's deviceless launch
lands on the device its arrays live on.

## 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`

## Checklist

- [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] My changes generate no new warnings
- [x] I have added a changelog fragment under
`source/<pkg>/changelog.d/` for every touched package
- [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 Oct 9, 2026
# Description

cuRobo's quad-mesh triangulation (`curobo/util/usd_helper.py`) creates
its Warp arrays on CUDA but calls `wp.launch()` without a device, so the
kernel runs on Warp's default device. Since #7658, `SimulationContext`
sets the Warp default
device to the sim device, so `--device cpu` runs execute the
CPU-compiled kernel against CUDA pointers.

Fix: wrap the planner's `get_obstacles_from_stage()` call in
`wp.ScopedDevice(f"cuda:{cuda_device}")` so cuRobo's deviceless launch
lands on the device its arrays live on.

## 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`

## Checklist

- [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] My changes generate no new warnings
- [x] I have added a changelog fragment under
`source/<pkg>/changelog.d/` for every touched package
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

(cherry picked from commit 2df15f9)
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.

3 participants