interplane.Get Omega
Read in your language

gpu-head-to-head

aien-dev/gpu-head-to-head

Brought by drakestapleton

branch main Branches Tags History

gpu-head-to-head / coldstart / build.sh

47 lines · 2576 bytes Raw Blame History
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.
5set -euo pipefail
6here=$(cd "$(dirname "$0")" && pwd)
7out=${1:-/tmp/h2h-coldstart-build}
8pin=cc0908bdc0a0377f2166e9328dcf1d985457e27f
9cuda=${CUDA:-/usr/local/cuda-13.0}
10mkdir -p "$out"
11out=$(cd "$out" && pwd)
12
13if [ ! -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"
17fi
18git -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).
23make -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.
25make -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
26rm -f "$out/cudapp/build/cs_cudapp.d" "$out/cs_cudapp.d"
27
28common=(-std=gnu11 -Wall -Wextra -Werror -O2 -D_GNU_SOURCE -I"$cuda/include")
29gcc "${common[@]}" -DCS_NVRTC -o "$out/cs_nvrtc" "$here/cs_cuda.c" -L"$cuda/lib64" -Wl,-rpath,"$cuda/lib64" -lnvrtc -lcuda
30gcc "${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"
34cmp -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"
46cat "$out/build.txt"
47echo "build: OK $out"