Repository navigation
Fix newton_gl visualizer CUDA illegal access with --device cpu - #7658
kellyguo11 merged 3 commits into
Conversation
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.
There was a problem hiding this comment.
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.devicebut validated againstPhysicsManager._devicerather than the same normalized device source. - API: The private
_ensure_mesh_registered(..., device)signature is updated consistently at its call sites and tests. The additiveSceneDataProvider.deviceproperty 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 configuredcudaalias compares unequal to the mapping’s ordinal-qualifiedcuda:0device 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) |
There was a problem hiding this comment.
🟡 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)).
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.
|
run-ci |
|
Backported to |
## 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)
# 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
# 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)
Summary
Fixes the CUDA illegal-memory access when a CPU simulation uses the
newton_glvisualizer on a machine with CUDA present.Root cause
Several allocations implicitly used Warp's process-global default device. Warp defaults to
cuda:0when 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
SimulationContextselects the configured PyTorch and Warp process device before constructing physics, rendering, or visualization backends.SceneDataProviderderives transform allocations and launches from the transform publication and geometry mappings from the points publication. Matching formats retain the zero-copy passthrough.viewer.device; registration remains owned and cached by each viewer.PhysicsManager, per-frame device guessing from the Newton mapping cache, redundant tests, and unrelateduv.lockchanges.The resulting PR is +31 net production lines versus +68 before this cleanup, and +112 total lines versus +369.
Validation
--max_steps 5: exited successfully with no CUDA illegal-access errors.SimulationContextdevice-ordering cases on CPU andcuda:0: 2 passed; the assertion runs insidePhysxManager.initialize, proving selection happens before backend setup.Release backport
develop