Skip to content

Commit

Permalink
Change scale_cuda to scale_npp
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko committed Sep 12, 2023
1 parent a3e725c commit d725d0e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 140 deletions.
135 changes: 21 additions & 114 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
linux-build:
name: Build binaries for ${{ matrix.platform.name }}-${{ matrix.arch }}
runs-on: ${{ matrix.platform.runner }}
container:
image: leszko/cuda:11.7.1-cudnn8-devel-ubuntu20.04-all
env:
DEBIAN_FRONTEND: noninteractive
strategy:
fail-fast: false
matrix:
Expand All @@ -35,10 +39,10 @@ jobs:
steps:
- name: Setup ubuntu container
run: |
sudo apt update
sudo apt install -yqq build-essential make software-properties-common
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt update && sudo apt install -yqq git zip unzip zlib1g-dev zlib1g
apt update
apt install -yqq build-essential make software-properties-common
add-apt-repository -y ppa:git-core/ppa
apt update && apt install -yqq git zip unzip zlib1g-dev zlib1g yasm
- name: Check out code
uses: actions/[email protected]
Expand All @@ -48,10 +52,6 @@ jobs:
# for ref value discussion
ref: ${{ github.event.pull_request.head.sha }}

- name: Cleanup hosted runner
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android
- name: Set up go
id: go
uses: actions/setup-go@v4
Expand All @@ -74,21 +74,25 @@ jobs:
echo "GOARCH=${{ matrix.arch }}" >> $GITHUB_ENV
echo "GOOS=${{ matrix.platform.name }}" >> $GITHUB_ENV
echo "GO_BUILD_DIR=lp-builds/" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=/github/home/compiled/lib/pkgconfig" >> $GITHUB_ENV
echo "CPATH=/usr/local/cuda_${{ matrix.arch }}/include" >> $GITHUB_ENV
echo "LIBRARY_PATH=/usr/local/cuda_${{ matrix.arch }}/lib64" >> $GITHUB_ENV
echo "CGO_LDFLAGS=-L/usr/local/cuda_${{ matrix.arch }}/lib64" >> $GITHUB_ENV
- name: Install dependencies
run: |
sudo apt update \
&& sudo apt install -yqq software-properties-common curl apt-transport-https lsb-release \
&& curl -fsSl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - \
&& sudo add-apt-repository "deb https://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-12 main" \
&& sudo apt update \
&& sudo apt -yqq install \
apt update \
&& apt install -yqq software-properties-common curl apt-transport-https lsb-release \
&& curl -fsSl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
&& add-apt-repository "deb https://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-12 main" \
&& apt update \
&& apt -yqq install \
clang-12 clang-tools-12 lld-12 build-essential pkg-config autoconf git python \
gcc-multilib gcc-mingw-w64 libgcc-9-dev-arm64-cross mingw-w64-tools gcc-mingw-w64-x86-64
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 30 \
&& sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 30 \
&& sudo update-alternatives --install /usr/bin/ld ld /usr/bin/lld-12 30
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 30 \
&& update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 30 \
&& update-alternatives --install /usr/bin/ld ld /usr/bin/lld-12 30
- name: Install go modules
if: steps.go.outputs.cache-hit != 'true'
Expand All @@ -101,7 +105,6 @@ jobs:
- name: Build binaries
env:
GHA_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
PKG_CONFIG_PATH: "/home/runner/compiled/lib/pkgconfig"
run: |
git config --global --add safe.directory '*'
./ci_env.sh make
Expand Down Expand Up @@ -224,101 +227,6 @@ jobs:
- name: Notify new build upload
run: curl -X POST https://holy-bread-207a.livepeer.workers.dev

linux-tensorflow:
name: Build binaries for linux using tensorflow
runs-on: ubuntu-20.04

steps:
- name: Setup ubuntu container
run: |
sudo apt update
sudo apt install -yqq build-essential make software-properties-common
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt update && sudo apt install -yqq git zip unzip zlib1g-dev zlib1g coreutils binutils libc++-dev libc++abi-dev libtool p7zip-full mediainfo xz-utils
- name: Check out code
uses: actions/[email protected]
with:
fetch-depth: 0
# Check https://github.com/livepeer/go-livepeer/pull/1891
# for ref value discussion
ref: ${{ github.event.pull_request.head.sha }}

- name: Cleanup hosted runner
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android
- name: Set up go
id: go
uses: actions/setup-go@v4
with:
go-version: 1.20.4
cache: true
cache-dependency-path: go.sum

