Skip to content

Refactor C++ library names #768

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

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions src/torchcodec/_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,55 +48,53 @@ function(make_torchcodec_libraries
# We create three shared libraries per version of FFmpeg, where the version
# is denoted by N:
#
# 1. libtorchcodec_decoderN.{ext}: Base library which contains the
# 1. libtorchcodec_coreN.{ext}: Base library which contains the
# implementation of VideoDecoder and everything VideoDecoder needs. On
# Linux, {ext} is so. On Mac, it is dylib.
#
# 2. libtorchcodec_custom_opsN.{ext}: Implementation of the PyTorch custom
# ops. Depends on libtorchcodec_decoderN.{ext}. On Linux, {ext} is so.
# ops. Depends on libtorchcodec_coreN.{ext}. On Linux, {ext} is so.
# On Mac, it is dylib.
#
# 3. libtorchcodec_pybind_opsN.{ext}: Implementation of the pybind11 ops. We
# keep these separate from the PyTorch custom ops because we have to
# load these libraries separately on the Python side. Depends on
# libtorchcodec_decoderN.{ext}. On BOTH Linux and Mac {ext} is so.
# libtorchcodec_coreN.{ext}. On BOTH Linux and Mac {ext} is so.

# 1. Create libtorchcodec_decoderN.{ext}.
set(decoder_library_name "libtorchcodec_decoder${ffmpeg_major_version}")
set(decoder_sources
# 1. Create libtorchcodec_coreN.{ext}.
set(core_library_name "libtorchcodec_core${ffmpeg_major_version}")
set(core_sources
AVIOContextHolder.cpp
AVIOTensorContext.cpp
FFMPEGCommon.cpp
Frame.cpp
DeviceInterface.cpp
CpuDeviceInterface.cpp
SingleStreamDecoder.cpp
# TODO: lib name should probably not be "*_decoder*" now that it also
# contains an encoder
Encoder.cpp
)

if(ENABLE_CUDA)
list(APPEND decoder_sources CudaDeviceInterface.cpp)
list(APPEND core_sources CudaDeviceInterface.cpp)
endif()

set(decoder_library_dependencies
set(core_library_dependencies
${ffmpeg_target}
${TORCH_LIBRARIES}
)

if(ENABLE_CUDA)
list(APPEND decoder_library_dependencies
list(APPEND core_library_dependencies
${CUDA_nppi_LIBRARY}
${CUDA_nppicc_LIBRARY}
)
endif()

make_torchcodec_sublibrary(
"${decoder_library_name}"
"${core_library_name}"
SHARED
"${decoder_sources}"
"${decoder_library_dependencies}"
"${core_sources}"
"${core_library_dependencies}"
)

# 2. Create libtorchcodec_custom_opsN.{ext}.
Expand All @@ -106,7 +104,7 @@ function(make_torchcodec_libraries
custom_ops.cpp
)
set(custom_ops_dependencies
${decoder_library_name}
${core_library_name}
${Python3_LIBRARIES}
)
make_torchcodec_sublibrary(
Expand All @@ -123,7 +121,7 @@ function(make_torchcodec_libraries
pybind_ops.cpp
)
set(pybind_ops_dependencies
${decoder_library_name}
${core_library_name}
pybind11::module # This library dependency makes sure we have the right
# Python libraries included as well as all of the right
# settings so that we can successfully load the shared
Expand Down Expand Up @@ -158,7 +156,7 @@ function(make_torchcodec_libraries
target_compile_definitions(
${pybind_ops_library_name}
PRIVATE
PYBIND_OPS_MODULE_NAME=decoder_core_pybind_ops
PYBIND_OPS_MODULE_NAME=core_pybind_ops
)
# If we don't make sure this flag is set, we run into segfauls at import
# time on Mac. See:
Expand All @@ -172,7 +170,7 @@ function(make_torchcodec_libraries
# Install all libraries.
set(
all_libraries
${decoder_library_name}
${core_library_name}
${custom_ops_library_name}
${pybind_ops_library_name}
)
Expand Down Expand Up @@ -249,7 +247,7 @@ else()
# Expose these values updwards so that the test compilation does not need
# to re-figure it out. FIXME: it's not great that we just copy-paste the
# library names.
set(libtorchcodec_library_name "libtorchcodec_decoder${ffmpeg_major_version}" PARENT_SCOPE)
set(libtorchcodec_library_name "libtorchcodec_core${ffmpeg_major_version}" PARENT_SCOPE)
set(libtorchcodec_custom_ops_name "libtorchcodec_custom_ops${ffmpeg_major_version}" PARENT_SCOPE)
set(libav_include_dirs ${LIBAV_INCLUDE_DIRS} PARENT_SCOPE)
endif()
2 changes: 1 addition & 1 deletion src/torchcodec/_core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def load_torchcodec_shared_libraries():
exceptions = []
for ffmpeg_major_version in (7, 6, 5, 4):
pybind_ops_module_name = _get_pybind_ops_module_name(ffmpeg_major_version)
decoder_library_name = f"libtorchcodec_decoder{ffmpeg_major_version}"
decoder_library_name = f"libtorchcodec_core{ffmpeg_major_version}"
custom_ops_library_name = f"libtorchcodec_custom_ops{ffmpeg_major_version}"
pybind_ops_library_name = f"libtorchcodec_pybind_ops{ffmpeg_major_version}"
try:
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_internally_replaced_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ def _get_pybind_ops_module_name(ffmpeg_major_version: str) -> str:
#
# The parameter ffmpeg_major_version is unused externally, but used
# internally.
return "decoder_core_pybind_ops"
return "core_pybind_ops"
Loading