name: CI on: workflow_dispatch: # allows manual triggering inputs: create_release: description: "Create new release" required: true type: boolean push: branches: - master - ci paths: [ ".github/workflows/**", ".dockerignore", "docs/dgl-builtins.md", "docker/Dockerfile*", "scripts/ci-cuda-cache.sh", "**/CMakeLists.txt", "**/Makefile", "**/*.h", "**/*.hpp", "**/*.c", "**/*.cpp", "**/*.cu", "**/*.cuh", "ggml", "examples/server/frontend", "examples/server/frontend/**", "examples/server/recipes/*.json", "start-server.sh", "start-server.bat", ] pull_request: types: [opened, synchronize, reopened] paths: [ ".github/workflows/**", ".dockerignore", "docs/dgl-builtins.md", "docker/Dockerfile*", "scripts/ci-cuda-cache.sh", "**/CMakeLists.txt", "**/Makefile", "**/*.h", "**/*.hpp", "**/*.c", "**/*.cpp", "**/*.cu", "**/*.cuh", "ggml", "examples/server/frontend", "examples/server/frontend/**", "examples/server/recipes/*.json", "start-server.sh", "start-server.bat", ] env: BRANCH_NAME: ${{ github.head_ref || github.ref_name }} permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }} cancel-in-progress: true jobs: ubuntu-latest-cmake: runs-on: ubuntu-latest steps: - name: Clone id: checkout uses: actions/checkout@v6 with: submodules: recursive - name: Setup Node uses: actions/setup-node@v5 with: node-version: 24 - name: Setup pnpm uses: pnpm/action-setup@v5 with: version: 10.15.1 - name: Dependencies id: depends run: | sudo apt-get update sudo apt-get install build-essential - name: Build id: cmake_build run: | mkdir build cd build cmake .. -DSD_BUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_INSTALL_RPATH='$ORIGIN' cmake --build . --config Release cmake --build . --config Release --target dgl-check-builtins - name: Get commit hash id: commit if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} shell: bash run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT" - 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 cp thirdparty/libwebm/LICENSE.TXT ./build/bin/libwebm.txt cp thirdparty/libwebp/COPYING ./build/bin/libwebp.txt chmod +x start-server.sh zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* ./start-server.sh ./start-server.bat - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v6 with: name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip path: | sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ubuntu-latest-cmake-vulkan: runs-on: ubuntu-latest steps: - name: Clone id: checkout uses: actions/checkout@v6 with: submodules: recursive - name: Setup Node uses: actions/setup-node@v5 with: node-version: 24 - name: Setup pnpm uses: pnpm/action-setup@v5 with: version: 10.15.1 - name: Dependencies id: depends run: | sudo apt-get update sudo apt-get install build-essential libvulkan-dev glslc spirv-headers - name: Build id: cmake_build run: | mkdir build cd build cmake .. -DSD_BUILD_SHARED_LIBS=ON -DSD_VULKAN=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_INSTALL_RPATH='$ORIGIN' 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' }} shell: bash run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT" - 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 cp thirdparty/libwebm/LICENSE.TXT ./build/bin/libwebm.txt cp thirdparty/libwebp/COPYING ./build/bin/libwebp.txt chmod +x start-server.sh zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-vulkan.zip ./build/bin/* ./start-server.sh ./start-server.bat - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v6 with: name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-vulkan.zip path: | sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-vulkan.zip build-and-push-docker-images: name: Build and push container images if: ${{ github.event_name != 'pull_request' }} runs-on: ${{ matrix.runner }} permissions: contents: read packages: write id-token: write attestations: write artifact-metadata: write strategy: matrix: variant: [musa, sycl, vulkan, cuda] platform: [linux/amd64] runner: [ubuntu-latest] build-args: [""] tag-suffix: [""] include: - variant: cuda platform: linux/arm64 runner: ubuntu-24.04-arm tag-suffix: "-spark" build-args: | CUDA_VERSION=13.0.0 UBUNTU_VERSION=24.04 CUDA_ARCHITECTURES=121 GGML_CUDA_FA_ALL_QUANTS=ON GGML_CUDA_ENABLE_DYNAMIC_CPU_BACKENDS=OFF env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} steps: - name: Checkout uses: actions/checkout@v6 with: submodules: recursive - name: Setup Node uses: actions/setup-node@v5 with: node-version: 24 - name: Setup pnpm uses: pnpm/action-setup@v5 with: version: 10.15.1 - name: Get commit hash id: commit if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} shell: bash run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT" - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v4 - name: Log in to the container registry uses: docker/login-action@v4 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata for Docker id: meta uses: docker/metadata-action@v6 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - name: Free Disk Space (Ubuntu) uses: jlumbroso/free-disk-space@v1.3.1 with: # this might remove tools that are actually needed, # if set to "true" but frees about 6 GB tool-cache: false - name: Cache CUDA compilation if: matrix.variant == 'cuda' uses: actions/cache@v5 with: path: ${{ runner.temp }}/cuda-ccache key: cuda-ccache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('docker/Dockerfile.cuda') }}-${{ github.run_id }}-${{ github.run_attempt }} restore-keys: | cuda-ccache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('docker/Dockerfile.cuda') }}- - name: Restore CUDA compiler cache mount if: matrix.variant == 'cuda' env: CUDA_CACHE_BUILDER: ${{ steps.buildx.outputs.name }} run: bash scripts/ci-cuda-cache.sh restore - name: Build and push Docker image id: build-push uses: docker/build-push-action@v7 with: context: . platforms: ${{ matrix.platform }} push: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} file: docker/Dockerfile.${{ matrix.variant }} tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }}-${{ matrix.variant }}${{ matrix.tag-suffix }} labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} build-args: ${{ matrix.build-args }} - name: Export CUDA compiler cache mount if: matrix.variant == 'cuda' env: CUDA_CACHE_BUILDER: ${{ steps.buildx.outputs.name }} run: bash scripts/ci-cuda-cache.sh save macOS-latest-cmake: runs-on: macos-latest steps: - name: Clone id: checkout uses: actions/checkout@v6 with: submodules: recursive - name: Setup Node uses: actions/setup-node@v5 with: node-version: 24 - name: Setup pnpm uses: pnpm/action-setup@v5 with: version: 10.15.1 - name: Dependencies id: depends run: | brew install zip - name: Build id: cmake_build run: | sysctl -a mkdir build cd build cmake .. -DGGML_AVX2=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -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' }} shell: bash run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT" - name: Fetch system info id: system-info run: | echo "CPU_ARCH=`uname -m`" >> "$GITHUB_OUTPUT" echo "OS_NAME=`sw_vers -productName`" >> "$GITHUB_OUTPUT" echo "OS_VERSION=`sw_vers -productVersion`" >> "$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 cp thirdparty/libwebm/LICENSE.TXT ./build/bin/libwebm.txt cp thirdparty/libwebp/COPYING ./build/bin/libwebp.txt chmod +x start-server.sh zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* ./start-server.sh ./start-server.bat - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v6 with: name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip path: | sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip windows-latest-cmake: runs-on: windows-2022 env: VULKAN_VERSION: 1.4.328.1 strategy: matrix: include: - build: "cpu" defines: "-DGGML_NATIVE=OFF -DSD_BUILD_SHARED_LIBS=ON -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON" - build: "cuda12" defines: "-DSD_CUDA=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_ARCHITECTURES='61;70;75;80;86;89;90;100;120' -DCMAKE_CUDA_FLAGS='-Xcudafe \"--diag_suppress=177\" -Xcudafe \"--diag_suppress=550\"' -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON" - build: "vulkan" defines: "-DSD_VULKAN=ON -DSD_BUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON" steps: - name: Clone id: checkout uses: actions/checkout@v6 with: submodules: recursive - name: Setup Node uses: actions/setup-node@v5 with: node-version: 24 - name: Setup pnpm uses: pnpm/action-setup@v5 with: version: 10.15.1 - name: Install cuda-toolkit id: cuda-toolkit if: ${{ matrix.build == 'cuda12' }} uses: Jimver/cuda-toolkit@v0.2.35 with: cuda: "12.8.1" method: "network" sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]' - name: Cache CUDA compilation if: matrix.build == 'cuda12' uses: ggml-org/ccache-action@v1.2.21 with: variant: ccache install: binary key: windows-cuda-12.8.1-x64 max-size: "2G" - name: Install Vulkan SDK id: get_vulkan if: ${{ matrix.build == 'vulkan' }} run: | curl.exe -o $env:RUNNER_TEMP/VulkanSDK-Installer.exe -L "https://sdk.lunarg.com/sdk/download/${env:VULKAN_VERSION}/windows/vulkansdk-windows-X64-${env:VULKAN_VERSION}.exe" & "$env:RUNNER_TEMP\VulkanSDK-Installer.exe" --accept-licenses --default-answer --confirm-command install Add-Content $env:GITHUB_ENV "VULKAN_SDK=C:\VulkanSDK\${env:VULKAN_VERSION}" Add-Content $env:GITHUB_PATH "C:\VulkanSDK\${env:VULKAN_VERSION}\bin" - name: Build id: cmake_build shell: pwsh run: | $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" $vsPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath if (-not $vsPath) { throw "Visual Studio C++ tools not found" } & "$vsPath\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64 -HostArch amd64 -SkipAutomaticLocation mkdir build cd build cmake .. -DCMAKE_CXX_FLAGS='/bigobj' -G Ninja -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_BUILD_TYPE=Release ${{ matrix.defines }} cmake --build . - name: Get commit hash id: commit if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} shell: bash run: echo "short=${GITHUB_SHA:0:7}" >> "$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: | $filePath = ".\build\bin\Release\*" if (Test-Path $filePath) { echo "Exists at path $filePath" Copy-Item ggml/LICENSE .\build\bin\Release\ggml.txt Copy-Item LICENSE .\build\bin\Release\stable-diffusion.cpp.txt } elseif (Test-Path ".\build\bin\stable-diffusion.dll") { $filePath = ".\build\bin\*" echo "Exists at path $filePath" Copy-Item ggml/LICENSE .\build\bin\ggml.txt Copy-Item LICENSE .\build\bin\stable-diffusion.cpp.txt } else { ls .\build\bin throw "Can't find stable-diffusion.dll" } $binPath = Split-Path -Parent $filePath Copy-Item thirdparty/libwebm/LICENSE.TXT (Join-Path $binPath 'libwebm.txt') Copy-Item thirdparty/libwebp/COPYING (Join-Path $binPath 'libwebp.txt') if ("${{ matrix.build }}" -eq "cuda12") { Copy-Item thirdparty/cutlass/LICENSE.txt (Join-Path $binPath 'cutlass.txt') } 7z a sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip $filePath .\start-server.sh .\start-server.bat - name: Copy and pack Cuda runtime id: pack_cuda_runtime if: ${{ matrix.build == 'cuda12' && (github.event_name == 'push' && github.ref == 'refs/heads/master' || github.event.inputs.create_release == 'true') }} run: | echo "Cuda install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}" $dst='.\build\bin\cudart\' robocopy "${{steps.cuda-toolkit.outputs.CUDA_PATH}}\bin" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll 7z a cudart-sd-bin-win-cu12-x64.zip $dst\* - name: Upload Cuda runtime if: ${{ matrix.build == 'cuda12' && (github.event_name == 'push' && github.ref == 'refs/heads/master' || github.event.inputs.create_release == 'true') }} uses: actions/upload-artifact@v6 with: name: sd-cudart-sd-bin-win-cu12-x64.zip path: | cudart-sd-bin-win-cu12-x64.zip - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v6 with: name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip path: | sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip windows-latest-rocm: runs-on: windows-2022 env: ROCM_VERSION: "10.1.0" gpu_targets: "gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201" steps: - uses: actions/checkout@v6 with: submodules: recursive - name: Setup Node uses: actions/setup-node@v5 with: node-version: 24 - name: Setup pnpm uses: pnpm/action-setup@v5 with: version: 10.15.1 - name: Cache ROCm Installation id: cache-rocm uses: actions/cache@v5 with: path: C:\TheRock\build key: rocm-wheels-${{ env.ROCM_VERSION }}-${{ runner.os }} - name: ccache uses: ggml-org/ccache-action@v1.2.21 with: key: windows-rocm-${{ env.ROCM_VERSION }}-x64 evict-old-files: 1d - name: Install ROCm with Wheels if: steps.cache-rocm.outputs.cache-hit != 'true' run: | $ErrorActionPreference = "Stop" write-host "Setting up Python virtual environment" # Create the venv directly at the cache location to avoid relocation issues New-Item -Path "C:\TheRock\build" -ItemType Directory -Force | Out-Null python -m venv C:\TheRock\build\.venv & C:\TheRock\build\.venv\Scripts\Activate.ps1 write-host "Upgrading pip" python -m pip install --upgrade pip write-host "Installing ROCm wheels for multi-arch support" # Install ROCm wheels for multi-arch support (this may take several minutes) python -m pip install --index-url https://stable.repo.amd.com/rocm/whl-next/ "rocm[libraries,devel]==${{env.ROCM_VERSION}}" # Pre-expand the devel tree so it is included in the cache write-host "Initializing ROCm devel tree" rocm-sdk init if ($LASTEXITCODE -ne 0) { throw "rocm-sdk init failed with exit code $LASTEXITCODE" } write-host "Completed ROCm wheel installation to C:\TheRock\build" - name: Setup ROCm Environment run: | $ErrorActionPreference = "Stop" # Activate venv from cache or fresh install & C:\TheRock\build\.venv\Scripts\Activate.ps1 # Expand the devel tree (idempotent; no-op if already done during install) rocm-sdk init if ($LASTEXITCODE -ne 0) { throw "rocm-sdk init failed with exit code $LASTEXITCODE" } # Get ROCm installation paths using the rocm-sdk CLI tool $rocmPath = (rocm-sdk path --root) if (-not $rocmPath) { throw "rocm-sdk path --root returned empty - devel package may not be installed" } $rocmPath = $rocmPath.Trim() $cmakePath = (rocm-sdk path --cmake).Trim() $binPath = (rocm-sdk path --bin).Trim() write-host "ROCm root: $rocmPath" write-host "CMake path: $cmakePath" write-host "Bin path: $binPath" echo "HIP_PATH=$rocmPath" >> $env:GITHUB_ENV echo "CMAKE_PREFIX_PATH=$cmakePath" >> $env:GITHUB_ENV echo "HIP_DEVICE_LIB_PATH=$rocmPath\lib\llvm\amdgcn\bitcode" >> $env:GITHUB_ENV echo "HIP_PLATFORM=amd" >> $env:GITHUB_ENV echo "LLVM_PATH=$rocmPath\lib\llvm" >> $env:GITHUB_ENV echo "$binPath" >> $env:GITHUB_PATH # Keep venv in PATH for subsequent steps echo "C:\TheRock\build\.venv\Scripts" >> $env:GITHUB_PATH - name: Build run: | mkdir build cd build cmake .. ` -G "Unix Makefiles" ` -DCMAKE_PREFIX_PATH="${env:HIP_PATH}" ` -DSD_HIPBLAS=ON ` -DSD_BUILD_SHARED_LIBS=ON ` -DGGML_NATIVE=OFF ` -DCMAKE_C_COMPILER="${env:HIP_PATH}\lib\llvm\bin\clang.exe" ` -DCMAKE_CXX_COMPILER="${env:HIP_PATH}\lib\llvm\bin\clang++.exe" ` -DCMAKE_HIP_COMPILER="${env:HIP_PATH}\lib\llvm\bin\clang.exe" ` -DHIP_PATH="${env:HIP_PATH}" ` -DCMAKE_BUILD_TYPE=Release ` -DGPU_TARGETS="${{ env.GPU_TARGETS }}" cmake --build . --config Release --parallel ${env:NUMBER_OF_PROCESSORS} - name: Get commit hash id: commit if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} shell: bash run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT" - name: Bundle HIP runtime libraries if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | $ErrorActionPreference = "Stop" $binPath = (rocm-sdk path --bin).Trim() if (-not $binPath) { throw "rocm-sdk path --bin returned empty" } foreach ($dll in @("amdhip64_7.dll", "rocm_kpack.dll", "amd_comgr.dll")) { $f = Get-ChildItem -Path $binPath -Filter $dll -ErrorAction SilentlyContinue if (-not $f) { throw "no match for $dll in $binPath" } Copy-Item $f.FullName -Destination .\build\bin\ -Force } - name: Pack artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | Copy-Item thirdparty/libwebm/LICENSE.TXT .\build\bin\libwebm.txt Copy-Item thirdparty/libwebp/COPYING .\build\bin\libwebp.txt 7z a sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-rocm-${{ env.ROCM_VERSION }}-x64.zip .\build\bin\* .\start-server.sh .\start-server.bat - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v6 with: name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-rocm-${{ env.ROCM_VERSION }}-x64.zip path: | sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-rocm-${{ env.ROCM_VERSION }}-x64.zip ubuntu-latest-rocm: runs-on: ubuntu-24.04 env: UBUNTU_VERSION: "24.04" strategy: matrix: include: - ROCM_VERSION: "10.1.0" gpu_targets: "gfx900;gfx906;gfx908;gfx90a;gfx90c;gfx942;gfx950;gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201" build: 'x64' steps: - name: Clone id: checkout uses: actions/checkout@v6 with: submodules: recursive - name: ccache uses: ggml-org/ccache-action@v1.2.21 with: key: ubuntu-rocm-cmake-${{ matrix.ROCM_VERSION }}-${{ matrix.build }} evict-old-files: 1d max-size: "2G" - name: Tune ccache for reinstalled ROCm toolchain run: | # ROCm is pip-installed fresh each run, so the clang binary's mtime # changes every time. With the default compiler_check=mtime that # invalidates the cache; hash compiler contents instead so warm # builds hit. ccache --set-config=compiler_check=content ccache --set-config=sloppiness=time_macros,include_file_mtime,include_file_ctime - name: Dependencies id: depends run: | sudo apt install -y build-essential git cmake wget - name: Free disk space run: | df -h # Remove preinstalled SDKs and caches not needed for this job before # installing ROCm. The legacy ROCm apt packages are large enough to # exhaust ubuntu-latest if cleanup runs after installation. 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 sudo rm -rf /usr/share/swift || true sudo rm -rf /usr/local/share/boost || true docker system prune -af || true sudo apt clean df -h - name: Setup TheRock with Wheels id: therock_env run: | # Create Python virtual environment python3 -m venv .venv source .venv/bin/activate # Install ROCm wheels for build # libraries = HIP runtime and CMake configs needed for linking # devel = compilers, headers, static libs python -m pip install --upgrade pip python -m pip install --index-url https://stable.repo.amd.com/rocm/whl-next/ "rocm[libraries,devel]==${{matrix.ROCM_VERSION}}" # Get ROCm installation paths using the rocm-sdk CLI tool ROCM_PATH=$(rocm-sdk path --root) CMAKE_PATH=$(rocm-sdk path --cmake) BIN_PATH=$(rocm-sdk path --bin) echo "ROCM_PATH=$ROCM_PATH" echo "CMAKE_PATH=$CMAKE_PATH" echo "BIN_PATH=$BIN_PATH" # Set environment variables echo "ROCM_PATH=$ROCM_PATH" >> $GITHUB_ENV echo "CMAKE_PREFIX_PATH=$CMAKE_PATH" >> $GITHUB_ENV echo "HIP_PATH=$ROCM_PATH" >> $GITHUB_ENV echo "PATH=$BIN_PATH:${PATH}" >> $GITHUB_ENV echo "LD_LIBRARY_PATH=$ROCM_PATH/lib:${LD_LIBRARY_PATH:-}" >> $GITHUB_ENV # Keep venv activated for subsequent steps echo "$(pwd)/.venv/bin" >> $GITHUB_PATH # setup-node installs into /opt/hostedtoolcache, which is removed above. # Keep Node/pnpm setup after disk cleanup so the server frontend can be embedded. - name: Setup Node uses: actions/setup-node@v5 with: node-version: 24 - name: Setup pnpm uses: pnpm/action-setup@v5 with: version: 10.15.1 - name: Build id: cmake_build run: | mkdir build cd build cmake .. -G Ninja \ -DCMAKE_HIP_COMPILER="$(hipconfig -l)/clang" \ -DCMAKE_HIP_FLAGS="-mllvm --amdgpu-unroll-threshold-local=600" \ -DCMAKE_BUILD_TYPE=Release \ -DSD_HIPBLAS=ON \ -DHIP_PLATFORM=amd \ -DGPU_TARGETS="${{ matrix.gpu_targets }}" \ -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DCMAKE_INSTALL_RPATH='$ORIGIN' \ -DGGML_NATIVE=OFF \ -DSD_BUILD_SHARED_GGML_LIB=ON \ -DGGML_BACKEND_DL=ON \ -DGGML_CPU_ALL_VARIANTS=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' }} shell: bash run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT" - 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 - 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 cp thirdparty/libwebm/LICENSE.TXT ./build/bin/libwebm.txt cp thirdparty/libwebp/COPYING ./build/bin/libwebp.txt chmod +x start-server.sh zip -y -r 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-${{ matrix.ROCM_VERSION }}.zip ./build/bin ./start-server.sh ./start-server.bat - name: Upload artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: actions/upload-artifact@v6 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-${{ matrix.ROCM_VERSION }}.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-${{ matrix.ROCM_VERSION }}.zip release: if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} runs-on: ubuntu-latest permissions: contents: write needs: - ubuntu-latest-cmake - ubuntu-latest-cmake-vulkan - ubuntu-latest-rocm - macOS-latest-cmake - windows-latest-cmake - windows-latest-rocm steps: - name: Clone uses: actions/checkout@v6 with: fetch-depth: 0 - name: Download artifacts id: download-artifact uses: actions/download-artifact@v7 with: path: ./artifact pattern: sd-* merge-multiple: true - name: Get commit count id: commit_count run: | echo "count=$(git rev-list --count HEAD)" >> $GITHUB_OUTPUT - name: Get commit hash id: commit shell: bash run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT" - name: Create release id: create_release if: ${{ github.event_name == 'workflow_dispatch' || github.ref_name == 'master' }} uses: actions/github-script@v9 env: RELEASE_TAG: ${{ format('{0}-{1}-{2}', env.BRANCH_NAME, steps.commit_count.outputs.count, steps.commit.outputs.short) }} with: script: | const { data: release } = await github.rest.repos.createRelease({ ...context.repo, tag_name: process.env.RELEASE_TAG, name: process.env.RELEASE_TAG, target_commitish: context.sha, draft: false, prerelease: false, }); core.setOutput('id', release.id); - name: Upload release id: upload_release if: ${{ github.event_name == 'workflow_dispatch' || github.ref_name == 'master' }} uses: actions/github-script@v9 env: RELEASE_ID: ${{ steps.create_release.outputs.id }} with: script: | const path = require('path'); const fs = require('fs').promises; const release_id = Number(process.env.RELEASE_ID); for (const file of await fs.readdir('./artifact')) { if (path.extname(file) === '.zip') { console.log('uploadReleaseAsset', file); await github.rest.repos.uploadReleaseAsset({ owner: context.repo.owner, repo: context.repo.repo, release_id: release_id, name: file, data: await fs.readFile(`./artifact/${file}`) }); } }