diff --git a/amdsmi_cli/amdsmi_cli_exceptions.py b/amdsmi_cli/amdsmi_cli_exceptions.py index c43f37379a..13fe9753eb 100644 --- a/amdsmi_cli/amdsmi_cli_exceptions.py +++ b/amdsmi_cli/amdsmi_cli_exceptions.py @@ -22,6 +22,7 @@ import json + AMDSMI_ERROR_MESSAGES = { 0: "Sucess", 1: "Invalid parameters", @@ -117,7 +118,7 @@ class AmdSmiDeviceNotFoundException(AmdSmiException): self.command = command self.output_format = outputformat - common_message = f"GPU Device with GPU_INDEX '{self.command}' cannot be found on the system." + common_message = f"Can not find a GPU with the corresponding identifier: '{self.command}'" self.json_message["error"] = common_message self.json_message["code"] = self.value diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index 65afc71a79..7326c83214 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -659,7 +659,6 @@ class AMDSMICommands(): args.retired = args.pending = args.un_res = True values_dict = {} - bad_page_err_output = '' # Get gpu_id for logging gpu_id = self.helpers.get_gpu_id_from_device_handle(args.gpu) diff --git a/amdsmi_cli/amdsmi_helpers.py b/amdsmi_cli/amdsmi_helpers.py index 9fbc4398ab..9bb790a73c 100644 --- a/amdsmi_cli/amdsmi_helpers.py +++ b/amdsmi_cli/amdsmi_helpers.py @@ -27,6 +27,7 @@ import time from subprocess import run from subprocess import PIPE, STDOUT +from typing import List from amdsmi_init import * from BDF import BDF @@ -169,11 +170,11 @@ class AMDSMIHelpers(): return (gpu_choices, gpu_choices_str) - def get_device_handles_from_gpu_selections(self, gpu_selections, gpu_choices=None): + def get_device_handles_from_gpu_selections(self, gpu_selections: List[str], gpu_choices=None): """Convert provided gpu_selections to device_handles Args: - gpu_selections (list[str]): This will be the GPU ID, BDF, or UUID: + gpu_selections (list[str]): Selected GPU ID(s), BDF(s), or UUID(s): ex: ID:0 | BDF:0000:23:00.0 | UUID:ffffffff-0000-1000-0000-000000000000 gpu_choices (dict{gpu_choices}): This is a dictionary of the possible gpu_choices Returns: @@ -181,7 +182,7 @@ class AMDSMIHelpers(): amdsmi device_handles (False, str): Return False, and the first input that failed to be converted """ - if gpu_selections == ["all"]: + if 'all' in gpu_selections: return (True, amdsmi_interface.amdsmi_get_processor_handles()) if isinstance(gpu_selections, str): @@ -307,7 +308,9 @@ class AMDSMIHelpers(): for gpu_index, device_handle in enumerate(device_handles): if input_device_handle.value == device_handle.value: return gpu_index - raise IndexError("Unable to find gpu ID from device_handle") + raise amdsmi_exception.AmdSmiParameterException(input_device_handle, + amdsmi_interface.amdsmi_wrapper.amdsmi_processor_handle, + "Unable to find gpu ID from device_handle") def get_amd_gpu_bdfs(self): diff --git a/amdsmi_cli/amdsmi_parser.py b/amdsmi_cli/amdsmi_parser.py index 679c8138b6..8ad7686f86 100644 --- a/amdsmi_cli/amdsmi_parser.py +++ b/amdsmi_cli/amdsmi_parser.py @@ -24,9 +24,10 @@ import argparse import errno import os -import time -from pathlib import Path import sys +import time + +from pathlib import Path from _version import __version__ from amdsmi_helpers import AMDSMIHelpers @@ -205,6 +206,8 @@ class AMDSMIParser(argparse.ArgumentParser): ouputformat=self.helpers.get_output_format() # Checks the values def __call__(self, parser, args, values, option_string=None): + if "all" in gpu_choices: + del gpu_choices["all"] status, selected_device_handles = amdsmi_helpers.get_device_handles_from_gpu_selections(gpu_selections=values, gpu_choices=gpu_choices) if status: