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

Enable Intel GPU support in torchcodec on Linux (xpu device) #558

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dvrogozh
Copy link

@dvrogozh dvrogozh commented Mar 13, 2025

Fixes: #559

This commit enables support for Intel GPUs in torchcodec. It adds:

  • ffmpeg-vaapi for decoding
  • VAAPI based color space conversion (decoding output to RGBA)
  • RGBA surface import as torch tensor (on torch xpu device)
  • RGBA to RGB24 tensor slicing

To build torchcodec with Intel GPU support:

  • Install pytorch with XPU backend support. For example, with:
pip3 install torch --index-url https://download.pytorch.org/whl/xpu

Notes:

  • RGB24 is not supported color format on current Intel GPUs (as it is considered to be suboptimal due to odd alignments)
  • Intel media and compute APIs can't seamlessly work with the memory from each other. For example, Intel computes's Unified Shared Memory pointers are not recognized by media APIs. Thus, lower level sharing via dma fds is needed. This alos makes this part of the solution OS dependent.
  • Color space conversion algoriths might be quite different as it happens for Intel. This requires to check PSNR values instead of per-pixel atol/rtol differences.
  • Installing oneAPI environment is neded due to xpu: target torch::xpurt not found linking with libtorch installed from XPU wheels pytorch#149075

This commit was primary verfied on Intel Battlemage G21 (0xe20b) and Intel Data Center GPU Flex (0x56c0).

CC: @scotts, @NicolasHug, @EikanWang

This commit enables support for Intel GPUs in torchcodec. It adds:
* ffmpeg-vaapi for decoding
* VAAPI based color space conversion (decoding output to RGBA)
* RGBA surface import as torch tensor (on torch xpu device)
* RGBA to RGB24 tensor slicing

To build torchcodec with Intel GPU support:
* Install pytorch with XPU backend support. For example, with:
```
pip3 install torch --index-url https://download.pytorch.org/whl/xpu
```
* Install oneAPI development environment following
  https://github.com/pytorch/pytorch?tab=readme-ov-file#intel-gpu-support
* Build and install FFmpeg with `--enable-vaapi`
* Install torcheval (for tests): `pip3 install torcheval`
* Build torchcodec with: `ENABLE_XPU=1 python3 setup.py devel`

Notes:
* RGB24 is not supported color format on current Intel GPUs (as it
  is considered to be suboptimal due to odd alignments)
* Intel media and compute APIs can't seamlessly work with the
  memory from each other. For example, Intel computes's Unified
  Shared Memory pointers are not recognized by media APIs. Thus,
  lower level sharing via dma fds is needed. This alos makes this
  part of the solution OS dependent.
* Color space conversion algoriths might be quite different as it
  happens for Intel. This requires to check PSNR values instead of
  per-pixel atol/rtol differences.
* Installing oneAPI environment is neded due to
  pytorch/pytorch#149075

This commit was primary verfied on Intel Battlemage G21 (0xe20b) and
Intel Data Center GPU Flex (0x56c0).

Signed-off-by: Dmitry Rogozhkin <[email protected]>
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] Enable Intel GPU support in torchcodec (pytorch xpu backend device)
2 participants