2025-06-30 10:17:18 +02:00
|
|
|
#!/usr/bin/env bash
|
2024-02-16 15:14:40 +02:00
|
|
|
|
|
|
|
if [ $# -lt 2 ]; then
|
2025-08-01 08:47:27 +08:00
|
|
|
echo "usage: ./scripts/compare-commits.sh <commit1> <commit2> [tool] [additional arguments]"
|
|
|
|
echo " tool: 'llama-bench' (default) or 'test-backend-ops'"
|
|
|
|
echo " additional arguments: passed to the selected tool"
|
2024-02-16 15:14:40 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
2025-08-01 08:47:27 +08:00
|
|
|
# Parse arguments
|
|
|
|
commit1=$1
|
|
|
|
commit2=$2
|
|
|
|
tool=${3:-llama-bench}
|
|
|
|
additional_args="${@:4}"
|
|
|
|
|
|
|
|
# Validate tool argument
|
|
|
|
if [ "$tool" != "llama-bench" ] && [ "$tool" != "test-backend-ops" ]; then
|
|
|
|
echo "Error: tool must be 'llama-bench' or 'test-backend-ops'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-09-18 18:34:32 +03:00
|
|
|
# verify at the start that the compare script has all the necessary dependencies installed
|
|
|
|
./scripts/compare-llama-bench.py --check
|
|
|
|
|
2025-08-01 08:47:27 +08:00
|
|
|
if [ "$tool" = "llama-bench" ]; then
|
|
|
|
db_file="llama-bench.sqlite"
|
|
|
|
target="llama-bench"
|
|
|
|
run_args="-o sql -oe md $additional_args"
|
|
|
|
else # test-backend-ops
|
|
|
|
db_file="test-backend-ops.sqlite"
|
|
|
|
target="test-backend-ops"
|
|
|
|
run_args="perf --output sql $additional_args"
|
|
|
|
fi
|
2024-02-16 15:14:40 +02:00
|
|
|
|
2025-08-01 08:47:27 +08:00
|
|
|
rm -f "$db_file" > /dev/null
|
2024-02-16 15:14:40 +02:00
|
|
|
|
2024-06-26 18:33:02 +03:00
|
|
|
# to test a backend, call the script with the corresponding environment variable (e.g. GGML_CUDA=1 ./scripts/compare-commits.sh ...)
|
2024-12-02 21:22:53 +02:00
|
|
|
if [ -n "$GGML_CUDA" ]; then
|
2025-05-26 22:24:01 +03:00
|
|
|
CMAKE_OPTS="${CMAKE_OPTS} -DGGML_CUDA=ON"
|
2024-12-02 21:22:53 +02:00
|
|
|
fi
|
|
|
|
|
2024-12-15 18:44:47 +02:00
|
|
|
dir="build-bench"
|
|
|
|
|
2024-12-02 21:22:53 +02:00
|
|
|
function run {
|
2024-12-15 18:44:47 +02:00
|
|
|
rm -fr ${dir} > /dev/null
|
2025-05-26 22:24:01 +03:00
|
|
|
cmake -B ${dir} -S . ${CMAKE_OPTS} > /dev/null
|
2025-08-01 08:47:27 +08:00
|
|
|
cmake --build ${dir} -t $target -j $(nproc) > /dev/null
|
|
|
|
${dir}/bin/$target $run_args | sqlite3 "$db_file"
|
2024-12-02 21:22:53 +02:00
|
|
|
}
|
2024-02-16 15:14:40 +02:00
|
|
|
|
2025-08-01 08:47:27 +08:00
|
|
|
git checkout $commit1 > /dev/null
|
2024-12-02 21:22:53 +02:00
|
|
|
run
|
2024-02-16 15:14:40 +02:00
|
|
|
|
2025-08-01 08:47:27 +08:00
|
|
|
git checkout $commit2 > /dev/null
|
2024-12-02 21:22:53 +02:00
|
|
|
run
|
2024-02-16 15:14:40 +02:00
|
|
|
|
2025-08-01 08:47:27 +08:00
|
|
|
./scripts/compare-llama-bench.py -b $commit1 -c $commit2 --tool $tool -i "$db_file"
|