From 8bc4abc88b9a54c17b664b503cfb2ea635aa3c68 Mon Sep 17 00:00:00 2001 From: gabrpham Date: Fri, 20 Sep 2024 16:01:09 -0500 Subject: [PATCH] Corrected partition changes in header and wrapper Signed-off-by: gabrpham Change-Id: Iafd7de8f08924873da841ee6eca62100a17b2b6c --- CHANGELOG.md | 29 ++++-- include/amd_smi/amdsmi.h | 29 +++++- py-interface/amdsmi_interface.py | 1 + py-interface/amdsmi_wrapper.py | 89 ++++++++++++------- .../amd_smi_test/functional/sys_info_read.cc | 2 +- tools/generator.py | 7 ++ 6 files changed, 114 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c9e0abf3..f9b898cf90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -238,16 +238,34 @@ typedef enum { AMDSMI_ACCELERATOR_PARTITION_QPX, //!< Quad GPU mode (QPX)- Quarter XCCs //!< work together with shared memory AMDSMI_ACCELERATOR_PARTITION_CPX, //!< Core mode (CPX)- Per-chip XCC with - //!< shared memory + //!< shared memory } amdsmi_accelerator_partition_type_t; +/** + * @brief Possible Memory Partition Modes. + * This union is used to identify various memory partitioning settings. + */ +typedef union { + struct { + uint32_t nps1_cap :1; // bool 1 = true; 0 = false; Max uint32 means unsupported + uint32_t nps2_cap :1; // bool 1 = true; 0 = false; Max uint32 means unsupported + uint32_t nps4_cap :1; // bool 1 = true; 0 = false; Max uint32 means unsupported + uint32_t nps8_cap :1; // bool 1 = true; 0 = false; Max uint32 means unsupported + uint32_t reserved :28; + } amdsmi_nps_flags_t; + + uint32_t nps_cap_mask; +} amdsmi_nps_caps_t; + + typedef struct { amdsmi_accelerator_partition_type_t profile_type; // SPX, DPX, QPX, CPX and so on - uint32_t num_partitions; // On MI300X, SPX: 1, DPX: 2, QPX: 4, CPX: 8, the length of resources array - uint32_t profile_index; // The index in the profiles array in amdsmi_compute_partition_profile_t + uint32_t num_partitions; // On MI300X, SPX: 1, DPX: 2, QPX: 4, CPX: 8, length of resources array + uint32_t profile_index; + amdsmi_nps_caps_t memory_caps; // Possible memory partition capabilities uint32_t num_resources; // length of index_of_resources_profile uint32_t resources[AMDSMI_MAX_ACCELERATOR_PARTITIONS][AMDSMI_MAX_CP_PROFILE_RESOURCES]; - uint32_t reserved[12]; + uint64_t reserved[6]; } amdsmi_accelerator_partition_profile_t; ``` @@ -288,8 +306,7 @@ GPU: 1 ### Resolved issues - **Fixed CPX not showing total number of logical GPUs**. - - Updates were made to `amdsmi_init()` and `amdsmi_get_gpu_bdf_id(..)`. In order to display all logical devices, we needed a way to provide order to GPU's enumerated. This was done -by adding a partition_id within the BDF optional pci_id bits. + - Updates were made to `amdsmi_init()` and `amdsmi_get_gpu_bdf_id(..)`. In order to display all logical devices, we needed a way to provide order to GPU's enumerated. This was done by adding a partition_id within the BDF optional pci_id bits. - Due to driver changes in KFD, some devices may report bits [31:28] or [2:0]. With the newly added `amdsmi_get_gpu_bdf_id(..)`, we provided this fallback to properly retreive partition ID. We plan to eventually remove partition ID from the function portion of the BDF (Bus Device Function). See below for PCI ID description. diff --git a/include/amd_smi/amdsmi.h b/include/amd_smi/amdsmi.h index 2625b07f40..4326f47115 100644 --- a/include/amd_smi/amdsmi.h +++ b/include/amd_smi/amdsmi.h @@ -293,7 +293,7 @@ typedef enum { AMDSMI_ACCELERATOR_PARTITION_QPX, //!< Quad GPU mode (QPX)- Quarter XCCs //!< work together with shared memory AMDSMI_ACCELERATOR_PARTITION_CPX, //!< Core mode (CPX)- Per-chip XCC with - //!< shared memory + //!< shared memory } amdsmi_accelerator_partition_type_t; /** @@ -620,10 +620,31 @@ typedef struct { uint32_t reserved[13]; } amdsmi_kfd_info_t; +/** + * @brief Possible Memory Partition Modes. + * This union is used to identify various memory partitioning settings. + */ +typedef union { + struct nps_flags_ { + uint32_t nps1_cap :1; // bool 1 = true; 0 = false; Max uint32 means unsupported + uint32_t nps2_cap :1; // bool 1 = true; 0 = false; Max uint32 means unsupported + uint32_t nps4_cap :1; // bool 1 = true; 0 = false; Max uint32 means unsupported + uint32_t nps8_cap :1; // bool 1 = true; 0 = false; Max uint32 means unsupported + uint32_t reserved :28; + } amdsmi_nps_flags_t; + + uint32_t nps_cap_mask; +} amdsmi_nps_caps_t; + +/** + * @brief Possible Memory Partition Modes. + * This union is used to identify various memory partitioning settings. + */ typedef struct { amdsmi_accelerator_partition_type_t profile_type; // SPX, DPX, QPX, CPX and so on - uint32_t num_partitions; // On MI300X, SPX: 1, DPX: 2, QPX: 4, CPX: 8, the length of resources array - uint32_t profile_index; // The index in the profiles array in amdsmi_accelerator_partition_profile_t + uint32_t num_partitions; // On MI300X, SPX: 1, DPX: 2, QPX: 4, CPX: 8, length of resources array + uint32_t profile_index; + amdsmi_nps_caps_t memory_caps; // Possible memory partition capabilities uint32_t num_resources; // length of index_of_resources_profile uint32_t resources[AMDSMI_MAX_ACCELERATOR_PARTITIONS][AMDSMI_MAX_CP_PROFILE_RESOURCES]; uint64_t reserved[6]; @@ -4772,7 +4793,7 @@ amdsmi_get_gpu_asic_info(amdsmi_processor_handle processor_handle, amdsmi_asic_i * @platform{gpu_bm_linux} @platform{guest_1vf} @platform{guest_mvf} * * @details This function returns KFD information populated into the amdsmi_kfd_info_t. - * This contains the kfd_id and node_id which allow for the ID and + * This contains the kfd_id and node_id which allow for the ID and * index of this device in the KFD. * * @param[in] processor_handle Device which to query diff --git a/py-interface/amdsmi_interface.py b/py-interface/amdsmi_interface.py index 43bffa1d92..cae4a2d1b7 100644 --- a/py-interface/amdsmi_interface.py +++ b/py-interface/amdsmi_interface.py @@ -2739,6 +2739,7 @@ def amdsmi_get_gpu_accelerator_partition_profile( "profile_type" : profile.profile_type, "num_partitions" : profile.num_partitions, "profile_index" : profile.profile_index, + "memory_caps" : "N/A", "num_resources" : profile.num_resources, "resources" : "N/A" } diff --git a/py-interface/amdsmi_wrapper.py b/py-interface/amdsmi_wrapper.py index 8089a2abbf..f7acf2026e 100644 --- a/py-interface/amdsmi_wrapper.py +++ b/py-interface/amdsmi_wrapper.py @@ -776,6 +776,19 @@ 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 @@ -794,19 +807,6 @@ 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_), @@ -937,6 +937,28 @@ struct_amdsmi_kfd_info_t._fields_ = [ ] amdsmi_kfd_info_t = struct_amdsmi_kfd_info_t +class union_amdsmi_nps_caps_t(Union): + pass + +class struct_nps_flags_(Structure): + pass + +struct_nps_flags_._pack_ = 1 # source:False +struct_nps_flags_._fields_ = [ + ('nps1_cap', ctypes.c_uint32, 1), + ('nps2_cap', ctypes.c_uint32, 1), + ('nps4_cap', ctypes.c_uint32, 1), + ('nps8_cap', ctypes.c_uint32, 1), + ('reserved', ctypes.c_uint32, 28), +] + +union_amdsmi_nps_caps_t._pack_ = 1 # source:False +union_amdsmi_nps_caps_t._fields_ = [ + ('amdsmi_nps_flags_t', struct_nps_flags_), + ('nps_cap_mask', ctypes.c_uint32), +] + +amdsmi_nps_caps_t = union_amdsmi_nps_caps_t class struct_amdsmi_accelerator_partition_profile_t(Structure): pass @@ -945,8 +967,10 @@ struct_amdsmi_accelerator_partition_profile_t._fields_ = [ ('profile_type', amdsmi_accelerator_partition_type_t), ('num_partitions', ctypes.c_uint32), ('profile_index', ctypes.c_uint32), + ('memory_caps', amdsmi_nps_caps_t), ('num_resources', ctypes.c_uint32), ('resources', ctypes.c_uint32 * 32 * 8), + ('PADDING_0', ctypes.c_ubyte * 4), ('reserved', ctypes.c_uint64 * 6), ] @@ -1076,6 +1100,16 @@ amdsmi_process_handle_t = ctypes.c_uint32 class struct_amdsmi_proc_info_t(Structure): pass +class struct_engine_usage_(Structure): + pass + +struct_engine_usage_._pack_ = 1 # source:False +struct_engine_usage_._fields_ = [ + ('gfx', ctypes.c_uint64), + ('enc', ctypes.c_uint64), + ('reserved', ctypes.c_uint32 * 12), +] + class struct_memory_usage_(Structure): pass @@ -1087,16 +1121,6 @@ struct_memory_usage_._fields_ = [ ('reserved', ctypes.c_uint32 * 10), ] -class struct_engine_usage_(Structure): - pass - -struct_engine_usage_._pack_ = 1 # source:False -struct_engine_usage_._fields_ = [ - ('gfx', ctypes.c_uint64), - ('enc', ctypes.c_uint64), - ('reserved', ctypes.c_uint32 * 12), -] - struct_amdsmi_proc_info_t._pack_ = 1 # source:False struct_amdsmi_proc_info_t._fields_ = [ ('name', ctypes.c_char * 32), @@ -2800,11 +2824,12 @@ __all__ = \ 'amdsmi_link_id_bw_type_t', 'amdsmi_link_metrics_t', 'amdsmi_link_type_t', 'amdsmi_memory_page_status_t', 'amdsmi_memory_partition_type_t', 'amdsmi_memory_type_t', - 'amdsmi_mm_ip_t', 'amdsmi_name_value_t', 'amdsmi_od_vddc_point_t', - 'amdsmi_od_volt_curve_t', 'amdsmi_od_volt_freq_data_t', - 'amdsmi_p2p_capability_t', 'amdsmi_pcie_bandwidth_t', - 'amdsmi_pcie_info_t', 'amdsmi_power_cap_info_t', - 'amdsmi_power_info_t', 'amdsmi_power_profile_preset_masks_t', + 'amdsmi_mm_ip_t', 'amdsmi_name_value_t', 'amdsmi_nps_caps_t', + 'amdsmi_od_vddc_point_t', 'amdsmi_od_volt_curve_t', + 'amdsmi_od_volt_freq_data_t', 'amdsmi_p2p_capability_t', + 'amdsmi_pcie_bandwidth_t', 'amdsmi_pcie_info_t', + 'amdsmi_power_cap_info_t', 'amdsmi_power_info_t', + 'amdsmi_power_profile_preset_masks_t', 'amdsmi_power_profile_status_t', 'amdsmi_power_type_t', 'amdsmi_proc_info_t', 'amdsmi_process_handle_t', 'amdsmi_process_info_t', 'amdsmi_processor_handle', @@ -2876,7 +2901,7 @@ __all__ = \ 'struct_amdsmi_vram_info_t', 'struct_amdsmi_vram_usage_t', 'struct_amdsmi_xgmi_info_t', 'struct_cache_', 'struct_engine_usage_', 'struct_fw_info_list_', - 'struct_memory_usage_', 'struct_pcie_metric_', - 'struct_pcie_static_', 'struct_amdsmi_bdf_t', - 'uint32_t', 'uint64_t', 'uint8_t', - 'union_amdsmi_bdf_t'] + 'struct_memory_usage_', 'struct_nps_flags_', + 'struct_pcie_metric_', 'struct_pcie_static_', + 'struct_amdsmi_bdf_t','uint32_t', 'uint64_t', 'uint8_t', + 'union_amdsmi_bdf_t', 'union_amdsmi_nps_caps_t'] diff --git a/tests/amd_smi_test/functional/sys_info_read.cc b/tests/amd_smi_test/functional/sys_info_read.cc index 7c9b7fd6b7..35d40e0818 100644 --- a/tests/amd_smi_test/functional/sys_info_read.cc +++ b/tests/amd_smi_test/functional/sys_info_read.cc @@ -202,7 +202,7 @@ void TestSysInfoRead::Run(void) { } // Verify api support checking functionality is working err = amdsmi_get_gpu_kfd_info(processor_handles_[i], nullptr); - ASSERT_EQ(err, AMDSMI_STATUS_NOT_SUPPORTED); + ASSERT_EQ(err, AMDSMI_STATUS_INVAL); err = amdsmi_get_lib_version(&ver); CHK_ERR_ASRT(err) diff --git a/tools/generator.py b/tools/generator.py index 6014746094..dd32cc03dc 100644 --- a/tools/generator.py +++ b/tools/generator.py @@ -190,6 +190,13 @@ except OSError as error: struct_amdsmi_bdf_t_line = "'struct_amdsmi_bdf_t'," replace_line(output_file, struct_anon_all_line, struct_amdsmi_bdf_t_line) + struct_anon_all_line = ", 'struct_struct" + replace_line(output_file, struct_anon_all_line, ",") + + struct_anon_all_line = "(anonymous at " + struct_amdsmi_bdf_t_line = "'struct_amdsmi_bdf_t'," + replace_line(output_file, struct_anon_all_line, struct_amdsmi_bdf_t_line) + struct_anon_all_line_to_remove = f"amdsmi.h:{line_number}:3)', " replace_line(output_file, struct_anon_all_line_to_remove, "")