From 23ef6e7d9bbe6d70e388586601d6e1bd22adfb38 Mon Sep 17 00:00:00 2001 From: "Mario Limonciello (AMD)" Date: Fri, 6 Feb 2026 21:06:51 -0600 Subject: [PATCH 1/3] Add a github action to generate a Linux ROCm artifact This uses the current stable release, ROCm 7.2. The following GPU ISA architectures are supported: * gfx1151 * gfx1150 * gfx1100 * gfx1101 * gfx1102 * gfx1200 * gfx1201 --- .github/workflows/build.yml | 146 ++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 76b179355..966c76d70 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -485,6 +485,151 @@ jobs: path: | sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-rocm-x64.zip + ubuntu-latest-rocm: + runs-on: ubuntu-latest + + env: + ROCM_VERSION: "7.2" + GPU_TARGETS: "gfx1151;gfx1150;gfx1100;gfx1101;gfx1102;gfx1200;gfx1201" + + steps: + - name: Clone + id: checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Free disk space + run: | + # Remove preinstalled SDKs and caches not needed for this job + sudo rm -rf /usr/share/dotnet || true + sudo rm -rf /usr/local/lib/android || true + sudo rm -rf /opt/ghc || true + sudo rm -rf /usr/local/.ghcup || true + sudo rm -rf /opt/hostedtoolcache || true + + # Remove old package lists and caches + sudo rm -rf /var/lib/apt/lists/* || true + sudo apt clean + + - name: Setup ROCm Repository + run: | + # Always setup ROCm repository (needed even when cache hits) + sudo apt update + sudo apt install -y wget gnupg2 + + # Add ROCm repository using modern GPG key handling + wget -q -O - https://repo.radeon.com/rocm/rocm.gpg.key | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/rocm-archive-keyring.gpg + echo "deb [arch=amd64] https://repo.radeon.com/rocm/apt/${{ env.ROCM_VERSION }}/ noble main" | sudo tee /etc/apt/sources.list.d/rocm.list + + # Set ROCm repository to highest priority to avoid conflicts with Ubuntu packages + echo "Package: *" | sudo tee /etc/apt/preferences.d/rocm-pin + echo "Pin: origin repo.radeon.com" | sudo tee -a /etc/apt/preferences.d/rocm-pin + echo "Pin-Priority: 1001" | sudo tee -a /etc/apt/preferences.d/rocm-pin + + sudo apt update + + - name: Install ROCm + run: | + # Check if ROCm packages are available + echo "Checking ROCm package availability..." + apt-cache show rocm-dev hip-dev hipblas-dev || { + echo "ROCm packages not found, listing available packages:" + apt-cache search rocm | head -10 + apt-cache search hip | head -10 + } + + # Check repository priorities + echo "Checking repository priorities..." + apt-cache policy hipcc rocm-cmake rocm-utils + + # Install ROCm packages (APT preferences will ensure ROCm repo versions are used) + echo "Installing ROCm packages..." + sudo apt install -y \ + rocm-dev \ + hip-dev \ + hipblas-dev \ + ninja-build + + # Clean apt caches to recover disk space + sudo apt clean + sudo rm -rf /var/lib/apt/lists/* || true + + - name: Setup ROCm Environment + run: | + # Add ROCm to PATH for current session + echo "/opt/rocm/bin" >> $GITHUB_PATH + + # Remove library files for architectures we're not building for to save disk space + echo "Cleaning up unneeded architecture files..." + cd /opt/rocm/lib/rocblas/library + # Keep only our target architectures + for file in *; do + if [[ ! "$file" =~ (gfx1151|gfx1150|gfx1100|gfx1101|gfx1102|gfx1200|gfx1201) ]]; then + sudo rm -f "$file" + fi + done + + cd /opt/rocm/lib/hipblaslt/library + for file in *; do + if [[ ! "$file" =~ (gfx1151|gfx1150|gfx1100|gfx1101|gfx1102|gfx1200|gfx1201) ]]; then + sudo rm -f "$file" + fi + done + + - name: Build + id: cmake_build + run: | + mkdir build + cd build + cmake .. -G Ninja \ + -DCMAKE_CXX_COMPILER=amdclang++ \ + -DCMAKE_C_COMPILER=amdclang \ + -DCMAKE_BUILD_TYPE=Release \ + -DSD_HIPBLAS=ON \ + -DGPU_TARGETS="${{ env.GPU_TARGETS }}" \ + -DAMDGPU_TARGETS="${{ env.GPU_TARGETS }}" \ + -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DSD_BUILD_SHARED_LIBS=ON + cmake --build . --config Release + + - name: Get commit hash + id: commit + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + uses: pr-mpt/actions-commit-hash@v2 + + - name: Prepare artifacts + id: prepare_artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + run: | + # Copy licenses + cp ggml/LICENSE ./build/bin/ggml.txt + cp LICENSE ./build/bin/stable-diffusion.cpp.txt + + # Create directories for ROCm libraries + mkdir -p ./build/bin/rocblas/library + mkdir -p ./build/bin/hipblaslt/library + + # Copy ROCm runtime libraries (use || true to continue if files don't exist) + cp /opt/rocm/lib/librocsparse.so* ./build/bin/ || true + cp /opt/rocm/lib/libhsa-runtime64.so* ./build/bin/ || true + cp /opt/rocm/lib/libamdhip64.so* ./build/bin/ || true + cp /opt/rocm/lib/libhipblas.so* ./build/bin/ || true + cp /opt/rocm/lib/libhipblaslt.so* ./build/bin/ || true + cp /opt/rocm/lib/librocblas.so* ./build/bin/ || true + + # Copy library files (already filtered to target architectures) + cp /opt/rocm/lib/rocblas/library/* ./build/bin/rocblas/library/ || true + cp /opt/rocm/lib/hipblaslt/library/* ./build/bin/hipblaslt/library/ || true + + - name: Upload artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-rocm-x64 + path: build/bin + release: if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} @@ -493,6 +638,7 @@ jobs: needs: - ubuntu-latest-cmake - ubuntu-latest-cmake-vulkan + - ubuntu-latest-rocm - build-and-push-docker-images - macOS-latest-cmake - windows-latest-cmake From 1c610c5346db693ec343094bdef30294debd6de0 Mon Sep 17 00:00:00 2001 From: "Mario Limonciello (AMD)" Date: Sat, 7 Feb 2026 10:02:07 -0600 Subject: [PATCH 2/3] Use AMD's container --- .github/workflows/build.yml | 63 ++++++++++++++----------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 966c76d70..3862042a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -487,15 +487,17 @@ jobs: ubuntu-latest-rocm: runs-on: ubuntu-latest + container: rocm/dev-ubuntu-24.04:7.2 env: ROCM_VERSION: "7.2" GPU_TARGETS: "gfx1151;gfx1150;gfx1100;gfx1101;gfx1102;gfx1200;gfx1201" steps: + - run: apt-get update && apt-get install -y git - name: Clone id: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v6 with: submodules: recursive @@ -512,45 +514,16 @@ jobs: sudo rm -rf /var/lib/apt/lists/* || true sudo apt clean - - name: Setup ROCm Repository - run: | - # Always setup ROCm repository (needed even when cache hits) - sudo apt update - sudo apt install -y wget gnupg2 - - # Add ROCm repository using modern GPG key handling - wget -q -O - https://repo.radeon.com/rocm/rocm.gpg.key | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/rocm-archive-keyring.gpg - echo "deb [arch=amd64] https://repo.radeon.com/rocm/apt/${{ env.ROCM_VERSION }}/ noble main" | sudo tee /etc/apt/sources.list.d/rocm.list - - # Set ROCm repository to highest priority to avoid conflicts with Ubuntu packages - echo "Package: *" | sudo tee /etc/apt/preferences.d/rocm-pin - echo "Pin: origin repo.radeon.com" | sudo tee -a /etc/apt/preferences.d/rocm-pin - echo "Pin-Priority: 1001" | sudo tee -a /etc/apt/preferences.d/rocm-pin - - sudo apt update - - - name: Install ROCm + - name: Dependencies + id: depends run: | - # Check if ROCm packages are available - echo "Checking ROCm package availability..." - apt-cache show rocm-dev hip-dev hipblas-dev || { - echo "ROCm packages not found, listing available packages:" - apt-cache search rocm | head -10 - apt-cache search hip | head -10 - } - - # Check repository priorities - echo "Checking repository priorities..." - apt-cache policy hipcc rocm-cmake rocm-utils - - # Install ROCm packages (APT preferences will ensure ROCm repo versions are used) - echo "Installing ROCm packages..." + sudo apt-get update sudo apt install -y \ rocm-dev \ hip-dev \ hipblas-dev \ + cmake \ ninja-build - # Clean apt caches to recover disk space sudo apt clean sudo rm -rf /var/lib/apt/lists/* || true @@ -560,21 +533,31 @@ jobs: # Add ROCm to PATH for current session echo "/opt/rocm/bin" >> $GITHUB_PATH + # Build case pattern from GPU_TARGETS + PATTERN=$(printf '%s' "$GPU_TARGETS" | sed 's/;/\*|\*/g') + PATTERN="*${PATTERN}*" + # Remove library files for architectures we're not building for to save disk space echo "Cleaning up unneeded architecture files..." cd /opt/rocm/lib/rocblas/library # Keep only our target architectures for file in *; do - if [[ ! "$file" =~ (gfx1151|gfx1150|gfx1100|gfx1101|gfx1102|gfx1200|gfx1201) ]]; then - sudo rm -f "$file" - fi + case "$file" in + $PATTERN) + ;; + *) + sudo rm -f "$file" ;; + esac; done cd /opt/rocm/lib/hipblaslt/library for file in *; do - if [[ ! "$file" =~ (gfx1151|gfx1150|gfx1100|gfx1101|gfx1102|gfx1200|gfx1201) ]]; then - sudo rm -f "$file" - fi + case "$file" in + $PATTERN) + ;; + *) + sudo rm -f "$file" ;; + esac; done - name: Build From 9f821bd759740a72b99f297fd8aa9551e7fb0b2d Mon Sep 17 00:00:00 2001 From: "Mario Limonciello (AMD)" Date: Sat, 7 Feb 2026 09:59:35 -0600 Subject: [PATCH 3/3] Include ROCm in target release --- .github/workflows/build.yml | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3862042a6..3c05caf52 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -491,6 +491,7 @@ jobs: env: ROCM_VERSION: "7.2" + UBUNTU_VERSION: "24.04" GPU_TARGETS: "gfx1151;gfx1150;gfx1100;gfx1101;gfx1102;gfx1200;gfx1201" steps: @@ -519,11 +520,12 @@ jobs: run: | sudo apt-get update sudo apt install -y \ - rocm-dev \ + cmake \ hip-dev \ hipblas-dev \ - cmake \ - ninja-build + ninja-build \ + rocm-dev \ + zip # Clean apt caches to recover disk space sudo apt clean sudo rm -rf /var/lib/apt/lists/* || true @@ -606,12 +608,29 @@ jobs: cp /opt/rocm/lib/rocblas/library/* ./build/bin/rocblas/library/ || true cp /opt/rocm/lib/hipblaslt/library/* ./build/bin/hipblaslt/library/ || true + - name: Fetch system info + id: system-info + run: | + echo "CPU_ARCH=`uname -m`" >> "$GITHUB_OUTPUT" + echo "OS_NAME=`lsb_release -s -i`" >> "$GITHUB_OUTPUT" + echo "OS_VERSION=`lsb_release -s -r`" >> "$GITHUB_OUTPUT" + echo "OS_TYPE=`uname -s`" >> "$GITHUB_OUTPUT" + + - name: Pack artifacts + id: pack_artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + run: | + cp ggml/LICENSE ./build/bin/ggml.txt + cp LICENSE ./build/bin/stable-diffusion.cpp.txt + zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-Ubuntu-${{ env.UBUNTU_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-rocm.zip ./build/bin/* + - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v4 with: - name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-rocm-x64 - path: build/bin + name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-Ubuntu-${{ env.UBUNTU_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-rocm.zip + path: | + sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-Ubuntu-${{ env.UBUNTU_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-rocm.zip release: if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}