-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Newton] Fix multi-GPU initialization on non-default devices #6322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hujc7
merged 5 commits into
isaac-sim:develop
from
hujc7:jichuanh/fix-newton-mgpu-capture-device-codex
Jul 7, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba72fac
Fix Newton initialization on non-default GPUs
hujc7 f20302c
Synchronize Torch and Warp CUDA devices
hujc7 59b72d3
Merge remote-tracking branch 'origin/develop' into jichuanh/fix-newto…
hujc7 64b5ec8
Harden CUDA device initialization
hujc7 0d8b98e
Merge remote-tracking branch 'origin/develop' into jichuanh/fix-newto…
hujc7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
source/isaaclab/changelog.d/jichuanh-fix-newton-mgpu-capture-device-codex.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fixed | ||
| ^^^^^ | ||
|
|
||
| * Fixed PyTorch and Warp selecting different CUDA devices during simulation | ||
| initialization. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright (c) 2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| """Internal utilities for selecting compute devices.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
|
|
||
| def set_cuda_device(device: str | int) -> None: | ||
| """Set the process-wide CUDA device for both PyTorch and Warp. | ||
|
|
||
| PyTorch must select the device before Warp so that a newly imported Warp | ||
| runtime initializes on that device, or an existing runtime switches to it. | ||
|
|
||
| Args: | ||
| device: CUDA device index or a device string such as ``"cuda:1"``. | ||
| """ | ||
| import torch | ||
|
|
||
| torch.cuda.set_device(device) | ||
|
|
||
| import warp as wp | ||
|
|
||
| warp_device = f"cuda:{device}" if isinstance(device, int) else device | ||
| wp.set_device(warp_device) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
source/isaaclab/test/devices/test_physics_manager_device.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Copyright (c) 2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| """Tests for physics-manager CUDA device initialization.""" | ||
|
|
||
| from types import SimpleNamespace | ||
|
|
||
| from isaaclab.physics import PhysicsManager | ||
| from isaaclab.physics import physics_manager as physics_manager_module | ||
|
|
||
|
|
||
| def test_initialize_synchronizes_cuda_before_backend_setup(monkeypatch): | ||
| """The base manager must synchronize CUDA before backend-specific setup.""" | ||
| calls = [] | ||
| monkeypatch.setattr(physics_manager_module, "set_cuda_device", lambda device: calls.append(("cuda", device))) | ||
| monkeypatch.setattr(PhysicsManager, "_sim", None) | ||
| monkeypatch.setattr(PhysicsManager, "_cfg", None) | ||
| monkeypatch.setattr(PhysicsManager, "_device", "cuda:0") | ||
|
|
||
| class _TestManager(PhysicsManager): | ||
| @classmethod | ||
| def initialize(cls, sim_context): | ||
| super().initialize(sim_context) | ||
| calls.append(("backend", PhysicsManager._device)) | ||
|
|
||
| sim_context = SimpleNamespace(cfg=SimpleNamespace(physics=object(), device="cuda:2")) | ||
|
|
||
| _TestManager.initialize(sim_context) | ||
|
|
||
| assert calls == [("cuda", "cuda:2"), ("backend", "cuda:2")] | ||
|
|
||
|
|
||
| def test_initialize_does_not_synchronize_cpu_device(monkeypatch): | ||
| """CPU simulation must not initialize or select CUDA runtimes.""" | ||
| devices = [] | ||
| monkeypatch.setattr(physics_manager_module, "set_cuda_device", devices.append) | ||
| monkeypatch.setattr(PhysicsManager, "_sim", None) | ||
| monkeypatch.setattr(PhysicsManager, "_cfg", None) | ||
| monkeypatch.setattr(PhysicsManager, "_device", "cuda:0") | ||
| sim_context = SimpleNamespace(cfg=SimpleNamespace(physics=object(), device="cpu")) | ||
|
|
||
| PhysicsManager.initialize(sim_context) | ||
|
|
||
| assert devices == [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright (c) 2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| """Tests for compute-device selection utilities.""" | ||
|
|
||
| import sys | ||
| from types import SimpleNamespace | ||
|
|
||
| from isaaclab.utils._device import set_cuda_device | ||
|
|
||
|
|
||
| def test_set_cuda_device_sets_torch_before_warp(monkeypatch): | ||
| """Setting a CUDA device must update PyTorch before Warp.""" | ||
| calls = [] | ||
| torch = SimpleNamespace(cuda=SimpleNamespace(set_device=lambda device: calls.append(("torch", device)))) | ||
| warp = SimpleNamespace(set_device=lambda device: calls.append(("warp", device))) | ||
| monkeypatch.setitem(sys.modules, "torch", torch) | ||
| monkeypatch.setitem(sys.modules, "warp", warp) | ||
|
|
||
| set_cuda_device("cuda:2") | ||
|
|
||
| assert calls == [("torch", "cuda:2"), ("warp", "cuda:2")] | ||
|
|
||
|
|
||
| def test_set_cuda_device_normalizes_integer_for_warp(monkeypatch): | ||
| """An integer device index must be converted to a Warp CUDA alias.""" | ||
| calls = [] | ||
| torch = SimpleNamespace(cuda=SimpleNamespace(set_device=lambda device: calls.append(("torch", device)))) | ||
| warp = SimpleNamespace(set_device=lambda device: calls.append(("warp", device))) | ||
| monkeypatch.setitem(sys.modules, "torch", torch) | ||
| monkeypatch.setitem(sys.modules, "warp", warp) | ||
|
|
||
| set_cuda_device(3) | ||
|
|
||
| assert calls == [("torch", 3), ("warp", "cuda:3")] |
5 changes: 5 additions & 0 deletions
5
...e/isaaclab_newton/changelog.d/jichuanh-fix-newton-mgpu-capture-device-codex.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fixed | ||
| ^^^^^ | ||
|
|
||
| * Fixed Newton physics failing to initialize on non-default CUDA devices | ||
| (``cuda:1`` and higher). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
source/isaaclab_tasks/changelog.d/jichuanh-fix-newton-mgpu-capture-device-codex.skip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Test-only updates for shared CUDA device-selection coverage. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialize_solver/start_simulationThe new test verifies that
wp.ScopedCapturereceivesdevice="cuda:1", but the twotorch.cuda.set_device+wp.set_deviceguards added instart_simulationandinitialize_solverare not exercised. If those guards were accidentally removed or made conditional on the wrong predicate, the regression would go undetected — the test would still pass. Consider adding a parallel test that monkeypatchestorch.cuda.set_deviceandwp.set_device, setsPhysicsManager._device = "cuda:1", calls the relevant entry points, and asserts both were invoked with the correct device string.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!