Skip to content

Commit

Permalink
Add GPU Core frequencyr eading from Python libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
mathoudebine committed Mar 3, 2024
1 parent 181c954 commit 7eebd7d
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions library/sensors/sensors_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,52 +275,42 @@ class GpuAmd(sensors.Gpu):
def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / used mem (Mb) / temp (°C)
if pyamdgpuinfo:
# Unlike other sensors, AMD GPU with pyamdgpuinfo pulls in all the stats at once
i = 0
amd_gpus = []
while i < pyamdgpuinfo.detect_gpus():
amd_gpus.append(pyamdgpuinfo.get_gpu(i))
i = i + 1
amd_gpu = pyamdgpuinfo.get_gpu(0)

try:
memory_used_all = [item.query_vram_usage() for item in amd_gpus]
memory_used_bytes = sum(memory_used_all) / len(memory_used_all)
memory_used_bytes = amd_gpu.query_vram_usage()
memory_used = memory_used_bytes / 1000000
except:
memory_used_bytes = math.nan
memory_used = math.nan

try:
memory_total_all = [item.memory_info["vram_size"] for item in amd_gpus]
memory_total_bytes = sum(memory_total_all) / len(memory_total_all)
memory_total_bytes = amd_gpu.memory_info["vram_size"]
memory_percentage = (memory_used_bytes / memory_total_bytes) * 100
except:
memory_percentage = math.nan

try:
load_all = [item.query_load() for item in amd_gpus]
load = (sum(load_all) / len(load_all)) * 100
load = amd_gpu.query_load()
except:
load = math.nan

try:
temperature_all = [item.query_temperature() for item in amd_gpus]
temperature = sum(temperature_all) / len(temperature_all)
temperature = amd_gpu.query_temperature()
except:
temperature = math.nan

return load, memory_percentage, memory_used, temperature
elif pyadl:
amd_gpus = pyadl.ADLManager.getInstance().getDevices()
amd_gpu = pyadl.ADLManager.getInstance().getDevices()[0]

try:
load_all = [item.getCurrentUsage() for item in amd_gpus]
load = (sum(load_all) / len(load_all))
load = amd_gpu.getCurrentUsage()
except:
load = math.nan

try:
temperature_all = [item.getCurrentTemperature() for item in amd_gpus]
temperature = sum(temperature_all) / len(temperature_all)
temperature = amd_gpu.getCurrentTemperature()
except:
temperature = math.nan

Expand Down Expand Up @@ -348,8 +338,10 @@ def fan_percent() -> float:

@staticmethod
def frequency() -> float:
# Not supported by Python libraries
return math.nan
if pyamdgpuinfo:
return pyamdgpuinfo.get_gpu(0).query_sclk()
elif pyadl:
return pyadl.ADLManager.getInstance().getDevices()[0].getCurrentEngineClock()

@staticmethod
def is_available() -> bool:
Expand Down

0 comments on commit 7eebd7d

Please sign in to comment.