- name: Cache ffmpeg
id: cache-ffmpeg
uses: actions/cache@v3
with:
path: /home/runner/compiled
key: ${{ runner.os }}-ffmpeg-tf-${{ hashFiles('**/install_ffmpeg.sh') }}
restore-keys: |
${{ runner.os }}-ffmpeg-tf-
- name: Install dependencies
env:
LIBTENSORFLOW_VERSION: "2.12.1"
run: |
sudo apt update \
&& sudo apt install -yqq software-properties-common curl apt-transport-https lsb-release \
&& curl -fsSl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - \
&& sudo add-apt-repository "deb https://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-12 main" \
&& sudo apt update \
&& sudo apt -yqq install clang-12 clang-tools-12 lld-12 build-essential pkg-config autoconf git python
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 30 \
&& sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 30 \
&& sudo update-alternatives --install /usr/bin/ld ld /usr/bin/lld-12 30
sudo 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 \
&& sudo ldconfig
- name: Install go modules
# if: steps.go.outputs.cache-hit != 'true'
run: go mod download

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

- name: Build binaries
env:
GHA_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
PKG_CONFIG_PATH: "/home/runner/compiled/lib/pkgconfig"
run: |
git config --global --add safe.directory '*'
./ci_env.sh make cgo_cflags="-lz" all
rm -rf ~/build && mkdir ~/build && mv livepeer* ~/build/
- name: Upload build
run: cp ~/build/* . && ./upload_build.sh
env:
GHA_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
GCLOUD_KEY: ${{ secrets.GCLOUD_KEY }}
GCLOUD_SECRET: ${{ secrets.GCLOUD_SECRET }}
DISCORD_URL: ${{ secrets.DISCORD_URL }}
RELEASE_TAG: "tensorflow"

- name: Upload artifacts for cutting release
uses: actions/upload-artifact@master
with:
name: release-artifacts
path: releases/

- name: Notify new build upload
run: curl -X POST https://holy-bread-207a.livepeer.workers.dev

upload:
name: Upload artifacts to google bucket
permissions:
Expand All @@ -328,7 +236,6 @@ jobs:
needs:
- macos-build
- linux-build
- linux-tensorflow
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ endif
.PHONY: livepeer livepeer_bench livepeer_cli livepeer_router docker

livepeer:
GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags)" go build -o $(GO_BUILD_DIR) -tags "$(BUILD_TAGS)" -ldflags="$(ldflags)" cmd/livepeer/*.go
GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags) ${CGO_LDFLAGS}" go build -o $(GO_BUILD_DIR) -tags "$(BUILD_TAGS)" -ldflags="$(ldflags)" cmd/livepeer/*.go

livepeer_cli:
GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags)" go build -o $(GO_BUILD_DIR) -tags "$(BUILD_TAGS)" -ldflags="$(ldflags)" cmd/livepeer_cli/*.go
GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags) ${CGO_LDFLAGS}" go build -o $(GO_BUILD_DIR) -tags "$(BUILD_TAGS)" -ldflags="$(ldflags)" cmd/livepeer_cli/*.go

livepeer_bench:
GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags)" go build -o $(GO_BUILD_DIR) -ldflags="$(ldflags)" cmd/livepeer_bench/*.go
GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags) ${CGO_LDFLAGS}" go build -o $(GO_BUILD_DIR) -ldflags="$(ldflags)" cmd/livepeer_bench/*.go

livepeer_router:
GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags)" go build -o $(GO_BUILD_DIR) -ldflags="$(ldflags)" cmd/livepeer_router/*.go
GO111MODULE=on CGO_ENABLED=1 CC="$(cc)" CGO_CFLAGS="$(cgo_cflags)" CGO_LDFLAGS="$(cgo_ldflags) ${CGO_LDFLAGS}" go build -o $(GO_BUILD_DIR) -ldflags="$(ldflags)" cmd/livepeer_router/*.go

docker:
docker build --build-arg='BUILD_TAGS=mainnet,experimental' -f docker/Dockerfile .
docker buildx build --build-arg='BUILD_TAGS=mainnet,experimental' -f docker/Dockerfile .
11 changes: 6 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
FROM --platform=$BUILDPLATFORM ubuntu:20.04 as build
FROM --platform=$BUILDPLATFORM leszko/cuda:11.7.1-cudnn8-devel-ubuntu20.04-all as build

ARG TARGETARCH
ARG BUILDARCH

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"
CPATH="/usr/local/cuda_${TARGETARCH}/include" \
LIBRARY_PATH="/usr/local/cuda_${TARGETARCH}/lib64" \
DEBIAN_FRONTEND="noninteractive" \
CGO_LDFLAGS="-L/usr/local/cuda_${TARGETARCH}/lib64"

RUN apt update \
&& apt install -yqq software-properties-common curl apt-transport-https lsb-release \
&& apt install -yqq software-properties-common curl apt-transport-https lsb-release yasm \
&& curl -fsSL https://dl.google.com/go/go1.20.4.linux-${BUILDARCH}.tar.gz | tar -C /usr/local -xz \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& add-apt-repository "deb [arch=${BUILDARCH}] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
Expand Down
18 changes: 18 additions & 0 deletions docker/Dockerfile.cuda-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# livepeer/cuda-base:11.7.1-cudnn8-devel-ubuntu20.04
#
# Base CUDA Develop image which contains CUDA SDK libs for the following architectures: linux amd64, linux arm64, windows amd64
#
# To build this image you need the following steps:
# 1. Download NVIDIA CUDA SDK for ARM64, extract, and copy into cuda/arm64/usr/local/cuda/
# 2. Download NVIDIA CUDA SDK for Windows AMD64, extract, and copy npp libs into npp_win/

FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu20.04

COPY npp_win/lib/x64/* /usr/local/cuda/lib64/
COPY npp_win/include/* /usr/local/cuda/include/

RUN mkdir -p /usr/local/cuda_arm64/lib64/
COPY cuda/arm64/usr/local/cuda/lib64/libnp* /usr/local/cuda_arm64/lib64/
COPY cuda/arm64/usr/local/cuda/include /usr/local/cuda_arm64/include

RUN ln -s /usr/local/cuda /usr/local/cuda_amd64
32 changes: 16 additions & 16 deletions install_ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ EXTRA_LDFLAGS=""
EXTRA_X264_FLAGS=""
EXTRA_FFMPEG_FLAGS=""


if [[ "$ARCH" == "arm64" && "$UNAME" == "Darwin" ]]; then
# Detect Apple Silicon
IS_ARM64=1
Expand All @@ -19,8 +20,8 @@ fi
if [[ "$ARCH" == "x86_64" && "$UNAME" == "Linux" && "${GOARCH:-}" == "arm64" ]]; then
echo "cross-compiling linux-arm64"
export CC="clang --sysroot=/usr/aarch64-linux-gnu"
EXTRA_CFLAGS="--target=aarch64-linux-gnu $EXTRA_CFLAGS"
EXTRA_LDFLAGS="--target=aarch64-linux-gnu $EXTRA_LDFLAGS"
EXTRA_CFLAGS="--target=aarch64-linux-gnu -I/usr/local/cuda_arm64/include $EXTRA_CFLAGS"
EXTRA_LDFLAGS="--target=aarch64-linux-gnu -L/usr/local/cuda_arm64/lib64 $EXTRA_LDFLAGS"
EXTRA_FFMPEG_FLAGS="$EXTRA_FFMPEG_FLAGS --arch=aarch64 --enable-cross-compile --cc=clang --sysroot=/usr/aarch64-linux-gnu"
HOST_OS="--host=aarch64-linux-gnu"
IS_ARM64=1
Expand Down Expand Up @@ -141,19 +142,18 @@ DEV_FFMPEG_FLAGS="--disable-programs"

if [[ "$UNAME" == "Darwin" ]]; then
EXTRA_FFMPEG_LDFLAGS="$EXTRA_FFMPEG_LDFLAGS -framework CoreFoundation -framework Security"
else
# If we have clang, we can compile with CUDA support!
if which clang >/dev/null; then
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 [[ ! -e "${ROOT}/compiled/lib/libtensorflow_framework.so" ]]; then
LIBTENSORFLOW_VERSION=2.12.1 &&
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"
elif [[ -e "/usr/local/cuda/lib64" ]]; then
echo "CUDA SDK detected, building with GPU support"
EXTRA_FFMPEG_FLAGS="$EXTRA_FFMPEG_FLAGS --enable-nonfree --enable-cuda-nvcc --enable-libnpp --enable-cuda --enable-cuda-llvm --enable-cuvid --enable-nvenc --enable-decoder=h264_cuvid,hevc_cuvid,vp8_cuvid,vp9_cuvid --enable-filter=scale_npp,signature_cuda,hwupload_cuda --enable-encoder=h264_nvenc,hevc_nvenc"
if [[ ! -e "${ROOT}/compiled/lib/libtensorflow_framework.so" ]]; then
LIBTENSORFLOW_VERSION=2.12.1 &&
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"
else
echo "No CUDA SDK detected, building without GPU support"
fi

if [[ $BUILD_TAGS == *"debug-video"* ]]; then
Expand Down Expand Up @@ -181,8 +181,8 @@ if [[ ! -e "$ROOT/ffmpeg/libavcodec/libavcodec.a" ]]; then
--enable-filter=aresample,asetnsamples,fps,scale,hwdownload,select,livepeer_dnn,signature \
--enable-encoder=aac,opus,libx264 \
--enable-decoder=aac,opus,h264 \
--extra-cflags="-I${ROOT}/compiled/include ${EXTRA_CFLAGS}" \
--extra-ldflags="-L${ROOT}/compiled/lib ${EXTRA_FFMPEG_LDFLAGS}" \
--extra-cflags="${EXTRA_CFLAGS} -I${ROOT}/compiled/include -I/usr/local/cuda/include" \
--extra-ldflags="${EXTRA_FFMPEG_LDFLAGS} -L${ROOT}/compiled/lib -L/usr/local/cuda/lib64" \
--prefix="$ROOT/compiled" \
$EXTRA_FFMPEG_FLAGS \
$DEV_FFMPEG_FLAGS
Expand Down

0 comments on commit d725d0e

Please sign in to comment.