mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-08-02 09:02:15 +03:00
Improve Intel Stats (#23190)
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / AMD64 Extra Build (push) Blocked by required conditions
* Implement per intel-gpu stats collection * Improve device naming * Improve GPU vendor handling * Cleanup
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
"""Resolve human-readable names for Intel GPUs via OpenVINO."""
|
||||
|
||||
import logging
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IntelGpuNameResolver:
|
||||
"""Build a pdev -> normalized device name map by enumerating OpenVINO GPUs.
|
||||
|
||||
The lookup is performed once on first access and cached for the process
|
||||
lifetime. OpenVINO exposes DEVICE_PCI_INFO (domain/bus/device/function) and
|
||||
FULL_DEVICE_NAME for each GPU it can see, which is enough to associate the
|
||||
name with the pdev string used by DRM fdinfo.
|
||||
"""
|
||||
|
||||
_names: Optional[dict[str, str]] = None
|
||||
|
||||
def get_names(self) -> dict[str, str]:
|
||||
if self._names is not None:
|
||||
return self._names
|
||||
|
||||
names: dict[str, str] = {}
|
||||
|
||||
try:
|
||||
from openvino import Core
|
||||
except ImportError:
|
||||
logger.debug("OpenVINO unavailable; cannot resolve Intel GPU names")
|
||||
self._names = names
|
||||
return names
|
||||
|
||||
try:
|
||||
core = Core()
|
||||
devices = core.available_devices
|
||||
except Exception as exc:
|
||||
logger.debug(f"OpenVINO Core initialization failed: {exc}")
|
||||
self._names = names
|
||||
return names
|
||||
|
||||
cpu_name: Optional[str] = None
|
||||
if "CPU" in devices:
|
||||
try:
|
||||
cpu_name = self._strip_trademarks(
|
||||
core.get_property("CPU", "FULL_DEVICE_NAME")
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.debug(f"Failed to read CPU FULL_DEVICE_NAME: {exc}")
|
||||
|
||||
for device in devices:
|
||||
if not device.startswith("GPU"):
|
||||
continue
|
||||
|
||||
try:
|
||||
pci = core.get_property(device, "DEVICE_PCI_INFO")
|
||||
raw_name = core.get_property(device, "FULL_DEVICE_NAME")
|
||||
device_type = core.get_property(device, "DEVICE_TYPE")
|
||||
except Exception as exc:
|
||||
logger.debug(f"Failed to read properties for {device}: {exc}")
|
||||
continue
|
||||
|
||||
pdev = self._format_pdev(pci)
|
||||
if not pdev:
|
||||
continue
|
||||
|
||||
names[pdev] = self._resolve_name(raw_name, device_type, cpu_name)
|
||||
|
||||
self._names = names
|
||||
return names
|
||||
|
||||
@staticmethod
|
||||
def _format_pdev(pci) -> Optional[str]:
|
||||
try:
|
||||
return f"{pci.domain:04x}:{pci.bus:02x}:{pci.device:02x}.{pci.function:x}"
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def _resolve_name(cls, raw_name: str, device_type, cpu_name: Optional[str]) -> str:
|
||||
"""Build a display name for a GPU.
|
||||
|
||||
Modern integrated Intel GPUs are reported by OpenVINO with a generic
|
||||
FULL_DEVICE_NAME like "Intel(R) Graphics (iGPU)" that gives no model
|
||||
information. Since the iGPU is part of the CPU on these platforms, fall
|
||||
back to the CPU name (which OpenVINO does report specifically) and
|
||||
suffix it with "iGPU" so it's clear what the entry is.
|
||||
"""
|
||||
is_integrated = "INTEGRATED" in str(device_type).upper()
|
||||
|
||||
if is_integrated and cpu_name:
|
||||
short_cpu = re.sub(r"^Intel\s+", "", cpu_name)
|
||||
return f"{short_cpu} iGPU"
|
||||
|
||||
return cls._normalize_name(raw_name)
|
||||
|
||||
@classmethod
|
||||
def _normalize_name(cls, name: str) -> str:
|
||||
cleaned = cls._strip_trademarks(name)
|
||||
cleaned = re.sub(r"\s*\((?:i|d)GPU\)\s*$", "", cleaned, flags=re.IGNORECASE)
|
||||
return " ".join(cleaned.split())
|
||||
|
||||
@staticmethod
|
||||
def _strip_trademarks(name: str) -> str:
|
||||
cleaned = re.sub(r"\(R\)|\(TM\)", "", name)
|
||||
return " ".join(cleaned.split())
|
||||
|
||||
|
||||
intel_gpu_name_resolver = IntelGpuNameResolver()
|
||||
+16
-11
@@ -230,6 +230,7 @@ async def set_gpu_stats(
|
||||
hwaccel_args.append(args)
|
||||
|
||||
stats: dict[str, dict] = {}
|
||||
intel_gpu_collected = False
|
||||
|
||||
for args in hwaccel_args:
|
||||
if args in hwaccel_errors:
|
||||
@@ -242,6 +243,7 @@ async def set_gpu_stats(
|
||||
if nvidia_usage:
|
||||
for i in range(len(nvidia_usage)):
|
||||
stats[nvidia_usage[i]["name"]] = {
|
||||
"vendor": "nvidia",
|
||||
"gpu": str(round(float(nvidia_usage[i]["gpu"]), 2)) + "%",
|
||||
"mem": str(round(float(nvidia_usage[i]["mem"]), 2)) + "%",
|
||||
"enc": str(round(float(nvidia_usage[i]["enc"]), 2)) + "%",
|
||||
@@ -250,31 +252,34 @@ async def set_gpu_stats(
|
||||
}
|
||||
|
||||
else:
|
||||
stats["nvidia-gpu"] = {"gpu": "", "mem": ""}
|
||||
stats["nvidia-gpu"] = {"vendor": "nvidia", "gpu": "", "mem": ""}
|
||||
hwaccel_errors.append(args)
|
||||
elif "nvmpi" in args or "jetson" in args:
|
||||
# nvidia Jetson
|
||||
jetson_usage = get_jetson_stats()
|
||||
|
||||
if jetson_usage:
|
||||
stats["jetson-gpu"] = jetson_usage
|
||||
stats["jetson-gpu"] = {"vendor": "nvidia", **jetson_usage}
|
||||
else:
|
||||
stats["jetson-gpu"] = {"gpu": "", "mem": ""}
|
||||
stats["jetson-gpu"] = {"vendor": "nvidia", "gpu": "", "mem": ""}
|
||||
hwaccel_errors.append(args)
|
||||
elif "qsv" in args or ("vaapi" in args and not is_vaapi_amd_driver()):
|
||||
if not config.telemetry.stats.intel_gpu_stats:
|
||||
continue
|
||||
|
||||
if "intel-gpu" not in stats:
|
||||
if not intel_gpu_collected:
|
||||
# intel GPU (QSV or VAAPI both use the same physical GPU)
|
||||
intel_gpu_collected = True
|
||||
intel_usage = get_intel_gpu_stats(
|
||||
config.telemetry.stats.intel_gpu_device
|
||||
)
|
||||
|
||||
if intel_usage is not None:
|
||||
stats["intel-gpu"] = intel_usage or {"gpu": "", "mem": ""}
|
||||
if intel_usage:
|
||||
for entry in intel_usage.values():
|
||||
name = entry.pop("name")
|
||||
stats[name] = entry
|
||||
else:
|
||||
stats["intel-gpu"] = {"gpu": "", "mem": ""}
|
||||
stats["intel-gpu"] = {"vendor": "intel", "gpu": "", "mem": ""}
|
||||
hwaccel_errors.append(args)
|
||||
elif "vaapi" in args:
|
||||
if not config.telemetry.stats.amd_gpu_stats:
|
||||
@@ -284,18 +289,18 @@ async def set_gpu_stats(
|
||||
amd_usage = get_amd_gpu_stats()
|
||||
|
||||
if amd_usage:
|
||||
stats["amd-vaapi"] = amd_usage
|
||||
stats["amd-vaapi"] = {"vendor": "amd", **amd_usage}
|
||||
else:
|
||||
stats["amd-vaapi"] = {"gpu": "", "mem": ""}
|
||||
stats["amd-vaapi"] = {"vendor": "amd", "gpu": "", "mem": ""}
|
||||
hwaccel_errors.append(args)
|
||||
elif "preset-rk" in args:
|
||||
rga_usage = get_rockchip_gpu_stats()
|
||||
|
||||
if rga_usage:
|
||||
stats["rockchip"] = rga_usage
|
||||
stats["rockchip"] = {"vendor": "rockchip", **rga_usage}
|
||||
elif "v4l2m2m" in args or "rpi" in args:
|
||||
# RPi v4l2m2m is currently not able to get usage stats
|
||||
stats["rpi-v4l2m2m"] = {"gpu": "", "mem": ""}
|
||||
stats["rpi-v4l2m2m"] = {"vendor": "rpi", "gpu": "", "mem": ""}
|
||||
|
||||
if stats:
|
||||
all_stats["gpu_usages"] = stats
|
||||
|
||||
Reference in New Issue
Block a user