From c3bfdbe8063694a89eaca707ab808da4b789f75b Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Tue, 20 Feb 2024 04:56:52 -0600 Subject: [PATCH] Aligned cache property enum with Host Signed-off-by: Maisam Arif Change-Id: Ie64a33f55c9a9a7cc8c806419509897351f37c70 [ROCm/amdsmi commit: 703fdb0ed24d7fb4cee16882541a96b062cf0597] --- projects/amdsmi/amdsmi_cli/amdsmi_commands.py | 20 ++++++--- projects/amdsmi/include/amd_smi/amdsmi.h | 14 +++--- projects/amdsmi/py-interface/README.md | 12 ++--- .../amdsmi/py-interface/amdsmi_interface.py | 17 +++---- .../amdsmi/py-interface/amdsmi_wrapper.py | 44 +++++++++---------- projects/amdsmi/src/amd_smi/amd_smi.cc | 8 ++-- 6 files changed, 59 insertions(+), 56 deletions(-) diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py index 7462d2c53e..dfc108ae25 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py @@ -550,11 +550,17 @@ class AMDSMICommands(): static_dict['vram'] = vram_info if args.cache: try: - cach_info_list = amdsmi_interface.amdsmi_get_gpu_cache_info(args.gpu) - logging.debug(f"cache_info dictionary = {cach_info_list}") + cache_info_list = amdsmi_interface.amdsmi_get_gpu_cache_info(args.gpu)['cache'] + logging.debug(f"cache_info dictionary = {cache_info_list}") + + for index, cache_info in enumerate(cache_info_list): + new_cache_info = {"cache" : index} + new_cache_info.update(cache_info) + cache_info_list[index] = new_cache_info + if self.logger.is_human_readable_format(): cache_info_dict_format = {} - for cache_dict in cach_info_list: + for cache_dict in cache_info_list: cache_index = "cache_" + str(cache_dict["cache"]) cache_info_dict_format[cache_index] = cache_dict @@ -567,15 +573,15 @@ class AMDSMICommands(): # take cache_properties out of list -> display as string, removing brackets cache_info_dict_format[cache_index]["cache_properties"] = ", ".join(cache_info_dict_format[cache_index]["cache_properties"]) - cach_info_list = cache_info_dict_format + cache_info_list = cache_info_dict_format - logging.debug(f"After human_readable | cache_info = {cach_info_list}") + logging.debug(f"After human_readable | cache_info = {cache_info_list}") except amdsmi_exception.AmdSmiLibraryException as e: - cach_info_list = "N/A" + cache_info_list = "N/A" logging.debug("Failed to get cache info for gpu %s | %s", gpu_id, e.get_error_info()) - static_dict['cache_info'] = cach_info_list + static_dict['cache_info'] = cache_info_list if 'ras' in current_platform_args: if args.ras: ras_dict = {"eeprom_version": "N/A", diff --git a/projects/amdsmi/include/amd_smi/amdsmi.h b/projects/amdsmi/include/amd_smi/amdsmi.h index e62974313f..13c11f76b0 100644 --- a/projects/amdsmi/include/amd_smi/amdsmi.h +++ b/projects/amdsmi/include/amd_smi/amdsmi.h @@ -541,17 +541,17 @@ typedef struct { * @brief cache properties */ typedef enum { - AMDSMI_CACHE_PROPERTIES_ENABLED = 0x00000001, - AMDSMI_CACHE_PROPERTIES_DATA_CACHE = 0x00000002, - AMDSMI_CACHE_PROPERTIES_INST_CACHE = 0x00000004, - AMDSMI_CACHE_PROPERTIES_CPU_CACHE = 0x00000008, - AMDSMI_CACHE_PROPERTIES_SIMD_CACHE = 0x00000010, -} amdsmi_cache_properties_type_t; + AMDSMI_CACHE_PROPERTY_ENABLED = 0x00000001, + AMDSMI_CACHE_PROPERTY_DATA_CACHE = 0x00000002, + AMDSMI_CACHE_PROPERTY_INST_CACHE = 0x00000004, + AMDSMI_CACHE_PROPERTY_CPU_CACHE = 0x00000008, + AMDSMI_CACHE_PROPERTY_SIMD_CACHE = 0x00000010, +} amdsmi_cache_property_type_t; typedef struct { uint32_t num_cache_types; struct cache_ { - uint32_t cache_properties; // amdsmi_cache_properties_type_t which is a bitmask + uint32_t cache_properties; // amdsmi_cache_property_type_t which is a bitmask uint32_t cache_size; /* In KB */ uint32_t cache_level; uint32_t max_num_cu_shared; /* Indicates how many Compute Units share this cache instance */ diff --git a/projects/amdsmi/py-interface/README.md b/projects/amdsmi/py-interface/README.md index 96abe99459..b4c79a351d 100644 --- a/projects/amdsmi/py-interface/README.md +++ b/projects/amdsmi/py-interface/README.md @@ -476,8 +476,7 @@ Schema: ```JSON { - cache: {"type" : "number"}, - cache_properties: + cache_properties: { "type" : "array", "items" : {"type" : "string"} @@ -491,7 +490,6 @@ Schema: Field | Description ---|--- -`cache` | cache index from 0-9 `cache_properties` | list of up to 4 cache property type strings. Ex. data ("DATA_CACHE"), instruction ("INST_CACHE"), CPU ("CPU_CACHE"), or SIMD ("SIMD_CACHE"). `cache_size` | size of cache in KB `cache_level` | level of cache @@ -515,13 +513,11 @@ try: for device in devices: cache_info = amdsmi_get_gpu_cache_info(device) for cache_index, cache_values in cache_info.items(): - print(cache_index) + print(cache_values['cache_properties']) print(cache_values['cache_size']) print(cache_values['cache_level']) - print(cache_values['data_cache']) - print(cache_values['instruction_cache']) - print(cache_values['cpu_cache']) - print(cache_values['simd_cache']) + print(cache_values['max_num_cu_shared']) + print(cache_values['num_cache_instance']) except AmdSmiException as e: print(e) ``` diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index 8dd3f11936..5f6627eb35 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -1670,7 +1670,6 @@ def amdsmi_get_gpu_cache_info( for cache_index in range(cache_info_struct.num_cache_types): # Put cache_properties at the start of the dictionary for readability cache_dict = { - "cache": cache_index, "cache_properties": [], # This will be a list of strings "cache_size": cache_info_struct.cache[cache_index].cache_size, "cache_level": cache_info_struct.cache[cache_index].cache_level, @@ -1680,17 +1679,17 @@ def amdsmi_get_gpu_cache_info( # Check against cache properties bitmask cache_properties = cache_info_struct.cache[cache_index].cache_properties - data_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTIES_DATA_CACHE - inst_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTIES_INST_CACHE - cpu_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTIES_CPU_CACHE - simd_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTIES_SIMD_CACHE + data_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTY_DATA_CACHE + inst_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTY_INST_CACHE + cpu_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTY_CPU_CACHE + simd_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTY_SIMD_CACHE cache_properties_status = [data_cache, inst_cache, cpu_cache, simd_cache] cache_property_list = [] for cache_property in cache_properties_status: if cache_property: - property_name = amdsmi_wrapper.amdsmi_cache_properties_type_t__enumvalues[cache_property] - property_name = property_name.replace("AMDSMI_CACHE_PROPERTIES_", "") + property_name = amdsmi_wrapper.amdsmi_cache_property_type_t__enumvalues[cache_property] + property_name = property_name.replace("AMDSMI_CACHE_PROPERTY_", "") cache_property_list.append(property_name) cache_dict["cache_properties"] = cache_property_list @@ -1699,7 +1698,9 @@ def amdsmi_get_gpu_cache_info( if not cache_info_list: raise AmdSmiLibraryException(amdsmi_wrapper.AMDSMI_STATUS_NO_DATA) - return cache_info_list + return { + "cache": cache_info_list + } def amdsmi_get_gpu_vbios_info( diff --git a/projects/amdsmi/py-interface/amdsmi_wrapper.py b/projects/amdsmi/py-interface/amdsmi_wrapper.py index 9c21209eb0..a1a6b9b70b 100644 --- a/projects/amdsmi/py-interface/amdsmi_wrapper.py +++ b/projects/amdsmi/py-interface/amdsmi_wrapper.py @@ -813,20 +813,20 @@ struct_amdsmi_vbios_info_t._fields_ = [ amdsmi_vbios_info_t = struct_amdsmi_vbios_info_t -# values for enumeration 'amdsmi_cache_properties_type_t' -amdsmi_cache_properties_type_t__enumvalues = { - 1: 'AMDSMI_CACHE_PROPERTIES_ENABLED', - 2: 'AMDSMI_CACHE_PROPERTIES_DATA_CACHE', - 4: 'AMDSMI_CACHE_PROPERTIES_INST_CACHE', - 8: 'AMDSMI_CACHE_PROPERTIES_CPU_CACHE', - 16: 'AMDSMI_CACHE_PROPERTIES_SIMD_CACHE', +# values for enumeration 'amdsmi_cache_property_type_t' +amdsmi_cache_property_type_t__enumvalues = { + 1: 'AMDSMI_CACHE_PROPERTY_ENABLED', + 2: 'AMDSMI_CACHE_PROPERTY_DATA_CACHE', + 4: 'AMDSMI_CACHE_PROPERTY_INST_CACHE', + 8: 'AMDSMI_CACHE_PROPERTY_CPU_CACHE', + 16: 'AMDSMI_CACHE_PROPERTY_SIMD_CACHE', } -AMDSMI_CACHE_PROPERTIES_ENABLED = 1 -AMDSMI_CACHE_PROPERTIES_DATA_CACHE = 2 -AMDSMI_CACHE_PROPERTIES_INST_CACHE = 4 -AMDSMI_CACHE_PROPERTIES_CPU_CACHE = 8 -AMDSMI_CACHE_PROPERTIES_SIMD_CACHE = 16 -amdsmi_cache_properties_type_t = ctypes.c_uint32 # enum +AMDSMI_CACHE_PROPERTY_ENABLED = 1 +AMDSMI_CACHE_PROPERTY_DATA_CACHE = 2 +AMDSMI_CACHE_PROPERTY_INST_CACHE = 4 +AMDSMI_CACHE_PROPERTY_CPU_CACHE = 8 +AMDSMI_CACHE_PROPERTY_SIMD_CACHE = 16 +amdsmi_cache_property_type_t = ctypes.c_uint32 # enum class struct_amdsmi_gpu_cache_info_t(Structure): pass @@ -2308,14 +2308,14 @@ amdsmi_get_esmi_err_msg.restype = amdsmi_status_t amdsmi_get_esmi_err_msg.argtypes = [amdsmi_status_t, ctypes.POINTER(ctypes.POINTER(ctypes.c_char))] __all__ = \ ['AGG_BW0', 'AMDSMI_ARG_PTR_NULL', 'AMDSMI_AVERAGE_POWER', - 'AMDSMI_CACHE_PROPERTIES_CPU_CACHE', - 'AMDSMI_CACHE_PROPERTIES_DATA_CACHE', - 'AMDSMI_CACHE_PROPERTIES_ENABLED', - 'AMDSMI_CACHE_PROPERTIES_INST_CACHE', - 'AMDSMI_CACHE_PROPERTIES_SIMD_CACHE', - 'AMDSMI_CARD_FORM_FACTOR_OAM', 'AMDSMI_CARD_FORM_FACTOR_PCIE', - 'AMDSMI_CARD_FORM_FACTOR_UNKNOWN', 'AMDSMI_CNTR_CMD_START', - 'AMDSMI_CNTR_CMD_STOP', 'AMDSMI_COARSE_GRAIN_GFX_ACTIVITY', + 'AMDSMI_CACHE_PROPERTY_CPU_CACHE', + 'AMDSMI_CACHE_PROPERTY_DATA_CACHE', + 'AMDSMI_CACHE_PROPERTY_ENABLED', + 'AMDSMI_CACHE_PROPERTY_INST_CACHE', + 'AMDSMI_CACHE_PROPERTY_SIMD_CACHE', 'AMDSMI_CARD_FORM_FACTOR_OAM', + 'AMDSMI_CARD_FORM_FACTOR_PCIE', 'AMDSMI_CARD_FORM_FACTOR_UNKNOWN', + 'AMDSMI_CNTR_CMD_START', 'AMDSMI_CNTR_CMD_STOP', + 'AMDSMI_COARSE_GRAIN_GFX_ACTIVITY', 'AMDSMI_COARSE_GRAIN_MEM_ACTIVITY', 'AMDSMI_CURRENT_POWER', 'AMDSMI_DEV_PERF_LEVEL_AUTO', 'AMDSMI_DEV_PERF_LEVEL_DETERMINISM', 'AMDSMI_DEV_PERF_LEVEL_FIRST', 'AMDSMI_DEV_PERF_LEVEL_HIGH', @@ -2477,7 +2477,7 @@ __all__ = \ 'VRAM_TYPE_GDDR6', 'VRAM_TYPE_HBM', 'VRAM_TYPE_UNKNOWN', 'VRAM_TYPE__MAX', 'WR_BW0', 'amd_metrics_table_header_t', 'amdsmi_asic_info_t', 'amdsmi_bdf_t', 'amdsmi_bit_field_t', - 'amdsmi_board_info_t', 'amdsmi_cache_properties_type_t', + 'amdsmi_board_info_t', 'amdsmi_cache_property_type_t', 'amdsmi_card_form_factor_t', 'amdsmi_clk_info_t', 'amdsmi_clk_type_t', 'amdsmi_compute_partition_type_t', 'amdsmi_container_types_t', 'amdsmi_counter_command_t', diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index 77b7fbe202..2f68823540 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -448,13 +448,13 @@ amdsmi_status_t amdsmi_get_gpu_cache_info( // convert from sysfs type to CRAT type(HSA Cache Affinity type) info->cache[i].cache_properties = 0; if (rsmi_info.cache[i].flags & HSA_CACHE_TYPE_DATA) - info->cache[i].cache_properties |= AMDSMI_CACHE_PROPERTIES_DATA_CACHE; + info->cache[i].cache_properties |= AMDSMI_CACHE_PROPERTY_DATA_CACHE; if (rsmi_info.cache[i].flags & HSA_CACHE_TYPE_INSTRUCTION) - info->cache[i].cache_properties |= AMDSMI_CACHE_PROPERTIES_INST_CACHE; + info->cache[i].cache_properties |= AMDSMI_CACHE_PROPERTY_INST_CACHE; if (rsmi_info.cache[i].flags & HSA_CACHE_TYPE_CPU) - info->cache[i].cache_properties |= AMDSMI_CACHE_PROPERTIES_CPU_CACHE; + info->cache[i].cache_properties |= AMDSMI_CACHE_PROPERTY_CPU_CACHE; if (rsmi_info.cache[i].flags & HSA_CACHE_TYPE_HSACU) - info->cache[i].cache_properties |= AMDSMI_CACHE_PROPERTIES_SIMD_CACHE; + info->cache[i].cache_properties |= AMDSMI_CACHE_PROPERTY_SIMD_CACHE; info->cache[i].cache_size = rsmi_info.cache[i].cache_size_kb; info->cache[i].cache_level = rsmi_info.cache[i].cache_level;