[SWDEV-399953] Smart Temperature detection + partitioning display
* Updates:
- Fix for devices which do not have edge sensors, but junction
- Added partitioning (memory and dynamic) displays for
base rocm-smi CLI calls
- Added subheading for base rocm-smi call output
- Added better hwmon and device detection logging
Change-Id: I8219884b2e532d6ed379527cacdc1f2b232a5451
Signed-off-by: Charis Poag <Charis.Poag@amd.com>
此提交包含在:
+72
-13
@@ -47,7 +47,7 @@ headerString = ' ROCm System Management Interface '
|
||||
footerString = ' End of ROCm SMI Log '
|
||||
|
||||
# Output formatting
|
||||
appWidth = 84
|
||||
appWidth = 100
|
||||
deviceList = []
|
||||
|
||||
# Enable or disable serialized format
|
||||
@@ -393,6 +393,25 @@ def getTemp(device, sensor):
|
||||
return temp.value / 1000
|
||||
return 'N/A'
|
||||
|
||||
def findFirstAvailableTemp(device):
|
||||
""" Discovers the first available device temperature to display
|
||||
|
||||
Returns a tuple of (temp_type, temp_value) for the device specified
|
||||
@param device: DRM device identifier
|
||||
"""
|
||||
temp = c_int64(0)
|
||||
metric = rsmi_temperature_metric_t.RSMI_TEMP_CURRENT
|
||||
ret_temp = "N/A"
|
||||
ret_temp_type = "(Unknown)"
|
||||
for i, templist_val in enumerate(temp_type_lst):
|
||||
ret = rocmsmi.rsmi_dev_temp_metric_get(c_uint32(device), i, metric, byref(temp))
|
||||
if rsmi_ret_ok(ret, device, 'get_temp_metric_' + templist_val, silent=True):
|
||||
ret_temp = temp.value / 1000
|
||||
ret_temp_type = '(' + templist_val.capitalize() + ')'
|
||||
break
|
||||
else:
|
||||
continue
|
||||
return (ret_temp_type, ret_temp)
|
||||
|
||||
def getVbiosVersion(device):
|
||||
""" Returns the VBIOS version for a given device
|
||||
@@ -429,7 +448,7 @@ def getComputePartition(device):
|
||||
ret = rocmsmi.rsmi_dev_compute_partition_get(device, currentComputePartition, 256)
|
||||
if rsmi_ret_ok(ret, device, 'get_compute_partition', silent=True) and currentComputePartition.value.decode():
|
||||
return str(currentComputePartition.value.decode())
|
||||
return "UNKNOWN"
|
||||
return "N/A"
|
||||
|
||||
|
||||
def getMemoryPartition(device):
|
||||
@@ -441,7 +460,7 @@ def getMemoryPartition(device):
|
||||
ret = rocmsmi.rsmi_dev_nps_mode_get(device, currentNPSMode, 256)
|
||||
if rsmi_ret_ok(ret, device, 'get_NPS_mode', silent=True) and currentNPSMode.value.decode():
|
||||
return str(currentNPSMode.value.decode())
|
||||
return "UNKNOWN"
|
||||
return "N/A"
|
||||
|
||||
|
||||
def print2DArray(dataArray):
|
||||
@@ -544,13 +563,20 @@ def printEventList(device, delay, eventList):
|
||||
print2DArray([['\rGPU[%d]:\t' % (data.dv_ind), ctime().split()[3], notification_type_names[data.event.value - 1],
|
||||
data.message.decode('utf8') + '\r']])
|
||||
|
||||
def printLog(device, metricName, value=None, extraSpace=False):
|
||||
def printLog(device, metricName, value=None, extraSpace=False, useItalics=False):
|
||||
""" Print out to the SMI log
|
||||
|
||||
@param device: DRM device identifier
|
||||
@param metricName: Title of the item to print to the log
|
||||
@param value: The item's value to print to the log
|
||||
"""
|
||||
red = '\033[91m'
|
||||
green = '\033[92m'
|
||||
blue = '\033[94m'
|
||||
bold = '\033[1m'
|
||||
italics = '\033[3m'
|
||||
underline = '\033[4m'
|
||||
end = '\033[0m'
|
||||
global PRINT_JSON
|
||||
if PRINT_JSON:
|
||||
if value is not None and device is not None:
|
||||
@@ -567,6 +593,8 @@ def printLog(device, metricName, value=None, extraSpace=False):
|
||||
# Force thread safe printing
|
||||
lock = multiprocessing.Lock()
|
||||
lock.acquire()
|
||||
if useItalics:
|
||||
logstr = italics + logstr + end
|
||||
if extraSpace:
|
||||
print('\n' + logstr + '\n', end='', flush=True)
|
||||
else:
|
||||
@@ -1544,18 +1572,39 @@ def showAllConcise(deviceList):
|
||||
print('ERROR: Cannot print JSON/CSV output for concise output')
|
||||
sys.exit(1)
|
||||
printLogSpacer(' Concise Info ')
|
||||
header = ['GPU', 'Temp (DieEdge)', 'AvgPwr', 'SCLK', 'MCLK', 'Fan', 'Perf', 'PwrCap', 'VRAM%', 'GPU%']
|
||||
deviceList.sort()
|
||||
(temp_type, _) = findFirstAvailableTemp(deviceList[0])
|
||||
available_temp_type = temp_type.lower()
|
||||
available_temp_type = available_temp_type.replace('(', '')
|
||||
available_temp_type = available_temp_type.replace(')', '')
|
||||
header = ['GPU', 'Temp', 'AvgPwr', 'Partitions', 'SCLK', 'MCLK', 'Fan', 'Perf', 'PwrCap', 'VRAM%', 'GPU%']
|
||||
subheader = ['', temp_type, '', '(Mem, Compute)', '', '', '', '', '', '', '']
|
||||
# add additional spaces to match header
|
||||
for idx, item in enumerate(subheader):
|
||||
header_size = len(header[idx])
|
||||
subheader_size = len(subheader[idx])
|
||||
if header_size != subheader_size:
|
||||
numSpacesToFill_subheader = header_size - subheader_size
|
||||
numSpacesToFill_header = subheader_size - header_size
|
||||
#take pos spaces to mean, we need to match size of the other
|
||||
if numSpacesToFill_subheader > 0:
|
||||
subheader[idx] = subheader[idx] + (' ' * numSpacesToFill_subheader)
|
||||
if numSpacesToFill_header > 0:
|
||||
header[idx] = header[idx] + (' ' * numSpacesToFill_header)
|
||||
head_widths = [len(head) + 2 for head in header]
|
||||
values = {}
|
||||
degree_sign = u'\N{DEGREE SIGN}'
|
||||
for device in deviceList:
|
||||
temp = str(getTemp(device, 'edge'))
|
||||
if temp != 'N/A':
|
||||
temp += 'c'
|
||||
temp_val = str(getTemp(device, available_temp_type))
|
||||
if temp_val != 'N/A':
|
||||
temp_val += degree_sign + 'C'
|
||||
avgPwr = str(getPower(device))
|
||||
if avgPwr != '0.0' and avgPwr != 'N/A':
|
||||
avgPwr += 'W'
|
||||
else:
|
||||
avgPwr = 'N/A'
|
||||
combined_partition = (getMemoryPartition(device) + ", "
|
||||
+ getComputePartition(device))
|
||||
concise = True
|
||||
sclk = showCurrentClocks([device], 'sclk', concise)
|
||||
mclk = showCurrentClocks([device], 'mclk', concise)
|
||||
@@ -1579,7 +1628,9 @@ def showAllConcise(deviceList):
|
||||
mem_use_pct='Unsupported'
|
||||
if vram_used != None and vram_total != None and float(vram_total) != 0:
|
||||
mem_use_pct = '% 3.0f%%' % (100 * (float(vram_used) / float(vram_total)))
|
||||
values['card%s' % (str(device))] = [device, temp, avgPwr, sclk, mclk, fan, str(perf).lower(), pwrCap,
|
||||
values['card%s' % (str(device))] = [device, temp_val, avgPwr,
|
||||
combined_partition, sclk, mclk,
|
||||
fan, str(perf).lower(), pwrCap,
|
||||
mem_use_pct, gpu_busy]
|
||||
val_widths = {}
|
||||
for device in deviceList:
|
||||
@@ -1589,6 +1640,9 @@ def showAllConcise(deviceList):
|
||||
for col in range(len(val_widths[device])):
|
||||
max_widths[col] = max(max_widths[col], val_widths[device][col])
|
||||
printLog(None, "".join(word.ljust(max_widths[col]) for col, word in zip(range(len(max_widths)), header)), None)
|
||||
printLog(None, "".join(word.ljust(max_widths[col]) for col, word in zip(range(len(max_widths)), subheader)),
|
||||
None, useItalics=True)
|
||||
printLogSpacer(fill='=')
|
||||
for device in deviceList:
|
||||
printLog(None, "".join(str(word).ljust(max_widths[col]) for col, word in
|
||||
zip(range(len(max_widths)), values['card%s' % (str(device))])), None)
|
||||
@@ -2548,7 +2602,7 @@ def showEvents(deviceList, eventTypes):
|
||||
break
|
||||
|
||||
|
||||
def printTempGraph(deviceList, delay):
|
||||
def printTempGraph(deviceList, delay, temp_type):
|
||||
# deviceList must be in ascending order
|
||||
deviceList.sort()
|
||||
devices = 0
|
||||
@@ -2562,7 +2616,7 @@ def printTempGraph(deviceList, delay):
|
||||
terminalWidth = os.get_terminal_size()[0]
|
||||
printStrings = list()
|
||||
for device in deviceList:
|
||||
temp = getTemp(device, 'edge')
|
||||
temp = getTemp(device, temp_type)
|
||||
if temp == 'N/A':
|
||||
percentage = 0
|
||||
else:
|
||||
@@ -2635,11 +2689,16 @@ def getGraphColor(percentage):
|
||||
|
||||
|
||||
def showTempGraph(deviceList):
|
||||
printLogSpacer(' Temperature Graph ')
|
||||
deviceList.sort()
|
||||
(temp_type, temp_value) = findFirstAvailableTemp(deviceList[0])
|
||||
printLogSpacer(' Temperature Graph ' + temp_type + ' ')
|
||||
temp_type = temp_type.lower()
|
||||
temp_type = temp_type.replace('(', '')
|
||||
temp_type = temp_type.replace(')', '')
|
||||
# Start a thread for constantly printing
|
||||
try:
|
||||
# Create a thread (call print function, devices, delay in ms)
|
||||
_thread.start_new_thread(printTempGraph, (deviceList, 150))
|
||||
_thread.start_new_thread(printTempGraph, (deviceList, 150, temp_type))
|
||||
except Exception as e:
|
||||
printErrLog(device, 'Unable to start new thread. %s' % (e))
|
||||
# Catch user input for program termination
|
||||
|
||||
新增問題並參考
封鎖使用者