| #!/usr/bin/env bash |
| |
| |
| |
| |
| |
| |
| |
| |
| set -euo pipefail |
| HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| SDCPP_REF="${SDCPP_REF:-master}" |
| CUDA_ARCH="${CUDA_ARCH:-}" |
| BUILD_CUDA="${BUILD_CUDA:-ON}" |
|
|
| echo "== clone sd.cpp ($SDCPP_REF) ==" |
| [ -d stable-diffusion.cpp ] || git clone --recursive https://github.com/leejet/stable-diffusion.cpp |
| cd stable-diffusion.cpp |
| git fetch --all --tags -q |
| git checkout -q "$SDCPP_REF" |
| git submodule update --init --recursive -q |
|
|
| echo "== apply the TQ{K}P kernel (into the ggml submodule) ==" |
| cd ggml |
| |
| |
| grep -q "GGML_TYPE_COUNT = 42," include/ggml.h || { |
| echo "!! this ggml revision does not have COUNT=42: the TQ{K}P type ids would collide." |
| echo "!! pin SDCPP_REF to a revision where they are free, or re-port the enum block by hand." |
| exit 1; } |
| for p in cpu cuda; do |
| [ "$p" = cuda ] && [ "$BUILD_CUDA" != ON ] && continue |
| git apply --check "$HERE/sdcpp-$p.patch" || { echo "!! sdcpp-$p.patch does not apply to $SDCPP_REF"; exit 1; } |
| git apply "$HERE/sdcpp-$p.patch" |
| echo " applied sdcpp-$p.patch" |
| done |
| cd .. |
|
|
| echo "== build ==" |
| CMAKE_ARGS=(-DCMAKE_BUILD_TYPE=Release -DSD_CUDA="$BUILD_CUDA") |
| [ -n "$CUDA_ARCH" ] && CMAKE_ARGS+=(-DCMAKE_CUDA_ARCHITECTURES="$CUDA_ARCH") |
| cmake -B build "${CMAKE_ARGS[@]}" |
| cmake --build build -j"$(nproc)" |
|
|
| echo |
| echo "OK -> $(pwd)/build/bin/sd-cli" |
| echo "Sanity check (the type must be known to the binary):" |
| echo " strings build/bin/sd-cli | grep TQ3P" |
|
|