From 78faf411f806c32e9be1a3e7b217a65ee8d89b70 Mon Sep 17 00:00:00 2001 From: Marko Oblak Date: Wed, 28 Jun 2023 17:54:36 +0200 Subject: [PATCH] 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(