Skip to content

Commit 7eebd7d

Browse files
committed
Add GPU Core frequencyr eading from Python libraries
1 parent 181c954 commit 7eebd7d

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

library/sensors/sensors_python.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -275,52 +275,42 @@ class GpuAmd(sensors.Gpu):
275275
def stats() -> Tuple[float, float, float, float]: # load (%) / used mem (%) / used mem (Mb) / temp (°C)
276276
if pyamdgpuinfo:
277277
# Unlike other sensors, AMD GPU with pyamdgpuinfo pulls in all the stats at once
278-
i = 0
279-
amd_gpus = []
280-
while i < pyamdgpuinfo.detect_gpus():
281-
amd_gpus.append(pyamdgpuinfo.get_gpu(i))
282-
i = i + 1
278+
amd_gpu = pyamdgpuinfo.get_gpu(0)
283279

284280
try:
285-
memory_used_all = [item.query_vram_usage() for item in amd_gpus]
286-
memory_used_bytes = sum(memory_used_all) / len(memory_used_all)
281+
memory_used_bytes = amd_gpu.query_vram_usage()
287282
memory_used = memory_used_bytes / 1000000
288283
except:
289284
memory_used_bytes = math.nan
290285
memory_used = math.nan
291286

292287
try:
293-
memory_total_all = [item.memory_info["vram_size"] for item in amd_gpus]
294-
memory_total_bytes = sum(memory_total_all) / len(memory_total_all)
288+
memory_total_bytes = amd_gpu.memory_info["vram_size"]
295289
memory_percentage = (memory_used_bytes / memory_total_bytes) * 100
296290
except:
297291
memory_percentage = math.nan
298292

299293
try:
300-
load_all = [item.query_load() for item in amd_gpus]
301-
load = (sum(load_all) / len(load_all)) * 100
294+
load = amd_gpu.query_load()
302295
except:
303296
load = math.nan
304297

305298
try:
306-
temperature_all = [item.query_temperature() for item in amd_gpus]
307-
temperature = sum(temperature_all) / len(temperature_all)
299+
temperature = amd_gpu.query_temperature()
308300
except:
309301
temperature = math.nan
310302

311303
return load, memory_percentage, memory_used, temperature
312304
elif pyadl:
313-
amd_gpus = pyadl.ADLManager.getInstance().getDevices()
305+
amd_gpu = pyadl.ADLManager.getInstance().getDevices()[0]
314306

315307
try:
316-
load_all = [item.getCurrentUsage() for item in amd_gpus]
317-
load = (sum(load_all) / len(load_all))
308+
load = amd_gpu.getCurrentUsage()
318309
except:
319310
load = math.nan
320311

321312
try:
322-
temperature_all = [item.getCurrentTemperature() for item in amd_gpus]
323-
temperature = sum(temperature_all) / len(temperature_all)
313+
temperature = amd_gpu.getCurrentTemperature()
324314
except:
325315
temperature = math.nan
326316

@@ -348,8 +338,10 @@ def fan_percent() -> float:
348338

349339
@staticmethod
350340
def frequency() -> float:
351-
# Not supported by Python libraries
352-
return math.nan
341+
if pyamdgpuinfo:
342+
return pyamdgpuinfo.get_gpu(0).query_sclk()
343+
elif pyadl:
344+
return pyadl.ADLManager.getInstance().getDevices()[0].getCurrentEngineClock()
353345

354346
@staticmethod
355347
def is_available() -> bool:

0 commit comments

Comments
 (0)