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

AV1 support for CUDA backend #443

Open
legraphista opened this issue Dec 23, 2024 · 1 comment
Open

AV1 support for CUDA backend #443

legraphista opened this issue Dec 23, 2024 · 1 comment

Comments

@legraphista
Copy link

legraphista commented Dec 23, 2024

🐛 Describe the bug

Assertion triggered when trying to decode AV1 on cuda


# install with cuda
pip install torchcodec --force-reinstall --index-url=https://download.pytorch.org/whl/cu124

# create test files
ffmpeg -f lavfi -i testsrc=duration=1:size=1280x720:rate=30,format=yuv420p -c:v libaom-av1 -crf 30 av1.mkv -n -loglevel error
ffmpeg -f lavfi -i testsrc=duration=1:size=1280x720:rate=30,format=yuv420p -c:v libx264 -crf 30 h264.mkv -n -loglevel error

I've added the videos in a zip file, in case you do not have access to an FFMPEG command that can produce them: videos.zip

import torchcodec
import traceback

for device in ['cpu', 'cuda']:
    for files in ['av1.mkv', 'h264.mkv']:
        try:
            print(f"Decoding {files} on {device}: ", end='')
            decoder = torchcodec.decoders.VideoDecoder(files, device=device, dimension_order='NHWC', num_ffmpeg_threads=0)
            torch_frame = decoder[0]
            assert torch_frame.shape == (720, 1280, 3)
            print(f"ok")
        except Exception as e:
            print(f"Error!")
            print(traceback.format_exc())
        finally:
            print("")
Decoding av1.mkv on cpu: ok

Decoding h264.mkv on cpu: ok

