Skip to content

Commit e99942d

Browse files
committed
refactor: enhance detector
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent a47d693 commit e99942d

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

gpustack_runtime/detector/amd.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,20 @@ def detect(self) -> Devices | None:
9191
for dev_idx, dev in enumerate(devs):
9292
dev_index = dev_idx
9393

94-
dev_card = None
94+
dev_card_id = None
9595
if hasattr(pyamdsmi, "amdsmi_get_gpu_kfd_info"):
9696
dev_kfd_info = pyamdsmi.amdsmi_get_gpu_kfd_info(dev)
97-
dev_card = dev_kfd_info.get("node_id")
97+
dev_card_id = dev_kfd_info.get("node_id")
9898
else:
9999
with contextlib.suppress(pyrocmsmi.ROCMSMIError):
100100
pyrocmsmi.rsmi_init()
101-
dev_card = pyrocmsmi.rsmi_dev_node_id_get(dev_idx)
101+
dev_card_id = pyrocmsmi.rsmi_dev_node_id_get(dev_idx)
102102

103103
dev_gpudev_info = None
104-
if dev_card is not None:
104+
if dev_card_id is not None:
105105
with contextlib.suppress(pyamdgpu.AMDGPUError):
106106
_, _, dev_gpudev = pyamdgpu.amdgpu_device_initialize(
107-
dev_card,
107+
dev_card_id,
108108
)
109109
dev_gpudev_info = pyamdgpu.amdgpu_query_gpu_info(dev_gpudev)
110110
pyamdgpu.amdgpu_device_deinitialize(dev_gpudev)
@@ -122,8 +122,6 @@ def detect(self) -> Devices | None:
122122
with contextlib.suppress(pyrocmsmi.ROCMSMIError):
123123
pyrocmsmi.rsmi_init()
124124
dev_cc = pyrocmsmi.rsmi_dev_target_graphics_version_get(dev_idx)
125-
if dev_cc:
126-
dev_cc = dev_cc[3:] # Strip "gfx" prefix
127125

128126
dev_gpu_metrics_info = pyamdsmi.amdsmi_get_gpu_metrics_info(dev)
129127
dev_cores = (
@@ -152,6 +150,7 @@ def detect(self) -> Devices | None:
152150
dev_appendix = {
153151
"arch_family": _get_arch_family(dev_gpudev_info),
154152
"vgpu": dev_compute_partition is not None,
153+
"card_id": dev_card_id,
155154
}
156155

157156
ret.append(

gpustack_runtime/detector/hygon.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ def detect(self) -> Devices | None:
8686
dev_uuid = pyrocmsmi.rsmi_dev_unique_id_get(dev_idx)
8787
dev_name = pyrocmsmi.rsmi_dev_name_get(dev_idx)
8888
dev_cc = pyrocmsmi.rsmi_dev_target_graphics_version_get(dev_idx)
89-
if dev_cc:
90-
dev_cc = dev_cc[3:] # Strip "gfx" prefix
9189

9290
dev_cores = None
9391
dev_cores_util = pyrocmsmi.rsmi_dev_busy_percent_get(dev_idx)

gpustack_runtime/detector/pyrocmsmi/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ def rsmi_dev_target_graphics_version_get(device=0):
197197
_rocmsmiCheckReturn(ret)
198198
version = str(c_version.value)
199199
if len(version) == 4:
200-
version = hex(c_version.value)[2:]
200+
dev_name = rsmi_dev_name_get(device)
201+
if "Instinct MI2" in dev_name:
202+
hex_part = str(hex(int(version[2:]))).replace("0x", "")
203+
version = version[:2] + hex_part
204+
else:
205+
version = str(c_version.value // 10 + c_version.value % 10)
201206
return "gfx" + version
202207

203208

0 commit comments

Comments
 (0)