compare-commits.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. if [ $# -lt 2 ]; then
  3. echo "usage: ./scripts/compare-commits.sh <commit1> <commit2> [tool] [additional arguments]"
  4. echo " tool: 'llama-bench' (default) or 'test-backend-ops'"
  5. echo " additional arguments: passed to the selected tool"
  6. exit 1
  7. fi
  8. set -e
  9. set -x
  10. # Parse arguments
  11. commit1=$1
  12. commit2=$2
  13. tool=${3:-llama-bench}
  14. additional_args="${@:4}"
  15. # Validate tool argument
  16. if [ "$tool" != "llama-bench" ] && [ "$tool" != "test-backend-ops" ]; then
  17. echo "Error: tool must be 'llama-bench' or 'test-backend-ops'"
  18. exit 1
  19. fi
  20. # verify at the start that the compare script has all the necessary dependencies installed
  21. ./scripts/compare-llama-bench.py --check
  22. if [ "$tool" = "llama-bench" ]; then
  23. db_file="llama-bench.sqlite"
  24. target="llama-bench"
  25. run_args="-o sql -oe md $additional_args"
  26. else # test-backend-ops
  27. db_file="test-backend-ops.sqlite"
  28. target="test-backend-ops"
  29. run_args="perf --output sql $additional_args"
  30. fi
  31. rm -f "$db_file" > /dev/null
  32. # to test a backend, call the script with the corresponding environment variable (e.g. GGML_CUDA=1 ./scripts/compare-commits.sh ...)
  33. if [ -n "$GGML_CUDA" ]; then
  34. CMAKE_OPTS="${CMAKE_OPTS} -DGGML_CUDA=ON"
  35. fi
  36. dir="build-bench"
  37. function run {
  38. rm -fr ${dir} > /dev/null
  39. cmake -B ${dir} -S . ${CMAKE_OPTS} > /dev/null
  40. cmake --build ${dir} -t $target -j $(nproc) > /dev/null
  41. ${dir}/bin/$target $run_args | sqlite3 "$db_file"
  42. }
  43. git checkout $commit1 > /dev/null
  44. run
  45. git checkout $commit2 > /dev/null
  46. run
  47. ./scripts/compare-llama-bench.py -b $commit1 -c $commit2 --tool $tool -i "$db_file"