From 801dbaedec8c1d9e41040e3c79912d812ea95675 Mon Sep 17 00:00:00 2001 From: "Castillo, Juan" Date: Tue, 15 Jul 2025 19:35:54 -0500 Subject: [PATCH] [SWDEV-531904] Added test_get_gpu_revision (#533) * [SWDEV-531904] Added test_get_gpu_revision New: - amdsmi_get_gpu_revision() previously not implemented in amdsmi_interface.py - test_get_gpu_revision() missing integration test. Updated: -changelog.md added new doc fields for ROCm 7.1 -amdsmi-py-api.md added field|description doc fields Signed-off-by: Juan Castillo [ROCm/amdsmi commit: 3b1957e674439471e4dfbf7cf278bf8fcb0271b5] --- projects/amdsmi/CHANGELOG.md | 23 ++++++++++++ .../amdsmi/docs/reference/amdsmi-py-api.md | 36 +++++++++++++++++++ projects/amdsmi/py-interface/__init__.py | 1 + .../amdsmi/py-interface/amdsmi_interface.py | 29 +++++++++++++++ .../tests/python_unittest/integration_test.py | 18 ++++++++++ 5 files changed, 107 insertions(+) diff --git a/projects/amdsmi/CHANGELOG.md b/projects/amdsmi/CHANGELOG.md index de32d5b9e8..676cd2603f 100644 --- a/projects/amdsmi/CHANGELOG.md +++ b/projects/amdsmi/CHANGELOG.md @@ -4,6 +4,29 @@ Full documentation for amd_smi_lib is available at [https://rocm.docs.amd.com/pr ***All information listed below is for reference and subject to change.*** +## amd_smi_lib for ROCm 7.1.0 + +### Added + +- **Added `amdsmi_get_gpu_revision()` to Python API** + - This function retrieves the GPU revision ID. Available in `amdsmi_interface.py` as `amdsmi_get_gpu_revision()`. + +### Changed + +### Removed + +### Optimized + +### Resolved Issues + +### Upcoming Changes + +- N/A + +### Known Issues + +- N/A + ## amd_smi_lib for ROCm 7.0.0 ### Added diff --git a/projects/amdsmi/docs/reference/amdsmi-py-api.md b/projects/amdsmi/docs/reference/amdsmi-py-api.md index a993ba266c..6362a43c63 100644 --- a/projects/amdsmi/docs/reference/amdsmi-py-api.md +++ b/projects/amdsmi/docs/reference/amdsmi-py-api.md @@ -550,6 +550,42 @@ except AmdSmiException as e: print(e) ``` +### amdsmi_get_gpu_revision + +Description: Returns the GPU revision for a given processor handle. + +Input parameters: + +* `processor_handle` device which to query + +Output: string hex value + +Field | Description +---|--- +`revision` | 16 bit integer value returned as hex string. + +Exceptions that can be thrown by `amdsmi_get_gpu_revision` function: + +* `AmdSmiLibraryException` If the processor handle is invalid. +* `AmdSmiParameterException` If the underlying library call fails. + +Example: + +```python +try: + devices = amdsmi_get_processor_handles(handle) + if len(devices) == 0: + print("No GPUs on machine") + else: + for device in devices: + revision = amdsmi_get_gpu_revision(device) + print(revision) +except AmdSmiLibraryException as e: + print(e) +except AmdSmiParameterException as e: + print(e) +``` + ### amdsmi_get_gpu_cache_info Description: Returns a list of dictionaries containing cache information for the given GPU. diff --git a/projects/amdsmi/py-interface/__init__.py b/projects/amdsmi/py-interface/__init__.py index c9dab2314a..9ad7b13d35 100644 --- a/projects/amdsmi/py-interface/__init__.py +++ b/projects/amdsmi/py-interface/__init__.py @@ -117,6 +117,7 @@ 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 +from .amdsmi_interface import amdsmi_get_gpu_revision # # Process Information from .amdsmi_interface import amdsmi_get_gpu_process_list diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index e95b30328c..bf3f29bbb5 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -5087,3 +5087,32 @@ def amdsmi_get_rocm_version()-> Tuple[bool, str]: return False, "Could not find librocm-core.so" except Exception as e: return False, f"Unable to detect ROCm installation, Unknown Error: {e}" + + +def amdsmi_get_gpu_revision(processor_handle: processor_handle) -> str: + """ + Get the GPU revision for a given processor handle. + + Parameters: + processor_handle (amdsmi_processor_handle): The processor handle for the GPU. + + Returns: + str: The GPU revision as a string. + + Raises: + AmdSmiParameterException: If the processor handle is invalid. + AmdSmiLibraryException: If the underlying library call fails. + """ + if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle): + raise AmdSmiParameterException( + processor_handle, amdsmi_wrapper.amdsmi_processor_handle + ) + + revision = ctypes.c_uint16() + _check_res( + amdsmi_wrapper.amdsmi_get_gpu_revision( + processor_handle, ctypes.byref(revision) + ) + ) + + return _pad_hex_value(hex(revision.value), 2) diff --git a/projects/amdsmi/tests/python_unittest/integration_test.py b/projects/amdsmi/tests/python_unittest/integration_test.py index ff4661c0e2..4c19641944 100755 --- a/projects/amdsmi/tests/python_unittest/integration_test.py +++ b/projects/amdsmi/tests/python_unittest/integration_test.py @@ -1244,6 +1244,24 @@ class TestAmdSmiPythonInterface(unittest.TestCase): print() self.tearDown() + def test_get_gpu_revision(self): + self.setUp() + processors = amdsmi.amdsmi_get_processor_handles() + self.assertGreaterEqual(len(processors), 1) + self.assertLessEqual(len(processors), self.max_num_physical_devices) + for i in range(0, len(processors)): + bdf = amdsmi.amdsmi_get_gpu_device_bdf(processors[i]) + print(f"\n\n###Test Processor {i}, bdf: {bdf}") + try: + print("\n###Test amdsmi_get_gpu_revision \n") + revision = amdsmi.amdsmi_get_gpu_revision(processors[i]) + except amdsmi.AmdSmiLibraryException as e: + self._check_exception(e) + continue + print(f" GPU revision is: {revision}") + print() + self.tearDown() + # Add test for amdsmi_get_gpu_pm_metrics_info @handle_exceptions def test_gpu_pm_metrics_info(self):