research/tools/benchmarks/Equi-X/scripts/build_variants.sh

76 lines
2.9 KiB
Bash
Raw Normal View History

2026-07-30 14:45:21 +02:00
#!/usr/bin/env bash
# Build the C runner (and its vendored libequix/hashx) under several compiler /
# optimization-flag combinations, registering each as its own benchmark impl so
# the harness can compare performance across compiler flags.
#
# Each variant -> build/variants/<name>/equix_runner and a manifest at
# adapters/generated/equix-c-<name>.manifest.toml (impl name "equix-c-<name>").
# Then: python -m equix_bench run --config configs/compiler_flags.toml --out results/
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
NPROC="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)"
have() { command -v "$1" >/dev/null 2>&1; }
git submodule update --init --recursive >/dev/null 2>&1 || true
EQUIX_COMMIT="$(git -C vendored/equix rev-parse --short HEAD 2>/dev/null || echo unknown)"
OUT="adapters/generated"
mkdir -p "$OUT" build/variants
# name | compiler | CFLAGS (-DNDEBUG kept so all variants match Release semantics)
VARIANTS=(
"gcc-o0|gcc|-O0 -DNDEBUG"
"gcc-o2|gcc|-O2 -DNDEBUG"
"gcc-o3|gcc|-O3 -DNDEBUG"
"gcc-o3-native|gcc|-O3 -march=native -DNDEBUG"
"gcc-o3-lto|gcc|-O3 -flto -DNDEBUG"
"clang-o3|clang|-O3 -DNDEBUG"
"clang-o3-native|clang|-O3 -march=native -DNDEBUG"
)
built=()
for entry in "${VARIANTS[@]}"; do
IFS='|' read -r name cc flags <<<"$entry"
if ! have "$cc"; then echo "skip $name ($cc not found)"; continue; fi
bdir="build/variants/$name"
# A copied/moved repo carries a CMake cache with old absolute paths; clean it.
if [ -f "$bdir/CMakeCache.txt" ]; then
recorded="$(sed -n 's/^CMAKE_CACHEFILE_DIR:INTERNAL=//p' "$bdir/CMakeCache.txt" | head -1)"
if [ -n "$recorded" ] && [ "$recorded" != "$(cd "$bdir" && pwd)" ]; then
rm -rf "$bdir"
fi
fi
echo "==> building $name ($cc $flags)"
if ! cmake -S runners/c -B "$bdir" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_POLICY_VERSION_MINIMUM=3.10 \
-DCMAKE_C_COMPILER="$cc" \
-DCMAKE_C_FLAGS_RELEASE="$flags" \
-DEQUIX_C_COMMIT="$EQUIX_COMMIT" \
-DEQUIX_C_VERSION="1.0.0-$name" >/dev/null 2>"build/variants/$name.log"; then
echo " configure FAILED for $name (see build/variants/$name.log)"; continue
fi
if ! cmake --build "$bdir" -j"$NPROC" --target equix_runner >>"build/variants/$name.log" 2>&1; then
echo " build FAILED for $name (see build/variants/$name.log)"; continue
fi
cat > "$OUT/equix-c-$name.manifest.toml" <<EOF
# Auto-generated by scripts/build_variants.sh -- do not edit.
name = "equix-c-$name"
exec = "build/variants/$name/equix_runner"
protocol_version = 1
capabilities = ["solve", "verify", "effort", "hashx_compile"]
runtimes = ["interpret", "try-compile", "must-compile"]
[env]
EQUIX_C_VERSION = "1.0.0-$name"
EQUIX_C_FLAGS = "$cc $flags"
EOF
built+=("equix-c-$name")
done
echo
echo "Built variants: ${built[*]:-none}"
echo "Manifests in $OUT/. Run:"
echo " python -m equix_bench run --config configs/compiler_flags.toml --out results/"