detectors/rocm: automatically override HSA_OVERRIDE_GFX_VERSION for couple of known chipsets

This commit is contained in:
Indrek Mandre 2024-02-04 15:32:08 +02:00
parent 77fc38c84f
commit 24cae6de47
2 changed files with 35 additions and 1 deletions

View File

@ -2,6 +2,13 @@
# shellcheck shell=bash
# Compile YoloV8 ONNX files into ROCm MIGraphX files
OVERRIDE=$(cd /opt/frigate && python3 -c 'import frigate.detectors.plugins.rocm as rocm; print(rocm.auto_override_gfx_version())')
if ! test -z "$OVERRIDE"; then
echo "Using HSA_OVERRIDE_GFX_VERSION=${OVERRIDE}"
export HSA_OVERRIDE_GFX_VERSION=$OVERRIDE
fi
for onnx in /config/model_cache/yolov8/*.onnx
do
mxr="${onnx%.onnx}.mxr"

View File

@ -7,7 +7,7 @@ import ctypes
from pydantic import Field
from typing_extensions import Literal
import glob
import cv2
import subprocess
from frigate.detectors.detection_api import DetectionApi
from frigate.detectors.detector_config import BaseDetectorConfig
@ -18,14 +18,41 @@ logger = logging.getLogger(__name__)
DETECTOR_KEY = "rocm"
def detect_gfx_version():
return subprocess.getoutput("unset HSA_OVERRIDE_GFX_VERSION && /opt/rocm/bin/rocminfo | grep gfx |head -1|awk '{print $2}'")
def auto_override_gfx_version():
# If environment varialbe already in place, do not override
gfx_version = detect_gfx_version()
old_override = os.getenv('HSA_OVERRIDE_GFX_VERSION')
if old_override not in (None, ''):
logger.warning(f"AMD/ROCm: detected {gfx_version} but HSA_OVERRIDE_GFX_VERSION already present ({old_override}), not overriding!")
return old_override
mapping = {
'gfx90c': '9.0.0',
'gfx1031': '10.3.0',
'gfx1103': '11.0.0',
}
override = mapping.get(gfx_version)
if override is not None:
logger.warning(f"AMD/ROCm: detected {gfx_version}, overriding HSA_OVERRIDE_GFX_VERSION={override}")
os.putenv('HSA_OVERRIDE_GFX_VERSION', override)
return override
return ''
class ROCmDetectorConfig(BaseDetectorConfig):
type: Literal[DETECTOR_KEY]
conserve_cpu: bool = Field(default=True, title="Conserve CPU at the expense of latency (and reduced max throughput)")
auto_override_gfx: bool = Field(default=True, title="Automatically detect and override gfx version")
class ROCmDetector(DetectionApi):
type_key = DETECTOR_KEY
def __init__(self, detector_config: ROCmDetectorConfig):
if detector_config.auto_override_gfx:
auto_override_gfx_version()
try:
sys.path.append("/opt/rocm/lib")
import migraphx