CLI help text clean up

Signed-off-by: Maisam Arif <maisarif@amd.com>
Change-Id: I46d8071f2bb38f3a6e366b436e7451116bfb6df9
This commit is contained in:
Maisam Arif
2023-10-16 11:11:03 -05:00
zatwierdzone przez Galantsev, Dmitrii
rodzic ec24a0f66d
commit 6d4d706f08
3 zmienionych plików z 40 dodań i 28 usunięć
+17 -17
Wyświetl plik
@@ -1751,7 +1751,7 @@ class AMDSMICommands():
def set_value(self, args, multiple_devices=False, gpu=None, fan=None, perf_level=None,
profile=None, perfdeterminism=None, compute_partition=None,
profile=None, perf_determinism=None, compute_partition=None,
memory_partition=None):
"""Issue reset commands to target gpu(s)
@@ -1762,7 +1762,7 @@ class AMDSMICommands():
fan (int, optional): Value override for args.fan. Defaults to None.
perf_level (amdsmi_interface.AmdSmiDevPerfLevel, optional): Value override for args.perf_level. Defaults to None.
profile (bool, optional): Value override for args.profile. Defaults to None.
perfdeterminism (int, optional): Value override for args.perfdeterminism. Defaults to None.
perf_determinism (int, optional): Value override for args.perf_determinism. Defaults to None.
compute_partition (amdsmi_interface.AmdSmiComputePartitionType, optional): Value override for args.compute_partition. Defaults to None.
memory_partition (amdsmi_interface.AmdSmiMemoryPartitionType, optional): Value override for args.memory_partition. Defaults to None.
@@ -1782,8 +1782,8 @@ class AMDSMICommands():
args.perf_level = perf_level
if profile:
args.profile = profile
if perfdeterminism:
args.perfdeterminism = perfdeterminism
if perf_determinism:
args.perf_determinism = perf_determinism
if compute_partition:
args.compute_partition = compute_partition
if memory_partition:
@@ -1801,7 +1801,7 @@ class AMDSMICommands():
args.gpu = device_handle
# Error if no subcommand args are passed
if not any([args.fan, args.perflevel, args.profile, args.perfdeterminism]):
if not any([args.fan, args.perflevel, args.profile, args.perf_determinism]):
command = " ".join(sys.argv[1:])
raise AmdSmiRequiredCommandException(command, self.logger.format)
@@ -1838,15 +1838,15 @@ class AMDSMICommands():
self.logger.store_output(args.gpu, 'perflevel', f"Successfully set performance level {args.perf_level}")
if args.profile:
self.logger.store_output(args.gpu, 'profile', "Not Yet Implemented")
if isinstance(args.perfdeterminism, int):
if isinstance(args.perf_determinism, int):
try:
amdsmi_interface.amdsmi_set_gpu_perf_determinism_mode(args.gpu, args.perfdeterminism)
amdsmi_interface.amdsmi_set_gpu_perf_determinism_mode(args.gpu, args.perf_determinism)
except amdsmi_exception.AmdSmiLibraryException as e:
if e.get_error_code() == amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NO_PERM:
raise PermissionError('Command requires elevation') from e
raise ValueError(f"Unable to set performance determinism and clock frequency to {args.perfdeterminism} on {gpu_string}") from e
raise ValueError(f"Unable to set performance determinism and clock frequency to {args.perf_determinism} on {gpu_string}") from e
self.logger.store_output(args.gpu, 'perfdeterminism', f"Successfully enabled performance determinism and set GFX clock frequency to {args.perfdeterminism}")
self.logger.store_output(args.gpu, 'perfdeterminism', f"Successfully enabled performance determinism and set GFX clock frequency to {args.perf_determinism}")
if args.compute_partition:
compute_partition = amdsmi_interface.AmdSmiComputePartitionType[args.compute_partition]
try:
@@ -1871,7 +1871,7 @@ class AMDSMICommands():
def reset(self, args, multiple_devices=False, gpu=None, gpureset=None,
clocks=None, fans=None, profile=None, xgmierr=None, perfdeterminism=None,
clocks=None, fans=None, profile=None, xgmierr=None, perf_determinism=None,
compute_partition=None, memory_partition=None):
"""Issue reset commands to target gpu(s)
@@ -1884,7 +1884,7 @@ class AMDSMICommands():
fans (bool, optional): Value override for args.fans. Defaults to None.
profile (bool, optional): Value override for args.profile. Defaults to None.
xgmierr (bool, optional): Value override for args.xgmierr. Defaults to None.
perfdeterminism (bool, optional): Value override for args.perfdeterminism. Defaults to None.
perf_determinism (bool, optional): Value override for args.perf_determinism. Defaults to None.
compute_partition (bool, optional): Value override for args.compute_partition. Defaults to None.
memory_partition (bool, optional): Value override for args.memory_partition. Defaults to None.
@@ -1908,8 +1908,8 @@ class AMDSMICommands():
args.profile = profile
if xgmierr:
args.xgmierr = xgmierr
if perfdeterminism:
args.perfdeterminism = perfdeterminism
if perf_determinism:
args.perf_determinism = perf_determinism
if compute_partition:
args.compute_partition = compute_partition
if memory_partition:
@@ -1930,7 +1930,7 @@ class AMDSMICommands():
gpu_id = self.helpers.get_gpu_id_from_device_handle(args.gpu)
# Error if no subcommand args are passed
if not any([args.gpureset, args.clocks, args.fans, args.profile, args.xgmierr, args.perfdeterminism]):
if not any([args.gpureset, args.clocks, args.fans, args.profile, args.xgmierr, args.perf_determinism]):
command = " ".join(sys.argv[1:])
raise AmdSmiRequiredCommandException(command, self.logger.format)
@@ -2026,7 +2026,7 @@ class AMDSMICommands():
result = "N/A"
logging.debug("Failed to reset xgmi error count on gpu %s | %s", gpu_id, e.get_error_info())
self.logger.store_output(args.gpu, 'reset_xgmi_err', result)
if args.perfdeterminism:
if args.perf_determinism:
try:
level_auto = amdsmi_interface.AmdSmiDevPerfLevel.AUTO
amdsmi_interface.amdsmi_set_gpu_perf_level(args.gpu, level_auto)
@@ -2039,7 +2039,7 @@ class AMDSMICommands():
self.logger.store_output(args.gpu, 'reset_perf_determinism', result)
if args.compute_partition:
try:
amdsmi_interface.amdsmi_reset_gpu_compute_partition(args.gpu)
amdsmi_interface.amdsmi_dev_compute_partition_reset(args.gpu)
result = 'Successfully reset compute partition'
except amdsmi_exception.AmdSmiLibraryException as e:
if e.get_error_code() == amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NO_PERM:
@@ -2049,7 +2049,7 @@ class AMDSMICommands():
self.logger.store_output(args.gpu, 'reset_compute_partition', result)
if args.memory_partition:
try:
amdsmi_interface.amdsmi_reset_gpu_memory_partition(args.gpu)
amdsmi_interface.amdsmi_dev_memory_partition_reset(args.gpu)
result = 'Successfully reset memory partition'
except amdsmi_exception.AmdSmiLibraryException as e:
if e.get_error_code() == amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NO_PERM:
+12 -3
Wyświetl plik
@@ -21,6 +21,7 @@
#
import logging
import math
import platform
import sys
import time
@@ -133,7 +134,7 @@ class AMDSMIHelpers():
"""Return dictionary of possible GPU choices and string of the output:
Dictionary will be in format: gpus[ID] : (BDF, UUID, Device Handle)
String output will be in format:
"ID:0 | BDF:0000:23:00.0 | UUID:ffffffff-0000-1000-0000-000000000000"
"ID: 0 | BDF: 0000:23:00.0 | UUID: ffffffff-0000-1000-0000-000000000000"
params:
None
return:
@@ -153,6 +154,9 @@ class AMDSMIHelpers():
else:
raise e
# Handle spacing for the gpu_choices_str
max_padding = int(math.log10(len(device_handles))) + 1
for gpu_id, device_handle in enumerate(device_handles):
bdf = amdsmi_interface.amdsmi_get_gpu_device_bdf(device_handle)
uuid = amdsmi_interface.amdsmi_get_gpu_device_uuid(device_handle)
@@ -161,11 +165,16 @@ class AMDSMIHelpers():
"UUID": uuid,
"Device Handle": device_handle,
}
gpu_choices_str += f"ID:{gpu_id} | BDF:{bdf} | UUID:{uuid}\n"
if gpu_id == 0:
id_padding = max_padding
else:
id_padding = max_padding - int(math.log10(gpu_id))
gpu_choices_str += f"\tID: {gpu_id}{' ' * id_padding}| BDF: {bdf} | UUID: {uuid}\n"
# Add the all option to the gpu_choices
gpu_choices["all"] = "all"
gpu_choices_str += " all | Selects all devices\n"
gpu_choices_str += f"\t all{' ' * max_padding}| Selects all devices\n"
return (gpu_choices, gpu_choices_str)
+11 -8
Wyświetl plik
@@ -226,7 +226,8 @@ class AMDSMIParser(argparse.ArgumentParser):
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)."
loglevel_choices = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
loglevel_help = f"Set the logging level from the possible choices:\n{loglevel_choices}"
loglevel_choices_str = ", ".join(loglevel_choices)
loglevel_help = f"Set the logging level from the possible choices:\n\t{loglevel_choices_str}"
command_modifier_group = subcommand_parser.add_argument_group('Command Modifiers')
@@ -632,12 +633,14 @@ class AMDSMIParser(argparse.ArgumentParser):
set_value_optionals_title = "Set Arguments"
# Help text for Arguments only on BM platforms
set_fan_help = "Sets GPU fan speed (0-255 or 0-100%%)"
set_perf_level_help = "Sets performance level"
set_fan_help = "Set GPU fan speed (0-255 or 0-100%%)"
set_perf_level_help = "Set performance level"
set_profile_help = "Set power profile level (#) or a quoted string of custom profile attributes"
set_perf_det_help = "Sets GPU clock frequency limit and performance level to determinism to get minimal performance variation"
set_compute_partition_help = "Sets compute partition mode"
set_memory_partition_help = "Sets memory partition mode"
set_perf_det_help = "Set GPU clock frequency limit and performance level to determinism to get minimal performance variation"
compute_partition_choices_str = ", ".join(self.helpers.get_compute_partition_types())
memory_partition_choices_str = ", ".join(self.helpers.get_memory_partition_types())
set_compute_partition_help = f"Set one of the following the compute partition modes:\n\t{compute_partition_choices_str}"
set_memory_partition_help = f"Set one of the following the memory partition modes:\n\t{memory_partition_choices_str}"
# Create set_value subparser
set_value_parser = subparsers.add_parser('set', help=set_value_help, description=set_value_subcommand_help)
@@ -769,7 +772,7 @@ class AMDSMIParser(argparse.ArgumentParser):
reset_fans_help = "Reset fans to automatic (driver) control"
reset_profile_help = "Reset power profile back to default"
reset_xgmierr_help = "Reset XGMI error counts"
reset_perfdet_help = "Disable performance determinism"
reset_perf_det_help = "Disable performance determinism"
reset_compute_help = "Reset compute partitions on the specified GPU"
reset_memory_help = "Reset memory partitions on the specified GPU"
@@ -790,7 +793,7 @@ class AMDSMIParser(argparse.ArgumentParser):
reset_parser.add_argument('-f', '--fans', action='store_true', required=False, help=reset_fans_help)
reset_parser.add_argument('-p', '--profile', action='store_true', required=False, help=reset_profile_help)
reset_parser.add_argument('-x', '--xgmierr', action='store_true', required=False, help=reset_xgmierr_help)
reset_parser.add_argument('-d', '--perf-determinism', action='store_true', required=False, help=reset_perfdet_help)
reset_parser.add_argument('-d', '--perf-determinism', action='store_true', required=False, help=reset_perf_det_help)
reset_parser.add_argument('-C', '--compute-partition', action='store_true', required=False, help=reset_compute_help)
reset_parser.add_argument('-M', '--memory-partition', action='store_true', required=False, help=reset_memory_help)