compare-commits.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 ! command -v sqlite3 >/dev/null 2>&1; then
  23. echo "Error: sqlite3 is not installed or not in PATH"
  24. echo "Please install sqlite3 to use this script"
  25. exit 1
  26. fi
  27. if [ "$tool" = "llama-bench" ]; then
  28. db_file="llama-bench.sqlite"
  29. target="llama-bench"
  30. run_args="-o sql -oe md $additional_args"
  31. else # test-backend-ops
  32. db_file="test-backend-ops.sqlite"
  33. target="test-backend-ops"
  34. run_args="perf --output sql $additional_args"
  35. fi
  36. rm -f "$db_file" > /dev/null
  37. # to test a backend, call the script with the corresponding environment variable (e.g. GGML_CUDA=1 ./scripts/compare-commits.sh ...)
  38. if [ -n "$GGML_CUDA" ]; then
  39. CMAKE_OPTS="${CMAKE_OPTS} -DGGML_CUDA=ON"
  40. fi
  41. dir="build-bench"
  42. function run {
  43. rm -fr ${dir} > /dev/null
  44. cmake -B ${dir} -S . ${CMAKE_OPTS} > /dev/null
  45. cmake --build ${dir} -t $target -j $(nproc) > /dev/null
  46. ${dir}/bin/$target $run_args | sqlite3 "$db_file"
  47. }
  48. git checkout $commit1 > /dev/null
  49. run
  50. git checkout $commit2 > /dev/null
  51. run
  52. ./scripts/compare-llama-bench.py -b $commit1 -c $commit2 --tool $tool -i "$db_file"