Decoding av1.mkv on cuda: Error!
Traceback (most recent call last):
  File "/tmp/ipykernel_2248132/3950552733.py", line 6, in <module>
    torch_frame = decoder[0]
  File "/shared/jupyter/.venv/lib/python3.10/site-packages/torchcodec/decoders/_video_decoder.py", line 169, in __getitem__
    return self._getitem_int(int(key))
  File "/shared/jupyter/.venv/lib/python3.10/site-packages/torchcodec/decoders/_video_decoder.py", line 141, in _getitem_int
    frame_data, *_ = core.get_frame_at_index(
  File "/shared/jupyter/.venv/lib/python3.10/site-packages/torch/_ops.py", line 716, in __call__
    return self._op(*args, **kwargs)
RuntimeError: Expected format to be AV_PIX_FMT_CUDA, got yuv420p


Decoding h264.mkv on cuda: ok

Sanity check: confirm that av1 decoding works (on a RTX4090)

With HW accel

$ ffmpeg -hide_banner -hwaccel cuda -c:v av1_cuvid -i av1.mkv -f null -
Input #0, matroska,webm, from 'av1.mkv':
  Metadata:
    ENCODER         : Lavf61.9.101
  Duration: 00:00:01.00, start: 0.000000, bitrate: 72 kb/s
  Stream #0:0: Video: av1 (libaom-av1) (Main), yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 1k tbn
    Metadata:
      ENCODER         : Lavc61.27.101 libaom-av1
      DURATION        : 00:00:01.000000000
Stream mapping:
  Stream #0:0 -> #0:0 (av1 (av1_cuvid) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf61.9.101
  Stream #0:0: Video: wrapped_avframe, nv12(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 30 fps, 30 tbn
    Metadata:
      encoder         : Lavc61.27.101 wrapped_avframe
      DURATION        : 00:00:01.000000000
[out#0/null @ 0x5b1bbdb719c0] video:13KiB audio:0KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown
frame=   30 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.00 bitrate=N/A speed=37.7x

Without HW accel:

$ ffmpeg -hide_banner -i av1.mkv -f null -
Input #0, matroska,webm, from 'av1.mkv':
  Metadata:
    ENCODER         : Lavf61.9.101
  Duration: 00:00:01.00, start: 0.000000, bitrate: 72 kb/s
  Stream #0:0: Video: av1 (libaom-av1) (Main), yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 1k tbn
    Metadata:
      ENCODER         : Lavc61.27.101 libaom-av1
      DURATION        : 00:00:01.000000000
Stream mapping:
  Stream #0:0 -> #0:0 (av1 (libaom-av1) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf61.9.101
  Stream #0:0: Video: wrapped_avframe, yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 30 fps, 30 tbn
    Metadata:
      encoder         : Lavc61.27.101 wrapped_avframe
      DURATION        : 00:00:01.000000000
[out#0/null @ 0x643c76376900] video:13KiB audio:0KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown
frame=   30 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.00 bitrate=N/A speed=  12x

Versions

$ python collect_env.py

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.1.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "/shared/jupyter/stefan/collect_env.py", line 17, in <module>
    import torch
  File "/usr/local/pyenv/versions/3.10.15/lib/python3.10/site-packages/torch/__init__.py", line 1382, in <module>
    from .functional import *  # noqa: F403
  File "/usr/local/pyenv/versions/3.10.15/lib/python3.10/site-packages/torch/functional.py", line 7, in <module>
    import torch.nn.functional as F
  File "/usr/local/pyenv/versions/3.10.15/lib/python3.10/site-packages/torch/nn/__init__.py", line 1, in <module>
    from .modules import *  # noqa: F403
  File "/usr/local/pyenv/versions/3.10.15/lib/python3.10/site-packages/torch/nn/modules/__init__.py", line 35, in <module>
    from .transformer import TransformerEncoder, TransformerDecoder, \
  File "/usr/local/pyenv/versions/3.10.15/lib/python3.10/site-packages/torch/nn/modules/transformer.py", line 20, in <module>
    device: torch.device = torch.device(torch._C._get_default_device()),  # torch.device('cpu'),
/usr/local/pyenv/versions/3.10.15/lib/python3.10/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:84.)
  device: torch.device = torch.device(torch._C._get_default_device()),  # torch.device('cpu'),
Collecting environment information...
PyTorch version: 2.1.2+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.1 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: version 3.28.3
Libc version: glibc-2.39

Python version: 3.10.15 (main, Sep 28 2024, 10:48:30) [GCC 13.2.0] (64-bit runtime)
Python platform: Linux-6.8.0-48-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: 12.6.68
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 4090
GPU 1: NVIDIA GeForce RTX 4090
GPU 2: NVIDIA GeForce RTX 4090
GPU 3: NVIDIA GeForce RTX 4090
GPU 4: NVIDIA GeForce RTX 4090
GPU 5: NVIDIA GeForce RTX 4090

Nvidia driver version: 560.35.03
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.7
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        52 bits physical, 57 bits virtual
Byte Order:                           Little Endian
CPU(s):                               64
On-line CPU(s) list:                  0-63
Vendor ID:                            AuthenticAMD
Model name:                           AMD Ryzen Threadripper PRO 7975WX 32-Cores
CPU family:                           25
Model:                                24
Thread(s) per core:                   2
Core(s) per socket:                   32
Socket(s):                            1
Stepping:                             1
CPU(s) scaling MHz:                   26%
CPU max MHz:                          7775.0000
CPU min MHz:                          545.0000
BogoMIPS:                             7988.18
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d debug_swap
Virtualization:                       AMD-V
L1d cache:                            1 MiB (32 instances)
L1i cache:                            1 MiB (32 instances)
L2 cache:                             32 MiB (32 instances)
L3 cache:                             128 MiB (4 instances)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-63
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Mitigation; Safe RET
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==2.1.2
[pip3] nvidia-cublas-cu12==12.1.3.1
[pip3] nvidia-cuda-cupti-cu12==12.1.105
[pip3] nvidia-cuda-nvrtc-cu12==12.1.105
[pip3] nvidia-cuda-runtime-cu12==12.1.105
[pip3] nvidia-cudnn-cu12==8.9.2.26
[pip3] nvidia-cufft-cu12==11.0.2.54
[pip3] nvidia-curand-cu12==10.3.2.106
[pip3] nvidia-cusolver-cu12==11.4.5.107
[pip3] nvidia-cusparse-cu12==12.1.0.106
[pip3] nvidia-nccl-cu12==2.18.1
[pip3] nvidia-nvjitlink-cu12==12.6.85
[pip3] nvidia-nvtx-cu12==12.1.105
[pip3] pytorchvideo==0.1.5
[pip3] torch==2.1.2
[pip3] torchvision==0.16.2
[pip3] triton==2.1.0
[conda] Could not collect
@devanshrpandey
Copy link

Have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants