90d2cf8326
- jarvisChat/JarvisChat/jarvischat → cAIc/cAIc/caic (branded/lower) - JARVISCHAT_ env vars → CAIC_ - jc- script/config prefix → caic- - jarvis_rag → caic_rag - jarvischat.db / volumes → caic.db / caic_* - AMQP vhost/user jarvischat → caic - Syslog, loggers, docstrings all updated - 47 files, zero stale references, 148 tests pass
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""
|
|
cAIc - AMD GPU stats via rocm-smi.
|
|
"""
|
|
import json
|
|
import logging
|
|
import subprocess
|
|
|
|
log = logging.getLogger("caic")
|
|
|
|
|
|
def get_gpu_stats() -> dict:
|
|
try:
|
|
result = subprocess.run(
|
|
["rocm-smi", "--showuse", "--showmemuse", "--json"],
|
|
capture_output=True, text=True, timeout=5,
|
|
)
|
|
if result.returncode == 0:
|
|
data = json.loads(result.stdout)
|
|
gpu_info = data.get("card0", {})
|
|
gpu_use = gpu_info.get("GPU use (%)", 0)
|
|
vram_use = gpu_info.get("GPU Memory Allocated (VRAM%)", 0)
|
|
if isinstance(gpu_use, str):
|
|
gpu_use = int(gpu_use.replace("%", "").strip() or 0)
|
|
if isinstance(vram_use, str):
|
|
vram_use = int(vram_use.replace("%", "").strip() or 0)
|
|
return {"gpu_percent": gpu_use, "vram_percent": vram_use, "available": True}
|
|
except (subprocess.TimeoutExpired, FileNotFoundError, json.JSONDecodeError):
|
|
pass
|
|
except Exception as e:
|
|
log.warning(f"GPU stats error: {e}")
|
|
return {"gpu_percent": 0, "vram_percent": 0, "available": False}
|