sync-ggml-am.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 -skip hash0,hash1,hash2... -C 3
  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. to_skip=""
  22. # context for git patches in number of lines
  23. ctx="8"
  24. while [ "$1" != "" ]; do
  25. case $1 in
  26. -skip )
  27. shift
  28. to_skip=$1
  29. ;;
  30. -C )
  31. shift
  32. ctx=$1
  33. ;;
  34. esac
  35. shift
  36. done
  37. cd $SRC_GGML
  38. git log --oneline $lc..HEAD
  39. git log --oneline $lc..HEAD --reverse | grep -v "(llama/[0-9]*)" | cut -d' ' -f1 > $SRC_LLAMA/ggml-commits
  40. if [ ! -s $SRC_LLAMA/ggml-commits ]; then
  41. rm -v $SRC_LLAMA/ggml-commits
  42. echo "No new commits"
  43. exit 0
  44. fi
  45. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  46. rm -v $SRC_LLAMA/ggml-src.patch
  47. fi
  48. while read c; do
  49. if [ -n "$to_skip" ]; then
  50. if [[ $to_skip == *"$c"* ]]; then
  51. echo "Skipping $c"
  52. continue
  53. fi
  54. fi
  55. git format-patch -U${ctx} -k $c~1..$c --stdout -- \
  56. CMakeLists.txt \
  57. src/CMakeLists.txt \
  58. cmake/FindSIMD.cmake \
  59. src/ggml*.h \
  60. src/ggml*.c \
  61. src/ggml*.cpp \
  62. src/ggml*.m \
  63. src/ggml*.metal \
  64. src/ggml*.cu \
  65. src/ggml-amx/* \
  66. src/ggml-cann/* \
  67. src/ggml-cuda/* \
  68. src/ggml-sycl/* \
  69. src/vulkan-shaders/* \
  70. include/ggml*.h \
  71. tests/test-opt.cpp \
  72. tests/test-grad0.cpp \
  73. tests/test-quantize-fns.cpp \
  74. tests/test-quantize-perf.cpp \
  75. tests/test-backend-ops.cpp \
  76. LICENSE \
  77. scripts/gen-authors.sh \
  78. >> $SRC_LLAMA/ggml-src.patch
  79. done < $SRC_LLAMA/ggml-commits
  80. rm -v $SRC_LLAMA/ggml-commits
  81. # delete files if empty
  82. if [ ! -s $SRC_LLAMA/ggml-src.patch ]; then
  83. rm -v $SRC_LLAMA/ggml-src.patch
  84. fi
  85. cd $SRC_LLAMA
  86. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  87. # replace PR numbers
  88. #
  89. # Subject: some text (#1234)
  90. # Subject: some text (ggml/1234)
  91. cat ggml-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (ggml\/\2)/' > ggml-src.patch.tmp
  92. mv ggml-src.patch.tmp ggml-src.patch
  93. cat ggml-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (ggml\/\2)/' > ggml-src.patch.tmp
  94. mv ggml-src.patch.tmp ggml-src.patch
  95. # replace filenames:
  96. #
  97. # CMakelists.txt -> ggml/CMakeLists.txt
  98. # src/CMakeLists.txt -> ggml/src/CMakeLists.txt
  99. # cmake/FindSIMD.cmake -> ggml/cmake/FindSIMD.cmake
  100. #
  101. # src/ggml.c -> ggml/src/ggml.c
  102. # src/ggml-aarch64.c -> ggml/src/ggml-aarch64.c
  103. # src/ggml-aarch64.h -> ggml/src/ggml-aarch64.h
  104. # src/ggml-alloc.c -> ggml/src/ggml-alloc.c
  105. # src/ggml-amx/* -> ggml/src/ggml-amx/
  106. # src/ggml-amx.cpp -> ggml/src/ggml-amx.cpp
  107. # src/ggml-backend-impl.h -> ggml/src/ggml-backend-impl.h
  108. # src/ggml-backend.cpp -> ggml/src/ggml-backend.cpp
  109. # src/ggml-cann/* -> ggml/src/ggml-cann/
  110. # src/ggml-cann.cpp -> ggml/src/ggml-cann.cpp
  111. # src/ggml-common.h -> ggml/src/ggml-common.h
  112. # src/ggml-cuda/* -> ggml/src/ggml-cuda/
  113. # src/ggml-cuda.cu -> ggml/src/ggml-cuda.cu
  114. # src/ggml-impl.h -> ggml/src/ggml-impl.h
  115. # src/ggml-kompute.cpp -> ggml/src/ggml-kompute.cpp
  116. # src/ggml-metal.m -> ggml/src/ggml-metal.m
  117. # src/ggml-quants.c -> ggml/src/ggml-quants.c
  118. # src/ggml-quants.h -> ggml/src/ggml-quants.h
  119. # src/ggml-rpc.cpp -> ggml/src/ggml-rpc.cpp
  120. # src/ggml-sycl/* -> ggml/src/ggml-sycl/
  121. # src/ggml-sycl.cpp -> ggml/src/ggml-sycl.cpp
  122. # src/ggml-vulkan.cpp -> ggml/src/ggml-vulkan.cpp
  123. # src/vulkan-shaders/* -> ggml/src/vulkan-shaders/
  124. #
  125. # include/ggml.h -> ggml/include/ggml.h
  126. # include/ggml-alloc.h -> ggml/include/ggml-alloc.h
  127. # include/ggml-amx.h -> ggml/include/ggml-amx.h
  128. # include/ggml-backend.h -> ggml/include/ggml-backend.h
  129. # include/ggml-blas.h -> ggml/include/ggml-blas.h
  130. # include/ggml-cann.h -> ggml/include/ggml-cann.h
  131. # include/ggml-cuda.h -> ggml/include/ggml-cuda.h
  132. # include/ggml-kompute.h -> ggml/include/ggml-kompute.h
  133. # include/ggml-metal.h -> ggml/include/ggml-metal.h
  134. # include/ggml-rpc.h -> ggml/include/ggml-rpc.h
  135. # include/ggml-sycl.h -> ggml/include/ggml-sycl.h
  136. # include/ggml-vulkan.h -> ggml/include/ggml-vulkan.h
  137. #
  138. # tests/test-opt.cpp -> tests/test-opt.cpp
  139. # tests/test-grad0.cpp -> tests/test-grad0.cpp
  140. # tests/test-quantize-fns.cpp -> tests/test-quantize-fns.cpp
  141. # tests/test-quantize-perf.cpp -> tests/test-quantize-perf.cpp
  142. # tests/test-backend-ops.cpp -> tests/test-backend-ops.cpp
  143. #
  144. # LICENSE -> LICENSE
  145. # scripts/gen-authors.sh -> scripts/gen-authors.sh
  146. cat ggml-src.patch | sed -E \
  147. -e 's/([[:space:]]|[ab]\/)CMakeLists.txt/\1ggml\/CMakeLists.txt/g' \
  148. -e 's/([[:space:]]|[ab]\/)src\/CMakeLists.txt/\1ggml\/src\/CMakeLists.txt/g' \
  149. -e 's/([[:space:]]|[ab]\/)cmake\/FindSIMD.cmake/\1ggml\/cmake\/FindSIMD.cmake/g' \
  150. -e 's/([[:space:]]|[ab]\/)src\/ggml\.c/\1ggml\/src\/ggml.c/g' \
  151. -e 's/([[:space:]]|[ab]\/)src\/ggml-aarch64\.c/\1ggml\/src\/ggml-aarch64.c/g' \
  152. -e 's/([[:space:]]|[ab]\/)src\/ggml-aarch64\.h/\1ggml\/src\/ggml-aarch64.h/g' \
  153. -e 's/([[:space:]]|[ab]\/)src\/ggml-alloc\.c/\1ggml\/src\/ggml-alloc.c/g' \
  154. -e 's/([[:space:]]|[ab]\/)src\/ggml-amx\//\1ggml\/src\/ggml-amx\//g' \
  155. -e 's/([[:space:]]|[ab]\/)src\/ggml-amx\.cpp/\1ggml\/src\/ggml-amx.cpp/g' \
  156. -e 's/([[:space:]]|[ab]\/)src\/ggml-backend-impl\.h/\1ggml\/src\/ggml-backend-impl.h/g' \
  157. -e 's/([[:space:]]|[ab]\/)src\/ggml-backend\.cpp/\1ggml\/src\/ggml-backend.cpp/g' \
  158. -e 's/([[:space:]]|[ab]\/)src\/ggml-cann\//\1ggml\/src\/ggml-cann\//g' \
  159. -e 's/([[:space:]]|[ab]\/)src\/ggml-cann\.cpp/\1ggml\/src\/ggml-cann.cpp/g' \
  160. -e 's/([[:space:]]|[ab]\/)src\/ggml-common\.h/\1ggml\/src\/ggml-common.h/g' \
  161. -e 's/([[:space:]]|[ab]\/)src\/ggml-cuda\//\1ggml\/src\/ggml-cuda\//g' \
  162. -e 's/([[:space:]]|[ab]\/)src\/ggml-cuda\.cu/\1ggml\/src\/ggml-cuda.cu/g' \
  163. -e 's/([[:space:]]|[ab]\/)src\/ggml-impl\.h/\1ggml\/src\/ggml-impl.h/g' \
  164. -e 's/([[:space:]]|[ab]\/)src\/ggml-kompute\.cpp/\1ggml\/src\/ggml-kompute.cpp/g' \
  165. -e 's/([[:space:]]|[ab]\/)src\/ggml-metal\.m/\1ggml\/src\/ggml-metal.m/g' \
  166. -e 's/([[:space:]]|[ab]\/)src\/ggml-quants\.c/\1ggml\/src\/ggml-quants.c/g' \
  167. -e 's/([[:space:]]|[ab]\/)src\/ggml-quants\.h/\1ggml\/src\/ggml-quants.h/g' \
  168. -e 's/([[:space:]]|[ab]\/)src\/ggml-rpc\.cpp/\1ggml\/src\/ggml-rpc.cpp/g' \
  169. -e 's/([[:space:]]|[ab]\/)src\/ggml-sycl\//\1ggml\/src\/ggml-sycl\//g' \
  170. -e 's/([[:space:]]|[ab]\/)src\/ggml-sycl\.cpp/\1ggml\/src\/ggml-sycl.cpp/g' \
  171. -e 's/([[:space:]]|[ab]\/)src\/ggml-vulkan\.cpp/\1ggml\/src\/ggml-vulkan.cpp/g' \
  172. -e 's/([[:space:]]|[ab]\/)src\/vulkan-shaders\//\1ggml\/src\/vulkan-shaders\//g' \
  173. -e 's/([[:space:]]|[ab]\/)include\/ggml\.h/\1ggml\/include\/ggml.h/g' \
  174. -e 's/([[:space:]]|[ab]\/)include\/ggml-alloc\.h/\1ggml\/include\/ggml-alloc.h/g' \
  175. -e 's/([[:space:]]|[ab]\/)include\/ggml-amx\.h/\1ggml\/include\/ggml-amx.h/g' \
  176. -e 's/([[:space:]]|[ab]\/)include\/ggml-backend\.h/\1ggml\/include\/ggml-backend.h/g' \
  177. -e 's/([[:space:]]|[ab]\/)include\/ggml-blas\.h/\1ggml\/include\/ggml-blas.h/g' \
  178. -e 's/([[:space:]]|[ab]\/)include\/ggml-cann\.h/\1ggml\/include\/ggml-cann.h/g' \
  179. -e 's/([[:space:]]|[ab]\/)include\/ggml-cuda\.h/\1ggml\/include\/ggml-cuda.h/g' \
  180. -e 's/([[:space:]]|[ab]\/)include\/ggml-kompute\.h/\1ggml\/include\/ggml-kompute.h/g' \
  181. -e 's/([[:space:]]|[ab]\/)include\/ggml-metal\.h/\1ggml\/include\/ggml-metal.h/g' \
  182. -e 's/([[:space:]]|[ab]\/)include\/ggml-rpc\.h/\1ggml\/include\/ggml-rpc.h/g' \
  183. -e 's/([[:space:]]|[ab]\/)include\/ggml-sycl\.h/\1ggml\/include\/ggml-sycl.h/g' \
  184. -e 's/([[:space:]]|[ab]\/)include\/ggml-vulkan\.h/\1ggml\/include\/ggml-vulkan.h/g' \
  185. -e 's/([[:space:]]|[ab]\/)examples\/common\.h/\1examples\/common.h/g' \
  186. -e 's/([[:space:]]|[ab]\/)examples\/common\.cpp/\1examples\/common.cpp/g' \
  187. -e 's/([[:space:]]|[ab]\/)examples\/common-ggml\.h/\1examples\/common-ggml.h/g' \
  188. -e 's/([[:space:]]|[ab]\/)examples\/common-ggml\.cpp/\1examples\/common-ggml.cpp/g' \
  189. -e 's/([[:space:]]|[ab]\/)LICENSE/\1LICENSE/g' \
  190. -e 's/([[:space:]]|[ab]\/)scripts\/gen-authors\.sh/\1scripts\/gen-authors.sh/g' \
  191. > ggml-src.patch.tmp
  192. mv ggml-src.patch.tmp ggml-src.patch
  193. git am -C${ctx} ggml-src.patch
  194. rm -v $SRC_LLAMA/ggml-src.patch
  195. fi
  196. # update last commit
  197. cd $SRC_GGML
  198. git log -1 --format=%H > $SRC_LLAMA/scripts/sync-ggml.last
  199. echo "Done"
  200. exit 0