Cleanup init commit

This commit is contained in:
Extraltodeus
2026-07-13 22:26:50 +02:00
commit 1ff4063282
46 changed files with 12724 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import pynvml
_initialized = False
def _ensure_init():
global _initialized
if not _initialized:
pynvml.nvmlInit()
_initialized = True
def gpu_stats():
_ensure_init()
stats = []
for index in range(pynvml.nvmlDeviceGetCount()):
handle = pynvml.nvmlDeviceGetHandleByIndex(index)
memory = pynvml.nvmlDeviceGetMemoryInfo(handle)
util = pynvml.nvmlDeviceGetUtilizationRates(handle)
name = pynvml.nvmlDeviceGetName(handle)
if isinstance(name, bytes):
name = name.decode()
stats.append(
{
"index": index,
"name": name,
"vram_total": memory.total,
"vram_used": memory.used,
"util_pct": util.gpu,
}
)
return stats