#!/bin/bash # SPDX-License-Identifier: BSD-3-Clause # # p2/build.sh - build the P2 "arbitrary CUDA kernels" acceptance programs. # # Target is sm_75 (Turing TU104) to match the project's GPU. The CUDA # runtime is linked statically (--cudart=static) so the guest needs only the # driver's libcuda.so, exactly like ab.sh/victory_mail. # # Usage: ./build.sh [program ...] (default: all programs) set -e HERE="$(cd "$(dirname "$0")" && pwd)" NVCC="${NVCC:-nvcc}" FLAGS="${P2_NVCC_FLAGS:--O2 -arch=sm_75 --cudart=static}" command -v "$NVCC" >/dev/null || { echo "nvcc not found"; exit 1; } mkdir -p "$HERE/bin" build_one() { local src="$HERE/src/$1.cu" local bin="$HERE/bin/$1" [ -f "$src" ] || { echo "[build] missing source: $src" >&2; return 1; } echo "[build] $1" # shellcheck disable=SC2086 "$NVCC" $FLAGS -I"$HERE/src" -o "$bin" "$src" } if [ "$#" -gt 0 ]; then for p in "$@"; do build_one "$p"; done else for src in "$HERE"/src/p2_*.cu; do build_one "$(basename "$src" .cu)" done fi echo "[build] OK: $(ls "$HERE"/bin/p2_* 2>/dev/null | wc -l) program(s) in $HERE/bin"