Skip to content

Commit

Permalink
Merge pull request #44 from mathoudebine/fix/unsupported-gpu-memory-v…
Browse files Browse the repository at this point in the history
…alues

Fix/unsupported gpu memory values
  • Loading branch information
mathoudebine authored Sep 13, 2022
2 parents f26413f + c9a6475 commit e8897c1
Showing 1 changed file with 87 additions and 65 deletions.
152 changes: 87 additions & 65 deletions library/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,68 +179,90 @@ def temperature():
# TODO: Built in function for *nix in psutil, for Windows can use WMI or a third party library


def display_gpu_stats(load, memory_percentage, memory_used, temperature):
def display_gpu_stats(load, memory_percentage, memory_used_mb, temperature):
if THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("SHOW", False):
# logger.debug(f"GPU Load: {load}")
display.lcd.DisplayProgressBar(
x=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("X", 0),
y=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("Y", 0),
width=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("WIDTH", 0),
height=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("HEIGHT", 0),
value=int(load) if not math.isnan(load) else 0,
min_value=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("MIN_VALUE", 0),
max_value=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("MAX_VALUE", 100),
bar_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BAR_COLOR", (0, 0, 0)),
bar_outline=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BAR_OUTLINE", False),
background_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BACKGROUND_COLOR", (255, 255, 255)),
background_image=get_full_path(THEME_DATA['PATH'],
THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BACKGROUND_IMAGE",
None))
)
if math.isnan(load):
logger.warning("Your GPU load is not supported yet")
THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH']['SHOW'] = False
THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT']['SHOW'] = False
else:
# logger.debug(f"GPU Load: {load}")
display.lcd.DisplayProgressBar(
x=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("X", 0),
y=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("Y", 0),
width=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("WIDTH", 0),
height=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("HEIGHT", 0),
value=int(load),
min_value=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("MIN_VALUE", 0),
max_value=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("MAX_VALUE", 100),
bar_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BAR_COLOR", (0, 0, 0)),
bar_outline=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BAR_OUTLINE", False),
background_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(THEME_DATA['PATH'],
THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BACKGROUND_IMAGE",
None))
)

if THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("SHOW", False):
display.lcd.DisplayText(
text=f"{int(load):>3}%" if not math.isnan(load) else f"{int(0):>3}%",
x=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("X", 0),
y=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("Y", 0),
font=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("FONT", "roboto-mono/RobotoMono-Regular.ttf"),
font_size=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("FONT_SIZE", 10),
font_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("BACKGROUND_COLOR", (255, 255, 255)),
background_image=get_full_path(THEME_DATA['PATH'],
THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("BACKGROUND_IMAGE",
None))
)
if math.isnan(load):
logger.warning("Your GPU load is not supported yet")
THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH']['SHOW'] = False
THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT']['SHOW'] = False
else:
display.lcd.DisplayText(
text=f"{int(load):>3}%",
x=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("X", 0),
y=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("Y", 0),
font=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("FONT", "roboto-mono/RobotoMono-Regular.ttf"),
font_size=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("FONT_SIZE", 10),
font_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(THEME_DATA['PATH'],
THEME_DATA['STATS']['GPU']['PERCENTAGE']['TEXT'].get("BACKGROUND_IMAGE",
None))
)

if THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("SHOW", False):
# logger.debug(f"GPU Load: {load}")
display.lcd.DisplayProgressBar(
x=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("X", 0),
y=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("Y", 0),
width=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("WIDTH", 0),
height=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("HEIGHT", 0),
value=int(memory_percentage),
min_value=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("MIN_VALUE", 0),
max_value=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("MAX_VALUE", 100),
bar_color=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("BAR_COLOR", (0, 0, 0)),
bar_outline=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("BAR_OUTLINE", False),
background_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BACKGROUND_COLOR", (255, 255, 255)),
background_image=get_full_path(THEME_DATA['PATH'],
THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("BACKGROUND_IMAGE", None))
)
if math.isnan(memory_percentage):
logger.warning("Your GPU memory relative usage (%) is not supported yet")
THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH']['SHOW'] = False
else:
display.lcd.DisplayProgressBar(
x=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("X", 0),
y=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("Y", 0),
width=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("WIDTH", 0),
height=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("HEIGHT", 0),
value=int(memory_percentage),
min_value=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("MIN_VALUE", 0),
max_value=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("MAX_VALUE", 100),
bar_color=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("BAR_COLOR", (0, 0, 0)),
bar_outline=THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("BAR_OUTLINE", False),
background_color=THEME_DATA['STATS']['GPU']['PERCENTAGE']['GRAPH'].get("BACKGROUND_COLOR",
(255, 255, 255)),
background_image=get_full_path(THEME_DATA['PATH'],
THEME_DATA['STATS']['GPU']['MEMORY']['GRAPH'].get("BACKGROUND_IMAGE",
None))
)

if THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("SHOW", False):
display.lcd.DisplayText(
text=f"{int(memory_used / 1000000):>5} M",
x=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("X", 0),
y=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("Y", 0),
font=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("FONT", "roboto-mono/RobotoMono-Regular.ttf"),
font_size=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("FONT_SIZE", 10),
font_color=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("BACKGROUND_COLOR", (255, 255, 255)),
background_image=get_full_path(THEME_DATA['PATH'],
THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("BACKGROUND_IMAGE", None))
)
if math.isnan(memory_used_mb):
logger.warning("Your GPU memory absolute usage (M) is not supported yet")
THEME_DATA['STATS']['GPU']['MEMORY']['TEXT']['SHOW'] = False
else:
display.lcd.DisplayText(
text=f"{int(memory_used_mb):>5} M",
x=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("X", 0),
y=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("Y", 0),
font=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("FONT", "roboto-mono/RobotoMono-Regular.ttf"),
font_size=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("FONT_SIZE", 10),
font_color=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("FONT_COLOR", (0, 0, 0)),
background_color=THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("BACKGROUND_COLOR", (255, 255, 255)),
background_image=get_full_path(THEME_DATA['PATH'],
THEME_DATA['STATS']['GPU']['MEMORY']['TEXT'].get("BACKGROUND_IMAGE",
None))
)

if THEME_DATA['STATS']['GPU']['TEMPERATURE']['TEXT'].get("SHOW", False):
display.lcd.DisplayText(
Expand All @@ -265,20 +287,20 @@ def stats():
nvidia_gpus = GPUtil.getGPUs()

memory_used_all = [item.memoryUsed for item in nvidia_gpus]
memory_used = sum(memory_used_all) / len(memory_used_all)
memory_used_mb = sum(memory_used_all) / len(memory_used_all)

memory_total_all = [item.memoryTotal for item in nvidia_gpus]
memory_total = sum(memory_total_all) / len(memory_total_all)
memory_total_mb = sum(memory_total_all) / len(memory_total_all)

memory_percentage = (memory_used / memory_total) * 100
memory_percentage = (memory_used_mb / memory_total_mb) * 100

load_all = [item.load for item in nvidia_gpus]
load = (sum(load_all) / len(load_all)) * 100

temperature_all = [item.temperature for item in nvidia_gpus]
temperature = sum(temperature_all) / len(temperature_all)

display_gpu_stats(load, memory_percentage, memory_used, temperature)
display_gpu_stats(load, memory_percentage, memory_used_mb, temperature)

@staticmethod
def is_available():
Expand All @@ -297,20 +319,20 @@ def stats():
i = i + 1

memory_used_all = [item.query_vram_usage() for item in amd_gpus]
memory_used = sum(memory_used_all) / len(memory_used_all)
memory_used_bytes = sum(memory_used_all) / len(memory_used_all)

memory_total_all = [item.memory_info["vram_size"] for item in amd_gpus]
memory_total = sum(memory_total_all) / len(memory_total_all)
memory_total_bytes = sum(memory_total_all) / len(memory_total_all)

memory_percentage = (memory_used / memory_total) * 100
memory_percentage = (memory_used_bytes / memory_total_bytes) * 100

load_all = [item.query_load() for item in amd_gpus]
load = (sum(load_all) / len(load_all)) * 100

temperature_all = [item.query_temperature() for item in amd_gpus]
temperature = sum(temperature_all) / len(temperature_all)

display_gpu_stats(load, memory_percentage, memory_used, temperature)
display_gpu_stats(load, memory_percentage, memory_used_bytes / 1000000, temperature)
elif pyadl:
amd_gpus = pyadl.ADLManager.getInstance().getDevices()

Expand All @@ -320,8 +342,8 @@ def stats():
temperature_all = [item.getCurrentTemperature() for item in amd_gpus]
temperature = sum(temperature_all) / len(temperature_all)

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

@staticmethod
def is_available():
Expand Down

0 comments on commit e8897c1

Please sign in to comment.