amdsmi [CPU]: Add implementation to get cpu handles and core handles API

- Update the API names, parameters to return cpu handles and core
handles in the system.
  - Update the amdsmi_wrapper.py.
  - Update the amdsmi_interface.py to use the processor handles and
    core handles API.

Change-Id: Ie24f62f345864f8b6773fdb3c6369993bca7e25b
This commit is contained in:
Khader Basha Shaik
2024-10-04 12:20:02 +00:00
committed by Naveen Krishna Chatradhi
parent dd8795b099
commit 8308ede9e8
4 changed files with 174 additions and 105 deletions
+32 -60
View File
@@ -668,36 +668,22 @@ def amdsmi_get_cpusocket_handles() -> List[amdsmi_wrapper.amdsmi_socket_handle]:
Returns:
`List`: List containing all of the found cpu socket handles.
"""
socket_handles = amdsmi_get_socket_handles()
cpu_handles = []
type = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_AMD_CPU
for socket in socket_handles:
cpu_count = ctypes.c_uint32()
null_ptr = ctypes.POINTER(amdsmi_wrapper.amdsmi_processor_handle)()
_check_res(
amdsmi_wrapper.amdsmi_get_processor_handles_by_type(
socket,
type,
null_ptr,
ctypes.byref(cpu_count),
)
)
processor_handles = (
amdsmi_wrapper.amdsmi_processor_handle * cpu_count.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_processor_handles_by_type(
socket,
type,
processor_handles,
ctypes.byref(cpu_count)
)
)
cpu_handles.extend(
[
amdsmi_wrapper.amdsmi_processor_handle(processor_handles[dev_idx])
for dev_idx in range(cpu_count.value)
]
)
cpu_count = ctypes.c_uint32(0)
null_ptr = ctypes.POINTER(amdsmi_wrapper.amdsmi_processor_handle)()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_handles(
ctypes.byref(cpu_count), null_ptr)
)
proc_handles = (amdsmi_wrapper.amdsmi_processor_handle *
cpu_count.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_handles(
ctypes.byref(cpu_count), proc_handles)
)
cpu_handles = [
amdsmi_wrapper.amdsmi_processor_handle(proc_handles[sock_idx])
for sock_idx in range(cpu_count.value)
]
return cpu_handles
@@ -761,37 +747,23 @@ def amdsmi_get_processor_handles() -> List[amdsmi_wrapper.amdsmi_processor_handl
return devices
def amdsmi_get_cpucore_handles() -> List[amdsmi_wrapper.amdsmi_processor_handle]:
socket_handles = amdsmi_get_socket_handles()
core_handles = []
type = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_AMD_CPU_CORE
cores_count = ctypes.c_uint32(0)
null_ptr = ctypes.POINTER(amdsmi_wrapper.amdsmi_processor_handle)()
_check_res(
amdsmi_wrapper.amdsmi_get_cpucore_handles(
ctypes.byref(cores_count), null_ptr)
)
proc_handles = (amdsmi_wrapper.amdsmi_processor_handle *
cores_count.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_cpucore_handles(
ctypes.byref(cores_count), proc_handles)
)
core_handles = [
amdsmi_wrapper.amdsmi_processor_handle(proc_handles[sock_idx])
for sock_idx in range(cores_count.value)
]
for socket in socket_handles:
core_count = ctypes.c_uint32()
null_ptr = ctypes.POINTER(amdsmi_wrapper.amdsmi_processor_handle)()
_check_res(
amdsmi_wrapper.amdsmi_get_processor_handles_by_type(
socket,
type,
null_ptr,
ctypes.byref(core_count),
)
)
c_handles = (
amdsmi_wrapper.amdsmi_processor_handle * core_count.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_processor_handles_by_type(
socket,
type,
c_handles,
ctypes.byref(core_count)
)
)
core_handles.extend(
[
amdsmi_wrapper.amdsmi_processor_handle(c_handles[dev_idx])
for dev_idx in range(core_count.value)
]
)
return core_handles
+10 -19
View File
@@ -181,16 +181,6 @@ try:
except OSError as error:
print(error)
print("Unable to find amdsmi library try installing amd-smi-lib from your package manager")
class FunctionFactoryStub:
def __getattr__(self, _):
return ctypes.CFUNCTYPE(lambda y:y)
# libraries['FIXME_STUB'] explanation
# As you did not list (-l libraryname.so) a library that exports this function
# This is a non-working stub instead.
# You can either re-run clan2py with -l /path/to/library.so
# Or manually fix this by comment the ctypes.CDLL loading
_libraries['FIXME_STUB'] = FunctionFactoryStub() # ctypes.CDLL('FIXME_STUB')
@@ -2081,9 +2071,9 @@ amdsmi_shut_down.argtypes = []
amdsmi_get_socket_handles = _libraries['libamd_smi.so'].amdsmi_get_socket_handles
amdsmi_get_socket_handles.restype = amdsmi_status_t
amdsmi_get_socket_handles.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.POINTER(None))]
amdsmi_get_cpusocket_handles = _libraries['FIXME_STUB'].amdsmi_get_cpusocket_handles
amdsmi_get_cpusocket_handles.restype = amdsmi_status_t
amdsmi_get_cpusocket_handles.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.POINTER(None))]
amdsmi_get_cpu_handles = _libraries['libamd_smi.so'].amdsmi_get_cpu_handles
amdsmi_get_cpu_handles.restype = amdsmi_status_t
amdsmi_get_cpu_handles.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.POINTER(None))]
size_t = ctypes.c_uint64
amdsmi_get_socket_info = _libraries['libamd_smi.so'].amdsmi_get_socket_info
amdsmi_get_socket_info.restype = amdsmi_status_t
@@ -2100,9 +2090,9 @@ amdsmi_get_processor_handles_by_type.argtypes = [amdsmi_socket_handle, processor
amdsmi_get_processor_handles = _libraries['libamd_smi.so'].amdsmi_get_processor_handles
amdsmi_get_processor_handles.restype = amdsmi_status_t
amdsmi_get_processor_handles.argtypes = [amdsmi_socket_handle, ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.POINTER(None))]
amdsmi_get_cpucore_handles = _libraries['FIXME_STUB'].amdsmi_get_cpucore_handles
amdsmi_get_cpucore_handles = _libraries['libamd_smi.so'].amdsmi_get_cpucore_handles
amdsmi_get_cpucore_handles.restype = amdsmi_status_t
amdsmi_get_cpucore_handles.argtypes = [amdsmi_cpusocket_handle, ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.POINTER(None))]
amdsmi_get_cpucore_handles.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.POINTER(None))]
amdsmi_get_processor_type = _libraries['libamd_smi.so'].amdsmi_get_processor_type
amdsmi_get_processor_type.restype = amdsmi_status_t
amdsmi_get_processor_type.argtypes = [amdsmi_processor_handle, ctypes.POINTER(processor_type_t)]
@@ -2818,8 +2808,9 @@ __all__ = \
'amdsmi_get_cpu_dimm_power_consumption',
'amdsmi_get_cpu_dimm_temp_range_and_refresh_rate',
'amdsmi_get_cpu_dimm_thermal_sensor', 'amdsmi_get_cpu_family',
'amdsmi_get_cpu_fclk_mclk', 'amdsmi_get_cpu_hsmp_proto_ver',
'amdsmi_get_cpu_model', 'amdsmi_get_cpu_prochot_status',
'amdsmi_get_cpu_fclk_mclk', 'amdsmi_get_cpu_handles',
'amdsmi_get_cpu_hsmp_proto_ver', 'amdsmi_get_cpu_model',
'amdsmi_get_cpu_prochot_status',
'amdsmi_get_cpu_pwr_svi_telemetry_all_rails',
'amdsmi_get_cpu_smu_fw_version',
'amdsmi_get_cpu_socket_c0_residency',
@@ -2830,8 +2821,8 @@ __all__ = \
'amdsmi_get_cpu_socket_power', 'amdsmi_get_cpu_socket_power_cap',
'amdsmi_get_cpu_socket_power_cap_max',
'amdsmi_get_cpu_socket_temperature', 'amdsmi_get_cpucore_handles',
'amdsmi_get_cpusocket_handles', 'amdsmi_get_energy_count',
'amdsmi_get_esmi_err_msg', 'amdsmi_get_fw_info',
'amdsmi_get_energy_count', 'amdsmi_get_esmi_err_msg',
'amdsmi_get_fw_info',
'amdsmi_get_gpu_accelerator_partition_profile',
'amdsmi_get_gpu_activity', 'amdsmi_get_gpu_asic_info',
'amdsmi_get_gpu_available_counters',