Skip to content

Fix deferred CUDA checks before Kit GPU filtering - #7669

Merged
kellyguo11 merged 1 commit into
isaac-sim:developfrom
ooctipus:fix/preloaded-torch-cuda-init
Sep 9, 2026
Merged

kellyguo11 merged 1 commit into
isaac-sim:developfrom
ooctipus:fix/preloaded-torch-cuda-init

Conversation

@ooctipus

@ooctipus ooctipus commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Initialize CUDA before Kit startup when PyTorch has already been imported and a CUDA simulation device was selected.

Importing PyTorch queues capability checks for every CUDA device visible at import time. On heterogeneous multi-GPU systems, Kit can subsequently filter the CUDA devices to those usable by its Vulkan backend. The queued checks then retain stale indices and fail during the post-Kit torch.cuda.set_device call with device >= 0 && device < num_gpus.

The launcher does not import PyTorch solely for this workaround. If PyTorch has not already been loaded, CUDA initialization remains deferred until after Kit startup as before.

Reproduction hardware:

  • Ubuntu 24.04 ARM64
  • NVIDIA RTX PRO 6000 Blackwell attached to the display as GPU 0
  • NVIDIA GB300 compute GPU as GPU 1
  • Driver 610.43.03
  • Isaac Sim 6.0.1

Previously failing command:

./isaaclab.sh -p scripts/demos/arms.py --device=cuda:0 --visualizer kit

The command now reaches setup completion and runs the visualized simulation with both GPUs visible. Restricting visibility to GPU 0 also continues to work.

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

Screenshots

Not applicable. The failure was a deferred CUDA initialization traceback; the fixed command was validated interactively through the Kit visualizer.

Validation

  • 3 passed, 47 deselected for the focused AppLauncher CUDA tests
  • GB300-only SKRL headless training completed one iteration and saved a checkpoint
  • The previously failing Kit arms demo ran successfully with both GPUs visible
  • Full ./isaaclab.sh --format pre-commit suite passed

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation via a changelog fragment
  • My changes generate no new warnings
  • I have added tests that prove the fix is effective
  • I have added a changelog fragment under source/isaaclab/changelog.d/
  • My name already exists in CONTRIBUTORS.md

@ooctipus
ooctipus requested a review from a team September 9, 2026 04:20
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Sep 9, 2026
@ooctipus

ooctipus commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator 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 Sep 9, 2026

@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 PR adds a private pre-Kit CUDA initialization hook when PyTorch is already loaded and a CUDA simulation device is selected, preventing deferred capability checks from retaining stale GPU indices after Kit filtering. The existing post-Kit device-selection path remains intact.

  • Design and architecture: The hook is correctly placed after device configuration resolves _deferred_cuda_device_id and before Kit startup. It avoids importing PyTorch itself, preserving deferred initialization for normal launches and the existing protection against pre-Kit PyTorch/OpenBLAS side effects.
  • API: No public APIs, CLI arguments, defaults, exports, or return types change. The behavior is confined to a private launcher lifecycle method, and the user-visible fix is documented with a package changelog fragment.
  • Implementation: The implementation guards CPU launches, absent PyTorch imports, and already-initialized CUDA runtimes. Focused tests cover both initializing preloaded PyTorch and retaining deferred behavior when PyTorch is absent. A CUDA runtime failure may now surface before Kit startup when PyTorch was preloaded, which is a proportionate consequence of draining the checks before GPU filtering.

No blocking issues. No inline issue met the actionable-evidence threshold; the assessment above records the review feedback.

Automated review; human maintainers own approval decisions.

@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, with only a non-blocking test-coverage concern remaining.

Summary

  • Adds guarded pre-Kit CUDA initialization without importing PyTorch itself.
  • Preserves deferred initialization when PyTorch is not already loaded.
  • Adds focused tests and a changelog fragment.

Diagram

sequenceDiagram
    participant Caller
    participant Launcher as AppLauncher
    participant Torch as Preloaded PyTorch
    participant Kit
    Caller->>Launcher: construct with CUDA device
    Launcher->>Launcher: resolve configuration
    alt PyTorch loaded and CUDA uninitialized
        Launcher->>Torch: cuda.init()
        Torch-->>Launcher: deferred checks completed
    end
    Launcher->>Kit: create application
    Kit-->>Launcher: GPU filtering complete
    Launcher->>Torch: set selected CUDA device
Loading

launcher = AppLauncher.__new__(AppLauncher)
launcher._deferred_cuda_device_id = 0

launcher._initialize_preloaded_torch_cuda()

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 Constructor Ordering Is Untested

This test calls _initialize_preloaded_torch_cuda() directly, so it would still pass if the constructor later invoked the method after _create_app(). Running CUDA initialization before Kit creates the application is essential to this regression fix. Add a mocked constructor-sequencing test that protects this ordering.

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!

@ooctipus ooctipus closed this Sep 9, 2026
@ooctipus ooctipus mentioned this pull request Sep 9, 2026
1 task done
@kellyguo11 kellyguo11 reopened this Sep 9, 2026
@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@kellyguo11
kellyguo11 merged commit 9470e1e into isaac-sim:develop Sep 9, 2026
77 checks passed
isaaclab-bot Bot pushed a commit that referenced this pull request Sep 9, 2026
@isaaclab-bot

isaaclab-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Backported to release/3.0.0 as bc2d23c.

ooctipus added a commit that referenced this pull request Sep 19, 2026
## Description

Upgrade PyTorch to 2.12.0 and torchvision to 0.27.0. PyTorch 2.12
includes the upstream fix for CUDA lazy initialization when NVML reports
more devices than the CUDA runtime exposes, avoiding the deferred
`device >= 0 && device < num_gpus` assertion after Kit initializes
graphics on a subset of GPUs.

PyTorch 2.12 is published for CUDA 13.0, so the supported x86_64 and
Windows installs move from the cu128 index to cu130 as well. TorchAudio
remains at 2.11.0 because it uses PyTorch stable ABI and officially
supports PyTorch 2.11 and later.

## Testing

- `uv lock --check`
- `uv run isaaclab -f`
- `LD_PRELOAD=/lib/aarch64-linux-gnu/libgomp.so.1
OMNI_KIT_ACCEPT_EULA=YES uv run pytest source/isaaclab/test/cli -q` (283
passed)
- Imported torch 2.12.0+cu130, torchvision 0.27.0+cu130, and torchaudio
2.11.0+cu130; exercised torchvision NMS and torchaudio resampling
- Ran `scripts/demos/arms.py --device=cuda:0 --visualizer kit` through
setup and repeated simulation resets on a 2-GPU ARM64 system where Kit
exposes one GPU to the CUDA runtime
- Ran the SKRL ANYmal-C training flow through environment setup and
active PPO rollout

Supersedes the application-level initialization workaround in #7669.

## Release backport

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

---------

Co-authored-by: ooctipus <[email protected]>
ooctipus added a commit to ooctipus/IsaacLab that referenced this pull request Sep 20, 2026
Upgrade PyTorch to 2.12.0 and torchvision to 0.27.0. PyTorch 2.12
includes the upstream fix for CUDA lazy initialization when NVML reports
more devices than the CUDA runtime exposes, avoiding the deferred
`device >= 0 && device < num_gpus` assertion after Kit initializes
graphics on a subset of GPUs.

PyTorch 2.12 is published for CUDA 13.0, so the supported x86_64 and
Windows installs move from the cu128 index to cu130 as well. TorchAudio
remains at 2.11.0 because it uses PyTorch stable ABI and officially
supports PyTorch 2.11 and later.

- `uv lock --check`
- `uv run isaaclab -f`
- `LD_PRELOAD=/lib/aarch64-linux-gnu/libgomp.so.1
OMNI_KIT_ACCEPT_EULA=YES uv run pytest source/isaaclab/test/cli -q` (283
passed)
- Imported torch 2.12.0+cu130, torchvision 0.27.0+cu130, and torchaudio
2.11.0+cu130; exercised torchvision NMS and torchaudio resampling
- Ran `scripts/demos/arms.py --device=cuda:0 --visualizer kit` through
setup and repeated simulation resets on a 2-GPU ARM64 system where Kit
exposes one GPU to the CUDA runtime
- Ran the SKRL ANYmal-C training flow through environment setup and
active PPO rollout

Supersedes the application-level initialization workaround in isaac-sim#7669.

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

---------

Co-authored-by: ooctipus <[email protected]>
(cherry picked from commit 4269c29)
@ooctipus
ooctipus deleted the fix/preloaded-torch-cuda-init branch October 14, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants