diff --git a/README.md b/README.md index b380260..703d52b 100644 --- a/README.md +++ b/README.md @@ -69,12 +69,10 @@ python3 -m pip install --no-build-isolation -vv -e . # How to use -Import the project in your Python script to register Intel device -interface for the TorchCodec: +TorchCodec will automatically load Intel Plugin if it is installed on the system via python packages entry point mechanism. No explcit project importing is required. Proceed by importing TorchCodec as usual: ``` import torchcodec -import torchcodec_xpu ``` Before executing, make sure to export environment variables to point to FFmpeg installation: @@ -84,6 +82,12 @@ export PATH=$HOME/_install/bin:$PATH export LD_LIBRARY_PATH=$HOME/_install/lib:$LD_LIBRARY_PATH ``` +Note that it is possible to disable auto loading by exporting the following environment variable: + +``` +export TORCHCODEC_DEVICE_BACKEND_AUTOLOAD=0 +``` + [Getting Started on Intel GPU]: https://docs.pytorch.org/docs/stable/notes/get_start_xpu.html [TorchCodec]: https://github.com/meta-pytorch/torchcodec diff --git a/patches/0001-Add-XPU-support-to-tests.patch b/patches/0001-Add-XPU-support-to-tests.patch index 0adccc9..26b39fb 100644 --- a/patches/0001-Add-XPU-support-to-tests.patch +++ b/patches/0001-Add-XPU-support-to-tests.patch @@ -1,4 +1,4 @@ -From 685063b320fb83aac6c1e9fa14d838b7e3fdb178 Mon Sep 17 00:00:00 2001 +From b0189f1fe8f367cb45981af3126e723ae3d515bf Mon Sep 17 00:00:00 2001 From: Edgar Romo Montiel Date: Tue, 9 Dec 2025 14:36:08 -0800 Subject: [PATCH] Add XPU support to tests @@ -7,8 +7,8 @@ Signed-off-by: Edgar Romo Montiel --- test/conftest.py | 19 +++++++++++++++++-- test/test_ops.py | 14 ++++++++++++++ - test/utils.py | 18 ++++++++++++++++++ - 3 files changed, 49 insertions(+), 2 deletions(-) + test/utils.py | 17 +++++++++++++++++ + 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index fa674bf..91ef29b 100644 @@ -73,17 +73,17 @@ index fa674bf..91ef29b 100644 + if torch.xpu.is_available(): + torch.xpu.set_rng_state(xpu_rng_state) diff --git a/test/test_ops.py b/test/test_ops.py -index 0ec4515..bd8d5db 100644 +index 0ec4515..76c8a09 100644 --- a/test/test_ops.py +++ b/test/test_ops.py -@@ -47,6 +47,7 @@ from .utils import ( - NASA_AUDIO_MP3, +@@ -48,6 +48,7 @@ from .utils import ( NASA_VIDEO, needs_cuda, -+ needs_xpu, needs_ffmpeg_cli, ++ needs_xpu, SINE_MONO_S32, SINE_MONO_S32_44100, + SINE_MONO_S32_8000, @@ -650,6 +651,19 @@ class TestVideoDecoderOps: duration, torch.tensor(0.0334).double(), atol=0, rtol=1e-3 ) @@ -105,18 +105,10 @@ index 0ec4515..bd8d5db 100644 class TestAudioDecoderOps: @pytest.mark.parametrize( diff --git a/test/utils.py b/test/utils.py -index 6f4c77b..ae211d9 100644 +index cd735cf..f0f874e 100644 --- a/test/utils.py +++ b/test/utils.py -@@ -12,6 +12,7 @@ import pytest - - import torch - -+import torchcodec_xpu - from torchcodec._core import get_ffmpeg_library_versions - from torchcodec.decoders import set_cuda_backend, VideoDecoder - from torchcodec.decoders._video_decoder import _read_custom_frame_mappings -@@ -26,6 +27,13 @@ def needs_cuda(test_item): +@@ -28,6 +28,13 @@ def needs_cuda(test_item): return pytest.mark.needs_cuda(test_item) @@ -130,7 +122,7 @@ index 6f4c77b..ae211d9 100644 # Decorator for skipping ffmpeg tests when ffmpeg cli isn't available. The tests are # effectively marked to be skipped in pytest_collection_modifyitems() of # conftest.py -@@ -48,6 +56,7 @@ def all_supported_devices(): +@@ -50,6 +57,7 @@ def all_supported_devices(): "cpu", pytest.param("cuda", marks=pytest.mark.needs_cuda), pytest.param(_CUDA_BETA_DEVICE_STR, marks=pytest.mark.needs_cuda), @@ -138,7 +130,7 @@ index 6f4c77b..ae211d9 100644 ) -@@ -147,6 +156,15 @@ def assert_frames_equal(*args, **kwargs): +@@ -156,6 +164,15 @@ def assert_frames_equal(*args, **kwargs): ) else: torch.testing.assert_close(*args, **kwargs, atol=atol, rtol=0) diff --git a/pyproject.toml b/pyproject.toml index 2e15e28..432b773 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,9 @@ dynamic = ["version"] [project.urls] GitHub = "https://github.com/dvrogozh/torchcodec-xpu" +[project.entry-points.'torchcodec.backends'] +device_backend = 'torchcodec_xpu:load_torchcodec_xpu_shared_library' + [tool.setuptools.dynamic] version = {file = "version.txt"} diff --git a/src/torchcodec_xpu/__init__.py b/src/torchcodec_xpu/__init__.py index 62ca1ba..a8cb87e 100644 --- a/src/torchcodec_xpu/__init__.py +++ b/src/torchcodec_xpu/__init__.py @@ -63,6 +63,3 @@ def load_torchcodec_xpu_shared_library(): """ f"{traceback}" ) - -load_torchcodec_xpu_shared_library() -