From 0cdc8fb26c76fa9f2c52b956d0cc78b12e2bfcad Mon Sep 17 00:00:00 2001 From: Ori Messinger Date: Tue, 22 Jun 2021 06:35:24 -0400 Subject: [PATCH] ROCm SMI Python CLI: Add Zero Padding to Device Model Use zero padding for the hexadecimal value 'device_model' inside showProductName with a padding length of 4. Signed-off-by: Ori Messinger Change-Id: I962b94d414c6ba050d951486ad9e7559123f8850 [ROCm/amdsmi commit: 03ae187a35d98e03a126cabcc127d3ab721689d6] --- projects/amdsmi/python_smi_tools/rocm_smi.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/projects/amdsmi/python_smi_tools/rocm_smi.py b/projects/amdsmi/python_smi_tools/rocm_smi.py index 4df63c24b5..43309ef639 100755 --- a/projects/amdsmi/python_smi_tools/rocm_smi.py +++ b/projects/amdsmi/python_smi_tools/rocm_smi.py @@ -1897,7 +1897,8 @@ def showProductName(deviceList): ret = rocmsmi.rsmi_dev_subsystem_name_get(device, model, 256) if rsmi_ret_ok(ret, device) and model.value.decode(): device_model = model.value.decode() - printLog(device, 'Card model', '\t\t' + device_model) + # padHexValue is used for applications that expect 4-digit card models + printLog(device, 'Card model', '\t\t' + padHexValue(device_model, 4)) printLog(device, 'Card vendor', '\t\t' + device_vendor) # TODO: Retrieve the SKU using 'rsmi_dev_sku_get' from the LIB # ret = rocmsmi.rsmi_dev_sku_get(device, sku, 256) @@ -2543,6 +2544,20 @@ def load(savefilepath, autoRespond): printLogSpacer() +def padHexValue(value, length): + """ Pad a hexadecimal value with a given length of zeros + + @param value: A hexadecimal value to be padded with zeros + @param length: Number of zeros to pad the hexadecimal value + """ + # Ensure value entered meets the minimum length and is hexadecimal + if len(value) > 2 and length > 1 and value[:2].lower() == '0x' \ + and all(c in '0123456789abcdefABCDEF' for c in value[2:]): + # Pad with zeros after '0x' prefix + return '0x' + value[2:].zfill(length) + return value + + def profileString(profile): dictionary = {1: 'CUSTOM', 2:'VIDEO', 4:'POWER SAVING', 8:'COMPUTE', 16:'VR', 32:'3D FULL SCREEN', 64:'BOOTUP DEFAULT'} # TODO: We should dynamically generate this to avoid hardcoding