Autodetect AMD GPUs for VAAPI GPU stats (#9898)

* Add autodetection logic

* Fix formatting

* Add some explanatory comments

* Actually fix lint
This commit is contained in:
Rob Arnold
2024-02-20 15:21:54 -08:00
committed by GitHub
parent 299511cd9d
commit aa99e11e1a
2 changed files with 28 additions and 5 deletions

View File

@@ -15,7 +15,12 @@ import psutil
import py3nvml.py3nvml as nvml
import 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_characters
logger = 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"]