How to build bdist_wheel with CUDA dynamic link

hi,
I have successfully built PyTorch 1.4.1, CentOS 7, cuda10.1, py3.6 from source, using python setup.py build, indeeded it generate the libtorch.so with dynamic linking of cudart/cudnn/cufft etc

However, next when “setup.py bdist_wheel” to pack the results, the final .whl actually is a static libtorch.so and all dynmaic linking are removed inclding cuda, mpi, mkl etc

so wondering how to build .whl with dynamic linking of cudart/cudnn/cufft etc?

Appreciated for help.

1 Like

When I install the official torch whl package and the package compiled from the source code, why are the linked dynamic libraries different? How does the official compile and link cuda library and system library?

  • Official torch whl,

$ ldd libtorch_cuda.so
linux-vdso.so.1 (0x00007fff513fa000)
libcudart-80664282.so.10.2 => /usr/local/lib/python3.6/dist-packages/torch/lib/./libcudart-80664282.so.10.2 (0x00007fc880a74000)
libc10_cuda.so => /usr/local/lib/python3.6/dist-packages/torch/lib/./libc10_cuda.so (0x00007fc880844000)
libnvToolsExt-3965bdd0.so.1 => /usr/local/lib/python3.6/dist-packages/torch/lib/./libnvToolsExt-3965bdd0.so.1 (0x00007fc88063a000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc88041b000)
libc10.so => /usr/local/lib/python3.6/dist-packages/torch/lib/./libc10.so (0x00007fc880184000)
libtorch_cpu.so => /usr/local/lib/python3.6/dist-packages/torch/lib/./libtorch_cpu.so (0x00007fc86e040000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc86dca2000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc86da9e000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc86d896000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc86d50d000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc86d2f5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc86cf04000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc8c0803000)
libgomp-a34b3233.so.1 => /usr/local/lib/python3.6/dist-packages/torch/lib/./libgomp-a34b3233.so.1 (0x00007fc86ccda000)

  • Source compiled whl.

$ ldd libtorch_cuda.so
linux-vdso.so.1 (0x00007ffec46ff000)
libcudart.so.10.2 => /usr/local/cuda/lib64/libcudart.so.10.2 (0x00007f04f4cab000)
libc10_cuda.so => /usr/local/lib/python3.6/dist-packages/torch/lib/./libc10_cuda.so (0x00007f04f4a89000)
libcusparse.so.10 => /usr/local/cuda/lib64/libcusparse.so.10 (0x00007f04ece23000)
libcurand.so.10 => /usr/local/cuda/lib64/libcurand.so.10 (0x00007f04e8d80000)
libcusolver.so.10 => /usr/local/cuda/lib64/libcusolver.so.10 (0x00007f04dd5b9000)
libcudnn.so.7 => /usr/lib/x86_64-linux-gnu/libcudnn.so.7 (0x00007f04c1ccf000)
libnvToolsExt.so.1 => /usr/local/cuda/lib64/libnvToolsExt.so.1 (0x00007f04c1ac6000)
libmpi_cxx.so.20 => /usr/lib/x86_64-linux-gnu/libmpi_cxx.so.20 (0x00007f04c18ac000)
libmpi.so.20 => /usr/lib/x86_64-linux-gnu/libmpi.so.20 (0x00007f04c15ba000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f04c139b000)
libtorch_cpu.so => /usr/local/lib/python3.6/dist-packages/torch/lib/./libtorch_cpu.so (0x00007f04baba0000)
libc10.so => /usr/local/lib/python3.6/dist-packages/torch/lib/./libc10.so (0x00007f04ba932000)
libcufft.so.10 => /usr/local/cuda/lib64/libcufft.so.10 (0x00007f04b1492000)
libcublas.so.10 => /usr/lib/x86_64-linux-gnu/libcublas.so.10 (0x00007f04ad1dc000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f04ace53000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f04acab5000)
libomp.so.5 => /usr/lib/x86_64-linux-gnu/libomp.so.5 (0x00007f04ac800000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f04ac5e8000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f04ac1f7000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0512449000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f04abff3000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f04abdeb000)
libopen-rte.so.20 => /usr/lib/x86_64-linux-gnu/libopen-rte.so.20 (0x00007f04abb63000)
libopen-pal.so.20 => /usr/lib/x86_64-linux-gnu/libopen-pal.so.20 (0x00007f04ab8b1000)
libhwloc.so.5 => /usr/lib/x86_64-linux-gnu/libhwloc.so.5 (0x00007f04ab674000)
libnuma.so.1 => /usr/lib/x86_64-linux-gnu/libnuma.so.1 (0x00007f04ab469000)
libblas.so.3 => /usr/lib/x86_64-linux-gnu/libblas.so.3 (0x00007f04ab1fc000)
liblapack.so.3 => /usr/lib/x86_64-linux-gnu/liblapack.so.3 (0x00007f04aa95e000)
libcublasLt.so.10 => /usr/lib/x86_64-linux-gnu/libcublasLt.so.10 (0x00007f04a8acb000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f04a88c8000)
libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f04a86be000)
libgfortran.so.4 => /usr/lib/x86_64-linux-gnu/libgfortran.so.4 (0x00007f04a82df000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f04a809f000)

The official wheels statically link e.g. libcudart so that you can install the PyTorch wheels without a CUDA toolkit installation on your system (only the NVIDIA drivers need to be installed).
The build scripts can be found in pytorch/builder.

I want to know how to run this script? Could you tell me the arguments to run this script. thank you very much.
builder/build_libtorch.sh at master · pytorch/builder · GitHub,