mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-08-01 07:19:30 +00:00
Adds a `-tensorrt-jp7` Frigate image for JetPack 7.2 / L4T R39.2 Jetson hosts, built on nvcr.io/nvidia/tensorrt:26.02-py3-igpu (TensorRT 10.11, CUDA 13, py3.12), keeping the existing JP6 path unchanged. ONNX Runtime GPU is built from source (no public aarch64 onnxruntime-gpu wheel), TensorRT-Python branch is selected by the base image, and TensorRT runtime library checks are major-version aware. VALIDATED on a real AGX Orin (L4T R39.2 / nv_tegra_release R39 rev 2.0): - image frigate:test-tensorrt-jp7 builds (rc=0, 16.3GB, sha256:c9e4d382f1603ee130ee4a7315b4f71f9461405e3785707251505e2d6d088df3) - ONNX Runtime 1.25.1 exposes CUDAExecutionProvider, and a real Add-model inference RAN on the iGPU CUDA EP (functional, not just listed) - frigate.util.model.get_ort_providers(False,"AUTO") = [CUDA, CPU] (CUDA first, CPU last, TensorRT EP excluded) -> the ONNX detector GPU-accelerates on JP7 - /etc/TENSORRT_VER = 10.11.0 Native `type: tensorrt` (.trt gen) + the ORT TensorRT EP stay DRAFT-GATED: the L4T R39 host ships NO libnvdla_compiler.so (absent from host AND base image), so `import tensorrt` and libonnxruntime_providers_tensorrt.so fail to load. ONNX detector GPU acceleration is the supported JP7 path; native trt is deferred. Build fixes the new noble/CUDA-13 base surfaced (beyond the plan): - build_nginx.sh: enable deb-src for the deb822 ubuntu.sources (Ubuntu 24.04) - tensorrt_libyolo.sh: strip -lnvToolsExt (removed in CUDA 13) + -lnvparsers (dropped in TensorRT 10) when those libs are absent - docker/main: noble/py3.12 build adjustments (Dockerfile, build_sqlite_vec.sh) Reproducible: `make -C docker/tensorrt ... local-trt-jp7` (JETPACK7_ARGS) on any arm64 builder; built on-device only because the GPU smoke test needs the iGPU.
207 lines
9.2 KiB
Docker
207 lines
9.2 KiB
Docker
# syntax=docker/dockerfile:1.6
|
|
|
|
# https://askubuntu.com/questions/972516/debian-frontend-environment-variable
|
|
ARG DEBIAN_FRONTEND=noninteractive
|
|
ARG BASE_IMAGE
|
|
ARG TRT_BASE=nvcr.io/nvidia/tensorrt:23.12-py3
|
|
ARG BUILD_ONNXRUNTIME_FROM_SOURCE=0
|
|
ARG ONNXRUNTIME_VERSION=1.25.1
|
|
ARG ONNXRUNTIME_BRANCH=rel-1.25.1
|
|
ARG TENSORRT_PYTHON_BRANCH=release/8.6
|
|
ARG L4T_APT_RELEASE=
|
|
ARG JETSON_SOC_REPO=
|
|
|
|
# Build TensorRT-specific library
|
|
FROM ${TRT_BASE} AS trt-deps
|
|
|
|
ARG TARGETARCH
|
|
ARG COMPUTE_LEVEL
|
|
|
|
RUN apt-get update \
|
|
&& TRT_DEV_PACKAGES="git build-essential cuda-nvcc-* cuda-nvtx-* libnvinfer-dev libnvinfer-plugin-dev libnvonnxparsers-dev" \
|
|
&& if apt-cache show libnvparsers-dev > /dev/null 2>&1; then TRT_DEV_PACKAGES="${TRT_DEV_PACKAGES} libnvparsers-dev"; fi \
|
|
&& apt-get install -y ${TRT_DEV_PACKAGES} \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
RUN --mount=type=bind,source=docker/tensorrt/detector/tensorrt_libyolo.sh,target=/tensorrt_libyolo.sh \
|
|
/tensorrt_libyolo.sh
|
|
|
|
# COPY required individual CUDA deps
|
|
RUN mkdir -p /usr/local/cuda-deps
|
|
RUN if [ "$TARGETARCH" = "amd64" ]; then \
|
|
cp /usr/local/cuda-12.3/targets/x86_64-linux/lib/libcurand.so.* /usr/local/cuda-deps/ && \
|
|
cp /usr/local/cuda-12.3/targets/x86_64-linux/lib/libnvrtc.so.* /usr/local/cuda-deps/ && \
|
|
cd /usr/local/cuda-deps/ && \
|
|
for lib in libnvrtc.so.*; do \
|
|
if [[ "$lib" =~ libnvrtc.so\.([0-9]+\.[0-9]+\.[0-9]+) ]]; then \
|
|
version="${BASH_REMATCH[1]}"; \
|
|
ln -sf "libnvrtc.so.$version" libnvrtc.so; \
|
|
fi; \
|
|
done && \
|
|
for lib in libcurand.so.*; do \
|
|
if [[ "$lib" =~ libcurand.so\.([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) ]]; then \
|
|
version="${BASH_REMATCH[1]}"; \
|
|
ln -sf "libcurand.so.$version" libcurand.so; \
|
|
fi; \
|
|
done; \
|
|
fi
|
|
|
|
# Frigate w/ TensorRT Support as separate image
|
|
FROM deps AS tensorrt-base
|
|
|
|
#Disable S6 Global timeout
|
|
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
|
|
|
|
# COPY TensorRT Model Generation Deps
|
|
COPY --from=trt-deps /usr/local/lib/libyolo_layer.so /usr/local/lib/libyolo_layer.so
|
|
COPY --from=trt-deps /usr/local/src/tensorrt_demos /usr/local/src/tensorrt_demos
|
|
|
|
# COPY Individual CUDA deps folder
|
|
COPY --from=trt-deps /usr/local/cuda-deps /usr/local/cuda
|
|
|
|
COPY docker/tensorrt/detector/rootfs/ /
|
|
ENV YOLO_MODELS=""
|
|
|
|
HEALTHCHECK --start-period=600s --start-interval=5s --interval=15s --timeout=5s --retries=3 \
|
|
CMD curl --fail --silent --show-error http://127.0.0.1:5000/api/version || exit 1
|
|
|
|
FROM ${BASE_IMAGE} AS build-wheels
|
|
ARG DEBIAN_FRONTEND
|
|
ARG BUILD_ONNXRUNTIME_FROM_SOURCE
|
|
ARG ONNXRUNTIME_VERSION
|
|
ARG ONNXRUNTIME_BRANCH
|
|
ARG TENSORRT_PYTHON_BRANCH
|
|
ARG L4T_APT_RELEASE
|
|
ARG JETSON_SOC_REPO
|
|
|
|
# Add deadsnakes PPA for python3.11
|
|
RUN apt-get -qq update && \
|
|
apt-get -qq install -y --no-install-recommends \
|
|
software-properties-common \
|
|
&& add-apt-repository ppa:deadsnakes/ppa
|
|
|
|
# Use a separate container to build wheels to prevent build dependencies in final image
|
|
RUN apt-get -qq update \
|
|
&& apt-get -qq install -y --no-install-recommends \
|
|
python3.11 python3.11-dev \
|
|
wget curl build-essential cmake git ninja-build \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Ensure python3 defaults to python3.11
|
|
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
|
|
|
|
# --ignore-installed: on the JP7 Ubuntu 24.04 (noble) base the deadsnakes python3.11 ships a
|
|
# distro-packaged pip 24.0 with no RECORD file, so get-pip.py's default reinstall fails with
|
|
# "uninstall-no-record-file". Installing over it without uninstalling avoids that; harmless on JP6.
|
|
RUN wget -q https://bootstrap.pypa.io/get-pip.py -O get-pip.py \
|
|
&& sed -i 's/args.append("setuptools")/args.append("setuptools==77.0.3")/' get-pip.py \
|
|
&& python3 get-pip.py --ignore-installed "pip"
|
|
|
|
FROM build-wheels AS trt-wheels
|
|
ARG DEBIAN_FRONTEND
|
|
ARG TARGETARCH
|
|
ARG BUILD_ONNXRUNTIME_FROM_SOURCE
|
|
ARG ONNXRUNTIME_VERSION
|
|
ARG ONNXRUNTIME_BRANCH
|
|
ARG TENSORRT_PYTHON_BRANCH
|
|
|
|
# python-tensorrt build deps are 3.4 GB!
|
|
RUN apt-get update \
|
|
&& TRT_DEV_PACKAGES="ccache cuda-cudart-dev-* cuda-nvcc-* libnvonnxparsers-dev libnvinfer-plugin-dev" \
|
|
&& if apt-cache show libnvparsers-dev > /dev/null 2>&1; then TRT_DEV_PACKAGES="${TRT_DEV_PACKAGES} libnvparsers-dev"; fi \
|
|
&& apt-get install -y ${TRT_DEV_PACKAGES} \
|
|
&& ([ -e /usr/local/cuda ] || ln -s /usr/local/cuda-* /usr/local/cuda) \
|
|
&& rm -rf /var/lib/apt/lists/*;
|
|
|
|
# The JP7 base image ships a stale cmake 3.24 at /usr/local/bin/cmake that shadows apt's 3.28.
|
|
# TensorRT 10.11's python CMakeLists (and the ONNX Runtime source build) require cmake >= 3.27,
|
|
# so install a current cmake from pip into /usr/local/bin ahead of the stale one. No-op risk on
|
|
# JP6 where the bundled cmake already satisfies the minimum.
|
|
RUN pip3 install --no-cache-dir --upgrade "cmake>=3.27"
|
|
|
|
# Determine version of tensorrt already installed in base image, e.g. "Version: 8.4.1-1+cuda11.4"
|
|
RUN NVINFER_VER="$(dpkg-query -W -f='${Version}\n' 'libnvinfer*' 2>/dev/null | grep -E '^[0-9]+[.][0-9]+[.][0-9]+' | sort -V | tail -n1)" \
|
|
&& test -n "$NVINFER_VER" \
|
|
&& TENSORRT_VER="$(echo "$NVINFER_VER" | grep -Eo '^[0-9]+[.][0-9]+[.][0-9]+')" \
|
|
&& TENSORRT_MAJOR="$(echo "$TENSORRT_VER" | cut -d. -f1)" \
|
|
&& echo "$TENSORRT_VER" > /etc/TENSORRT_VER \
|
|
&& echo "$TENSORRT_MAJOR" > /etc/TENSORRT_MAJOR
|
|
|
|
RUN --mount=type=bind,source=docker/tensorrt/detector/build_python_tensorrt.sh,target=/deps/build_python_tensorrt.sh \
|
|
--mount=type=cache,target=/root/.ccache \
|
|
export PATH="/usr/lib/ccache:$PATH" CCACHE_DIR=/root/.ccache CCACHE_MAXSIZE=2G \
|
|
&& TENSORRT_VER=$(cat /etc/TENSORRT_VER) TENSORRT_PYTHON_BRANCH="${TENSORRT_PYTHON_BRANCH}" /deps/build_python_tensorrt.sh
|
|
|
|
COPY docker/tensorrt/requirements-arm64.txt /requirements-tensorrt.txt
|
|
|
|
RUN pip3 wheel --wheel-dir=/trt-wheels -r /requirements-tensorrt.txt
|
|
|
|
# See https://elinux.org/Jetson_Zoo#ONNX_Runtime
|
|
RUN --mount=type=bind,source=docker/tensorrt/detector/build_onnxruntime_arm64.sh,target=/deps/build_onnxruntime_arm64.sh \
|
|
mkdir -p /trt-wheels \
|
|
&& if [ "${BUILD_ONNXRUNTIME_FROM_SOURCE}" = "1" ]; then \
|
|
ONNXRUNTIME_VERSION="${ONNXRUNTIME_VERSION}" ONNXRUNTIME_BRANCH="${ONNXRUNTIME_BRANCH}" /deps/build_onnxruntime_arm64.sh; \
|
|
else \
|
|
wget -q https://nvidia.box.com/shared/static/9yvw05k6u343qfnkhdv2x6xhygze0aq1.whl -O /trt-wheels/onnxruntime_gpu-1.19.0-cp311-cp311-linux_aarch64.whl; \
|
|
fi
|
|
|
|
FROM build-wheels AS trt-model-wheels
|
|
ARG DEBIAN_FRONTEND
|
|
|
|
RUN apt-get update \
|
|
&& apt-get install -y protobuf-compiler libprotobuf-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
RUN --mount=type=bind,source=docker/tensorrt/requirements-models-arm64.txt,target=/requirements-tensorrt-models.txt \
|
|
pip3 wheel --wheel-dir=/trt-model-wheels --no-deps -r /requirements-tensorrt-models.txt
|
|
|
|
FROM wget AS jetson-ffmpeg
|
|
ARG DEBIAN_FRONTEND
|
|
ARG L4T_APT_RELEASE
|
|
ARG JETSON_SOC_REPO
|
|
ENV CCACHE_DIR /root/.ccache
|
|
ENV CCACHE_MAXSIZE 2G
|
|
RUN --mount=type=bind,source=docker/tensorrt/build_jetson_ffmpeg.sh,target=/deps/build_jetson_ffmpeg.sh \
|
|
--mount=type=cache,target=/root/.ccache \
|
|
L4T_APT_RELEASE="${L4T_APT_RELEASE}" JETSON_SOC_REPO="${JETSON_SOC_REPO}" /deps/build_jetson_ffmpeg.sh
|
|
|
|
# Frigate w/ TensorRT for NVIDIA Jetson platforms
|
|
FROM tensorrt-base AS frigate-tensorrt
|
|
RUN apt-get update \
|
|
&& pick_package() { for package in "$@"; do if apt-cache show "$package" > /dev/null 2>&1; then echo "$package"; return 0; fi; done; return 1; } \
|
|
&& PROTOBUF_RUNTIME="$(pick_package libprotobuf23 libprotobuf32t64 libprotobuf32)" \
|
|
&& apt-get install -y python-is-python3 "${PROTOBUF_RUNTIME}" \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
COPY --from=jetson-ffmpeg /rootfs /
|
|
ENV DEFAULT_FFMPEG_VERSION="jetson"
|
|
ENV INCLUDED_FFMPEG_VERSIONS="${DEFAULT_FFMPEG_VERSION}:${INCLUDED_FFMPEG_VERSIONS}"
|
|
|
|
# ffmpeg runtime dependencies
|
|
RUN apt-get -qq update \
|
|
&& pick_package() { for package in "$@"; do if apt-cache show "$package" > /dev/null 2>&1; then echo "$package"; return 0; fi; done; return 1; } \
|
|
&& X264_RUNTIME="$(pick_package libx264-163 libx264-164)" \
|
|
&& X265_RUNTIME="$(pick_package libx265-199 libx265-209)" \
|
|
&& apt-get -qq install -y --no-install-recommends \
|
|
"${X264_RUNTIME}" "${X265_RUNTIME}" libegl1 \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Fixes "Error loading shared libs"
|
|
RUN mkdir -p /etc/ld.so.conf.d && echo /usr/lib/ffmpeg/jetson/lib/ > /etc/ld.so.conf.d/ffmpeg.conf
|
|
|
|
COPY --from=trt-wheels /etc/TENSORRT_VER /etc/TENSORRT_VER
|
|
COPY --from=trt-wheels /etc/TENSORRT_MAJOR /etc/TENSORRT_MAJOR
|
|
RUN --mount=type=bind,from=trt-wheels,source=/trt-wheels,target=/deps/trt-wheels \
|
|
--mount=type=bind,from=trt-model-wheels,source=/trt-model-wheels,target=/deps/trt-model-wheels \
|
|
pip3 uninstall -y onnxruntime \
|
|
# --ignore-installed: on the noble JP7 base, `-U` would try to upgrade distro-managed deps that
|
|
# lack a RECORD file (e.g. wheel/setuptools), failing with "uninstall-no-record-file". Install
|
|
# the TRT/ORT GPU wheels over them into /usr/local instead. Harmless on JP6.
|
|
&& pip3 install -U --ignore-installed /deps/trt-wheels/*.whl \
|
|
&& pip3 install -U --ignore-installed /deps/trt-model-wheels/*.whl \
|
|
&& ldconfig
|
|
|
|
WORKDIR /opt/frigate/
|
|
COPY --from=rootfs / /
|
|
|
|
# Fixes "Error importing detector runtime: /usr/lib/aarch64-linux-gnu/libstdc++.so.6: cannot allocate memory in static TLS block"
|
|
ENV LD_PRELOAD /usr/lib/aarch64-linux-gnu/libstdc++.so.6
|