Skip to content

No hardcoded versions #2

No hardcoded versions

No hardcoded versions #2

name: ROCm Test
on:
workflow_dispatch: # allows manual triggering
inputs:
create_release:
description: "Create new release"
required: true
type: boolean
push:
branches:
- master
- ci
paths:
[
".github/workflows/**",
"**/CMakeLists.txt",
"**/Makefile",
"**/*.h",
"**/*.hpp",
"**/*.c",
"**/*.cpp",
"**/*.cu",
]
pull_request:
types: [opened, synchronize, reopened]
paths:
[
"**/CMakeLists.txt",
"**/Makefile",
"**/*.h",
"**/*.hpp",
"**/*.c",
"**/*.cpp",
"**/*.cu",
]
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
cancel-in-progress: true
jobs:
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: Cache ROCm Installation
id: cache-rocm
uses: actions/cache@v4
with:
path: /opt/rocm
key: rocm-${{ env.ROCM_VERSION }}-${{ runner.os }}
- name: ccache
uses: ggml-org/ccache-action@v1.2.16
with:
key: ubuntu-latest-rocm-${{ env.ROCM_VERSION }}-x64
evict-old-files: 1d
- name: Setup ROCm Repository
run: |
# Always setup ROCm repository (needed even when cache hits)
sudo apt-get update
sudo apt-get 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-get update
- name: Install ROCm
if: steps.cache-rocm.outputs.cache-hit != 'true'
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 install -y \
rocm-dev \
hip-dev \
hipblas-dev \
ninja-build
- name: Setup ROCm Environment
run: |
# Add ROCm to PATH for current session
echo "/opt/rocm/bin" >> $GITHUB_PATH
- name: Verify ROCm Installation
run: |
# Verify ROCm installation
if [ -f "/opt/rocm/bin/clang" ]; then
echo "ROCm clang found at /opt/rocm/bin/clang"
/opt/rocm/bin/clang --version
else
echo "ERROR: ROCm clang not found"
ls -la /opt/rocm/bin/ || echo "ROCm bin directory not found"
exit 1
fi
# Test rocminfo if available
if command -v rocminfo >/dev/null 2>&1; then
echo "ROCm device info:"
rocminfo | head -20 || echo "Warning: rocminfo failed, but continuing"
else
echo "rocminfo not available (expected in CI environment)"
fi
- name: Build
id: cmake_build
run: |
mkdir build
cd build
cmake .. -G Ninja \
-DCMAKE_CXX_COMPILER=/opt/rocm/bin/clang++ \
-DCMAKE_C_COMPILER=/opt/rocm/bin/clang \
-DCMAKE_BUILD_TYPE=Release \
-DGGML_HIPBLAS=ON \
-DGGML_AVX2=ON \
-DAMDGPU_TARGETS="${{ env.GPU_TARGETS }}" \
-DSD_BUILD_SHARED_LIBS=ON
cmake --build . --config Release
- name: Test ROCm Integration
run: |
cd build
./bin/sd --help || {
echo "Binary execution failed. Checking dependencies..."
ldd ./bin/sd || echo "ldd failed"
ls -la ./bin/ || echo "bin directory listing failed"
exit 1
}
- 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: Pack artifacts
id: pack_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
cp /opt/rocm/lib/rocblas/library/* ./build/bin/rocblas/library/ || true
cp /opt/rocm/lib/hipblaslt/library/* ./build/bin/hipblaslt/library/ || true
# Create archive
tar -czf sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-rocm-x64.tar.gz -C ./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.tar.gz
path: |
sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-rocm-x64.tar.gz