From 3b1e2f0817790464af56ae4617b0bc53068b7b0b Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Thu, 29 Jun 2023 14:33:47 -0500 Subject: [PATCH 1/3] amdsmi_init() fail when miss voltage sysfs Fix the error handling when voltage sysfs is missing. Change-Id: I457289eb4fd45bb05af83a67289b056f7e2ad966 --- rocm_smi/src/rocm_smi_monitor.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rocm_smi/src/rocm_smi_monitor.cc b/rocm_smi/src/rocm_smi_monitor.cc index 15c995ebae..4adffdd50f 100755 --- a/rocm_smi/src/rocm_smi_monitor.cc +++ b/rocm_smi/src/rocm_smi_monitor.cc @@ -367,17 +367,19 @@ Monitor::setVoltSensorLabelMap(void) { } auto add_volt_sensor_entry = [&](uint32_t file_index) { ret = readMonitor(kMonVoltLabel, file_index, &type_str); - rsmi_voltage_type_t t_type = kVoltSensorNameMap.at(type_str); + rsmi_voltage_type_t t_type; + // If readMonitor fails, there is no label file for the file_index. // In that case, map the type to file index 0, which is not supported // and will fail appropriately later when we check for support. if (ret) { - volt_type_index_map_.insert({t_type, 0}); index_volt_type_map_.insert({file_index, RSMI_VOLT_TYPE_INVALID}); } else { - volt_type_index_map_.insert({t_type, file_index}); + t_type = kVoltSensorNameMap.at(type_str); + volt_type_index_map_[t_type] = file_index; index_volt_type_map_.insert({file_index, t_type}); } + return 0; }; From 78faf411f806c32e9be1a3e7b217a65ee8d89b70 Mon Sep 17 00:00:00 2001 From: Marko Oblak Date: Wed, 28 Jun 2023 17:54:36 +0200 Subject: [PATCH 2/3] SWDEV-391188 - [AMDSMI][LinuxGuest] Added description in amdsmi header file for amdsmi_get_gpu_process_list, changed mentioned API in py_interface Signed-off-by: Marko Oblak Change-Id: I8cb7f2c6595da6ab0263e6fa4365bde91d900979 --- include/amd_smi/amdsmi.h | 15 ++++++++++----- py-interface/amdsmi_interface.py | 14 +++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/amd_smi/amdsmi.h b/include/amd_smi/amdsmi.h index 5890fb9e86..3a2b082bdb 100644 --- a/include/amd_smi/amdsmi.h +++ b/include/amd_smi/amdsmi.h @@ -3390,16 +3390,21 @@ amdsmi_get_gpu_vram_usage(amdsmi_processor_handle processor_handle, amdsmi_vram_ /** * @brief Returns the list of processes running on a given GPU including itself. * - * @note The user provides a buffer to store the list and the - * maximum number of processes that can be returned. If the user - * sets max_processes to 0, the total number of processes will be - * returned. + * @note The user provides a buffer to store the list and the maximum + * number of processes that can be returned. If the user sets + * max_processes to 0, the current total number of processes will + * replace max_processes param. After that, the function needs to be + * called again, with updated max_processes, to successfully fill the + * process list, which was previously allocated with max_processes * * @param[in] processor_handle Device which to query * * @param[in,out] max_processes Reference to the size of the list buffer in * number of elements. Returns the return number of elements - * in list or the number of running processes if equal to 0. + * in list or the number of running processes if equal to 0, + * and if given value in param max_processes is less than + * number of processes currently running, + * AMDSMI_STATUS_OUT_OF_RESOURCES will be returned. * * @param[out] list Reference to a user-provided buffer where the process * list will be returned. This buffer must contain at least diff --git a/py-interface/amdsmi_interface.py b/py-interface/amdsmi_interface.py index 15ad58ad87..5ab5ad4be4 100644 --- a/py-interface/amdsmi_interface.py +++ b/py-interface/amdsmi_interface.py @@ -28,6 +28,8 @@ from collections.abc import Iterable from . import amdsmi_wrapper from .amdsmi_exception import * +MAX_NUM_PROCESSES = 1024 + class AmdSmiInitFlags(IntEnum): INIT_ALL_PROCESSORS = amdsmi_wrapper.AMDSMI_INIT_ALL_PROCESSORS INIT_AMD_CPUS = amdsmi_wrapper.AMDSMI_INIT_AMD_CPUS @@ -845,14 +847,7 @@ def amdsmi_get_gpu_process_list( processor_handle, amdsmi_wrapper.amdsmi_processor_handle ) - max_processes = ctypes.c_uint32(0) - process_list = (amdsmi_wrapper.amdsmi_process_handle_t * - max_processes.value)() - _check_res( - amdsmi_wrapper.amdsmi_get_gpu_process_list( - processor_handle, ctypes.byref(max_processes), process_list - ) - ) + max_processes = ctypes.c_uint32(MAX_NUM_PROCESSES) process_list = (amdsmi_wrapper.amdsmi_process_handle_t * max_processes.value)() @@ -862,7 +857,8 @@ def amdsmi_get_gpu_process_list( ) ) - return [amdsmi_wrapper.amdsmi_process_handle_t(x) for x in list(process_list)] + return [amdsmi_wrapper.amdsmi_process_handle_t(process_list[x])\ + for x in range(0, max_processes.value)] def amdsmi_get_gpu_process_info( From 7b107258ffc27fa50684053671f86cd22852f204 Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Fri, 30 Jun 2023 15:16:30 -0500 Subject: [PATCH 3/3] Handle key not exists errors for voltage sensor Check the key exists or not before access sensor map. Change-Id: I0ac5d63ae981ec2f984b1d464e93508560a4d030 --- rocm_smi/src/rocm_smi_monitor.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rocm_smi/src/rocm_smi_monitor.cc b/rocm_smi/src/rocm_smi_monitor.cc index 4adffdd50f..856281053b 100755 --- a/rocm_smi/src/rocm_smi_monitor.cc +++ b/rocm_smi/src/rocm_smi_monitor.cc @@ -465,6 +465,8 @@ Monitor::getVoltSensorIndex(rsmi_voltage_type_t type) { rsmi_voltage_type_t Monitor::getVoltSensorEnum(uint64_t ind) { + // check if ind is a key or not + if (index_volt_type_map_.count(ind) == 0) return RSMI_VOLT_TYPE_INVALID; return index_volt_type_map_.at(ind); }