Skip to content

Commit 8e34ede

Browse files
authored
Fix the field-id enum name in the nvml test helper supports_nvlink (#2560)
def supports_nvlink(device): fields = nvml.FieldValue(1) fields[0].field_id = nvml.FI.DEV_NVLINK_GET_STATE There is no `FI` attribute on cuda.bindings.nvml. The enum is `FieldId` (nvml.pyx:1229), with DEV_NVLINK_GET_STATE at nvml.pyx:1454, and the sibling test uses the correct spelling: test_nvlink.py:19 does `fields[0].field_id = nvml.FieldId.DEV_NVLINK_LINK_COUNT`. So the helper raises AttributeError on its first line of real work. Nobody has noticed because it has no callers -- a repo-wide grep for `supports_nvlink` finds only its own definition. Contrast util.supports_ecc, which is called from test_page_retirement.py. Adds tests/nvml/test_util.py, which stubs nvml.device_get_field_values so the helper can be exercised without an NVLink-capable device, and asserts both that it returns True and that it queried FieldId.DEV_NVLINK_GET_STATE. It fails with AttributeError before this change.
1 parent ffb776c commit 8e34ede

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
5+
import pytest
6+
7+
from cuda.bindings import nvml
8+
9+
from . import util
10+
11+
12+
class _FakeFieldValue:
13+
nvml_return = nvml.Return.SUCCESS
14+
15+
16+
@pytest.mark.agent_authored(model="claude-opus-5")
17+
def test_supports_nvlink_queries_a_real_field_id(monkeypatch):
18+
"""The helper has to name an enum that exists; nvml.FI never did."""
19+
queried = {}
20+
21+
def fake_device_get_field_values(device, fields):
22+
queried["field_id"] = fields[0].field_id
23+
return [_FakeFieldValue()]
24+
25+
monkeypatch.setattr(nvml, "device_get_field_values", fake_device_get_field_values)
26+
27+
assert util.supports_nvlink(object()) is True
28+
assert queried["field_id"] == nvml.FieldId.DEV_NVLINK_GET_STATE

cuda_bindings/tests/nvml/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ def supports_ecc(device):
2222

2323
def supports_nvlink(device):
2424
fields = nvml.FieldValue(1)
25-
fields[0].field_id = nvml.FI.DEV_NVLINK_GET_STATE
25+
fields[0].field_id = nvml.FieldId.DEV_NVLINK_GET_STATE
2626
return nvml.device_get_field_values(device, fields)[0].nvml_return == nvml.Return.SUCCESS

0 commit comments

Comments
 (0)