Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gpustack_runtime/detector/__types__.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ def index_mig_devices(
devices: Devices,
mig_devices: dict[int, list[dict]],
slots: int,
reserved: int = 0,
) -> None:
"""
Number the given cards' MIG devices in place.
Expand All @@ -503,9 +504,13 @@ def index_mig_devices(
found at, which the block offset is added to.
slots:
The number of MIG devices a card can host, i.e. the block size.
reserved:
The number of card indexes taken even if no detected card reports
them, e.g. by a card the detector skipped, so that skipping the
card with the largest index does not renumber the MIG devices.

"""
base = max((dev.index for dev in devices), default=-1) + 1
base = max(max((dev.index for dev in devices), default=-1) + 1, reserved)
for dev_idx, migs in mig_devices.items():
for mig in migs:
mig["index"] += base + dev_idx * slots
Expand Down
10 changes: 9 additions & 1 deletion gpustack_runtime/detector/nvidia.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,15 @@ def detect_info(self) -> Devices | None:
),
)

index_mig_devices(ret, devs_mig_devices, devs_mig_slots)
# A skipped card's enumeration index stays taken. Minor numbers are
# not the enumeration range, so they get no reservation.
reserved = 0
if (
unqueryable_error
and not envs.GPUSTACK_RUNTIME_DETECT_PHYSICAL_INDEX_PRIORITY
):
reserved = dev_count
index_mig_devices(ret, devs_mig_devices, devs_mig_slots, reserved=reserved)
except pynvml.NVMLError:
debug_log_exception(logger, "Failed to fetch devices")
raise
Expand Down
50 changes: 50 additions & 0 deletions tests/gpustack_runtime/detector/test_nvidia.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,56 @@ def test_detect_info_fails_when_no_card_can_be_queried(fake_nvml):
NVIDIADetector().detect_info()


def test_detect_info_keeps_mig_indexes_when_the_last_card_cannot_be_queried(
fake_nvml,
):
# MIG indexes are numbered above the cards' indexes. Skipping the card with
# the largest index must not renumber the MIG devices of the other cards.
def mig_indexes(lost: bool) -> list[int]:
error = {"query_error_code": _FakeNVML.NVML_ERROR_GPU_IS_LOST} if lost else {}
fake_nvml(
[
_mig_card(),
_FakeDevice(uuid="GPU-1"),
_FakeDevice(uuid="GPU-2", **error),
],
)
devices = NVIDIADetector().detect_info()
return [mig["index"] for mig in devices[0].appendix["mig_devices"]]

assert mig_indexes(lost=False) == [3, 4]
assert mig_indexes(lost=True) == [3, 4]


def test_detect_info_keeps_physical_mig_indexes_when_a_card_cannot_be_queried(
fake_nvml,
monkeypatch,
):
# With minor numbers as indexes, the card count is not the index namespace:
# a card without a readable minor number is already left out.
monkeypatch.setattr(
nvidia.envs,
"GPUSTACK_RUNTIME_DETECT_PHYSICAL_INDEX_PRIORITY",
True,
raising=False,
)

def mig_indexes(lost: bool) -> list[int]:
error = {"query_error_code": _FakeNVML.NVML_ERROR_GPU_IS_LOST} if lost else {}
fake_nvml(
[
_FakeDevice(uuid="GPU-A", minor_number=0, **error),
_mig_card(minor_number=1),
_FakeDevice(uuid="GPU-C", minor_number=None),
],
)
devices = NVIDIADetector().detect_info()
card = next(dev for dev in devices if dev.index == 1)
return [mig["index"] for mig in card.appendix["mig_devices"]]

assert mig_indexes(lost=True) == mig_indexes(lost=False)


@pytest.mark.usefixtures("health_check")
def test_detect_info_reports_the_memory_health(fake_nvml):
fake_nvml([_FakeDevice(ecc_errors=1)])
Expand Down
Loading