Files
rocm-systems/amdsmi_cli/rocm_version.py
T
Bill(Shuzhou) Liu 9dd24a2b5a Add the ROCm version in CLI
Print the ROCm version in CLI

Change-Id: I529201274e114bde44722aa9a6aec13c2bedecf7
2024-01-04 15:25:08 -06:00

30 lines
1.0 KiB
Python

import os
import ctypes
from pathlib import Path
# Get the ROCm version for rocm-core library
def get_rocm_version():
try:
librocm_core_file = Path(__file__).resolve().parent.parent.parent / "lib" / "librocm-core.so"
if not librocm_core_file.is_file():
return "N/A"
# python binding
librocm_core = ctypes.CDLL(librocm_core_file)
VerErrors = ctypes.c_uint32
get_rocm_core_version = librocm_core.getROCmVersion
get_rocm_core_version.restype = VerErrors
get_rocm_core_version.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32),ctypes.POINTER(ctypes.c_uint32)]
# call the function
major = ctypes.c_uint32()
minor = ctypes.c_uint32()
patch = ctypes.c_uint32()
if get_rocm_core_version(ctypes.byref(major), ctypes.byref(minor),ctypes.byref(patch)) == 0:
return "%d.%d.%d" % (major.value, minor.value, patch.value)
return "N/A"
except:
return "N/A"