Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable tensorflow for content detection in a production build #2695

Merged
merged 15 commits into from
Jan 4, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ jobs:

- name: Install ffmpeg
if: steps.cache-ffmpeg.outputs.cache-hit != 'true'
run: BUILD_TAGS=experimental ./install_ffmpeg.sh
run: ./install_ffmpeg.sh

- name: Build binaries
run: |
Expand Down
25 changes: 12 additions & 13 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ FROM --platform=$BUILDPLATFORM ubuntu:18.04 as build

ARG TARGETARCH
ARG BUILDARCH
ARG BUILD_TAGS

ENV GOARCH="$TARGETARCH" \
PATH="/usr/local/go/bin:/go/bin:${PATH}" \
PKG_CONFIG_PATH="/root/compiled/lib/pkgconfig" \
CPATH="/usr/local/cuda/include" \
LIBRARY_PATH="/usr/local/cuda/lib64" \
DEBIAN_FRONTEND="noninteractive"
DEBIAN_FRONTEND="noninteractive" \
BUILD_TAGS=${BUILD_TAGS}

RUN apt update \
&& apt install -yqq software-properties-common curl apt-transport-https lsb-release \
Expand All @@ -27,9 +29,13 @@ RUN update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 3
RUN GRPC_HEALTH_PROBE_VERSION=v0.3.6 \
&& curl -fsSL https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-${TARGETARCH} -o /usr/bin/grpc_health_probe \
&& chmod +x /usr/bin/grpc_health_probe \
&& curl -fsSL https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.8.0.tar.gz | tar -C /usr/local -xzf - \
&& ldconfig /usr/local/lib

# note: for runtime, Tensorflow version needs to be compatible with CUDA and CuDNN of the image
RUN LIBTENSORFLOW_VERSION=2.6.3 \
&& curl -LO https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz \
&& mkdir /tf && tar -C /tf -xzf libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz

ENV GOPATH=/go \
GO_BUILD_DIR=/build/ \
GOFLAGS="-mod=readonly"
Expand All @@ -41,7 +47,7 @@ RUN mkdir -p /go \

COPY ./install_ffmpeg.sh ./install_ffmpeg.sh

RUN ./install_ffmpeg.sh \
RUN ./install_ffmpeg.sh \
&& GO111MODULE=on go get -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.25.0 \
&& go get -v github.com/jstemmer/go-junit-report

Expand All @@ -51,24 +57,17 @@ RUN go mod download

COPY . .

ARG BUILD_TAGS
cyberj0g marked this conversation as resolved.
Show resolved Hide resolved
ENV BUILD_TAGS=${BUILD_TAGS}

RUN make livepeer livepeer_cli livepeer_bench livepeer_router

FROM --platform=$TARGETPLATFORM nvidia/cuda:10.1-cudnn7-runtime AS livepeer-amd64-base

FROM --platform=$TARGETPLATFORM nvidia/cuda:11.6.2-cudnn8-runtime-ubuntu20.04 AS livepeer-arm64-base

FROM livepeer-${TARGETARCH}-base
FROM --platform=${TARGETPLATFORM} nvidia/cuda:11.6.2-cudnn8-runtime-ubuntu20.04 AS livepeer-base

ENV NVIDIA_DRIVER_CAPABILITIES=all

COPY --from=build /build/ /usr/local/bin/
COPY --from=build /usr/bin/grpc_health_probe /usr/local/bin/grpc_health_probe
COPY --from=build /src/tasmodel.pb /tasmodel.pb
COPY --from=build /usr/share/misc/pci.ids /usr/share/misc/pci.ids

RUN ldconfig
# libtensorflow.so is required at runtime, because Ffmpeg DNN filter loads it dynamically
COPY --from=build /tf/ /usr/local/
cyberj0g marked this conversation as resolved.
Show resolved Hide resolved

ENTRYPOINT ["/usr/local/bin/livepeer"]
17 changes: 7 additions & 10 deletions install_ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,15 @@ if [[ "$UNAME" == "Darwin" ]]; then
else
# If we have clang, we can compile with CUDA support!
if which clang >/dev/null; then
echo "clang detected, building with GPU support"
echo "clang detected, building with GPU and Tensorflow support"
EXTRA_FFMPEG_FLAGS="$EXTRA_FFMPEG_FLAGS --enable-cuda --enable-cuda-llvm --enable-cuvid --enable-nvenc --enable-decoder=h264_cuvid,hevc_cuvid,vp8_cuvid,vp9_cuvid --enable-filter=scale_cuda,signature_cuda,hwupload_cuda --enable-encoder=h264_nvenc,hevc_nvenc"
if [[ $BUILD_TAGS == *"experimental"* ]]; then
if [[ ! -e "/usr/local/lib/libtensorflow_framework.so" ]]; then
LIBTENSORFLOW_VERSION=2.6.3 &&
curl -LO https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz &&
sudo tar -C /usr/local -xzf libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz &&
rm libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz
fi
echo "experimental tag detected, building with Tensorflow support"
EXTRA_FFMPEG_FLAGS="$EXTRA_FFMPEG_FLAGS --enable-libtensorflow"
if [[ ! -e "${ROOT}/compiled/lib/libtensorflow_framework.so" ]]; then
LIBTENSORFLOW_VERSION=2.6.3 &&
curl -LO https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz &&
tar -C ${ROOT}/compiled/ -xzf libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz &&
rm libtensorflow-gpu-linux-x86_64-${LIBTENSORFLOW_VERSION}.tar.gz
fi
EXTRA_FFMPEG_FLAGS="$EXTRA_FFMPEG_FLAGS --enable-libtensorflow"
fi
fi

Expand Down