From 4b308c8d482a1df86c6fe187677640bef111e8fa Mon Sep 17 00:00:00 2001 From: Charis Poag Date: Thu, 22 Aug 2024 21:57:36 -0500 Subject: [PATCH 1/4] Fix amdsmi_reg_type_t not defined Latest updates need to use a wrapper defined value. Breaks basic CLI functionality. $ /opt/rocm/bin/amd-smi list Traceback (most recent call last): File "/opt/rocm/bin/amd-smi", line 44, in from amdsmi_commands import AMDSMICommands File "/opt/rocm/libexec/amdsmi_cli/amdsmi_commands.py", line 30, in from amdsmi_helpers import AMDSMIHelpers File "/opt/rocm/libexec/amdsmi_cli/amdsmi_helpers.py", line 35, in from amdsmi_init import * File "/opt/rocm/libexec/amdsmi_cli/amdsmi_init.py", line 35, in from amdsmi import amdsmi_interface File "/usr/local/lib/python3.8/dist-packages/amdsmi/__init__.py", line 26, in from .amdsmi_interface import amdsmi_init File "/usr/local/lib/python3.8/dist-packages/amdsmi/amdsmi_interface.py", line 1725, in reg_type: amdsmi_reg_type_t, NameError: name 'amdsmi_reg_type_t' is not defined Change-Id: I628c811c137f57f3177a718c9bce859bc553bf7d Signed-off-by: Charis Poag [ROCm/amdsmi commit: a2dc934b05875540169ba8d70d07106da183bfc7] --- .../amdsmi/py-interface/amdsmi_interface.py | 2 +- .../amdsmi/py-interface/amdsmi_wrapper.py | 52 ++++++++++++------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index 7463a2284f..23d4b65334 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -1722,7 +1722,7 @@ def amdsmi_get_gpu_pm_metrics_info( def amdsmi_get_gpu_reg_table_info( processor_handle: amdsmi_wrapper.amdsmi_processor_handle, - reg_type: amdsmi_reg_type_t, + reg_type: amdsmi_wrapper.amdsmi_reg_type_t, ) -> Dict[str, Any]: if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle): raise AmdSmiParameterException( diff --git a/projects/amdsmi/py-interface/amdsmi_wrapper.py b/projects/amdsmi/py-interface/amdsmi_wrapper.py index 5aa163656a..c7650bb4aa 100644 --- a/projects/amdsmi/py-interface/amdsmi_wrapper.py +++ b/projects/amdsmi/py-interface/amdsmi_wrapper.py @@ -759,19 +759,6 @@ amdsmi_card_form_factor_t = ctypes.c_uint32 # enum class struct_amdsmi_pcie_info_t(Structure): pass -class struct_pcie_static_(Structure): - pass - -struct_pcie_static_._pack_ = 1 # source:False -struct_pcie_static_._fields_ = [ - ('max_pcie_width', ctypes.c_uint16), - ('PADDING_0', ctypes.c_ubyte * 2), - ('max_pcie_speed', ctypes.c_uint32), - ('pcie_interface_version', ctypes.c_uint32), - ('slot_type', amdsmi_card_form_factor_t), - ('reserved', ctypes.c_uint64 * 10), -] - class struct_pcie_metric_(Structure): pass @@ -790,6 +777,19 @@ struct_pcie_metric_._fields_ = [ ('reserved', ctypes.c_uint64 * 13), ] +class struct_pcie_static_(Structure): + pass + +struct_pcie_static_._pack_ = 1 # source:False +struct_pcie_static_._fields_ = [ + ('max_pcie_width', ctypes.c_uint16), + ('PADDING_0', ctypes.c_ubyte * 2), + ('max_pcie_speed', ctypes.c_uint32), + ('pcie_interface_version', ctypes.c_uint32), + ('slot_type', amdsmi_card_form_factor_t), + ('reserved', ctypes.c_uint64 * 10), +] + struct_amdsmi_pcie_info_t._pack_ = 1 # source:False struct_amdsmi_pcie_info_t._fields_ = [ ('pcie_static', struct_pcie_static_), @@ -1351,6 +1351,15 @@ AMDSMI_GPU_BLOCK_LAST = 262144 AMDSMI_GPU_BLOCK_RESERVED = 9223372036854775808 amdsmi_gpu_block_t = ctypes.c_uint64 # enum +# values for enumeration 'amdsmi_clk_limit_type_t' +amdsmi_clk_limit_type_t__enumvalues = { + 0: 'CLK_LIMIT_MIN', + 1: 'CLK_LIMIT_MAX', +} +CLK_LIMIT_MIN = 0 +CLK_LIMIT_MAX = 1 +amdsmi_clk_limit_type_t = ctypes.c_uint32 # enum + # values for enumeration 'amdsmi_ras_err_state_t' amdsmi_ras_err_state_t__enumvalues = { 0: 'AMDSMI_RAS_ERR_STATE_NONE', @@ -2061,6 +2070,9 @@ amdsmi_get_gpu_reg_table_info.argtypes = [amdsmi_processor_handle, amdsmi_reg_ty amdsmi_set_gpu_clk_range = _libraries['libamd_smi.so'].amdsmi_set_gpu_clk_range amdsmi_set_gpu_clk_range.restype = amdsmi_status_t amdsmi_set_gpu_clk_range.argtypes = [amdsmi_processor_handle, uint64_t, uint64_t, amdsmi_clk_type_t] +amdsmi_set_gpu_clk_limit = _libraries['libamd_smi.so'].amdsmi_set_gpu_clk_limit +amdsmi_set_gpu_clk_limit.restype = amdsmi_status_t +amdsmi_set_gpu_clk_limit.argtypes = [amdsmi_processor_handle, amdsmi_clk_type_t, amdsmi_clk_limit_type_t, uint64_t] amdsmi_free_name_value_pairs = _libraries['libamd_smi.so'].amdsmi_free_name_value_pairs amdsmi_free_name_value_pairs.restype = None amdsmi_free_name_value_pairs.argtypes = [ctypes.POINTER(None)] @@ -2583,11 +2595,12 @@ __all__ = \ 'AMDSMI_VRAM_VENDOR__PLACEHOLDER5', 'AMDSMI_VRAM_VENDOR__SAMSUNG', 'AMDSMI_VRAM_VENDOR__WINBOND', 'AMDSMI_XGMI_STATUS_ERROR', 'AMDSMI_XGMI_STATUS_MULTIPLE_ERRORS', - 'AMDSMI_XGMI_STATUS_NO_ERRORS', 'RD_BW0', 'WR_BW0', - 'amd_metrics_table_header_t', 'amdsmi_asic_info_t', - 'amdsmi_bdf_t', 'amdsmi_bit_field_t', 'amdsmi_board_info_t', - 'amdsmi_cache_property_type_t', 'amdsmi_card_form_factor_t', - 'amdsmi_clean_gpu_local_data', 'amdsmi_clk_info_t', + 'AMDSMI_XGMI_STATUS_NO_ERRORS', 'CLK_LIMIT_MAX', 'CLK_LIMIT_MIN', + 'RD_BW0', 'WR_BW0', 'amd_metrics_table_header_t', + 'amdsmi_asic_info_t', 'amdsmi_bdf_t', 'amdsmi_bit_field_t', + 'amdsmi_board_info_t', 'amdsmi_cache_property_type_t', + 'amdsmi_card_form_factor_t', 'amdsmi_clean_gpu_local_data', + 'amdsmi_clk_info_t', 'amdsmi_clk_limit_type_t', 'amdsmi_clk_type_t', 'amdsmi_compute_partition_type_t', 'amdsmi_container_types_t', 'amdsmi_counter_command_t', 'amdsmi_counter_value_t', 'amdsmi_cpu_apb_disable', @@ -2711,7 +2724,8 @@ __all__ = \ 'amdsmi_set_cpu_socket_boostlimit', 'amdsmi_set_cpu_socket_lclk_dpm_level', 'amdsmi_set_cpu_socket_power_cap', 'amdsmi_set_cpu_xgmi_width', - 'amdsmi_set_gpu_clk_range', 'amdsmi_set_gpu_compute_partition', + 'amdsmi_set_gpu_clk_limit', 'amdsmi_set_gpu_clk_range', + 'amdsmi_set_gpu_compute_partition', 'amdsmi_set_gpu_event_notification_mask', 'amdsmi_set_gpu_fan_speed', 'amdsmi_set_gpu_memory_partition', 'amdsmi_set_gpu_od_clk_info', 'amdsmi_set_gpu_od_volt_info', From ee66b03dc83456061bdd92ecb9c54fa55b79d9cd Mon Sep 17 00:00:00 2001 From: Charis Poag Date: Thu, 22 Aug 2024 23:50:19 -0500 Subject: [PATCH 2/4] [SWDEV-478807] Fix incorrect firmware versions and names - Fix updates API to have correct enum names (PM->SMU) - Python API/CLI now reports correct versions and names for SMC/TA_XGMI/TA_RAS Change-Id: Icbe115b3070b9f252ef15b09b781b9b3f5861e50 Signed-off-by: Charis Poag [ROCm/amdsmi commit: d7c583d422ba296d0c4240fb23cbdfd3f4f70e2a] --- projects/amdsmi/CHANGELOG.md | 10 +++++- .../amdsmi/py-interface/amdsmi_interface.py | 34 +++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/projects/amdsmi/CHANGELOG.md b/projects/amdsmi/CHANGELOG.md index 95dccc8593..3370ea348a 100644 --- a/projects/amdsmi/CHANGELOG.md +++ b/projects/amdsmi/CHANGELOG.md @@ -8,7 +8,11 @@ Full documentation for amd_smi_lib is available at [https://rocm.docs.amd.com/pr ### Additions -- N/A +- **Removed `amd-smi metric --ecc` & `amd-smi metric --ecc-blocks` on Guest VMs**. +Guest VMs do not support getting current ECC counts from the Host cards. + +- **Added `amd-smi static --ras`on Guest VMs**. +Guest VMs can view enabled/disabled ras features that are on Host cards. ### Optimizations @@ -20,6 +24,10 @@ Full documentation for amd_smi_lib is available at [https://rocm.docs.amd.com/pr - **Updated CLI error strings to handle empty and invalid GPU/CPU inputs**. +- **Fixed Guest VM showing passthrough options**. + +- **Fixed firmware formatting where leading 0s were missing**. + ### Known Issues - N/A diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index 23d4b65334..a15ba8e68f 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -2175,8 +2175,16 @@ def amdsmi_get_fw_info( raise AmdSmiParameterException( processor_handle, amdsmi_wrapper.amdsmi_processor_handle) fw_info = amdsmi_wrapper.amdsmi_fw_info_t() - _check_res(amdsmi_wrapper.amdsmi_get_fw_info( - processor_handle, ctypes.byref(fw_info))) + _check_res( + amdsmi_wrapper.amdsmi_get_fw_info( + processor_handle, ctypes.byref(fw_info) + ) + ) + + # Certain FW blocks are padded with 0s in the front intentionally + # But the C library converts the hex to an integer which trims the leading 0s + # Nor do we have a flag that defines the expected format for each FW block + # We can expect the following blocks to have a padded value and a specified format hex_format_fw = [AmdSmiFwBlock.AMDSMI_FW_ID_PSP_SOSDRV, AmdSmiFwBlock.AMDSMI_FW_ID_TA_RAS, @@ -2185,20 +2193,34 @@ def amdsmi_get_fw_info( AmdSmiFwBlock.AMDSMI_FW_ID_VCE, AmdSmiFwBlock.AMDSMI_FW_ID_VCN] + # PM(AKA: SMC) firmware's hex value looks like 0x12345678 + # However, they are parsed as: int(0x12).int(0x34).int(0x56).int(0x78) + # Which results in the following: 12.34.56.78 dec_format_fw = [AmdSmiFwBlock.AMDSMI_FW_ID_PM] firmwares = [] for i in range(0, fw_info.num_fw_info): fw_name = AmdSmiFwBlock(fw_info.fw_info_list[i].fw_id) - fw_version = fw_info.fw_info_list[i].fw_version + fw_version = fw_info.fw_info_list[i].fw_version # This is in int format (base 10) if fw_name in hex_format_fw: - fw_version_string = ".".join(re.findall('..?', hex(fw_version)[2:])) + # Convert the fw_version from a int to a hex string padded leading 0s + fw_version_string = hex(fw_version)[2:].zfill(8) + + # Join every two hex digits with a dot + fw_version_string = ".".join(re.findall('..?', fw_version_string)) elif fw_name in dec_format_fw: + # Convert the fw_version from a int to a hex string padded leading 0s + fw_version_string = hex(fw_version)[2:].zfill(8) + print(fw_version_string) + # Convert every two hex digits to decimal and join them with a dot dec_version_string = '' - for ver1,ver2 in zip(hex(fw_version)[2::2], hex(fw_version)[3::2]): - dec_version_string += str(int(f"0x{ver1}{ver2}", 0)) + "." + for index, _ in enumerate(fw_version_string): + if index % 2 != 0: + continue + hex_digits = f"0x{fw_version_string[index:index+2]}" + dec_version_string += str(int(hex_digits, 16)).zfill(2) + "." fw_version_string = dec_version_string.strip('.') else: fw_version_string = str(fw_version) From bc357f1500fd28e9c26666d59ad52b102fc15cca Mon Sep 17 00:00:00 2001 From: Charis Poag Date: Thu, 22 Aug 2024 23:50:19 -0500 Subject: [PATCH 3/4] [SWDEV-478807] Add leading 0s to amdsmi_get_fw_info() Signed-off-by: Charis Poag Change-Id: Ie535dcb8cb44138c115e29a4bc41db3cc488097f [ROCm/amdsmi commit: c46eab4e9e28702f0c7964a54e407ba094f9c161] From 2e927911924762a30f45dece9ce440b8620119c7 Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Fri, 23 Aug 2024 19:22:05 -0500 Subject: [PATCH 4/4] Removed extra print statement Signed-off-by: Maisam Arif Change-Id: I0043567f4cc17d69860b0c77f42fa77fd41e354d [ROCm/amdsmi commit: 7ac0a494708609686b1a846d294a755375d0d878] --- projects/amdsmi/py-interface/amdsmi_interface.py | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index a15ba8e68f..db00f18226 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -2212,7 +2212,6 @@ def amdsmi_get_fw_info( elif fw_name in dec_format_fw: # Convert the fw_version from a int to a hex string padded leading 0s fw_version_string = hex(fw_version)[2:].zfill(8) - print(fw_version_string) # Convert every two hex digits to decimal and join them with a dot dec_version_string = ''