Skip to content

Commit 90f0490

Browse files
committed
Be more permissive if some GPU stats are not available
1 parent 3bc198d commit 90f0490

File tree

1 file changed

+78
-42
lines changed

1 file changed

+78
-42
lines changed

library/stats.py

Lines changed: 78 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,24 @@ def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature):
265265
)
266266

267267
if THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("SHOW", False):
268-
display.lcd.DisplayText(
269-
text=f"{int(temperature):>3}°C",
270-
x=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("X", 0),
271-
y=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("Y", 0),
272-
font=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("FONT", "roboto-mono/RobotoMono-Regular.ttf"),
273-
font_size=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("FONT_SIZE", 10),
274-
font_color=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
275-
background_color=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("BACKGROUND_COLOR", (255, 255, 255)),
276-
background_image=get_full_path(THEME_DATA['PATH'],
277-
THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("BACKGROUND_IMAGE",
278-
None))
279-
)
268+
if math.isnan(temperature):
269+
logger.warning("Your GPU temperature is not supported yet")
270+
THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT']['SHOW'] = False
271+
else:
272+
display.lcd.DisplayText(
273+
text=f"{int(temperature):>3}°C",
274+
x=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("X", 0),
275+
y=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("Y", 0),
276+
font=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("FONT",
277+
"roboto-mono/RobotoMono-Regular.ttf"),
278+
font_size=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("FONT_SIZE", 10),
279+
font_color=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
280+
background_color=THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("BACKGROUND_COLOR",
281+
(255, 255, 255)),
282+
background_image=get_full_path(THEME_DATA['PATH'],
283+
THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("BACKGROUND_IMAGE",
284+
None))
285+
)
280286
pass
281287

282288

@@ -286,19 +292,30 @@ def stats():
286292
# Unlike the CPU, the GPU pulls in all the stats at once
287293
nvidia_gpus = GPUtil.getGPUs()
288294

289-
memory_used_all = [item.memoryUsed for item in nvidia_gpus]
290-
memory_used_mb = sum(memory_used_all) / len(memory_used_all)
291-
292-
memory_total_all = [item.memoryTotal for item in nvidia_gpus]
293-
memory_total_mb = sum(memory_total_all) / len(memory_total_all)
295+
try:
296+
memory_used_all = [item.memoryUsed for item in nvidia_gpus]
297+
memory_used_mb = sum(memory_used_all) / len(memory_used_all)
298+
except:
299+
memory_used_mb = math.nan
294300

295-
memory_percentage = (memory_used_mb / memory_total_mb) * 100
301+
try:
302+
memory_total_all = [item.memoryTotal for item in nvidia_gpus]
303+
memory_total_mb = sum(memory_total_all) / len(memory_total_all)
304+
memory_percentage = (memory_used_mb / memory_total_mb) * 100
305+
except:
306+
memory_percentage = math.nan
296307

297-
load_all = [item.load for item in nvidia_gpus]
298-
load = (sum(load_all) / len(load_all)) * 100
308+
try:
309+
load_all = [item.load for item in nvidia_gpus]
310+
load = (sum(load_all) / len(load_all)) * 100
311+
except:
312+
load = math.nan
299313

300-
temperature_all = [item.temperature for item in nvidia_gpus]
301-
temperature = sum(temperature_all) / len(temperature_all)
314+
try:
315+
temperature_all = [item.temperature for item in nvidia_gpus]
316+
temperature = sum(temperature_all) / len(temperature_all)
317+
except:
318+
temperature = math.nan
302319

303320
display_gpu_stats(load, memory_percentage, memory_used_mb, temperature)
304321

@@ -318,29 +335,48 @@ def stats():
318335
amd_gpus.append(pyamdgpuinfo.get_gpu(i))
319336
i = i + 1
320337

321-
memory_used_all = [item.query_vram_usage() for item in amd_gpus]
322-
memory_used_bytes = sum(memory_used_all) / len(memory_used_all)
323-
324-
memory_total_all = [item.memory_info["vram_size"] for item in amd_gpus]
325-
memory_total_bytes = sum(memory_total_all) / len(memory_total_all)
326-
327-
memory_percentage = (memory_used_bytes / memory_total_bytes) * 100
328-
329-
load_all = [item.query_load() for item in amd_gpus]
330-
load = (sum(load_all) / len(load_all)) * 100
331-
332-
temperature_all = [item.query_temperature() for item in amd_gpus]
333-
temperature = sum(temperature_all) / len(temperature_all)
334-
335-
display_gpu_stats(load, memory_percentage, memory_used_bytes / 1000000, temperature)
338+
try:
339+
memory_used_all = [item.query_vram_usage() for item in amd_gpus]
340+
memory_used_bytes = sum(memory_used_all) / len(memory_used_all)
341+
memory_used = memory_used_bytes / 1000000
342+
except:
343+
memory_used_bytes = math.nan
344+
memory_used = math.nan
345+
346+
try:
347+
memory_total_all = [item.memory_info["vram_size"] for item in amd_gpus]
348+
memory_total_bytes = sum(memory_total_all) / len(memory_total_all)
349+
memory_percentage = (memory_used_bytes / memory_total_bytes) * 100
350+
except:
351+
memory_percentage = math.nan
352+
353+
try:
354+
load_all = [item.query_load() for item in amd_gpus]
355+
load = (sum(load_all) / len(load_all)) * 100
356+
except:
357+
load = math.nan
358+
359+
try:
360+
temperature_all = [item.query_temperature() for item in amd_gpus]
361+
temperature = sum(temperature_all) / len(temperature_all)
362+
except:
363+
temperature = math.nan
364+
365+
display_gpu_stats(load, memory_percentage, memory_used, temperature)
336366
elif pyadl:
337367
amd_gpus = pyadl.ADLManager.getInstance().getDevices()
338368

339-
load_all = [item.getCurrentUsage() for item in amd_gpus]
340-
load = (sum(load_all) / len(load_all))
341-
342-
temperature_all = [item.getCurrentTemperature() for item in amd_gpus]
343-
temperature = sum(temperature_all) / len(temperature_all)
369+
try:
370+
load_all = [item.getCurrentUsage() for item in amd_gpus]
371+
load = (sum(load_all) / len(load_all))
372+
except:
373+
load = math.nan
374+
375+
try:
376+
temperature_all = [item.getCurrentTemperature() for item in amd_gpus]
377+
temperature = sum(temperature_all) / len(temperature_all)
378+
except:
379+
temperature = math.nan
344380

345381
# Memory absolute (M) and relative (%) usage not supported by pyadl
346382
display_gpu_stats(load, math.nan, math.nan, temperature)

0 commit comments

Comments
 (0)