Skip to content

Include cuda.bindings.nvml in docs#1778

Merged
mdboom merged 5 commits intoNVIDIA:mainfrom
mdboom:include-nvml-in-docs
Mar 17, 2026
Merged

Include cuda.bindings.nvml in docs#1778
mdboom merged 5 commits intoNVIDIA:mainfrom
mdboom:include-nvml-in-docs

Conversation

@mdboom
Copy link
Contributor

@mdboom mdboom commented Mar 17, 2026

I just completely neglected to include cuda.bindings.nvml bindings in the docs. This adds them.

This also updates the release note about cuda.bindings.nvml -- the text there applies to cuda.core.system, not cuda.bindings.nvml.

(Relatedly, cuda.core.system is already integrated in the docs).

New enum documenter

Before this PR, if you automatically document an enum class, you get something that looks like this. In other words, since an enum is a subclass of int, it documents all of the methods that come from int. This is really confusing. Additionally, it doesn't document the meaning of each of the enumeration values (only their name and value). Since the FastEnum work landed, each enumeration value actually has a docstring that we can pull in.

Elsewhere in the code base, this is worked around by explicitly writing out each of the values by hand, with a docstring: https://github.com/NVIDIA/cuda-python/blob/main/cuda_bindings/docs/source/module/driver.rst?plain=1#L120

.. autoclass:: cuda.bindings.driver.CUctx_flags
    .. autoattribute:: cuda.bindings.driver.CUctx_flags.CU_CTX_SCHED_AUTO
        Automatic scheduling
    .. autoattribute:: cuda.bindings.driver.CUctx_flags.CU_CTX_SCHED_SPIN
        Set spin as default scheduling
    .. autoattribute:: cuda.bindings.driver.CUctx_flags.CU_CTX_SCHED_YIELD
        Set yield as default scheduling
    .. autoattribute:: cuda.bindings.driver.CUctx_flags.CU_CTX_SCHED_BLOCKING_SYNC
        Set blocking synchronization as default scheduling
    .. autoattribute:: cuda.bindings.driver.CUctx_flags.CU_CTX_BLOCKING_SYNC
        Set blocking synchronization as default scheduling [Deprecated]
    .. autoattribute:: cuda.bindings.driver.CUctx_flags.CU_CTX_SCHED_MASK
    .. autoattribute:: cuda.bindings.driver.CUctx_flags.CU_CTX_MAP_HOST
        [Deprecated]

This manual approach is not going to scale for NVML, which has 112 enums, some of which have more than 300 values.

So, it was easy enough to write a Sphinx extension to handle this automatically. We were using a third-party extension to automatically document enums (enum_tools.autoenum), but as far as I can tell, that has bit-rotted and hasn't been working for some time. In any event, it can't be used to automatically extract docstrings from enum values (since that feature doesn't exist in the stdlib enum implementation).

This greatly simplifies documenting NVML, and as a follow-up, we can go through and remove all of the places elsewhere in the doc where manually documenting enumeration values is no longer necessary.

@mdboom mdboom requested a review from rparolin March 17, 2026 14:26
@mdboom
Copy link
Contributor Author

mdboom commented Mar 17, 2026

/ok to test

1 similar comment
@mdboom
Copy link
Contributor Author

mdboom commented Mar 17, 2026

/ok to test

@github-actions

This comment has been minimized.

@mdboom mdboom added documentation Improvements or additions to documentation P0 High priority - Must do! cuda.bindings Everything related to the cuda.bindings module labels Mar 17, 2026
@mdboom mdboom self-assigned this Mar 17, 2026
@mdboom mdboom marked this pull request as draft March 17, 2026 15:05
@mdboom mdboom marked this pull request as draft March 17, 2026 15:05
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Mar 17, 2026

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.

1 similar comment
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Mar 17, 2026

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.

Update copyright year in nvml.rst

Automatically document enums
@mdboom mdboom force-pushed the include-nvml-in-docs branch from 4e19502 to 2071c69 Compare March 17, 2026 16:38
@mdboom mdboom marked this pull request as ready for review March 17, 2026 16:48
@mdboom
Copy link
Contributor Author

mdboom commented Mar 17, 2026

/ok to test

device_get_vgpu_type_creatable_placements
device_get_vgpu_type_supported_placements
device_get_vgpu_utilization
device_get_virtualization_mode
Copy link
Contributor

Choose a reason for hiding this comment

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

Building the bindings docs locally now emits a docutils error for this page: docstring of cuda.bindings.nvml.device_get_virtualization_mode:6: ERROR: Unknown target name: "nvml_gpu_virtualization". The same happens for device_set_virtualization_mode. The underlying autogenerated docstring text includes NVML_GPU_VIRTUALIZATION_?, which docutils is parsing as a broken reference, so these entries currently add broken pages to the new NVML docs.

FanState
FBCSessionType
FieldId
GpmMetricId
Copy link
Contributor

Choose a reason for hiding this comment

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

Including GpmMetricId also adds a new NVML-specific docutils warning in the local docs build: docstring of cuda.bindings.nvml.GpmMetricId:1: WARNING: Inline emphasis start-string without end-string. This looks like it comes from one of the enum member docstrings containing 0.0 - 100.0 *..., so it would be good to clean that up before merging the new autosummary page.

Copy link
Contributor

@cpcloud cpcloud left a comment

Choose a reason for hiding this comment

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

I built the bindings docs locally in a pixi-backed Sphinx environment and found a couple of NVML-specific docutils issues introduced by the new nvml page.

  • device_get_virtualization_mode and device_set_virtualization_mode now surface Unknown target name: "nvml_gpu_virtualization" errors.
  • GpmMetricId now surfaces an inline-emphasis warning from one of its member docstrings.

Once those newly exposed doc issues are addressed, the rest of the NVML docs wiring and the enum autosummary flow looked good in my local build.

@mdboom
Copy link
Contributor Author

mdboom commented Mar 17, 2026

I built the bindings docs locally in a pixi-backed Sphinx environment and found a couple of NVML-specific docutils issues introduced by the new nvml page.

  • device_get_virtualization_mode and device_set_virtualization_mode now surface Unknown target name: "nvml_gpu_virtualization" errors.
  • GpmMetricId now surfaces an inline-emphasis warning from one of its member docstrings.

Once those newly exposed doc issues are addressed, the rest of the NVML docs wiring and the enum autosummary flow looked good in my local build.

Since these docstrings come from the C headers, it's going to be multiple steps to get them right, but right we shall...

@cpcloud
Copy link
Contributor

cpcloud commented Mar 17, 2026

@mdboom I'm happy to unblock this if you want do that in a follow-up. Fine by me.

@mdboom
Copy link
Contributor Author

mdboom commented Mar 17, 2026

@mdboom I'm happy to unblock this if you want do that in a follow-up. Fine by me.

I decided to just patch them at the end of the file (since it's easy to add content to the end from the generator).

Longer term, these are bugs to fix in the doxygen-to-rst conversion step in the generator, or bugs to file against the C header content.

I actually have it on my TODO to refactor the doc converter in the next few weeks, so it will be easiest to handle that then. In the meantime, this is just a bit of a workaround here that at least won't create dangling references.

@mdboom mdboom requested a review from cpcloud March 17, 2026 20:56
@mdboom mdboom enabled auto-merge (squash) March 17, 2026 21:23
@mdboom mdboom merged commit e20ef78 into NVIDIA:main Mar 17, 2026
86 checks passed
@github-actions
Copy link

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

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

Labels

cuda.bindings Everything related to the cuda.bindings module documentation Improvements or additions to documentation P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants