diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 76b179355..3c05caf52 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -485,6 +485,153 @@ jobs: path: | sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-rocm-x64.zip + ubuntu-latest-rocm: + runs-on: ubuntu-latest + container: rocm/dev-ubuntu-24.04:7.2 + + env: + ROCM_VERSION: "7.2" + UBUNTU_VERSION: "24.04" + 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@v6 + 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: Dependencies + id: depends + run: | + sudo apt-get update + sudo apt install -y \ + cmake \ + hip-dev \ + hipblas-dev \ + ninja-build \ + rocm-dev \ + zip + # 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 + + # 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 + case "$file" in + $PATTERN) + ;; + *) + sudo rm -f "$file" ;; + esac; + done + + cd /opt/rocm/lib/hipblaslt/library + for file in *; do + case "$file" in + $PATTERN) + ;; + *) + sudo rm -f "$file" ;; + esac; + 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: 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-${{ 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' }} @@ -493,6 +640,7 @@ jobs: needs: - ubuntu-latest-cmake - ubuntu-latest-cmake-vulkan + - ubuntu-latest-rocm - build-and-push-docker-images - macOS-latest-cmake - windows-latest-cmake