Skip to content

Conversation

@mdboom
Copy link
Contributor

@mdboom mdboom commented Feb 3, 2026

Based on a discussion elsewhere with the NVML team, it seems that these APIs should really be bytes (containing embedded NULL characters), not str.

@mdboom mdboom requested review from Copilot and cpcloud February 3, 2026 21:03
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Feb 3, 2026

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 mdboom self-assigned this Feb 3, 2026
@mdboom mdboom added cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module labels Feb 3, 2026
@mdboom
Copy link
Contributor Author

mdboom commented Feb 3, 2026

/ok to test

Copy link
Contributor

Copilot AI left a comment

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 changes three NVML Inforom-related APIs from returning str to bytes based on guidance from the NVML team that these APIs should preserve embedded NULL characters.

Changes:

  • Modified return types from str to bytes for Inforom version and board part number APIs
  • Updated low-level bindings to use PyBytes_FromStringAndSize instead of PyUnicode_FromString
  • Updated type hints and test assertions to reflect the new bytes return type

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
cuda_bindings/cuda/bindings/nvml.pxd Updated function signatures to return bytes instead of str
cuda_bindings/cuda/bindings/nvml.pyx Changed implementation to use PyBytes_FromStringAndSize with full buffer sizes
cuda_core/cuda/core/system/_inforom.pxi Updated type hints to indicate bytes return type
cuda_core/tests/system/test_system_device.py Updated test assertions to check for bytes type instead of str

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

__status__ = nvmlDeviceGetBoardPartNumber(<Device>device, part_number, length)
check_status(__status__)
return cpython.PyUnicode_FromString(part_number)
return cpython.PyBytes_FromStringAndSize(part_number, 80)
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

Using PyBytes_FromStringAndSize with the full buffer size (80) may include uninitialized or garbage data beyond the actual string content returned by the NVML API. Consider using the actual string length (e.g., via strlen) instead of the hardcoded buffer size, unless the NVML API guarantees that all 80 bytes are meaningful. If embedded NULLs need to be preserved, you could use strlen to find the length up to the first NULL, or modify the approach based on confirmed NVML API behavior.

Copilot uses AI. Check for mistakes.
__status__ = nvmlDeviceGetInforomVersion(<Device>device, <_InforomObject>object, version, length)
check_status(__status__)
return cpython.PyUnicode_FromString(version)
return cpython.PyBytes_FromStringAndSize(version, 16)
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

Using PyBytes_FromStringAndSize with the full buffer size (16) may include uninitialized or garbage data beyond the actual string content returned by the NVML API. Consider using the actual string length (e.g., via strlen) instead of the hardcoded buffer size, unless the NVML API guarantees that all 16 bytes are meaningful. If embedded NULLs need to be preserved, you could use strlen to find the length up to the first NULL, or modify the approach based on confirmed NVML API behavior.

Copilot uses AI. Check for mistakes.
__status__ = nvmlDeviceGetInforomImageVersion(<Device>device, version, length)
check_status(__status__)
return cpython.PyUnicode_FromString(version)
return cpython.PyBytes_FromStringAndSize(version, 16)
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

Using PyBytes_FromStringAndSize with the full buffer size (16) may include uninitialized or garbage data beyond the actual string content returned by the NVML API. Consider using the actual string length (e.g., via strlen) instead of the hardcoded buffer size, unless the NVML API guarantees that all 16 bytes are meaningful. If embedded NULLs need to be preserved, you could use strlen to find the length up to the first NULL, or modify the approach based on confirmed NVML API behavior.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Feb 3, 2026

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.

LGTM, where are the specific sizes coming from?

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 cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants