okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-1b (033cfdd8c) into f-own-int: nothing downloads llama.cppb2de2641f

main
4.1 KiB61 linesraw
1#!/bin/bash
2# strata-split-N (the all-cards split engine, src/split, from sFNX, MIT, John Fink) for AMD on Linux, built next to the HIP engine package (packaging/build_hip_linux.sh)
3# so package_engine.py ships it with `--include 'strata-split-*'` beside `strata`. One executable per card count with a code object for every listed architecture
4# (ARCHS: gfx1201 = Radeon AI PRO R9700 / RX 9070, which Strata has run; gfx1200 = RX 9060; gfx11-generic = one code object for gfx1100..gfx1103, RDNA3: RX 7000 and the 780M, whose self-test passes on a 780M), named
5# strata-split-<N>-amd (the launcher, strata_cli/launch/runner.py, looks for strata-split-<N>-<arch> first and then -amd): the AMD Linux package ships N = 2, 3 and 4. Only gfx1201 starts
6# the split by itself; the other architectures only with `--split-engine on`, and the engine then runs its kernel self-test first (src/split/src/hip/selftest_policy.hpp).
7# Which counts run which model is the launcher's rule (strata_control/split_engine.py: all the experts must fit in the cards' memory), not the binary's. RUNPATH $ORIGIN: it finds the ROCm libraries the engine package bundles (libamdhip64, hipblas, rocblas and its
8# Tensile data for gfx1201) beside itself, the same set `strata` uses.
9#
10#   SRC=<checkout> B=<build dir> HP=<ROCm devel root> [LIBW=<ROCm libraries root>] [ARCHS="gfx1201;gfx1200;gfx11-generic"] [GG=<llama.cpp checkout, an override>] [CARDS="2 3 4"] [JOBS=12]  packaging/build_split_hip.sh
11#
12# After the build the script FAILS if the binary
13#   - links librccl (RCCL is loaded at run time with dlopen when FNX_PF_RCCL=1 and is optional: the split must start without it),
14#   - can call hipMemcpyPeer* (the engine's peer traffic is kernel stores only; src/split/src/hip/peer.h is the one file that touches peer access),
15#   - or is missing the code object of any architecture in ARCHS.
16# Prints the binary paths (strata-split-<N>-amd), one per line, last.
17set -eu
18SRC=${SRC:-$(cd "$(dirname "$0")/.." && pwd)}
19B=${B:?B=<build dir>}
20HP=${HP:?HP=<ROCm devel root>}
21LIBW=${LIBW:-$HP}
22GG=${GG:-}      # optional override (kept for two releases): a llama.cpp checkout to take ggml from; empty: the vendored third_party/strata-ggml
23ggml=""; [ -z "$GG" ] || ggml="-DSTRATA_GGML_DIR=$GG"
24CARDS=${CARDS:-2 3 4}
25JOBS=${JOBS:-12}
26ARCHS=${ARCHS:-gfx1201;gfx1200;gfx11-generic}
27export HIP_PLATFORM=amd HIP_COMPILER=clang HIP_RUNTIME=rocclr ROCM_PATH=$HP HIP_PATH=$HP PATH=$HP/bin:$PATH
28SYSDEPS=""; [ -d "$HP/lib/rocm_sysdeps" ] && SYSDEPS=";$HP/lib/rocm_sysdeps"
29BC=$HP/lib/llvm/amdgcn/bitcode; [ -d "$BC" ] || BC=$HP/amdgcn/bitcode
30rm -f "$B/CMakeCache.txt"
31cmake -G Ninja -S "$SRC" -B "$B" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF -DSTRATA_BUILD_SPLIT=ON \
32  "-DSTRATA_SPLIT_CARDS=${CARDS// /;}" "-DCMAKE_HIP_ARCHITECTURES=gfx1201" "-DSTRATA_SPLIT_HIP_ARCHS=$ARCHS" -DSTRATA_PREFILL_MMQ=ON -DSTRATA_NATIVE_EXPERTS=ON $ggml \
33  -DCMAKE_HIP_COMPILER="$HP/llvm/bin/clang++" -DCMAKE_HIP_COMPILER_ROCM_ROOT="$HP" "-DCMAKE_PREFIX_PATH=$HP;$LIBW$SYSDEPS" \
34  "-DCMAKE_HIP_FLAGS=--rocm-path=$HP --rocm-device-lib-path=$BC" -DSTRATA_PORTABLE=ON \
35  "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,'\$ORIGIN' -Wl,--enable-new-dtags"
36out=""
37for n in $CARDS; do
38  ninja -j "$JOBS" -C "$B" "strata-split-$n"
39  exe=$(find "$B" -name "strata-split-$n" -type f | head -1)
40  [ -x "$exe" ] || { echo "build_split_hip.sh: no strata-split-$n" >&2; exit 1; }
41  if readelf -d "$exe" | grep -qi 'NEEDED.*rccl'; then
42    echo "build_split_hip.sh: $exe links librccl (it must be dlopen'ed only):" >&2
43    readelf -d "$exe" | grep -i needed >&2
44    exit 1
45  fi
46  if nm -D --undefined-only "$exe" | grep -qiE 'hipMemcpy(3D)?Peer'; then
47    echo "build_split_hip.sh: $exe can call hipMemcpyPeer*:" >&2
48    nm -D --undefined-only "$exe" | grep -iE 'hipMemcpy(3D)?Peer' >&2
49    exit 1
50  fi
51  for a in ${ARCHS//;/ }; do
52    if ! grep -aq "$a" "$exe"; then
53      echo "build_split_hip.sh: $exe has no $a code object" >&2
54      exit 1
55    fi
56  done
57  named="$(dirname "$exe")/strata-split-$n-amd"
58  cp -f "$exe" "$named"
59  out="$out$named"$'\n'
60done
61printf '%s' "$out"