sync-ggml-am.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/bin/bash
  2. #
  3. # Synchronize ggml changes to llama.cpp
  4. #
  5. # Usage:
  6. #
  7. # $ cd /path/to/llama.cpp
  8. # $ ./scripts/sync-ggml-am.sh
  9. #
  10. set -e
  11. sd=$(dirname $0)
  12. cd $sd/../
  13. SRC_LLAMA=$(pwd)
  14. SRC_GGML=$(cd ../ggml; pwd)
  15. if [ ! -d $SRC_GGML ]; then
  16. echo "ggml not found at $SRC_GGML"
  17. exit 1
  18. fi
  19. lc=$(cat $SRC_LLAMA/scripts/sync-ggml.last)
  20. echo "Syncing ggml changes since commit $lc"
  21. cd $SRC_GGML
  22. git log --oneline $lc..HEAD
  23. git log --oneline $lc..HEAD | grep -v "(llama/[0-9]*)" | cut -d' ' -f1 > $SRC_LLAMA/ggml-commits
  24. if [ ! -s $SRC_LLAMA/ggml-commits ]; then
  25. rm -v $SRC_LLAMA/ggml-commits
  26. echo "No new commits"
  27. exit 0
  28. fi
  29. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  30. rm -v $SRC_LLAMA/ggml-src.patch
  31. fi
  32. while read c; do
  33. git format-patch -k $c~1..$c --stdout -- \
  34. include/ggml/ggml*.h \
  35. src/ggml*.h \
  36. src/ggml*.c \
  37. src/ggml*.cpp \
  38. src/ggml*.m \
  39. src/ggml*.metal \
  40. src/ggml*.cu \
  41. tests/test-opt.cpp \
  42. tests/test-grad0.cpp \
  43. tests/test-quantize-fns.cpp \
  44. tests/test-quantize-perf.cpp \
  45. tests/test-backend-ops.cpp \
  46. >> $SRC_LLAMA/ggml-src.patch
  47. done < $SRC_LLAMA/ggml-commits
  48. rm -v $SRC_LLAMA/ggml-commits
  49. # delete files if empty
  50. if [ ! -s $SRC_LLAMA/ggml-src.patch ]; then
  51. rm -v $SRC_LLAMA/ggml-src.patch
  52. fi
  53. cd $SRC_LLAMA
  54. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  55. # replace PR numbers
  56. #
  57. # Subject: some text (#1234)
  58. # Subject: some text (ggml/1234)
  59. cat ggml-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (ggml\/\2)/' > ggml-src.patch.tmp
  60. mv ggml-src.patch.tmp ggml-src.patch
  61. cat ggml-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (ggml\/\2)/' > ggml-src.patch.tmp
  62. mv ggml-src.patch.tmp ggml-src.patch
  63. # replace filenames:
  64. #
  65. # src/ggml.c -> ggml.c
  66. # src/ggml-alloc.c -> ggml-alloc.c
  67. # src/ggml-backend-impl.h -> ggml-backend-impl.h
  68. # src/ggml-backend.c -> ggml-backend.c
  69. # src/ggml-cuda.cu -> ggml-cuda.cu
  70. # src/ggml-cuda.h -> ggml-cuda.h
  71. # src/ggml-impl.h -> ggml-impl.h
  72. # src/ggml-metal.h -> ggml-metal.h
  73. # src/ggml-metal.m -> ggml-metal.m
  74. # src/ggml-metal.metal -> ggml-metal.metal
  75. # src/ggml-mpi.h -> ggml-mpi.h
  76. # src/ggml-mpi.c -> ggml-mpi.c
  77. # src/ggml-opencl.cpp -> ggml-opencl.cpp
  78. # src/ggml-opencl.h -> ggml-opencl.h
  79. # src/ggml-quants.c -> ggml-quants.c
  80. # src/ggml-quants.h -> ggml-quants.h
  81. # include/ggml/ggml.h -> ggml.h
  82. # include/ggml/ggml-alloc.h -> ggml-alloc.h
  83. # include/ggml/ggml-backend.h -> ggml-backend.h
  84. #
  85. # tests/test-opt.cpp -> tests/test-opt.cpp
  86. # tests/test-grad0.cpp -> tests/test-grad0.cpp
  87. # tests/test-quantize-fns.cpp -> tests/test-quantize-fns.cpp
  88. # tests/test-quantize-perf.cpp -> tests/test-quantize-perf.cpp
  89. # tests/test-backend-ops.cpp -> tests/test-backend-ops.cpp
  90. cat ggml-src.patch | sed \
  91. -e 's/src\/ggml\.c/ggml.c/g' \
  92. -e 's/src\/ggml-alloc\.c/ggml-alloc.c/g' \
  93. -e 's/src\/ggml-backend-impl\.h/ggml-backend-impl.h/g' \
  94. -e 's/src\/ggml-backend\.c/ggml-backend.c/g' \
  95. -e 's/src\/ggml-cuda\.cu/ggml-cuda.cu/g' \
  96. -e 's/src\/ggml-cuda\.h/ggml-cuda.h/g' \
  97. -e 's/src\/ggml-impl\.h/ggml-impl.h/g' \
  98. -e 's/src\/ggml-metal\.h/ggml-metal.h/g' \
  99. -e 's/src\/ggml-metal\.m/ggml-metal.m/g' \
  100. -e 's/src\/ggml-metal\.metal/ggml-metal.metal/g' \
  101. -e 's/src\/ggml-mpi\.h/ggml-mpi.h/g' \
  102. -e 's/src\/ggml-mpi\.c/ggml-mpi.c/g' \
  103. -e 's/src\/ggml-opencl\.cpp/ggml-opencl.cpp/g' \
  104. -e 's/src\/ggml-opencl\.h/ggml-opencl.h/g' \
  105. -e 's/src\/ggml-quants\.c/ggml-quants.c/g' \
  106. -e 's/src\/ggml-quants\.h/ggml-quants.h/g' \
  107. -e 's/include\/ggml\/ggml\.h/ggml.h/g' \
  108. -e 's/include\/ggml\/ggml-alloc\.h/ggml-alloc.h/g' \
  109. -e 's/include\/ggml\/ggml-backend\.h/ggml-backend.h/g' \
  110. -e 's/tests\/test-opt\.cpp/tests\/test-opt.cpp/g' \
  111. -e 's/tests\/test-grad0\.cpp/tests\/test-grad0.cpp/g' \
  112. -e 's/tests\/test-quantize-fns\.cpp/tests\/test-quantize-fns.cpp/g' \
  113. -e 's/tests\/test-quantize-perf\.cpp/tests\/test-quantize-perf.cpp/g' \
  114. -e 's/tests\/test-backend-ops\.cpp/tests\/test-backend-ops.cpp/g' \
  115. > ggml-src.patch.tmp
  116. mv ggml-src.patch.tmp ggml-src.patch
  117. git am ggml-src.patch
  118. rm -v $SRC_LLAMA/ggml-src.patch
  119. fi
  120. # update last commit
  121. cd $SRC_GGML
  122. git log -1 --format=%H > $SRC_LLAMA/scripts/sync-ggml.last
  123. echo "Done"
  124. exit 0