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

Docker + CUDA documentation #1232

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Dockerfile.cuda
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ARG CUDA_VERSION=12.1.0
# By copying the installation from a devel to a runtime container one could likely save a lot container size
FROM nvidia/cuda:$CUDA_VERSION-devel-ubuntu22.04

RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libopenjp2-7-dev \
ninja-build cmake git python3 python3-pip nasm xxd pkg-config curl unzip

RUN git clone https://github.com/Netflix/vmaf.git

RUN git clone https://github.com/FFmpeg/FFmpeg.git

RUN git clone https://github.com/FFmpeg/nv-codec-headers.git && cd nv-codec-headers && make && make install

# install vmaf
RUN python3 -m pip install meson cpython
RUN cd vmaf && meson libvmaf/build libvmaf -Denable_cuda=true -Denable_avx512=true --buildtype release && \
ninja -vC libvmaf/build && \
ninja -vC libvmaf/build install

# install ffmpeg
RUN cd FFmpeg && ./configure \
--enable-libnpp \
--enable-nonfree \
--enable-nvdec \
--enable-nvenc \
--enable-cuvid \
--enable-cuda \
--enable-cuda-nvcc \
--enable-libvmaf \
--enable-ffnvcodec \
--disable-stripping \
--extra-cflags="-I/usr/local/cuda/include" \
--extra-ldflags="-L/usr/local/cuda/lib64 -L/usr/local/cuda/lib64/stubs/"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking against stubs as during build the driver is not available.


RUN cd FFmpeg && make -j && make install

RUN mkdir /data
# VMAF+decode GPU (only works for NVDec supported formats https://developer.nvidia.com/video-encode-and-decode-gpu-support-matrix-new)
ENTRYPOINT ["ffmpeg" ,"-hwaccel", "cuda", "-hwaccel_output_format" ,"cuda", \
"-i" ,"/data/ref.mp4", \
"-hwaccel", "cuda", "-hwaccel_output_format", "cuda", \
"-i", "/data/dis.mp4" ,\
"-filter_complex", "[0:v][1:v]libvmaf_cuda" ,"-f" ,"null", "-"]
6 changes: 5 additions & 1 deletion libvmaf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ Run:
meson build --buildtype release
```

(add `-Denable_float=true` flag in the rare case if you want to use the floating-point feature extractors.)
Special cases:
- add `-Denable_float=true` flag in the rare case if you want to use the floating-point feature extractors.
- add `-Denable_avx512=true` to support wider SIMD instructions to achieve the fastest processing on supported CPUs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is now enabled by default so this wording may be misleading. We can fix this later though.

- add `-Denable_cuda=true` to build with CUDA support, which requires `nvcc` for compilation (tested with CUDA >= 11)
- add `-Denable_nvtx=true` to build with [NVTX](https://github.com/NVIDIA/NVTX) marker support, which enables easy profiling using Nsight Systems

Build with:

Expand Down
25 changes: 25 additions & 0 deletions resource/doc/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,28 @@ Note that you need to first download the test videos from [vmaf_resource](https:
wget https://github.com/Netflix/vmaf_resource/raw/master/python/test/resource/yuv/src01_hrc00_576x324.yuv
wget https://github.com/Netflix/vmaf_resource/raw/master/python/test/resource/yuv/src01_hrc01_576x324.yuv
```

## Docker with CUDA support

To run docker containers with GPU support you have to install the [nvidia container toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
After that a CUDA enabled container can be built using the below command line:
```shell script
docker build -f Dockerfile.cuda -t vmaf_cuda .
```

Besides VMAF the container also build ffmpeg support to enable GPU enabled decode to be able to run VMAF at speed of light.

```shell script
REF_VIDEO=$PWD/data/text_ref.mp4
DIS_VIDEO=$PWD/data/text_dis.mp4

docker run --gpus all -e NVIDIA_DRIVER_CAPABILITIES=compute,video -v $REF_VIDEO:/data/ref.mp4 -v $DIS_VIDEO:/data/dis.mp4 vmaf_cuda
```
To run a custom ffmpeg command line inside the container use:
```shell script
docker run --gpus all -e NVIDIA_DRIVER_CAPABILITIES=compute,video --entrypoint=bash -it --rm vmaf_cuda
```

For 420 video format we will have to convert from NV12 to 420 as well:
`-filter_complex [0:v]scale_cuda=format=yuv420p[ref];[1:v]scale_cuda=format=yuv420p[dist];[ref][dist]libvmaf_cuda`

Loading