From 260fd7faae543fad9d5f04f395a86b3e95b0de1f Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Sun, 24 Sep 2023 02:03:51 -0500 Subject: [PATCH] Removed compatibility modes Removed gpuv-smi and rocm-smi compatibility options Updated py-interface README Signed-off-by: Maisam Arif Change-Id: I1cad3e65e0928e7041727c6d5e7e7bdc39d667d0 Signed-off-by: Maisam Arif [ROCm/amdsmi commit: 5c52f82328aec8986a5855c2522fc43c73dac0a0] --- projects/amdsmi/amdsmi_cli/CMakeLists.txt | 7 +- projects/amdsmi/amdsmi_cli/amdsmi_cli.py | 10 +-- projects/amdsmi/amdsmi_cli/amdsmi_commands.py | 49 ++--------- projects/amdsmi/amdsmi_cli/amdsmi_logger.py | 81 +------------------ projects/amdsmi/amdsmi_cli/amdsmi_parser.py | 4 +- projects/amdsmi/py-interface/README.md | 22 ++--- 6 files changed, 23 insertions(+), 150 deletions(-) diff --git a/projects/amdsmi/amdsmi_cli/CMakeLists.txt b/projects/amdsmi/amdsmi_cli/CMakeLists.txt index 34626a24ee..3cd72a9fb1 100644 --- a/projects/amdsmi/amdsmi_cli/CMakeLists.txt +++ b/projects/amdsmi/amdsmi_cli/CMakeLists.txt @@ -72,17 +72,12 @@ add_custom_target( link_amdsmi_cli ALL DEPENDS amdsmi_cli BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/bin/amd-smi - ${CMAKE_CURRENT_BINARY_DIR}/bin/gpuv-smi WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink ../${PY_CLI_INSTALL_DIR}/${PY_PACKAGE_DIR}/amdsmi_cli.py - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/amd-smi - COMMAND ${CMAKE_COMMAND} -E create_symlink - amd-smi - ${CMAKE_CURRENT_BINARY_DIR}/bin/gpuv-smi) + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/amd-smi) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/bin/amd-smi - ${CMAKE_CURRENT_BINARY_DIR}/bin/gpuv-smi DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT dev) diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_cli.py b/projects/amdsmi/amdsmi_cli/amdsmi_cli.py index e07db5457e..a696a774a8 100755 --- a/projects/amdsmi/amdsmi_cli/amdsmi_cli.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_cli.py @@ -42,15 +42,7 @@ def _print_error(e, destination): if __name__ == "__main__": - # Set compatability mode based on which cli mapping user selects - if 'gpuv-smi' in sys.argv[0]: - compatibility = AMDSMILogger.LoggerCompatibility.gpuvsmi.value - elif 'rocm-smi' in sys.argv[0]: - compatibility = AMDSMILogger.LoggerCompatibility.rocmsmi.value - else: - compatibility = AMDSMILogger.LoggerCompatibility.amdsmi.value - - amd_smi_commands = AMDSMICommands(compatibility=compatibility) + amd_smi_commands = AMDSMICommands() amd_smi_parser = AMDSMIParser(amd_smi_commands.version, amd_smi_commands.list, amd_smi_commands.static, diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py index b54768bd4d..41ccfc4fe1 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py @@ -34,16 +34,11 @@ from amdsmi import amdsmi_exception class AMDSMICommands(): """This class contains all the commands corresponding to AMDSMIParser Each command function will interact with AMDSMILogger to handle - displaying the output to the specified compatibility, format, and - destination. + displaying the output to the specified format and destination. """ - def __init__(self, compatibility='amdsmi', - format='human_readable', - destination='stdout') -> None: + def __init__(self, format='human_readable', destination='stdout') -> None: self.helpers = AMDSMIHelpers() - self.logger = AMDSMILogger(compatibility=compatibility, - format=format, - destination=destination) + self.logger = AMDSMILogger(format=format, destination=destination) try: self.device_handles = amdsmi_interface.amdsmi_get_processor_handles() except amdsmi_exception.AmdSmiLibraryException as e: @@ -125,12 +120,7 @@ class AMDSMICommands(): self.logger.store_multiple_device_output() return # Skip printing when there are multiple devices - # compatibility with gpuvsmi needs a list for single gpu - if self.logger.is_gpuvsmi_compatibility() and not multiple_devices: - self.logger.store_multiple_device_output() - self.logger.print_output(multiple_device_enabled=True) - else: - self.logger.print_output() + self.logger.print_output() def static(self, args, multiple_devices=False, gpu=None, asic=None, @@ -262,11 +252,6 @@ class AMDSMICommands(): if args.vbios: try: vbios_info = amdsmi_interface.amdsmi_get_gpu_vbios_info(args.gpu) - if self.logger.is_gpuvsmi_compatibility(): - vbios_info['version'] = vbios_info.pop('version') - vbios_info['build_date'] = vbios_info.pop('build_date') - vbios_info['part_number'] = vbios_info.pop('part_number') - static_dict['vbios'] = vbios_info except amdsmi_exception.AmdSmiLibraryException as e: static_dict['vbios'] = "N/A" @@ -500,7 +485,7 @@ class AMDSMICommands(): """ if gpu: args.gpu = gpu - if fw_list: # Currently a compatiblity option of gpuv-smi + if fw_list: args.fw_list = fw_list # Handle No GPU passed @@ -525,20 +510,12 @@ class AMDSMICommands(): fw_entry['fw_version'] = fw_entry.pop('fw_version') firmware_identifier = 'FW' - if self.logger.is_gpuvsmi_compatibility(): - firmware_identifier = 'UCODE' - fw_entry['name'] = fw_entry.pop('fw_id') - fw_entry['version'] = fw_entry.pop('fw_version') - # Add custom human readable formatting if self.logger.is_human_readable_format(): fw_info['fw_list'][fw_index] = {f'{firmware_identifier} {fw_index}': fw_entry} else: fw_info['fw_list'][fw_index] = fw_entry - if self.logger.is_gpuvsmi_compatibility(): - fw_info['ucode_list'] = fw_info.pop('fw_list') - fw_list.update(fw_info) except amdsmi_exception.AmdSmiLibraryException as e: fw_list['fw_list'] = "N/A" @@ -547,11 +524,7 @@ class AMDSMICommands(): multiple_devices_csv_override = False # Convert and store output by pid for csv format if self.logger.is_csv_format(): - if self.logger.is_gpuvsmi_compatibility(): - fw_key = 'ucode_list' - else: - fw_key = 'fw_list' - + fw_key = 'fw_list' for fw_info_dict in fw_list[fw_key]: for key, value in fw_info_dict.items(): multiple_devices_csv_override = True @@ -961,15 +934,8 @@ class AMDSMICommands(): 'hotspot': temperature_hotspot_current, 'mem': temperature_vram_current} - if self.logger.is_gpuvsmi_compatibility(): - temperatures = {'edge_temperature': temperature_edge_current, - 'hotspot_temperature': temperature_hotspot_current, - 'mem_temperature': temperature_vram_current} - if self.logger.is_human_readable_format(): unit = '\N{DEGREE SIGN}C' - if self.logger.is_gpuvsmi_compatibility(): - unit = 'C' for temperature_key, temperature_value in temperatures.items(): if 'AMD_SMI_STATUS' not in str(temperature_value): temperatures[temperature_key] = f"{temperature_value} {unit}" @@ -1001,8 +967,6 @@ class AMDSMICommands(): except amdsmi_exception.AmdSmiLibraryException as e: ecc_count = "N/A" logging.debug("Failed to get ecc count for gpu %s at block %s | %s", args.gpu, gpu_block, e.get_error_info()) - if self.logger.is_gpuvsmi_compatibility(): - ecc_count = "N/A" ecc_dict[state['block']] = {'correctable' : ecc_count, 'uncorrectable': ecc_count} @@ -1434,7 +1398,6 @@ class AMDSMICommands(): def topology(self, args, multiple_devices=False, gpu=None, access=None, weight=None, hops=None, link_type=None, numa_bw=None): """ Get topology information for target gpus - The compatibility mode for this will only be in amdsmi & rocm-smi params: args - argparser args to pass to subcommand multiple_devices (bool) - True if checking for multiple devices diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py index 100747bb91..563798a486 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py @@ -31,12 +31,10 @@ from amdsmi_helpers import AMDSMIHelpers import amdsmi_cli_exceptions class AMDSMILogger(): - def __init__(self, compatibility='amdsmi', format='human_readable', - destination='stdout') -> None: + def __init__(self, format='human_readable', destination='stdout') -> None: self.output = {} self.multiple_device_output = [] self.watch_output = [] - self.compatibility = compatibility # amd-smi, gpuv-smi, or rocm-smi self.format = format # csv, json, or human_readable self.destination = destination # stdout, path to a file (append) self.helpers = AMDSMIHelpers() @@ -49,13 +47,6 @@ class AMDSMILogger(): human_readable = 'human_readable' - class LoggerCompatibility(Enum): - """Enum for logger compatibility""" - amdsmi = 'amdsmi' - rocmsmi = 'rocmsmi' - gpuvsmi = 'gpuvsmi' - - class CsvStdoutBuilder(object): def __init__(self): self.csv_string = [] @@ -79,18 +70,6 @@ class AMDSMILogger(): return self.format == self.LoggerFormat.human_readable.value - def is_amdsmi_compatibility(self): - return self.compatibility == self.LoggerCompatibility.amdsmi.value - - - def is_rocmsmi_compatibility(self): - return self.compatibility == self.LoggerCompatibility.rocmsmi.value - - - def is_gpuvsmi_compatibility(self): - return self.compatibility == self.LoggerCompatibility.gpuvsmi.value - - def _capitalize_keys(self, input_dict): output_dict = {} for key in input_dict.keys(): @@ -123,10 +102,6 @@ class AMDSMILogger(): yaml_data = yaml.safe_load(json_string) yaml_output = yaml.dump(yaml_data, sort_keys=False, allow_unicode=True) - if self.is_gpuvsmi_compatibility(): - # Convert from GPU: 0 to GPU 0: - yaml_output = re.sub('GPU: ([0-9]+)', 'GPU \\1:', yaml_output) - # Remove a key line if it is a spacer yaml_output = yaml_output.replace("AMDSMI_SPACING_REMOVAL:\n", "") yaml_output = yaml_output.replace("'", "") # Remove '' @@ -196,13 +171,6 @@ class AMDSMILogger(): value_with_parent_key[parent_key] = child_dict value = value_with_parent_key - if self.is_gpuvsmi_compatibility(): - if key in ('asic', 'bus', 'pcie', 'vbios','board', 'limit'): - value_with_parent_key = {} - for child_key, child_value in value.items(): - value_with_parent_key[key + '_' + child_key] = child_value - value = value_with_parent_key - output_dict.update(self.flatten_dict(value).items()) else: output_dict[key] = value @@ -210,9 +178,7 @@ class AMDSMILogger(): def store_output(self, device_handle, argument, data): - """ Store the argument and device handle according to the compatibility. - Each compatibility function will handle the output format and - populate the output + """ Convert device handle to gpu id and store output params: device_handle - device handle object to the target device output argument (str) - key to store data @@ -221,12 +187,7 @@ class AMDSMILogger(): Nothing """ gpu_id = self.helpers.get_gpu_id_from_device_handle(device_handle) - if self.is_amdsmi_compatibility(): - self._store_output_amdsmi(gpu_id=gpu_id, argument=argument, data=data) - elif self.is_rocmsmi_compatibility(): - self._store_output_rocmsmi(gpu_id=gpu_id, argument=argument, data=data) - elif self.is_gpuvsmi_compatibility(): - self._store_output_gpuvsmi(gpu_id=gpu_id, argument=argument, data=data) + self._store_output_amdsmi(gpu_id=gpu_id, argument=argument, data=data) def _store_output_amdsmi(self, gpu_id, argument, data): @@ -265,42 +226,6 @@ class AMDSMILogger(): raise amdsmi_cli_exceptions(self, "Invalid output format given, only json, csv, and human_readable supported") - def _store_output_gpuvsmi(self, gpu_id, argument, data): - if argument == 'timestamp': # Make sure timestamp is the first element in the output - self.output['timestamp'] = int(time.time()) - - if self.is_json_format() or self.is_human_readable_format(): - self.output['gpu'] = int(gpu_id) - self.output[argument] = data - elif self.is_csv_format(): - self.output['gpu'] = int(gpu_id) - - if argument == 'values' or isinstance(data, dict): - flat_dict = self.flatten_dict(data) - self.output.update(flat_dict) - else: - self.output[argument] = data - - gpuv_flat_dict = {} - for key, value in self.output.items(): - gpuv_flat_dict[key] = value - - # Change AMDSMI_STATUS strings to N/A for gpuv compatability - if isinstance(value, str): - if 'AMDSMI_STATUS' in value: - gpuv_flat_dict[key] = 'N/A' - - # Change bdf and uuid keys for gpuv compatability - if isinstance(key, str): - if key in ('bdf','uuid'): - gpuv_flat_dict['gpu_' + key] = gpuv_flat_dict.pop(key) - - self.output = gpuv_flat_dict - - else: - raise amdsmi_cli_exceptions(self, "Invalid output format given, only json, csv, and human_readable supported") - - def store_multiple_device_output(self): """ Store the current output into the multiple_device_output then clear the current output diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_parser.py b/projects/amdsmi/amdsmi_cli/amdsmi_parser.py index cbfcc87172..e58344598a 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_parser.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_parser.py @@ -53,8 +53,6 @@ class AMDSMIParser(argparse.ArgumentParser): platform_string = f"Platform: {self.helpers.os_info()}" program_name = 'amd-smi' - if 'gpuv-smi' in sys.argv[0]: - program_name = 'gpuv-smi' # Adjust argument parser options super().__init__( @@ -207,7 +205,7 @@ class AMDSMIParser(argparse.ArgumentParser): return _GPUSelectAction - def _add_command_modifiers(self, subcommand_parser, rocm_smi=True, gpuv_smi=True): + def _add_command_modifiers(self, subcommand_parser): json_help = "Displays output in JSON format (human readable by default)." csv_help = "Displays output in CSV format (human readable by default)." file_help = "Saves output into a file on the provided path (stdout by default)." diff --git a/projects/amdsmi/py-interface/README.md b/projects/amdsmi/py-interface/README.md index 09eb158b49..ca39ab110c 100644 --- a/projects/amdsmi/py-interface/README.md +++ b/projects/amdsmi/py-interface/README.md @@ -1208,7 +1208,7 @@ Example: ```python try: - devices = gpuvsmi_get_devices() + devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: @@ -1253,7 +1253,7 @@ Example: ```python try: - devices = gpuvsmi_get_devices() + devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: @@ -1290,7 +1290,7 @@ Example: ```python try: - devices = gpuvsmi_get_devices() + devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: @@ -1322,7 +1322,7 @@ Example: ```python try: - devices = gpuvsmi_get_devices() + devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: @@ -1353,7 +1353,7 @@ Example: ```python try: - devices = gpuvsmi_get_devices() + devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: @@ -1391,7 +1391,7 @@ Example: ```python try: - devices = gpuvsmi_get_devices() + devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: @@ -1423,7 +1423,7 @@ Example: ```python try: - devices = gpuvsmi_get_devices() + devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: @@ -1495,7 +1495,7 @@ Example: ```python try: - devices = gpuvsmi_get_devices() + devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: @@ -1658,11 +1658,11 @@ Exceptions that can be thrown by `amdsmi_is_gpu_power_management_enabled` functi Example: ```python try: - processors = amdsmi_get_processor_handles() - if len(processors) == 0: + devices = amdsmi_get_processor_handles() + if len(devices) == 0: print("No GPUs on machine") else: - for processor in processors: + for processor in devices: is_power_management_enabled = amdsmi_is_gpu_power_management_enabled(processor) print(is_power_management_enabled) except AmdSmiException as e: