Skip to content

Commit 0b51144

Browse files
Refactor PyTorch wheel and libtorch build scripts for ROCm (#1232)
* Refactor wheel and libtorch build scripts (ROCm#7) * 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 * rocfft/hipfft link to libhiprtc.so in ROCm5.4 (ROCm#15) Co-authored-by: Jack Taylor <[email protected]>
1 parent d168714 commit 0b51144

File tree

3 files changed

+106
-565
lines changed

3 files changed

+106
-565
lines changed

manywheel/build_common.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ replace_needed_sofiles() {
279279
find $1 -name '*.so*' | while read sofile; do
280280
origname=$2
281281
patchedname=$3
282-
if [[ "$origname" != "$patchedname" ]]; then
282+
if [[ "$origname" != "$patchedname" ]] || [[ "$DESIRED_CUDA" == *"rocm"* ]]; then
283283
set +e
284-
$PATCHELF_BIN --print-needed $sofile | grep $origname 2>&1 >/dev/null
284+
origname=$($PATCHELF_BIN --print-needed $sofile | grep "$origname*")
285285
ERRCODE=$?
286286
set -e
287287
if [ "$ERRCODE" -eq "0" ]; then

manywheel/build_libtorch.sh

+13-4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ fname_with_sha256() {
228228
fi
229229
}
230230

231+
fname_without_so_number() {
232+
LINKNAME=$(echo $1 | sed -e 's/\.so.*/.so/g')
233+
echo "$LINKNAME"
234+
}
235+
231236
make_wheel_record() {
232237
FPATH=$1
233238
if echo $FPATH | grep RECORD >/dev/null 2>&1; then
@@ -277,8 +282,12 @@ for pkg in /$LIBTORCH_HOUSE_DIR/libtorch*.zip; do
277282
if [[ "$filepath" != "$destpath" ]]; then
278283
cp $filepath $destpath
279284
fi
280-
281-
patchedpath=$(fname_with_sha256 $destpath)
285+
286+
if [[ "$DESIRED_CUDA" == *"rocm"* ]]; then
287+
patchedpath=$(fname_without_so_number $destpath)
288+
else
289+
patchedpath=$(fname_with_sha256 $destpath)
290+
fi
282291
patchedname=$(basename $patchedpath)
283292
if [[ "$destpath" != "$patchedpath" ]]; then
284293
mv $destpath $patchedpath
@@ -292,9 +301,9 @@ for pkg in /$LIBTORCH_HOUSE_DIR/libtorch*.zip; do
292301
find $PREFIX -name '*.so*' | while read sofile; do
293302
origname=${DEPS_SONAME[i]}
294303
patchedname=${patched[i]}
295-
if [[ "$origname" != "$patchedname" ]]; then
304+
if [[ "$origname" != "$patchedname" ]] || [[ "$DESIRED_CUDA" == *"rocm"* ]]; then
296305
set +e
297-
$PATCHELF_BIN --print-needed $sofile | grep $origname 2>&1 >/dev/null
306+
origname=$($PATCHELF_BIN --print-needed $sofile | grep "$origname*")
298307
ERRCODE=$?
299308
set -e
300309
if [ "$ERRCODE" -eq "0" ]; then

0 commit comments

Comments
 (0)