From d5ed9582f83d8ff3fe27ce63710a705ee24a3853 Mon Sep 17 00:00:00 2001 From: LeSingh1 Date: Sat, 8 Aug 2026 19:10:21 -0700 Subject: [PATCH] Fix the field-id enum name in the nvml test helper supports_nvlink 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. --- cuda_bindings/tests/nvml/test_util.py | 28 +++++++++++++++++++++++++++ cuda_bindings/tests/nvml/util.py | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 cuda_bindings/tests/nvml/test_util.py diff --git a/cuda_bindings/tests/nvml/test_util.py b/cuda_bindings/tests/nvml/test_util.py new file mode 100644 index 00000000000..2eb46647777 --- /dev/null +++ b/cuda_bindings/tests/nvml/test_util.py @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + + +import pytest + +from cuda.bindings import nvml + +from . import util + + +class _FakeFieldValue: + nvml_return = nvml.Return.SUCCESS + + +@pytest.mark.agent_authored(model="claude-opus-5") +def test_supports_nvlink_queries_a_real_field_id(monkeypatch): + """The helper has to name an enum that exists; nvml.FI never did.""" + queried = {} + + def fake_device_get_field_values(device, fields): + queried["field_id"] = fields[0].field_id + return [_FakeFieldValue()] + + monkeypatch.setattr(nvml, "device_get_field_values", fake_device_get_field_values) + + assert util.supports_nvlink(object()) is True + assert queried["field_id"] == nvml.FieldId.DEV_NVLINK_GET_STATE diff --git a/cuda_bindings/tests/nvml/util.py b/cuda_bindings/tests/nvml/util.py index 129ded8f83c..7d63a141706 100644 --- a/cuda_bindings/tests/nvml/util.py +++ b/cuda_bindings/tests/nvml/util.py @@ -22,5 +22,5 @@ def supports_ecc(device): def supports_nvlink(device): fields = nvml.FieldValue(1) - fields[0].field_id = nvml.FI.DEV_NVLINK_GET_STATE + fields[0].field_id = nvml.FieldId.DEV_NVLINK_GET_STATE return nvml.device_get_field_values(device, fields)[0].nvml_return == nvml.Return.SUCCESS