From 5f6b909003690b06253045bcdff6e375f17eb06d Mon Sep 17 00:00:00 2001 From: Syed Tousif Ahmed Date: Fri, 9 Sep 2022 21:31:46 -0700 Subject: [PATCH 1/4] Refactors rpath to externally set var. Adds mechanism to add metadata --- manywheel/build_common.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/manywheel/build_common.sh b/manywheel/build_common.sh index 95a67cdd9..0856f8d2c 100644 --- a/manywheel/build_common.sh +++ b/manywheel/build_common.sh @@ -357,20 +357,40 @@ for pkg in /$WHEELHOUSE_DIR/torch*linux*.whl /$LIBTORCH_HOUSE_DIR/libtorch*.zip; done fi + : "${C_SO_RPATH:='$ORIGIN:$ORIGIN/lib'}" + : "${LIB_SO_RPATH:='$ORIGIN'}" + # set RPATH of _C.so and similar to $ORIGIN, $ORIGIN/lib find $PREFIX -maxdepth 1 -type f -name "*.so*" | while read sofile; do - echo "Setting rpath of $sofile to " '$ORIGIN:$ORIGIN/lib' - $PATCHELF_BIN --set-rpath '$ORIGIN:$ORIGIN/lib' $sofile + echo "Setting rpath of $sofile to $C_SO_RPATH" + $PATCHELF_BIN --set-rpath $C_SO_RPATH $sofile $PATCHELF_BIN --print-rpath $sofile done # set RPATH of lib/ files to $ORIGIN find $PREFIX/lib -maxdepth 1 -type f -name "*.so*" | while read sofile; do - echo "Setting rpath of $sofile to " '$ORIGIN' - $PATCHELF_BIN --set-rpath '$ORIGIN' $sofile + echo "Setting rpath of $sofile to $LIB_SO_RPATH" + $PATCHELF_BIN --set-rpath $LIB_SO_RPATH $sofile $PATCHELF_BIN --print-rpath $sofile done + # add dependencies to METADATA + # set WHEEL_DEPENDENCIES to be a string in your wrapper script. e.g.: set the + # following in build_cuda.sh to get cuda dependencies. + # + # export WHEEL_DEPENDENCIES="Requires-Dist: nvidia-cublas-cu11\nRequires-Dist: nvidia-cuda-cupti-cu11" + # + # Notice that each dependency is prefixed 'Requires-Dist: ' and suffixed with a new line char. + # The last dependency in the string doesn't have the new line char. + # This formatting conforms to the METADATA file in a wheel. + if [[ -n "$WHEEL_DEPENDENCIES" ]]; then + metadata_file=$(echo $(basename $pkg) | sed -e 's/-cp.*$/.dist-info\/METADATA/g') + if [[ -e $metadata_file ]]; then + echo "Adding dependencies to metadata file $metadata_file" + sed -i "/^Requires-Dist.*/a$WHEEL_DEPENDENCIES" $metadata_file + fi + fi + # regenerate the RECORD file with new hashes record_file=$(echo $(basename $pkg) | sed -e 's/-cp.*$/.dist-info\/RECORD/g') if [[ -e $record_file ]]; then From 3ce99603a03f9a1f35de394fc496b07c9a1de30e Mon Sep 17 00:00:00 2001 From: Syed Tousif Ahmed Date: Thu, 22 Sep 2022 10:30:56 -0700 Subject: [PATCH 2/4] Sets RUNPATH when using cudnn and cublas wheels --- manywheel/build_common.sh | 17 ----------------- manywheel/build_cuda.sh | 9 +++++++++ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/manywheel/build_common.sh b/manywheel/build_common.sh index 0856f8d2c..06ecadaee 100644 --- a/manywheel/build_common.sh +++ b/manywheel/build_common.sh @@ -374,23 +374,6 @@ for pkg in /$WHEELHOUSE_DIR/torch*linux*.whl /$LIBTORCH_HOUSE_DIR/libtorch*.zip; $PATCHELF_BIN --print-rpath $sofile done - # add dependencies to METADATA - # set WHEEL_DEPENDENCIES to be a string in your wrapper script. e.g.: set the - # following in build_cuda.sh to get cuda dependencies. - # - # export WHEEL_DEPENDENCIES="Requires-Dist: nvidia-cublas-cu11\nRequires-Dist: nvidia-cuda-cupti-cu11" - # - # Notice that each dependency is prefixed 'Requires-Dist: ' and suffixed with a new line char. - # The last dependency in the string doesn't have the new line char. - # This formatting conforms to the METADATA file in a wheel. - if [[ -n "$WHEEL_DEPENDENCIES" ]]; then - metadata_file=$(echo $(basename $pkg) | sed -e 's/-cp.*$/.dist-info\/METADATA/g') - if [[ -e $metadata_file ]]; then - echo "Adding dependencies to metadata file $metadata_file" - sed -i "/^Requires-Dist.*/a$WHEEL_DEPENDENCIES" $metadata_file - fi - fi - # regenerate the RECORD file with new hashes record_file=$(echo $(basename $pkg) | sed -e 's/-cp.*$/.dist-info\/RECORD/g') if [[ -e $record_file ]]; then diff --git a/manywheel/build_cuda.sh b/manywheel/build_cuda.sh index c7a177fee..1dc787709 100644 --- a/manywheel/build_cuda.sh +++ b/manywheel/build_cuda.sh @@ -274,6 +274,15 @@ elif [[ $CUDA_VERSION == "11.7" ]]; then "libcublas.so.11" "libcublasLt.so.11" ) + else + echo "Using cudnn and cublas from pypi." + CUDA_RPATHS=( + '$ORIGIN/../../nvidia/cublas/lib' + '$ORIGIN/../../nvidia/cudnn/lib' + ) + CUDA_RPATHS=$(IFS=: ; echo "${CUDA_RPATHS[*]}") + export C_SO_RPATH=$CUDA_RPATHS':$ORIGIN:$ORIGIN/lib' + export LIB_SO_RPATH=$CUDA_RPATHS':$ORIGIN' fi else echo "Unknown cuda version $CUDA_VERSION" From 6ac61ae211cd7ce9fbac199a6a55ba441fe3befa Mon Sep 17 00:00:00 2001 From: Syed Tousif Ahmed Date: Thu, 22 Sep 2022 14:18:22 -0700 Subject: [PATCH 3/4] Escapes dollar sign --- manywheel/build_common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manywheel/build_common.sh b/manywheel/build_common.sh index 06ecadaee..0c56b89a7 100644 --- a/manywheel/build_common.sh +++ b/manywheel/build_common.sh @@ -357,8 +357,8 @@ for pkg in /$WHEELHOUSE_DIR/torch*linux*.whl /$LIBTORCH_HOUSE_DIR/libtorch*.zip; done fi - : "${C_SO_RPATH:='$ORIGIN:$ORIGIN/lib'}" - : "${LIB_SO_RPATH:='$ORIGIN'}" + : "${C_SO_RPATH:='\$ORIGIN:\$ORIGIN/lib'}" + : "${LIB_SO_RPATH:='\$ORIGIN'}" # set RPATH of _C.so and similar to $ORIGIN, $ORIGIN/lib find $PREFIX -maxdepth 1 -type f -name "*.so*" | while read sofile; do From 6a1dac636f9b0981b33d8e15e38a55f0fddec524 Mon Sep 17 00:00:00 2001 From: atalman Date: Fri, 23 Sep 2022 08:39:45 -0700 Subject: [PATCH 4/4] Fix rpath for cpu builds --- manywheel/build_common.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/manywheel/build_common.sh b/manywheel/build_common.sh index 0c56b89a7..7ad15147a 100644 --- a/manywheel/build_common.sh +++ b/manywheel/build_common.sh @@ -357,20 +357,17 @@ for pkg in /$WHEELHOUSE_DIR/torch*linux*.whl /$LIBTORCH_HOUSE_DIR/libtorch*.zip; done fi - : "${C_SO_RPATH:='\$ORIGIN:\$ORIGIN/lib'}" - : "${LIB_SO_RPATH:='\$ORIGIN'}" - # set RPATH of _C.so and similar to $ORIGIN, $ORIGIN/lib find $PREFIX -maxdepth 1 -type f -name "*.so*" | while read sofile; do - echo "Setting rpath of $sofile to $C_SO_RPATH" - $PATCHELF_BIN --set-rpath $C_SO_RPATH $sofile + echo "Setting rpath of $sofile to ${C_SO_RPATH:-'$ORIGIN:$ORIGIN/lib'}" + $PATCHELF_BIN --set-rpath ${C_SO_RPATH:-'$ORIGIN:$ORIGIN/lib'} $sofile $PATCHELF_BIN --print-rpath $sofile done # set RPATH of lib/ files to $ORIGIN find $PREFIX/lib -maxdepth 1 -type f -name "*.so*" | while read sofile; do - echo "Setting rpath of $sofile to $LIB_SO_RPATH" - $PATCHELF_BIN --set-rpath $LIB_SO_RPATH $sofile + echo "Setting rpath of $sofile to ${LIB_SO_RPATH:-'$ORIGIN'}" + $PATCHELF_BIN --set-rpath ${LIB_SO_RPATH:-'$ORIGIN'} $sofile $PATCHELF_BIN --print-rpath $sofile done