Skip to content

Commit

Permalink
Refactor wheel and libtorch build scripts (ROCm#7)
Browse files Browse the repository at this point in the history
* Update to so patching for ROCm

Wildcard used in grep to grab the actual numbered so file referenced
in patchelf. This allows the removal of specifying the so number in
DEPS_LIST & DEPS_SONAME

This commit also adds the functionality for trimming so names to
build_libtorch.sh from build_common.sh

* Refactor to remove switch statement in build_rocm.sh

This commit refactors build_rocm.sh and brings in a few major updates:
 - No longer required to specify the full .so name (with number) for ROCm libraries
       - The .so versions are copied and the patching code will fix the links to point to this version
 - No longer required to specify paths for ROCm libraries allowing the removal of the large switch
       - Paths are acquired programmatically with find
 - No longer required to specify both the path and filename for the OS specific libraries
       - Programatically extract file name from the path
 - Automatically extract Tensile/Kernels files for the architectures specified in PYTORCH_ROCM_ARCH
   and any non-arch specific files e.g. TensileLibrary.dat
  • Loading branch information
jataylo authored and jithunnair-amd committed Dec 14, 2022
1 parent 00d0ac6 commit 1cce409
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 549 deletions.
4 changes: 2 additions & 2 deletions manywheel/build_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ replace_needed_sofiles() {
find $1 -name '*.so*' | while read sofile; do
origname=$2
patchedname=$3
if [[ "$origname" != "$patchedname" ]]; then
if [[ "$origname" != "$patchedname" ]] || [[ "$DESIRED_CUDA" == *"rocm"* ]]; then
set +e
$PATCHELF_BIN --print-needed $sofile | grep $origname 2>&1 >/dev/null
origname=$($PATCHELF_BIN --print-needed $sofile | grep "$origname*")
ERRCODE=$?
set -e
if [ "$ERRCODE" -eq "0" ]; then
Expand Down
17 changes: 13 additions & 4 deletions manywheel/build_libtorch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ fname_with_sha256() {
fi
}

fname_without_so_number() {
LINKNAME=$(echo $1 | sed -e 's/\.so.*/.so/g')
echo "$LINKNAME"
}

make_wheel_record() {
FPATH=$1
if echo $FPATH | grep RECORD >/dev/null 2>&1; then
Expand Down Expand Up @@ -277,8 +282,12 @@ for pkg in /$LIBTORCH_HOUSE_DIR/libtorch*.zip; do
if [[ "$filepath" != "$destpath" ]]; then
cp $filepath $destpath
fi

patchedpath=$(fname_with_sha256 $destpath)

if [[ "$DESIRED_CUDA" == *"rocm"* ]]; then
patchedpath=$(fname_without_so_number $destpath)
else
patchedpath=$(fname_with_sha256 $destpath)
fi
patchedname=$(basename $patchedpath)
if [[ "$destpath" != "$patchedpath" ]]; then
mv $destpath $patchedpath
Expand All @@ -292,9 +301,9 @@ for pkg in /$LIBTORCH_HOUSE_DIR/libtorch*.zip; do
find $PREFIX -name '*.so*' | while read sofile; do
origname=${DEPS_SONAME[i]}
patchedname=${patched[i]}
if [[ "$origname" != "$patchedname" ]]; then
if [[ "$origname" != "$patchedname" ]] || [[ "$DESIRED_CUDA" == *"rocm"* ]]; then
set +e
$PATCHELF_BIN --print-needed $sofile | grep $origname 2>&1 >/dev/null
origname=$($PATCHELF_BIN --print-needed $sofile | grep "$origname*")
ERRCODE=$?
set -e
if [ "$ERRCODE" -eq "0" ]; then
Expand Down
Loading

0 comments on commit 1cce409

Please sign in to comment.