Skip to content

Commit 949803e

Browse files
author
Dmitry Rogozhkin
committed
Expose TorchCodecConfig.cmake
This commit exposes torchcodec core library to be used by third party modules on the C++ level. The primary purpose is to allow non-CUDA device interfaces out-of-tree implementations. There are the following major changes: * Exposed TorchCodecConfig.cmake which defines torchcodec targets to be linked with * Provided Python level APIs to faciliate out-of-tree device interfaces work with torchcodec: * `torchcodec.cmake_prefix_path` - path which points to `TorchCodecConfig.cmake` configuration * `torchcodec.variant` - variant of the torchcodec library which was loaded, i.e. N in libtorchcodec_core{N}.so (currently ffmpeg_major_version) * `torchcodec.core_library_path` - full path of the loaded torchcodec core library * `src/torchcodec/_core/` dropped from include paths to allow using of the core library out-of-tree `TorchCodecConfig.cmake` has 2 working modes: * By default config works by checking available version of FFmpeg libraries via `pkg-config` and configures corresponding (single) version of torchcodec * Altenatively, if `TORCHCODEC_FFMPEG{N}_INSTALL_PREFIX` is set (`N=4,5,6,7` - version of FFmpeg), then config defines torchcodec target corresponding to the specified FFmpeg version. Note that multiple prefixes can be specified at the same time allowing to build against few torchcodec versions at once. Config will define `TORCHCODEC_VARIANTS` variable with value corresponding to FFmpeg major versions of available torchcodec core libraries. Further, config will also define `torchcodec::ffmpeg${N}` and `torchcodec::core${N}` targets where `N` takes values from `TORCHCODEC_VARIANTS`. Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@gmail.com>
1 parent 9fa4fd1 commit 949803e

32 files changed

+261
-61
lines changed

src/torchcodec/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
import os.path as _osp
8+
79
# Note: usort wants to put Frame and FrameBatch after decoders and samplers,
810
# but that results in circular import.
11+
from ._core import core_library_path, variant
912
from ._frame import AudioSamples, Frame, FrameBatch # usort:skip # noqa
1013
from . import decoders, samplers # noqa
1114

@@ -14,3 +17,5 @@
1417
from .version import __version__ # noqa: F401
1518
except Exception:
1619
pass
20+
21+
cmake_prefix_path = _osp.join(_osp.dirname(__file__), "share", "cmake")

src/torchcodec/_core/AVIOContextHolder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
#include "src/torchcodec/_core/AVIOContextHolder.h"
7+
#include "AVIOContextHolder.h"
88
#include <torch/types.h>
99

1010
namespace facebook::torchcodec {

src/torchcodec/_core/AVIOContextHolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
#include "src/torchcodec/_core/FFMPEGCommon.h"
9+
#include "FFMPEGCommon.h"
1010

1111
namespace facebook::torchcodec {
1212

src/torchcodec/_core/AVIOFileLikeContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
#include "src/torchcodec/_core/AVIOFileLikeContext.h"
7+
#include "AVIOFileLikeContext.h"
88
#include <torch/types.h>
99

1010
namespace facebook::torchcodec {

src/torchcodec/_core/AVIOFileLikeContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <pybind11/pybind11.h>
1010
#include <pybind11/stl.h>
1111

12-
#include "src/torchcodec/_core/AVIOContextHolder.h"
12+
#include "AVIOContextHolder.h"
1313

1414
namespace py = pybind11;
1515

src/torchcodec/_core/AVIOTensorContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
#include "src/torchcodec/_core/AVIOTensorContext.h"
7+
#include "AVIOTensorContext.h"
88
#include <torch/types.h>
99

1010
namespace facebook::torchcodec {

src/torchcodec/_core/AVIOTensorContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#pragma once
88

99
#include <torch/types.h>
10-
#include "src/torchcodec/_core/AVIOContextHolder.h"
10+
#include "AVIOContextHolder.h"
1111

1212
namespace facebook::torchcodec {
1313

src/torchcodec/_core/BetaCudaDeviceInterface.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
#pragma once
1717

18-
#include "src/torchcodec/_core/CUDACommon.h"
19-
#include "src/torchcodec/_core/Cache.h"
20-
#include "src/torchcodec/_core/DeviceInterface.h"
21-
#include "src/torchcodec/_core/FFMPEGCommon.h"
22-
#include "src/torchcodec/_core/NVDECCache.h"
18+
#include "CUDACommon.h"
19+
#include "Cache.h"
20+
#include "DeviceInterface.h"
21+
#include "FFMPEGCommon.h"
22+
#include "NVDECCache.h"
2323

2424
#include <map>
2525
#include <memory>
@@ -28,8 +28,8 @@
2828
#include <unordered_map>
2929
#include <vector>
3030

31-
#include "src/torchcodec/_core/nvcuvid_include/cuviddec.h"
32-
#include "src/torchcodec/_core/nvcuvid_include/nvcuvid.h"
31+
#include "nvcuvid_include/cuviddec.h"
32+
#include "nvcuvid_include/nvcuvid.h"
3333

3434
namespace facebook::torchcodec {
3535

src/torchcodec/_core/CUDACommon.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include <npp.h>
1212
#include <torch/types.h>
1313

14-
#include "src/torchcodec/_core/Cache.h"
15-
#include "src/torchcodec/_core/FFMPEGCommon.h"
16-
#include "src/torchcodec/_core/Frame.h"
14+
#include "Cache.h"
15+
#include "FFMPEGCommon.h"
16+
#include "Frame.h"
1717

1818
extern "C" {
1919
#include <libavutil/hwcontext_cuda.h>

src/torchcodec/_core/CpuDeviceInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7-
#include "src/torchcodec/_core/CpuDeviceInterface.h"
7+
#include "CpuDeviceInterface.h"
88

99
namespace facebook::torchcodec {
1010
namespace {

0 commit comments

Comments
 (0)