Skip to content

Initial import of cuda.core.system - #1393

Merged
mdboom merged 29 commits into
NVIDIA:mainfrom
mdboom:cuda.core.system
Jan 7, 2026
Merged

Initial import of cuda.core.system#1393
mdboom merged 29 commits into
NVIDIA:mainfrom
mdboom:cuda.core.system

Conversation

@mdboom

@mdboommdboom commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

(Marked as draft as a reminder to not merge until after the 0.5.0 release...)

Prerequisites to get this PR to pass:

This is the first landing of cuda.core.system, with all of the features in the nvutil prototype (which sort of has an arbitrary collection of the most core things in NVML, but is a reasonable starting point for a first PR).

This requires a generator change (not yet merged) to include AUTO_LOWPP_* classes in the .pxd file so they can be cimport'ed. I know we don't usually do that, but it seems important to be able to use those high-level bindings and not repeat ourselves. ABI stability there should be ok -- I don't anticipate needing to change anything on the .pxd side of those classes.

Following the nvutil design, this initializes NVML immediately upon import of cuda.core.system. That feels convenient and may be the right choice, but it will be hard to walk that back. Questions the NVML docs don't answer for me: are there any use cases where you would want to init/shutdown NVML repeatedly. The cuda.bindings.nvml tests do this, so I know it works. Is there any harm in init'ing and never shutting down -- we could add an atexit handler, but I don't know if it's required.

@copy-pr-bot

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

from cuda.bindings cimport _nvml as nvml


def get_driver_version() -> tuple[int, int]:

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

This is a bit confusing. This is an existing API that returns the CUDA version. It really should be called get_cuda_version to avoid confusion, but that would be a breaking change. There is a new API to return the driver version called get_gpu_driver_version below, but that naming isn't great.

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.

Could we provide those functions for backwards compat and provide a better named alternative that we are willing to support longer term?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is actually confusing to call it get_cuda_version. This used to return the UMD (user-mode driver) version, e.g. 13.0, 13.1, .... Now that we have access to NVML, we gain in addition the capability of querying the KMD (kernel-mode driver) version, e.g. 580.65.06. So I'd suggest something like

defget_driver_version(kernel_mode: bool=False) ->tuple[int, ...]:

for users to query either UMD or KMD version. Alternatively, we can allow users to query both at once.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In any case, get_cuda_version is too ambiguous. Depending on the context a CUDA version could refer to any of the versions of KMD, UMD, CTK, NVCC, NVRTC, CUDART, ... and we should help avoid spreading such confusion.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks for the context. Makes sense. I think I've addressed this now in the latest commit.

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

Comment threadcuda_core/cuda/core/system/__init__.py
@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

5 similar comments
@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

CopilotAI 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.

Pull request overview

This PR introduces the new cuda.core.system module that provides system-level GPU information via NVML (NVIDIA Management Library). It replaces the previous singleton System class with a more comprehensive module that offers both backward-compatible functions and new NVML-powered device management capabilities.

Key changes:

  • Replaces singleton System class with module-level functions (get_num_devices(), get_driver_version(), etc.)
  • Adds comprehensive Device class with NVML-backed properties for device information (architecture, memory, PCI info, etc.)
  • Implements automatic NVML initialization on module import with version-gated availability
  • Provides utility functions for formatting bytes and unpacking bitmasks

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.

