Local preservation snapshot, not a new deployment or simulation acceptance.
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""Best-effort scene/resource diagnostics. Never a Gaussian-count admission gate."""
|
|
|
|
import ctypes
|
|
import subprocess
|
|
|
|
|
|
class ScenePreparationError(RuntimeError):
|
|
"""A bounded, operator-readable preparation failure."""
|
|
|
|
|
|
def host_available_bytes():
|
|
class Memory(ctypes.Structure):
|
|
_fields_ = [("length", ctypes.c_ulong), ("load", ctypes.c_ulong)] + [
|
|
(name, ctypes.c_ulonglong) for name in (
|
|
"total", "available", "total_page", "available_page",
|
|
"total_virtual", "available_virtual", "extended")]
|
|
memory = Memory()
|
|
memory.length = ctypes.sizeof(memory)
|
|
if not ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(memory)):
|
|
raise OSError("Memory observation unavailable")
|
|
return memory.available
|
|
|
|
|
|
def capacity_snapshot():
|
|
result = subprocess.run([
|
|
"nvidia-smi", "--query-gpu=memory.free", "--format=csv,noheader,nounits",
|
|
], capture_output=True, text=True, timeout=10, check=True)
|
|
return dict(gpu_free_bytes=int(result.stdout.splitlines()[0].strip()) * 1024**2,
|
|
host_free_bytes=host_available_bytes())
|
|
|
|
|
|
def scene_diagnostics(count, source_bytes):
|
|
value = dict(schema_version="missioncore.scene-diagnostics/v1",
|
|
gaussian_count=count, source_bytes=source_bytes, authority="observation-only")
|
|
try:
|
|
value.update(capacity_snapshot())
|
|
except Exception as exc:
|
|
value["capacity_unavailable"] = type(exc).__name__
|
|
return value
|