Skip to content

Commit d6fffe7

Browse files
[AMD] Fix deprecated amdsmi api (pytorch#126962) (#1432)
Summary: pytorch#119182 uses an API that has already been deprecated by ROCm/amdsmi@c551c3c. So fixing this in a backward compatible way Reviewed By: nmacchioni Differential Revision: D57711088 (cherry picked from commit a04cda7) Co-authored-by: Xiaodong Wang <[email protected]>
1 parent 9480afe commit d6fffe7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

tools/stats/monitor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ def rocm_get_per_process_gpu_info(handle: Any) -> List[Dict[str, Any]]:
6262
processes = amdsmi.amdsmi_get_gpu_process_list(handle)
6363
per_process_info = []
6464
for p in processes:
65-
proc_info = amdsmi.amdsmi_get_gpu_process_info(handle, p)
65+
try:
66+
proc_info = amdsmi.amdsmi_get_gpu_process_info(handle, p)
67+
except AttributeError:
68+
# https://github.com/ROCm/amdsmi/commit/c551c3caedbd903ba828e7fdffa5b56d475a15e7
69+
# BC-breaking change that removes amdsmi_get_gpu_process_info API from amdsmi
70+
proc_info = p
6671
info = {
6772
"pid": proc_info["pid"],
6873
"gpu_memory": proc_info["memory_usage"]["vram_mem"],

torch/cuda/memory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,12 @@ def list_gpu_processes(device: Union[Device, int] = None) -> str:
653653
mem = p.usedGpuMemory / (1024 * 1024)
654654
pid = p.pid
655655
else:
656-
proc_info = amdsmi.amdsmi_get_gpu_process_info(handle, p) # type: ignore[possibly-undefined]
656+
try:
657+
proc_info = amdsmi.amdsmi_get_gpu_process_info(handle, p) # type: ignore[possibly-undefined]
658+
except AttributeError:
659+
# https://github.com/ROCm/amdsmi/commit/c551c3caedbd903ba828e7fdffa5b56d475a15e7
660+
# is a BC-breaking change that removes amdsmi_get_gpu_process_info API from amdsmi
661+
proc_info = p
657662
mem = proc_info["memory_usage"]["vram_mem"] / (1024 * 1024)
658663
pid = proc_info["pid"]
659664
lines.append(f"process {pid:>10d} uses {mem:>12.3f} MB GPU memory")

0 commit comments

Comments
 (0)