"""System information endpoints (GPU hardware).""" from fastapi import APIRouter router = APIRouter(prefix="/api/system", tags=["system"]) @router.post("/gpu-reset") def gpu_reset(): """ Re-enable GPU acceleration for all services without restarting the container. After a CUDA OOM or 'unknown error', the lyric transcriber marks the GPU context as failed and falls back to CPU. The separator may also fail with a CUDA context error. Calling this endpoint clears the CUDA allocation cache and resets the Whisper device flag, so both services can retry on GPU. NOTE: if the CUDA context is truly corrupted (persistent 'unknown error'), a container restart is still required. """ from ..services.lyric_transcriber_service import reset_cuda return reset_cuda() @router.get("/gpu-info") def gpu_info(): """Return GPU name, VRAM figures, and cuda_ok health flag.""" try: from ..services.lyric_transcriber_service import _cuda_ok as whisper_ok except Exception: whisper_ok = True try: import torch # type: ignore if not torch.cuda.is_available(): return {"cuda_available": False, "cuda_ok": whisper_ok, "name": None, "total_mb": 0, "free_mb": 0} props = torch.cuda.get_device_properties(0) free_bytes, total_bytes = torch.cuda.mem_get_info(0) return { "cuda_available": True, "cuda_ok": whisper_ok, "name": props.name, "total_mb": total_bytes // (1024 * 1024), "free_mb": free_bytes // (1024 * 1024), } except Exception as exc: # pragma: no cover return {"cuda_available": False, "cuda_ok": False, "name": None, "total_mb": 0, "free_mb": 0, "error": str(exc)}