Make the C++ backend of the torchvision wheel usable for C++ development
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
π The feature
Currently, the torchvision wheel packages the C++ DSO as _C.so for python bindings.
We'd like the python wheel to have the C++ backend be standalone, so it can be extracted/used by C++ applications, like is done today for the PyTorch wheels.
This means:
- export DSO as
libtorchvision.soinstead of_C.so - do not hardlink
libtorchvision.soagainstlibtorch_python.so.- maybe
_C.sois kept for symbols that requirelibtorch_python.so?
- maybe
- export cpp headers
- export CMake configs
Motivation, pitch
C++ developers can currently use the distributed PyTorch wheels to develop C++ native applications against libtorch, as libraries, headers, and cmake configs are available in the wheels.
C++ developers who also need to use torchvision cannot leverage the standard vision wheel the same way even though all C++ symbols are available in _C.so. Instead, they must build libtorchvision C++ from source which is more cumbersome, requires extra dev packages to be installed, especially for cuda support.
Additional context
see ld links for torchvision 0.22.0+cu128 (wheel)
libc.so.6
libc10.so
libc10_cuda.so
libcudart.so.12
libdl.so.2
libgcc_s.so.1
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6
libtorch.so
libtorch_cpu.so
libtorch_cuda.so
libtorch_python.so # requires python
linux-vdso.so.1
see ld links for c++ source build of torchvision
no link against
libtorch_python.so
libc.so.6
libc10.so
libc10_cuda.so
libcudart.so.12
libdl.so.2
libgcc_s.so.1
libm.so.6
libpthread.so.0
librt.so.1
libstdc++.so.6
libtorch.so
libtorch_cpu.so
libtorch_cuda.so
linux-vdso.so.1
example of a cpp torchvision installation with files needed for C++ development
The install tree below can be imported for building with CMake with:
cmake ... -D TorchVision_ROOT="$torch_vision_install_dir" # Or add to CMAKE_PREFIX_PATH
find_package(TorchVision)
βββ include
β βββ torchvision
β βββ io
β β βββ image
β β βββ cpu
β β β βββ common_jpeg.cpp
β β β βββ common_jpeg.h
β β β βββ common_png.h
β β β βββ decode_gif.cpp
β β β βββ decode_gif.h
β β β βββ decode_image.cpp
β β β βββ decode_image.h
β β β βββ decode_jpeg.cpp
β β β βββ decode_jpeg.h
β β β βββ decode_png.cpp
β β β βββ decode_png.h
β β β βββ encode_jpeg.cpp
β β β βββ encode_jpeg.h
β β β βββ encode_png.cpp
β β β βββ encode_png.h
β β β βββ exif.h
β β β βββ giflib
β β β β βββ dgif_lib.c
β β β β βββ gif_hash.c
β β β β βββ gif_hash.h
β β β β βββ gif_lib.h
β β β β βββ gif_lib_private.h
β β β β βββ gifalloc.c
β β β β βββ openbsd-reallocarray.c
β β β βββ read_write_file.cpp
β β β βββ read_write_file.h
β β βββ cuda
β β β βββ decode_jpeg_cuda.cpp
β β β βββ encode_decode_jpegs_cuda.h
β β β βββ encode_jpegs_cuda.cpp
β β β βββ encode_jpegs_cuda.h
β β βββ image.cpp
β β βββ image.h
β β βββ image_read_mode.h
β βββ macros.h
β βββ ops
β β βββ autocast
β β β βββ deform_conv2d_kernel.cpp
β β β βββ nms_kernel.cpp
β β β βββ ps_roi_align_kernel.cpp
β β β βββ ps_roi_pool_kernel.cpp
β β β βββ roi_align_kernel.cpp
β β β βββ roi_pool_kernel.cpp
β β βββ autograd
β β β βββ deform_conv2d_kernel.cpp
β β β βββ ps_roi_align_kernel.cpp
β β β βββ ps_roi_pool_kernel.cpp
β β β βββ roi_align_kernel.cpp
β β β βββ roi_pool_kernel.cpp
β β βββ cpu
β β β βββ deform_conv2d_kernel.cpp
β β β βββ nms_kernel.cpp
β β β βββ ps_roi_align_kernel.cpp
β β β βββ ps_roi_pool_kernel.cpp
β β β βββ roi_align_common.h
β β β βββ roi_align_kernel.cpp
β β β βββ roi_pool_kernel.cpp
β β βββ cuda
β β β βββ cuda_helpers.h
β β β βββ deform_conv2d_kernel.cu
β β β βββ nms_kernel.cu
β β β βββ ps_roi_align_kernel.cu
β β β βββ ps_roi_pool_kernel.cu
β β β βββ roi_align_kernel.cu
β β β βββ roi_pool_kernel.cu
β β βββ deform_conv2d.cpp
β β βββ deform_conv2d.h
β β βββ nms.cpp
β β βββ nms.h
β β βββ ops.h
β β βββ ps_roi_align.cpp
β β βββ ps_roi_align.h
β β βββ ps_roi_pool.cpp
β β βββ ps_roi_pool.h
β β βββ roi_align.cpp
β β βββ roi_align.h
β β βββ roi_pool.cpp
β β βββ roi_pool.h
β βββ vision.cpp
β βββ vision.h
βββ lib
β βββ libtorchvision.so
βββ share
βββ cmake
βββ TorchVision
βββ TorchVisionConfig.cmake
βββ TorchVisionConfigVersion.cmake
βββ TorchVisionTargets-noconfig.cmake
βββ TorchVisionTargets.cmake
How libtorch C++ can be used today with C++ CMake projects
torch_install=$(python3 -c "import torch; print(torch.__path__[0])")
cmake ... -D Torch_ROOT="$torch_install" # Or add to CMAKE_PREFIX_PATH
find_package(Torch)
> ls $torch_install/include
ATen/ dnnl_config.h dnnl_sycl_types.h fp16.h psimd.h tensorpipe/
c10/ dnnl_debug.h dnnl_threadpool.h fxdiv.h pthreadpool.h THC/
caffe2/ dnnl.h dnnl_types.h kineto/ pybind11/ torch/
clog.h dnnl_ocl.h dnnl_version.h libshm.h qnnpack_func.h xnnpack.h
cpuinfo.h dnnl_sycl.h experiments-config.h nnpack.h sleef.h
> ls $torch_install/include
ATen/ dnnl_config.h dnnl_sycl_types.h fp16.h psimd.h tensorpipe/
c10/ dnnl_debug.h dnnl_threadpool.h fxdiv.h pthreadpool.h THC/
caffe2/ dnnl.h dnnl_types.h kineto/ pybind11/ torch/
clog.h dnnl_ocl.h dnnl_version.h libshm.h qnnpack_func.h xnnpack.h
cpuinfo.h dnnl_sycl.h experiments-config.h nnpack.h sleef.h
> ls $torch_install/share/cmake/Torch/
TorchConfig.cmake TorchConfigVersion.cmake
> ls $torch_install/lib
libarm_compute_graph.so* libcudnn_ops.so.9* libnvpl_blas_lp64_gomp.so.0*
libarm_compute.so* libcudnn.so.9* libnvpl_lapack_core.so.0
libc10_cuda.so* libcufft.so.11* libnvpl_lapack_lp64_gomp.so.0
libc10.so* libcufile_rdma.so.1* libnvrtc-builtins.so.12.8*
libcaffe2_nvrtc.so* libcufile.so.0* libnvrtc.so.12*
libcublasLt.so.12* libcupti.so.12* libnvToolsExt.so.1*
libcublas.so.12* libcurand.so.10* libshm.so*
libcudart.so.12* libcusolver.so.11* libtorch_cpu.so*
libcudnn_adv.so.9* libcusparseLt.so.0 libtorch_cuda_linalg.so*
libcudnn_cnn.so.9* libcusparse.so.12* libtorch_cuda.so*
libcudnn_engines_precompiled.so.9* libgfortran.so.5* libtorch_global_deps.so*
libcudnn_engines_runtime_compiled.so.9* libgomp.so.1* libtorch_python.so*
libcudnn_graph.so.9* libnvJitLink.so.12* libtorch.so*
libcudnn_heuristic.so.9* libnvpl_blas_core.so.0*
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up β it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the wheel packaging and CMake export entry points that produce the current _C.so; the issue provides no source files or tests to begin with. Done means the wheel exposes lib/libtorchvision.so, include/torchvision, and share/cmake/TorchVision, without requiring libtorch_python.so for the standalone library.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, python
- Domain
- build-system, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100