NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Autodetect AMD GPUs for VAAPI GPU stats (#9898)
Rob Arnoldaa99e11e1ab7
diff --git a/frigate/stats.py b/frigate/stats.pyindex c542e8022b..185d532fe8 100644--- a/frigate/stats.py+++ b/frigate/stats.py@@ -14,7 +14,7 @@ from requests.exceptions import RequestExceptionfrom frigate.comms.dispatcher import Dispatcherfrom frigate.config import FrigateConfig-from frigate.const import CACHE_DIR, CLIPS_DIR, DRIVER_AMD, DRIVER_ENV_VAR, RECORD_DIR+from frigate.const import CACHE_DIR, CLIPS_DIR, RECORD_DIRfrom frigate.object_detection import ObjectDetectProcessfrom frigate.types import CameraMetricsTypes, StatsTrackingTypesfrom frigate.util.services import (@@ -24,6 +24,7 @@ from frigate.util.services import (get_intel_gpu_stats,get_jetson_stats,get_nvidia_gpu_stats,+ is_vaapi_amd_driver,)from frigate.version import VERSION@@ -205,9 +206,7 @@ async def set_gpu_stats(stats["intel-qsv"] = {"gpu": -1, "mem": -1}hwaccel_errors.append(args)elif "vaapi" in args:- driver = os.environ.get(DRIVER_ENV_VAR)-- if driver == DRIVER_AMD:+ if is_vaapi_amd_driver():if not config.telemetry.stats.amd_gpu_stats:continuediff --git a/frigate/util/services.py b/frigate/util/services.pyindex 4c22bab2c0..fa86222107 100644--- a/frigate/util/services.py+++ b/frigate/util/services.py@@ -15,7 +15,12 @@ import psutilimport py3nvml.py3nvml as nvmlimport requests-from frigate.const import FFMPEG_HWACCEL_NVIDIA, FFMPEG_HWACCEL_VAAPI+from frigate.const import (+ DRIVER_AMD,+ DRIVER_ENV_VAR,+ FFMPEG_HWACCEL_NVIDIA,+ FFMPEG_HWACCEL_VAAPI,+)from frigate.util.builtin import clean_camera_user_pass, escape_special_characterslogger = logging.getLogger(__name__)@@ -196,6 +201,25 @@ def get_bandwidth_stats(config) -> dict[str, dict]:return usages+def is_vaapi_amd_driver() -> bool:+ # Use the explicitly configured driver, if available+ driver = os.environ.get(DRIVER_ENV_VAR)+ if driver:+ return driver == DRIVER_AMD++ # Otherwise, ask vainfo what is has autodetected+ p = vainfo_hwaccel()++ if p.returncode != 0:+ logger.error(f"Unable to poll vainfo: {p.stderr}")+ return False+ else:+ output = p.stdout.decode("unicode_escape").split("\n")++ # VA Info will print out the friendly name of the driver+ return any("AMD Radeon Graphics" in line for line in output)++def get_amd_gpu_stats() -> dict[str, str]:"""Get stats using radeontop."""radeontop_command = ["radeontop", "-d", "-", "-l", "1"]