167 rader
4.9 KiB
Bash
167 rader
4.9 KiB
Bash
#!/bin/bash
|
|
# Build stable-diffusion.cpp with Vulkan support and create container image
|
|
# Usage: ./build-container.sh [--no-cache]
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
TMP_BUILD_DIR="${SCRIPT_DIR}/.tmp"
|
|
BUILD_DIR="${TMP_BUILD_DIR}/sdcpp"
|
|
BIN_DIR="${TMP_BUILD_DIR}/bin-vulkan"
|
|
HOME_DIR="${HOME}"
|
|
NO_CACHE=""
|
|
|
|
cleanup() {
|
|
local exit_code=$?
|
|
if [ $exit_code -ne 0 ]; then
|
|
echo
|
|
echo "⚠ Build failed (exit code: $exit_code). Cleaning up temporary files..."
|
|
fi
|
|
rm -rf "$TMP_BUILD_DIR" "${SCRIPT_DIR}/bin-vulkan" 2>/dev/null || true
|
|
if [ $exit_code -eq 0 ]; then
|
|
echo "✓ Cleanup complete"
|
|
fi
|
|
return $exit_code
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
if [[ "$1" == "--no-cache" ]]; then
|
|
NO_CACHE="--no-cache"
|
|
echo "Build mode: NO CACHE (clean rebuild)"
|
|
fi
|
|
|
|
echo "=== stable-diffusion.cpp Vulkan Build ==="
|
|
echo "Temporary build directory: $TMP_BUILD_DIR"
|
|
echo "Output directory: $BIN_DIR"
|
|
echo "Home directory: $HOME_DIR"
|
|
if [ -n "$NO_CACHE" ]; then
|
|
echo "Cache mode: DISABLED"
|
|
fi
|
|
echo
|
|
|
|
mkdir -p "$TMP_BUILD_DIR"
|
|
echo
|
|
|
|
# Install dependencies
|
|
echo "[1/5] Installing dependencies..."
|
|
REQUIRED_PACKAGES="build-essential cmake git libvulkan-dev glslc spirv-headers"
|
|
MISSING_PACKAGES=""
|
|
|
|
for pkg in $REQUIRED_PACKAGES; do
|
|
if ! dpkg -l | grep -q "^ii $pkg"; then
|
|
MISSING_PACKAGES="$MISSING_PACKAGES $pkg"
|
|
fi
|
|
done
|
|
|
|
if [ -n "$MISSING_PACKAGES" ]; then
|
|
echo " Installing missing packages:$MISSING_PACKAGES"
|
|
sudo apt-get update
|
|
sudo apt-get install -y $MISSING_PACKAGES
|
|
echo "✓ Dependencies installed"
|
|
else
|
|
echo "✓ All dependencies already installed"
|
|
fi
|
|
|
|
echo " Verifying dependencies..."
|
|
for cmd in git cmake make gcc g++ glslc; do
|
|
if ! command -v $cmd &> /dev/null; then
|
|
echo "ERROR: $cmd is still not available after installation."
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
if ! pkg-config --exists vulkan; then
|
|
echo "ERROR: Vulkan development files not found."
|
|
exit 1
|
|
fi
|
|
|
|
echo "✓ All dependencies verified"
|
|
echo
|
|
|
|
# Clone or update stable-diffusion.cpp (with submodules: ggml is vendored as a submodule)
|
|
echo "[2/5] Cloning/updating stable-diffusion.cpp repository..."
|
|
if [ -d "$BUILD_DIR" ]; then
|
|
echo " Updating existing repository..."
|
|
cd "$BUILD_DIR"
|
|
git fetch origin
|
|
git checkout master
|
|
git pull origin master
|
|
git submodule update --init --recursive
|
|
else
|
|
echo " Cloning stable-diffusion.cpp (with submodules)..."
|
|
git clone --recursive https://github.com/leejet/stable-diffusion.cpp.git "$BUILD_DIR"
|
|
cd "$BUILD_DIR"
|
|
fi
|
|
echo "✓ Repository ready"
|
|
echo
|
|
|
|
# Build with Vulkan support
|
|
echo "[3/5] Building with Vulkan support (this may take a while)..."
|
|
mkdir -p build
|
|
cd build
|
|
|
|
if [ -n "$NO_CACHE" ]; then
|
|
echo " Cleaning previous build..."
|
|
rm -rf * .cmake
|
|
fi
|
|
|
|
cmake .. -DSD_VULKAN=ON -DCMAKE_BUILD_TYPE=Release
|
|
cmake --build . --config Release -j "$(nproc)"
|
|
echo "✓ Build complete"
|
|
echo
|
|
|
|
# Prepare binary directory
|
|
echo "[4/5] Preparing binary directory..."
|
|
mkdir -p "$BIN_DIR"
|
|
cd "$BUILD_DIR"
|
|
|
|
echo " Copying binaries..."
|
|
# sd-cli is the current binary name (renamed from the old 'sd' in upstream #1037)
|
|
cp build/bin/sd-cli "$BIN_DIR/"
|
|
chmod +x "$BIN_DIR"/*
|
|
echo "✓ Binaries ready"
|
|
echo
|
|
|
|
# Build Podman image
|
|
echo "[5/5] Building Podman image..."
|
|
|
|
echo " Preparing build context..."
|
|
cp "${SCRIPT_DIR}/sdcpp-vulkan.Containerfile" "${TMP_BUILD_DIR}/"
|
|
cp "${SCRIPT_DIR}/sdcpp-entrypoint.sh" "${TMP_BUILD_DIR}/entrypoint.sh"
|
|
cp "${SCRIPT_DIR}/watch-gpu.sh" "${TMP_BUILD_DIR}/"
|
|
|
|
cd "$TMP_BUILD_DIR"
|
|
podman build $NO_CACHE -t sdcpp:vulkan-amd64 -f sdcpp-vulkan.Containerfile .
|
|
echo "✓ Podman image built"
|
|
echo
|
|
|
|
echo "=== BUILD COMPLETE ==="
|
|
echo
|
|
echo "✓ Container image created: sdcpp:vulkan-amd64"
|
|
echo
|
|
echo "Next steps:"
|
|
echo " 1. Create a models directory with the GGUF files, e.g.:"
|
|
echo " mkdir -p ~/sdcpp-models"
|
|
echo " # place minimax_h3_fl2va_pruned-*.gguf, qwen3vl_32b_minimax_h3-*.gguf,"
|
|
echo " # minimax_h3_video_vae_fp16.safetensors, minimax_h3_audio_vae_fp32.safetensors there"
|
|
echo
|
|
echo " 2. Run directly:"
|
|
echo " podman run --rm -it \\"
|
|
echo " --device /dev/dri/renderD128 \\"
|
|
echo " --group-add keep-groups \\"
|
|
echo " -v ~/sdcpp-models:/app/models \\"
|
|
echo " -v ~/sdcpp-output:/app/output \\"
|
|
echo " sdcpp:vulkan-amd64 \\"
|
|
echo " --mode vid_gen \\"
|
|
echo " --diffusion-model /app/models/minimax_h3_fl2va_pruned-Q4_K.gguf \\"
|
|
echo " --llm /app/models/qwen3vl_32b_minimax_h3-Q4_K_M.gguf \\"
|
|
echo " --vae /app/models/minimax_h3_video_vae_fp16.safetensors \\"
|
|
echo " --audio-vae /app/models/minimax_h3_audio_vae_fp32.safetensors \\"
|
|
echo " --prompt \"a red fox trotting through falling snow, cinematic\" \\"
|
|
echo " --width 640 --height 384 --video-frames 25 --steps 4 --cfg-scale 1.0 \\"
|
|
echo " --backend te=cpu --diffusion-fa \\"
|
|
echo " --output /app/output/out.webm"
|
|
echo
|
|
echo " 3. Or install as a Quadlet service (see sdcpp.container)"
|
|
echo
|