Reuse existing cuda context if possible when creating decoders #128
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test on Linux CUDA | |
on: | |
pull_request: | |
push: | |
branches: | |
- nightly | |
- main | |
- release/* | |
workflow_dispatch: | |
jobs: | |
tests: | |
strategy: | |
matrix: | |
python_version: ["3.9"] | |
# TODO: Add more cuda versions. | |
cuda_arch_version: ["12.4"] | |
ffmpeg_version: ["origin/release/6.1"] | |
fail-fast: false | |
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main | |
with: | |
runner: linux.g5.4xlarge.nvidia.gpu | |
repository: pytorch/torchcodec | |
gpu-arch-type: cuda | |
gpu-arch-version: ${{ matrix.cuda_arch_version }} | |
timeout: 120 | |
script: | | |
echo '::group::Install prereqs' | |
nvidia-smi | |
conda create --yes --name test python=${{ matrix.python_version }} | |
conda activate test | |
conda install --quiet --yes pip cmake pkg-config nasm | |
pip install --quiet --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu124 | |
conda install --quiet --yes nvidia::libnpp | |
echo '::endgroup::' | |
echo '::group::Build FFMPEG' | |
# Build and install FFMPEG from source with CUDA enabled. | |
# The one on conda doesn't have CUDA enabled. | |
# Sub-step: install nvidia headers. Reference this link for details: | |
# https://docs.nvidia.com/video-technologies/video-codec-sdk/12.1/ffmpeg-with-nvidia-gpu/index.html | |
git clone --quiet https://git.videolan.org/git/ffmpeg/nv-codec-headers.git | |
pushd nv-codec-headers | |
make --silent PREFIX=$CONDA_PREFIX -j install | |
popd | |
# Now build FFMPEG from source with CUDA enabled. | |
git clone --quiet https://git.ffmpeg.org/ffmpeg.git ffmpeg/ | |
pushd ffmpeg | |
git checkout ${{ matrix.ffmpeg_version }} | |
which pkg-config | |
pkg-config --list-all | |
./configure --prefix=$CONDA_PREFIX --enable-nonfree --enable-cuda-nvcc --disable-static --enable-shared --optflags=-fno-omit-frame-pointer --disable-stripping --enable-cuvid --enable-rpath | |
make --silent -j install | |
popd | |
echo '::endgroup::' | |
echo '::group::Build TorchCodec' | |
CMAKE_BUILD_PARALLEL_LEVEL=8 CXXFLAGS="" LDFLAGS="-Wl,--allow-shlib-undefined -Wl,-rpath,$CONDA_PREFIX/lib -Wl,-rpath-link,$CONDA_PREFIX/lib -L$CONDA_PREFIX/lib" CMAKE_BUILD_TYPE=Release ENABLE_CUDA=1 ENABLE_NVTX=1 pip install -e ".[dev]" --no-build-isolation -vv --debug | |
echo '::endgroup::' | |
echo '::group::Test TorchCodec' | |
# Ensure our compiled ffmpeg binary is in the path. | |
which ffmpeg | |
# We skip certain tests because they are not relevant to GPU decoding and they always fail with | |
# a custom FFMPEG build. | |
pytest -k "not (test_get_metadata or get_ffmpeg_version)" -vvv | |
echo '::endgroup::' | |
python benchmarks/decoders/gpu_benchmark.py --devices=cuda:0 --resize_devices=none | |
python benchmarks/decoders/gpu_benchmark.py --devices=cuda:0 --resize_devices=none --num_threads=5 --num_videos=100 | |
conda deactivate |