gpu-head-to-head
aien-dev/gpu-head-to-head
Brought by drakestapleton
gpu-head-to-head / coldstart / build.sh
| 1 | #!/usr/bin/env bash |
| 2 | # coldstart/build.sh: build the three cold-start arms from pinned sources (coldstart/PROTOCOL.md section 3). |
| 3 | # CPU only, no GPU. Usage: coldstart/build.sh OUTDIR (default /tmp/h2h-coldstart-build) |
| 4 | # Env: CUDAPP_REF=path of an existing CUDApp clone to borrow objects from (optional), CUDA=/usr/local/cuda-13.0. |
| 5 | set -euo pipefail |
| 6 | here=$(cd "$(dirname "$0")" && pwd) |
| 7 | out=${1:-/tmp/h2h-coldstart-build} |
| 8 | pin=cc0908bdc0a0377f2166e9328dcf1d985457e27f |
| 9 | cuda=${CUDA:-/usr/local/cuda-13.0} |
| 10 | mkdir -p "$out" |
| 11 | out=$(cd "$out" && pwd) |
| 12 | |
| 13 | if [ ! -d "$out/cudapp/.git" ]; then |
| 14 | ref=() |
| 15 | [ -n "${CUDAPP_REF:-}" ] && ref=(--reference-if-able "$CUDAPP_REF") |
| 16 | git clone --quiet "${ref[@]}" https://github.com/aien-dev/CUDApp "$out/cudapp" |
| 17 | fi |
| 18 | git -C "$out/cudapp" -c advice.detachedHead=false checkout --quiet "$pin" |
| 19 | [ "$(git -C "$out/cudapp" rev-parse HEAD)" = "$pin" ] || { echo "build: CUDApp is not at $pin" >&2; exit 1; } |
| 20 | [ -z "$(git -C "$out/cudapp" status --porcelain)" ] || { echo "build: CUDApp tree is dirty" >&2; exit 1; } |
| 21 | |
| 22 | # CUDApp's library and its own hello_gpu, with CUDApp's own Makefile and flags (default encoder: om). |
| 23 | make -C "$out/cudapp" -s -j5 build/libomega_gpu.a build/hello_gpu |
| 24 | # cs_cudapp with CUDApp's exact CFLAGS (including -Werror), linked like build/hello_gpu. |
| 25 | make -C "$out/cudapp" -s --eval "cs_cudapp: ; \$(CC) \$(CFLAGS) -I. -o $out/cs_cudapp $here/cs_cudapp.c \$(OUT_DIR)/libomega_gpu.a -lpthread -lm" cs_cudapp |
| 26 | rm -f "$out/cudapp/build/cs_cudapp.d" "$out/cs_cudapp.d" |
| 27 | |
| 28 | common=(-std=gnu11 -Wall -Wextra -Werror -O2 -D_GNU_SOURCE -I"$cuda/include") |
| 29 | gcc "${common[@]}" -DCS_NVRTC -o "$out/cs_nvrtc" "$here/cs_cuda.c" -L"$cuda/lib64" -Wl,-rpath,"$cuda/lib64" -lnvrtc -lcuda |
| 30 | gcc "${common[@]}" -DCS_PTXC -o "$out/cs_ptxc" "$here/cs_cuda.c" "$cuda/lib64/libnvptxcompiler_static.a" -lcuda -lpthread -lm -ldl -lrt |
| 31 | |
| 32 | # The committed PTX must be what NVRTC emits for the same source today (drift check). |
| 33 | "$out/cs_nvrtc" --emit-ptx "$out/vecadd.ptx" |
| 34 | cmp -s "$out/vecadd.ptx" "$here/vecadd.ptx" || { echo "build: coldstart/vecadd.ptx differs from NVRTC output ($out/vecadd.ptx)" >&2; exit 1; } |
| 35 | |
| 36 | { |
| 37 | echo "cudapp_pin $pin" |
| 38 | echo "gcc $(gcc -dumpfullversion)" |
| 39 | for f in cs_cudapp cs_nvrtc cs_ptxc cudapp/build/hello_gpu cudapp/build/libomega_gpu.a; do |
| 40 | echo "sha256 $f $(sha256sum "$out/$f" | cut -d' ' -f1)" |
| 41 | done |
| 42 | echo "sha256 vecadd.ptx $(sha256sum "$here/vecadd.ptx" | cut -d' ' -f1)" |
| 43 | echo "versions $("$out/cs_nvrtc" --versions)" |
| 44 | echo "versions $("$out/cs_ptxc" --versions)" |
| 45 | } > "$out/build.txt" |
| 46 | cat "$out/build.txt" |
| 47 | echo "build: OK $out" |