From 9d7964dff57cc4f56907719bdbdb633a4f5c5b1f Mon Sep 17 00:00:00 2001 From: "Kanangot Balakrishnan, Bindhiya" Date: Mon, 14 Apr 2025 04:19:45 -0500 Subject: [PATCH] [SWDEV-516592] Add python interface API for Bad Page Threshold (#141) - Added python interface APIs for amdsmi_get_gpu_bad_page_threshold() - Updated the docs and changelog. --------- Signed-off-by: Kanangot Balakrishnan, Bindhiya Signed-off-by: Arif, Maisam --- CHANGELOG.md | 15 +++++++++++++++ amdsmi_cli/amdsmi_commands.py | 5 +++++ amdsmi_cli/amdsmi_parser.py | 3 ++- docs/reference/amdsmi-py-api.md | 32 ++++++++++++++++++++++++++++++++ py-interface/__init__.py | 1 + py-interface/amdsmi_interface.py | 16 ++++++++++++++++ 6 files changed, 71 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4842b6064..a9f3b6a1f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,21 @@ Full documentation for amd_smi_lib is available at [https://rocm.docs.amd.com/pr ### Added +- **Added bad page threshold count**. + - Added `amdsmi_get_gpu_bad_page_threshold` to Python API and CLI; root/sudo permissions required to display the count. + +### Changed + +### Removed + +### Optimized + +### Resolved issues + +### Upcoming changes + +### Known issues + - **Added cpu model name for RDC**. - Added new C and Python API `amdsmi_get_cpu_model_name` - Not sourced from esmi library. diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index 84f1cbf43e..9d8920e186 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -712,6 +712,7 @@ class AMDSMICommands(): if 'ras' in current_platform_args: if args.ras: ras_dict = {"eeprom_version": "N/A", + "bad_page_threshold": "N/A", "parity_schema" : "N/A", "single_bit_schema" : "N/A", "double_bit_schema" : "N/A", @@ -735,6 +736,10 @@ class AMDSMICommands(): ras_dict.update(ras_info) except amdsmi_exception.AmdSmiLibraryException as e: logging.debug("Failed to get ras info for gpu %s | %s", gpu_id, e.get_error_info()) + try: + ras_dict["bad_page_threshold"] = amdsmi_interface.amdsmi_get_gpu_bad_page_threshold(args.gpu) + except amdsmi_exception.AmdSmiLibraryException as e: + logging.debug("Failed to get bad page threshold count for gpu %s | %s", gpu_id, e.get_error_info()) try: ras_states = amdsmi_interface.amdsmi_get_gpu_ras_block_features_enabled(args.gpu) diff --git a/amdsmi_cli/amdsmi_parser.py b/amdsmi_cli/amdsmi_parser.py index ff006cb1a1..659309744c 100644 --- a/amdsmi_cli/amdsmi_parser.py +++ b/amdsmi_cli/amdsmi_parser.py @@ -682,7 +682,8 @@ class AMDSMIParser(argparse.ArgumentParser): clock_help = f"Show one or more valid clock frequency levels. Available options:\n\t{clk_option_str}" # Options arguments help text for Hypervisors and Baremetal - ras_help = "Displays RAS features information" + # Might be able to remove Sudo requirement in ROCm 7.0 + ras_help = "Displays RAS features information;\n\tSudo may be required for some features" numa_help = "All numa node information" # Linux Baremetal only partition_help = "Partition information" diff --git a/docs/reference/amdsmi-py-api.md b/docs/reference/amdsmi-py-api.md index 9ac67f91ec..91fd3dcc25 100644 --- a/docs/reference/amdsmi-py-api.md +++ b/docs/reference/amdsmi-py-api.md @@ -990,6 +990,38 @@ except AmdSmiException as e: print(e) ``` +### amdsmi_get_gpu_bad_page_threshold + +Description: Returns bad page threshold for the given GPU; Requires root level access to display bad page threshold count; otherwise will return "N/A". +It is not supported on virtual machine guest + +Input parameters: + +* `processor_handle` device which to query + +Output: Bad page threshold value + +Exceptions that can be thrown by `amdsmi_get_gpu_bad_page_threshold` 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: + threshold = amdsmi_get_gpu_bad_page_threshold(device) + print(bad_page["threshold"]) +except AmdSmiException as e: + print(e) +``` + ### amdsmi_get_gpu_memory_reserved_pages Description: Returns reserved memory page info for the given GPU. diff --git a/py-interface/__init__.py b/py-interface/__init__.py index e89e1a957f..a1318455a4 100644 --- a/py-interface/__init__.py +++ b/py-interface/__init__.py @@ -109,6 +109,7 @@ from .amdsmi_interface import amdsmi_get_clock_info from .amdsmi_interface import amdsmi_get_pcie_info from .amdsmi_interface import amdsmi_get_gpu_bad_page_info +from .amdsmi_interface import amdsmi_get_gpu_bad_page_threshold from .amdsmi_interface import amdsmi_get_violation_status from .amdsmi_interface import amdsmi_get_gpu_xgmi_link_status diff --git a/py-interface/amdsmi_interface.py b/py-interface/amdsmi_interface.py index 7d6d75fb85..86220c240d 100644 --- a/py-interface/amdsmi_interface.py +++ b/py-interface/amdsmi_interface.py @@ -2214,6 +2214,22 @@ def amdsmi_get_gpu_bad_page_info( return _format_bad_page_info(bad_pages, num_pages) +def amdsmi_get_gpu_bad_page_threshold( + processor_handle: amdsmi_wrapper.amdsmi_processor_handle, +) -> Dict[str, Any]: + if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle): + raise AmdSmiParameterException( + processor_handle, amdsmi_wrapper.amdsmi_processor_handle + ) + + threshold = ctypes.c_uint32() + _check_res( + amdsmi_wrapper.amdsmi_get_gpu_bad_page_threshold( + processor_handle, ctypes.byref(threshold) + ) + ) + + return threshold.value def amdsmi_get_violation_status( processor_handle: amdsmi_wrapper.amdsmi_processor_handle,