Skip to content

Commit fa8c64f

Browse files
committed
refactor: support pci class prefixes
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent de1ceac commit fa8c64f

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

gpustack_runtime/detector/__utils__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from pathlib import Path
1414
from typing import Any
1515

16+
from gpustack_runtime import envs
17+
1618

1719
@dataclass
1820
class PCIDevice:
@@ -69,7 +71,10 @@ def get_pci_devices(
6971
return pci_devices
7072

7173
if not class_prefix:
72-
class_prefix = ["0x02", "0x03", "0x12", "0x0b"]
74+
class_prefix = []
75+
for prefix in envs.GPUSTACK_RUNTIME_DETECT_PCI_CLASS_PREFIXES:
76+
if prefix:
77+
class_prefix.append(f"0x{prefix.lower()}")
7378

7479
if address and isinstance(address, str):
7580
address = [address]

gpustack_runtime/envs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
Set true to disable PCI check during detection.
4040
Useful for WSL environments, where PCI information may not be available.
4141
"""
42+
GPUSTACK_RUNTIME_DETECT_PCI_CLASS_PREFIXES: set[str] | None = None
43+
"""
44+
The PCI class prefixes to check during detection.
45+
When `GPUSTACK_RUNTIME_DETECT_NO_PCI_CHECK` is false, the detector will check if the PCI class of the device starts with any of the given prefixes.
46+
"""
4247
GPUSTACK_RUNTIME_DETECT_NO_TOOLKIT_CALL: bool = False
4348
"""
4449
Set true to disable toolkit calls during detection.
@@ -374,6 +379,16 @@
374379
lambda: to_bool(getenv("GPUSTACK_RUNTIME_DETECT_NO_PCI_CHECK")),
375380
lambda: any(x in get_os_release() for x in ("microsoft", "wsl")),
376381
),
382+
"GPUSTACK_RUNTIME_DETECT_PCI_CLASS_PREFIXES": lambda: to_set(
383+
getenvs(
384+
[
385+
"GPUSTACK_RUNTIME_DETECT_PCI_CLASS_PREFIXES",
386+
"GPUSTACK_PCI_CLASS_PREFIXES",
387+
],
388+
"02,03,0b,12",
389+
),
390+
sep=",",
391+
),
377392
"GPUSTACK_RUNTIME_DETECT_NO_TOOLKIT_CALL": lambda: to_bool(
378393
getenv(
379394
"GPUSTACK_RUNTIME_DETECT_NO_TOOLKIT_CALL",

0 commit comments

Comments
 (0)