@mytec: iter3.7.0 start, gpu calc int
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from contextlib import asynccontextmanager
|
||||
import logging
|
||||
import platform
|
||||
|
||||
from fastapi import FastAPI, WebSocket
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@@ -7,9 +9,54 @@ from app.core.database import connect_to_mongo, close_mongo_connection
|
||||
from app.api.routes import health, projects, terrain, coverage, regions, system, gpu
|
||||
from app.api.websocket import websocket_endpoint
|
||||
|
||||
logger = logging.getLogger("rfcp.startup")
|
||||
|
||||
|
||||
def check_gpu_availability():
|
||||
"""Log GPU status on startup for debugging."""
|
||||
is_wsl = "microsoft" in platform.release().lower()
|
||||
env_note = " (WSL2)" if is_wsl else ""
|
||||
|
||||
# Check CuPy / CUDA
|
||||
try:
|
||||
import cupy as cp
|
||||
device_count = cp.cuda.runtime.getDeviceCount()
|
||||
if device_count > 0:
|
||||
props = cp.cuda.runtime.getDeviceProperties(0)
|
||||
name = props["name"]
|
||||
if isinstance(name, bytes):
|
||||
name = name.decode()
|
||||
mem_mb = props["totalGlobalMem"] // (1024 * 1024)
|
||||
logger.info(f"GPU detected{env_note}: {name} ({mem_mb} MB VRAM)")
|
||||
logger.info(f"CuPy {cp.__version__}, CUDA devices: {device_count}")
|
||||
else:
|
||||
logger.warning(f"CuPy installed but no CUDA devices found{env_note}")
|
||||
except Exception as e:
|
||||
logger.warning(f"CuPy FAILED {env_note}: {e}")
|
||||
if is_wsl:
|
||||
logger.warning("Install: pip3 install cupy-cuda12x --break-system-packages")
|
||||
else:
|
||||
logger.warning("Install: pip install cupy-cuda12x")
|
||||
except Exception as e:
|
||||
logger.warning(f"CuPy error{env_note}: {e}")
|
||||
|
||||
# Check PyOpenCL
|
||||
try:
|
||||
import pyopencl as cl
|
||||
platforms = cl.get_platforms()
|
||||
for p in platforms:
|
||||
for d in p.get_devices():
|
||||
logger.info(f"OpenCL device: {d.name.strip()}")
|
||||
except Exception as e:
|
||||
logger.debug("PyOpenCL not installed (optional)")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Log GPU status on startup
|
||||
check_gpu_availability()
|
||||
await connect_to_mongo()
|
||||
yield
|
||||
await close_mongo_connection()
|
||||
|
||||
Reference in New Issue
Block a user