From 4cde0acc0e4e795e1a12cbdd9b93c8c04c1fa05d Mon Sep 17 00:00:00 2001 From: Jithun Nair Date: Wed, 13 Aug 2025 19:49:23 +0000 Subject: [PATCH] Make triton build ROCm library version-agnostic (#158408) Fixes maintenance of triton packaging script when library versions change from one ROCm version to next. Pull Request resolved: https://github.com/pytorch/pytorch/pull/158408 Approved by: https://github.com/jeffdaily Co-authored-by: Ethan Wee --- .github/scripts/amd/package_triton_wheel.sh | 31 +++++---------------- .github/scripts/amd/patch_triton_wheel.sh | 16 +++++------ 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/.github/scripts/amd/package_triton_wheel.sh b/.github/scripts/amd/package_triton_wheel.sh index 6ecf8bab116..fe8d915422d 100755 --- a/.github/scripts/amd/package_triton_wheel.sh +++ b/.github/scripts/amd/package_triton_wheel.sh @@ -1,3 +1,4 @@ +#!/bin/bash set -ex # Set ROCM_HOME isn't available, use ROCM_PATH if set or /opt/rocm @@ -50,29 +51,15 @@ do cp $lib $TRITON_ROCM_DIR/lib/ done -# Required ROCm libraries -if [[ "${MAJOR_VERSION}" == "6" ]]; then - libamdhip="libamdhip64.so.6" -else - libamdhip="libamdhip64.so.5" -fi - # Required ROCm libraries - ROCm 6.0 ROCM_SO=( - "${libamdhip}" - "libhsa-runtime64.so.1" - "libdrm.so.2" - "libdrm_amdgpu.so.1" + "libamdhip64.so" + "libhsa-runtime64.so" + "libdrm.so" + "libdrm_amdgpu.so" + "libamd_comgr.so" + "librocprofiler-register.so" ) -if [[ $ROCM_INT -ge 60400 ]]; then - ROCM_SO+=("libamd_comgr.so.3") -else - ROCM_SO+=("libamd_comgr.so.2") -fi - -if [[ $ROCM_INT -ge 60100 ]]; then - ROCM_SO+=("librocprofiler-register.so.0") -fi for lib in "${ROCM_SO[@]}" do @@ -94,10 +81,6 @@ do fi cp $file_path $TRITON_ROCM_DIR/lib - # When running locally, and not building a wheel, we need to satisfy shared objects requests that don't look for versions - LINKNAME=$(echo $lib | sed -e 's/\.so.*/.so/g') - ln -sf $lib $TRITON_ROCM_DIR/lib/$LINKNAME - done # Copy Include Files diff --git a/.github/scripts/amd/patch_triton_wheel.sh b/.github/scripts/amd/patch_triton_wheel.sh index 36691346315..fb3c0f36ddb 100755 --- a/.github/scripts/amd/patch_triton_wheel.sh +++ b/.github/scripts/amd/patch_triton_wheel.sh @@ -19,15 +19,13 @@ replace_needed_sofiles() { find $1 -name '*.so*' -o -name 'ld.lld' | while read sofile; do origname=$2 patchedname=$3 - if [[ "$origname" != "$patchedname" ]]; then - set +e - origname=$($PATCHELF_BIN --print-needed $sofile | grep "$origname.*") - ERRCODE=$? - set -e - if [ "$ERRCODE" -eq "0" ]; then - echo "patching $sofile entry $origname to $patchedname" - $PATCHELF_BIN --replace-needed $origname $patchedname $sofile - fi + set +e + origname=$($PATCHELF_BIN --print-needed $sofile | grep "$origname.*") + ERRCODE=$? + set -e + if [ "$ERRCODE" -eq "0" ]; then + echo "patching $sofile entry $origname to $patchedname" + $PATCHELF_BIN --replace-needed $origname $patchedname $sofile fi done }