Skip to content

Commit 9201878

Browse files
ahmadsharif1NicolasHug
authored andcommitted
Improve CUDA documentation by adding TorchCodec installation instructions (meta-pytorch#365)
1 parent c2111af commit 9201878

File tree

2 files changed

+62
-21
lines changed

2 files changed

+62
-21
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ ffmpeg -f lavfi -i \
9393
```
9494

9595
## Installing TorchCodec
96+
### Installing CPU-only TorchCodec
9697

9798
1. Install the latest stable version of PyTorch following the
9899
[official instructions](https://pytorch.org/get-started/locally/). For other
@@ -127,6 +128,61 @@ The following table indicates the compatibility between versions of
127128
| not yet supported | `2.5` | `>=3.9`, `<=3.12` |
128129
| `0.0.3` | `2.4` | `>=3.8`, `<=3.12` |
129130

131+
### Installing CUDA-enabled TorchCodec
132+
133+
First, make sure you have a GPU that has NVDEC hardware that can decode the
134+
format you want. Refer to Nvidia's GPU support matrix for more details
135+
[here](https://developer.nvidia.com/video-encode-and-decode-gpu-support-matrix-new).
136+
137+
1. Install CUDA Toolkit. Pytorch and TorchCodec supports CUDA Toolkit
138+
versions 11.8, 12.1 or 12.4. In particular TorchCodec depends on
139+
CUDA libraries libnpp and libnvrtc (which are part of CUDA Toolkit).
140+
141+
2. Install Pytorch that corresponds to your CUDA Toolkit version using the
142+
[official instructions](https://pytorch.org/get-started/locally/).
143+
144+
3. Install or compile FFmpeg with NVDEC support.
145+
TorchCodec with CUDA should work with FFmpeg versions in [4, 7].
146+
147+
If FFmpeg is not already installed, or you need a more recent version, an
148+
easy way to install it is to use `conda`:
149+
150+
```bash
151+
conda install ffmpeg
152+
# or
153+
conda install ffmpeg -c conda-forge
154+
```
155+
156+
If you are building FFmpeg from source you can follow Nvidia's guide to
157+
configuring and installing FFmpeg with NVDEC support
158+
[here](https://docs.nvidia.com/video-technologies/video-codec-sdk/12.0/ffmpeg-with-nvidia-gpu/index.html).
159+
160+
After installing FFmpeg make sure it has NVDEC support when you list the supported
161+
decoders:
162+
163+
```bash
164+
ffmpeg -decoders | grep -i nvidia
165+
# This should show a line like this:
166+
# V..... h264_cuvid Nvidia CUVID H264 decoder (codec h264)
167+
```
168+
169+
To check that FFmpeg libraries work with NVDEC correctly you can decode a sample video:
170+
171+
```bash
172+
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i test/resources/nasa_13013.mp4 -f null -
173+
```
174+
175+
4. Install TorchCodec by passing in an `--index-url` parameter that corresponds to your CUDA
176+
Toolkit version, example:
177+
178+
```bash
179+
# This corresponds to CUDA Toolkit version 12.4 and nightly Pytorch.
180+
pip install torchcodec --index-url=https://download.pytorch.org/whl/nightly/cu124
181+
```
182+
183+
Note that without passing in the `--index-url` parameter, `pip` installs TorchCodec
184+
binaries from PyPi which are CPU-only and do not have CUDA support.
185+
130186
## Benchmark Results
131187

132188
The following was generated by running [our benchmark script](./benchmarks/decoders/generate_readme_data.py) on a lightly loaded 56-core machine.

examples/basic_cuda_example.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
running the transform steps. Encoded packets are often much smaller than decoded frames so
1919
CUDA decoding also uses less PCI-e bandwidth.
2020
21+
When to and when not to use CUDA Decoding
22+
-----------------------------------------
23+
2124
CUDA Decoding can offer speed-up over CPU Decoding in a few scenarios:
2225
2326
#. You are decoding a large resolution video
@@ -37,28 +40,10 @@
3740
TorchCodec you can simply pass in a device parameter to the
3841
:class:`~torchcodec.decoders.VideoDecoder` class to use CUDA Decoding.
3942
43+
Installing TorchCodec with CUDA Enabled
44+
---------------------------------------
4045
41-
In order to use CUDA Decoding will need the following installed in your environment:
42-
43-
#. An Nvidia GPU that supports decoding the video format you want to decode. See
44-
the support matrix `here <https://developer.nvidia.com/video-encode-and-decode-gpu-support-matrix-new>`_
45-
#. `CUDA-enabled pytorch <https://pytorch.org/get-started/locally/>`_
46-
#. FFmpeg binaries that support
47-
`NVDEC-enabled <https://docs.nvidia.com/video-technologies/video-codec-sdk/12.0/ffmpeg-with-nvidia-gpu/index.html>`_
48-
codecs
49-
#. libnpp and nvrtc (these are usually installed when you install the full cuda-toolkit)
50-
51-
52-
FFmpeg versions 5, 6 and 7 from conda-forge are built with
53-
`NVDEC support <https://docs.nvidia.com/video-technologies/video-codec-sdk/12.0/ffmpeg-with-nvidia-gpu/index.html>`_
54-
and you can install them with conda. For example, to install FFmpeg version 7:
55-
56-
57-
.. code-block:: bash
58-
59-
conda install ffmpeg=7 -c conda-forge
60-
conda install libnpp cuda-nvrtc -c nvidia
61-
46+
Refer to the installation guide in the `README <https://github.com/pytorch/torchcodec#installing-cuda-enabled-torchcodec>`_.
6247
6348
"""
6449

0 commit comments

Comments
 (0)