Show a summary per file
FileDescription
cuda_core/tests/test_memory.pyUpdates API calls from ccx_system.num_devices property to ccx_system.get_num_devices() function
cuda_core/tests/system/test_system_utils.pyAdds comprehensive tests for utility functions (format_bytes, unpack_bitmask)
cuda_core/tests/system/test_system_system.pyAdds tests for system-level functions (driver versions, device count, process name)
cuda_core/tests/system/test_system_device.pyAdds extensive tests for Device class properties (architecture, memory, PCI info, etc.)
cuda_core/tests/system/test_nvml_context.pyAdds tests for NVML initialization state management across processes
cuda_core/tests/system/conftest.pyDefines NVML version requirements and skip marker for unsupported versions
cuda_core/tests/system/init.pyEmpty init file for test module
cuda_core/cuda/core/experimental/system/utils.pyxImplements utility functions for byte formatting and bitmask unpacking
cuda_core/cuda/core/experimental/system/system.pyxImplements system-level query functions with NVML and fallback support
cuda_core/cuda/core/experimental/system/device.pyxImplements Device class with comprehensive GPU properties via NVML
cuda_core/cuda/core/experimental/system/_nvml_context.pyxImplements thread-safe, per-process NVML initialization logic
cuda_core/cuda/core/experimental/system/init.pyModule entry point with version-gated NVML imports and initialization
cuda_core/cuda/core/experimental/_system.pyRemoves deprecated singleton System class
cuda_core/cuda/core/experimental/init.pyUpdates imports to use new system module instead of System singleton
cuda_bindings/cuda/bindings/_nvml.pyxAdds enums and fixes BAR1Memory property naming (breaking change)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadcuda_core/tests/system/test_system_device.py
Comment threadcuda_core/cuda/core/experimental/system/__init__.py Outdated
Comment threadcuda_core/cuda/core/experimental/system/device.pyx Outdated
Comment threadcuda_core/cuda/core/experimental/system/device.pyx Outdated
Comment threadcuda_core/cuda/core/experimental/system/utils.pyx Outdated
Comment threadcuda_core/tests/system/conftest.py Outdated
Comment threadcuda_bindings/cuda/bindings/_nvml.pyx
Comment threadcuda_core/cuda/core/experimental/system/device.pyx Outdated
Comment threadcuda_core/cuda/core/experimental/system/utils.pyx Outdated
@leofangleofang added P0 High priority - Must do! feature New feature or request cuda.core Everything related to the cuda.core module labels Dec 18, 2025
@leofangleofang added this to the cuda.core backlog milestone Dec 18, 2025
@leofangleofang added the triage Needs the team's attention label Dec 18, 2025
@mdboom
mdboom marked this pull request as ready for review December 18, 2025 13:22
@copy-pr-bot

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@github-actions

This comment has been minimized.

@rparolin

Copy link
Copy Markdown
Collaborator

"Following the nvutil design, this initializes NVML immediately upon import of cuda.core.system. That feels convenient and may be the right choice, but it will be hard to walk that back."

Even if we decide to ship with a backwards compatible version that initializes on import and never shuts down. It would be if we at least had API that we used internally to test the system init/shutdown for multiple test suites so we can gain confidence that is stable. Then we can always provide an API to people as an alternative to the legacy behaviour.

Comment threadcuda_core/cuda/core/system/exceptions.py
Comment threadcuda_core/cuda/core/system/_system.pyx
Comment threadcuda_core/cuda/core/system/system.pyx Outdated
Comment threadcuda_core/cuda/core/system/__init__.py Outdated
Comment threadcuda_core/cuda/core/system/exceptions.py
@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom
mdboom requested a review from rparolinJanuary 7, 2026 16:58
@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@rparolin

Copy link
Copy Markdown
Collaborator

lgtm to me. Just make sure the spelling mistakes that copilot flagged are resolved. Thank you!

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom
mdboom enabled auto-merge (squash) January 7, 2026 20:10
@mdboom
mdboom disabled auto-merge January 7, 2026 20:12
@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom
mdboom enabled auto-merge (squash) January 7, 2026 21:17
@mdboom
mdboom merged commit 43af7de into NVIDIA:mainJan 7, 2026
77 of 80 checks passed
@github-actions

Copy link
Copy Markdown
Doc Preview CI
Preview removed because the pull request was closed or merged.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.coreEverything related to the cuda.core modulefeatureNew feature or requestP0High priority - Must do!triageNeeds the team's attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@mdboom@rparolin@pentschev@leofang