Skip to content

Commit afb63c0

Browse files
authored
Enable CUDA support with FFmpeg4 (#517)
1 parent ba0063a commit afb63c0

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

.github/workflows/linux_cuda_wheel.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ jobs:
6868
python-version: ['3.9']
6969
cuda-version: ['11.8', '12.4', '12.6']
7070
# TODO: put back ffmpeg 5 https://github.com/pytorch/torchcodec/issues/325
71-
ffmpeg-version-for-tests: ['6', '7']
71+
ffmpeg-version-for-tests: ['4.4.2', '6', '7']
72+
exclude:
73+
- cuda-version: '12.4' # TODO put this back it fails with infra issue.
74+
ffmpeg-version-for-tests: '4.4.2'
75+
7276
container:
7377
image: "pytorch/manylinux2_28-builder:cuda${{ matrix.cuda-version }}"
7478
options: "--gpus all -e NVIDIA_DRIVER_CAPABILITIES=video,compute,utility"
@@ -141,7 +145,7 @@ jobs:
141145
${CONDA_RUN} python test/decoders/manual_smoke_test.py
142146
- name: Run Python tests
143147
run: |
144-
${CONDA_RUN} FAIL_WITHOUT_CUDA=1 pytest test -vvv
148+
${CONDA_RUN} FAIL_WITHOUT_CUDA=1 pytest test -v --tb=short
145149
- name: Run Python benchmark
146150
run: |
147151
${CONDA_RUN} time python benchmarks/decoders/gpu_benchmark.py --devices=cuda:0,cpu --resize_devices=none

src/torchcodec/decoders/_core/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ if(DEFINED ENV{BUILD_AGAINST_ALL_FFMPEG_FROM_S3})
7777
)
7878

7979

80-
if(NOT ENABLE_CUDA)
81-
# TODO: Enable more ffmpeg versions for cuda.
82-
make_torchcodec_library(libtorchcodec4 ffmpeg4)
83-
endif()
80+
make_torchcodec_library(libtorchcodec4 ffmpeg4)
8481
make_torchcodec_library(libtorchcodec7 ffmpeg7)
8582
make_torchcodec_library(libtorchcodec6 ffmpeg6)
8683
make_torchcodec_library(libtorchcodec5 ffmpeg5)

test/decoders/test_video_decoder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
assert_frames_equal,
1616
AV1_VIDEO,
1717
cpu_and_cuda,
18+
get_ffmpeg_major_version,
1819
H265_VIDEO,
19-
in_fbcode,
2020
NASA_VIDEO,
2121
)
2222

@@ -249,7 +249,7 @@ def test_getitem_slice(self, device, seek_mode):
249249
]
250250
)
251251
for sliced, ref in zip(all_frames, decoder):
252-
if not (in_fbcode() and device == "cuda"):
252+
if not (device == "cuda" and get_ffmpeg_major_version() == 4):
253253
# TODO: remove the "if".
254254
# See https://github.com/pytorch/torchcodec/issues/428
255255
assert_frames_equal(sliced, ref)
@@ -428,7 +428,7 @@ def test_get_frames_at_fails(self, device, seek_mode):
428428

429429
@pytest.mark.parametrize("device", cpu_and_cuda())
430430
def test_get_frame_at_av1(self, device):
431-
if in_fbcode() and device == "cuda":
431+
if device == "cuda" and get_ffmpeg_major_version() == 4:
432432
return
433433

434434
decoder = VideoDecoder(AV1_VIDEO.path, device=device)

test/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import torch
1313

14+
from torchcodec.decoders._core import get_ffmpeg_library_versions
15+
1416

1517
# Decorator for skipping CUDA tests when CUDA isn't available. The tests are
1618
# effectively marked to be skipped in pytest_collection_modifyitems() of
@@ -23,6 +25,10 @@ def cpu_and_cuda():
2325
return ("cpu", pytest.param("cuda", marks=pytest.mark.needs_cuda))
2426

2527

28+
def get_ffmpeg_major_version():
29+
return int(get_ffmpeg_library_versions()["ffmpeg_version"].split(".")[0])
30+
31+
2632
# For use with decoded data frames. On CPU Linux, we expect exact, bit-for-bit
2733
# equality. On CUDA Linux, we expect a small tolerance.
2834
# On other platforms (e.g. MacOS), we also allow a small tolerance. FFmpeg does
@@ -32,7 +38,7 @@ def assert_frames_equal(*args, **kwargs):
3238
if sys.platform == "linux":
3339
if args[0].device.type == "cuda":
3440
atol = 2
35-
if in_fbcode():
41+
if get_ffmpeg_major_version() == 4:
3642
assert_tensor_close_on_at_least(
3743
args[0], args[1], percentage=95, atol=atol
3844
)

0 commit comments

Comments
 (0)