fix: [SWDEV-442525] [rocm/amd_smi_lib]

Fixes gpu_process_list

Code changes related to the following:
  * amdsmi_get_gpu_process_list()
  * CLI
  * Examples
  * Unit tests
  * Changelog
  * Readme
  * rocm_smi_lib commit: 677433b367

Change-Id: I9210fbca7a5da92d0a8b472b72ca82597c8e4fb5
Signed-off-by: Oliveira, Daniel <daniel.oliveira@amd.com>
This commit is contained in:
Oliveira, Daniel
2024-03-14 05:53:26 -05:00
parent 9800156a7a
commit 08e2e21bab
14 changed files with 380 additions and 246 deletions
+18 -44
View File
@@ -882,13 +882,24 @@ except AmdSmiException as e:
### amdsmi_get_gpu_process_list
Description: Returns the list of processes for the given GPU
Description: Returns the list of processes for the given GPU.
The list is of type `amdsmi_proc_info_t` and holds information about the running process.
Input parameters:
* `processor_handle` device which to query
Output: List of process handles found
Output: List of process processes with fields
Output: Dictionary with fields
Field | Description
---|---
`name` | Name of process
`pid` | Process ID
`mem` | Process memory usage
`engine_usage` | <table><thead><tr> <th> Subfield </th> <th> Description</th> </tr></thead><tbody><tr><td>`gfx`</td><td>GFX engine usage in ns</td></tr><tr><td>`enc`</td><td>Encode engine usage in ns</td></tr></tbody></table>
`memory_usage` | <table><thead><tr> <th> Subfield </th> <th> Description</th> </tr></thead><tbody><tr><td>`gtt_mem`</td><td>GTT memory usage</td></tr><tr><td>`cpu_mem`</td><td>CPU memory usage</td></tr><tr><td>`vram_mem`</td><td>VRAM memory usage</td></tr> </tbody></table>
Exceptions that can be thrown by `amdsmi_get_gpu_process_list` function:
@@ -906,48 +917,11 @@ try:
else:
for device in devices:
processes = amdsmi_get_gpu_process_list(device)
print(processes)
except AmdSmiException as e:
print(e)
```
### amdsmi_get_gpu_process_info
Description: Returns the info for the given process
Input parameters:
* `processor_handle` device which to query
* `process_handle` process which to query
Output: Dictionary with fields
Field | Description
---|---
`name` | Name of process
`pid` | Process ID
`mem` | Process memory usage
`engine_usage` | <table><thead><tr> <th> Subfield </th> <th> Description</th> </tr></thead><tbody><tr><td>`gfx`</td><td>GFX engine usage in ns</td></tr><tr><td>`enc`</td><td>Encode engine usage in ns</td></tr></tbody></table>
`memory_usage` | <table><thead><tr> <th> Subfield </th> <th> Description</th> </tr></thead><tbody><tr><td>`gtt_mem`</td><td>GTT memory usage</td></tr><tr><td>`cpu_mem`</td><td>CPU memory usage</td></tr><tr><td>`vram_mem`</td><td>VRAM memory usage</td></tr> </tbody></table>
Exceptions that can be thrown by `amdsmi_get_gpu_process_info` function:
* `AmdSmiLibraryException`
* `AmdSmiRetryException`
* `AmdSmiParameterException`
Example:
```python
try:
devices = amdsmi_get_processor_handles()
if len(devices) == 0:
print("No GPUs on machine")
else:
for device in devices:
processes = amdsmi_get_gpu_process_list(device)
for process in processes:
print(amdsmi_get_gpu_process_info(device, process))
if len(processes) == 0:
print("No processes running on this GPU")
else:
for process in processes:
print(process)
except AmdSmiException as e:
print(e)
```
+18 -22
View File
@@ -1923,15 +1923,16 @@ def amdsmi_get_gpu_ras_block_features_enabled(
def amdsmi_get_gpu_process_list(
processor_handle: amdsmi_wrapper.amdsmi_processor_handle,
) -> List[amdsmi_wrapper.amdsmi_process_handle_t]:
) -> List[amdsmi_wrapper.amdsmi_proc_info_t]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
# This will get populated with the number of processes found
max_processes = ctypes.c_uint32(MAX_NUM_PROCESSES)
process_list = (amdsmi_wrapper.amdsmi_process_handle_t *
process_list = (amdsmi_wrapper.amdsmi_proc_info_t *
max_processes.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_process_list(
@@ -1939,42 +1940,37 @@ def amdsmi_get_gpu_process_list(
)
)
return [amdsmi_wrapper.amdsmi_process_handle_t(process_list[x])\
for x in range(0, max_processes.value)]
result = []
for index in range(max_processes.value):
result.append(process_list[index])
return result
def amdsmi_get_gpu_process_info(
processor_handle: amdsmi_wrapper.amdsmi_processor_handle,
process: amdsmi_wrapper.amdsmi_process_handle_t,
process: amdsmi_wrapper.amdsmi_proc_info_t,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(process, amdsmi_wrapper.amdsmi_process_handle_t):
if not isinstance(process, amdsmi_wrapper.amdsmi_proc_info_t):
raise AmdSmiParameterException(
process, amdsmi_wrapper.amdsmi_process_handle_t)
info = amdsmi_wrapper.amdsmi_proc_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_process_info(
processor_handle, process, ctypes.byref(info)
)
)
process, amdsmi_wrapper.amdsmi_proc_info_t)
return {
"name": info.name.decode("utf-8"),
"pid": info.pid,
"mem": info.mem,
"name": process.name.decode("utf-8"),
"pid": process.pid,
"mem": process.mem,
"engine_usage": {
"gfx": info.engine_usage.gfx,
"enc": info.engine_usage.enc
"gfx": process.engine_usage.gfx,
"enc": process.engine_usage.enc
},
"memory_usage": {
"gtt_mem": info.memory_usage.gtt_mem,
"cpu_mem": info.memory_usage.cpu_mem,
"vram_mem": info.memory_usage.vram_mem,
"gtt_mem": process.memory_usage.gtt_mem,
"cpu_mem": process.memory_usage.cpu_mem,
"vram_mem": process.memory_usage.vram_mem,
},
}
+2 -5
View File
@@ -2212,10 +2212,7 @@ amdsmi_get_gpu_vram_usage.restype = amdsmi_status_t
amdsmi_get_gpu_vram_usage.argtypes = [amdsmi_processor_handle, ctypes.POINTER(struct_amdsmi_vram_usage_t)]
amdsmi_get_gpu_process_list = _libraries['libamd_smi.so'].amdsmi_get_gpu_process_list
amdsmi_get_gpu_process_list.restype = amdsmi_status_t
amdsmi_get_gpu_process_list.argtypes = [amdsmi_processor_handle, ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32)]
amdsmi_get_gpu_process_info = _libraries['libamd_smi.so'].amdsmi_get_gpu_process_info
amdsmi_get_gpu_process_info.restype = amdsmi_status_t
amdsmi_get_gpu_process_info.argtypes = [amdsmi_processor_handle, amdsmi_process_handle_t, ctypes.POINTER(struct_amdsmi_proc_info_t)]
amdsmi_get_gpu_process_list.argtypes = [amdsmi_processor_handle, ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(struct_amdsmi_proc_info_t)]
amdsmi_get_gpu_total_ecc_count = _libraries['libamd_smi.so'].amdsmi_get_gpu_total_ecc_count
amdsmi_get_gpu_total_ecc_count.restype = amdsmi_status_t
amdsmi_get_gpu_total_ecc_count.argtypes = [amdsmi_processor_handle, ctypes.POINTER(struct_amdsmi_error_count_t)]
@@ -2580,7 +2577,7 @@ __all__ = \
'amdsmi_get_gpu_pci_throughput', 'amdsmi_get_gpu_perf_level',
'amdsmi_get_gpu_pm_metrics_info',
'amdsmi_get_gpu_power_profile_presets',
'amdsmi_get_gpu_process_info', 'amdsmi_get_gpu_process_list',
'amdsmi_get_gpu_process_list',
'amdsmi_get_gpu_ras_block_features_enabled',
'amdsmi_get_gpu_ras_feature_info',
'amdsmi_get_gpu_reg_table_info', 'amdsmi_get_gpu_revision',