Files

68 lines
2.1 KiB
Bash

#!/bin/bash
# milestone 10: find the best NON-vectorized scalar variant.
# we compile each scalar (double, no-intrinsics) variant with vectorization
# turned off (-fno-tree-vectorize -fno-tree-slp-vectorize) so -march=native
# can't sneak SIMD in, then time them on a small input.
#
# small on purpose: N=500, 200 iters -> each build+run is a couple seconds.
# compare T(n) [cycles] to pick the fastest. flops/cycle is printed too but
# don't rank by it: the symmetry variants do half the work, so their
# flops/cycle looks low even when the runtime is good.
#
# run from the repo root: bash scripts/test_novec.sh
set -e
CXX="${CXX:-$(command -v g++ || command -v clang++)}"
N=500
ITER=200
NOVEC="-fno-tree-vectorize -fno-tree-slp-vectorize"
FLAGS="-O3 -march=native -std=c++23 -flto $NOVEC -DBENCHMARK=1 -DFLOPCOUNT=0 -DRANDOM_SEED=0 -DROOFLINE=0"
# variant:main_file . symmetry variants need main-symmetry.cpp (halved flop formula),
# everything else uses main.cpp. only double, no-AVX variants here.
CANDIDATES=(
"baseline:main.cpp"
"inlining_7:main.cpp"
"inlining_8:main.cpp"
"cutoff:main.cpp"
"cutoff_callsite:main.cpp"
"branchless:main.cpp"
"branchless_sqrtfree:main.cpp"
"lut_exp:main.cpp"
"inlining_7_SoA:main.cpp"
"inlining_7_symmetry_2:main-symmetry.cpp"
"inlining_7_symmetry_2_ilp_2:main-symmetry.cpp"
)
echo "compiler: $CXX"
echo "flags: $FLAGS"
echo "input: N=$N ITER=$ITER"
echo ""
printf "%-34s %18s %14s\n" "variant" "cycles" "flops/cycle"
printf "%-34s %18s %14s\n" "-------" "------" "-----------"
for entry in "${CANDIDATES[@]}"; do
v="${entry%%:*}"
main="${entry##*:}"
src="variants/variant_${v}.cpp"
if [ ! -f "$src" ]; then
printf "%-34s %18s\n" "$v" "(no source, skipped)"
continue
fi
bin="novec_${v}"
$CXX "$main" "$src" -o "$bin" $FLAGS 2>/dev/null
out="$(./"$bin" "$N" "$ITER")"
cyc="$(echo "$out" | grep 'T(n):' | grep -oE '[0-9.]+')"
fpc="$(echo "$out" | grep 'P(n):' | grep -oE '[0-9.]+')"
printf "%-34s %18s %14s\n" "$v" "$cyc" "$fpc"
rm -f "$bin"
done
echo ""
echo "lowest cycles = best non-vectorized variant. report that number for milestone 10."