sync-ggml-am.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 format-patch $lc --stdout -- \
  24. include/ggml/ggml*.h \
  25. src/ggml*.h \
  26. src/ggml*.c \
  27. src/ggml*.cpp \
  28. src/ggml*.m \
  29. src/ggml*.metal \
  30. src/ggml*.cu \
  31. tests/test-opt.cpp \
  32. tests/test-grad0.cpp \
  33. tests/test-quantize-fns.cpp \
  34. tests/test-quantize-perf.cpp \
  35. tests/test-backend-ops.cpp \
  36. > $SRC_LLAMA/ggml-src.patch
  37. # delete files if empty
  38. if [ ! -s $SRC_LLAMA/ggml-src.patch ]; then
  39. rm -v $SRC_LLAMA/ggml-src.patch
  40. fi
  41. cd $SRC_LLAMA
  42. if [ -f $SRC_LLAMA/ggml-src.patch ]; then
  43. # replace PR numbers
  44. #
  45. # Subject: some text (#1234)
  46. # Subject: some text (ggml/1234)
  47. cat ggml-src.patch | sed -e 's/^Subject: \(.*\) (#\([0-9]*\))/Subject: \1 (ggml\/\2)/' > ggml-src.patch.tmp
  48. mv ggml-src.patch.tmp ggml-src.patch
  49. cat ggml-src.patch | sed -e 's/^\(.*\) (#\([0-9]*\))$/\1 (ggml\/\2)/' > ggml-src.patch.tmp
  50. mv ggml-src.patch.tmp ggml-src.patch
  51. # replace filenames:
  52. #
  53. # src/ggml.c -> ggml.c
  54. # src/ggml-alloc.c -> ggml-alloc.c
  55. # src/ggml-backend-impl.h -> ggml-backend-impl.h
  56. # src/ggml-backend.c -> ggml-backend.c
  57. # src/ggml-cuda.cu -> ggml-cuda.cu
  58. # src/ggml-cuda.h -> ggml-cuda.h
  59. # src/ggml-impl.h -> ggml-impl.h
  60. # src/ggml-metal.h -> ggml-metal.h
  61. # src/ggml-metal.m -> ggml-metal.m
  62. # src/ggml-metal.metal -> ggml-metal.metal
  63. # src/ggml-mpi.h -> ggml-mpi.h
  64. # src/ggml-mpi.c -> ggml-mpi.c
  65. # src/ggml-opencl.cpp -> ggml-opencl.cpp
  66. # src/ggml-opencl.h -> ggml-opencl.h
  67. # src/ggml-quants.c -> ggml-quants.c
  68. # src/ggml-quants.h -> ggml-quants.h
  69. # include/ggml/ggml.h -> ggml.h
  70. # include/ggml/ggml-alloc.h -> ggml-alloc.h
  71. # include/ggml/ggml-backend.h -> ggml-backend.h
  72. #
  73. # tests/test-opt.cpp -> tests/test-opt.cpp
  74. # tests/test-grad0.cpp -> tests/test-grad0.cpp
  75. # tests/test-quantize-fns.cpp -> tests/test-quantize-fns.cpp
  76. # tests/test-quantize-perf.cpp -> tests/test-quantize-perf.cpp
  77. # tests/test-backend-ops.cpp -> tests/test-backend-ops.cpp
  78. cat ggml-src.patch | sed \
  79. -e 's/src\/ggml\.c/ggml.c/g' \
  80. -e 's/src\/ggml-alloc\.c/ggml-alloc.c/g' \
  81. -e 's/src\/ggml-backend-impl\.h/ggml-backend-impl.h/g' \
  82. -e 's/src\/ggml-backend\.c/ggml-backend.c/g' \
  83. -e 's/src\/ggml-cuda\.cu/ggml-cuda.cu/g' \
  84. -e 's/src\/ggml-cuda\.h/ggml-cuda.h/g' \
  85. -e 's/src\/ggml-impl\.h/ggml-impl.h/g' \
  86. -e 's/src\/ggml-metal\.h/ggml-metal.h/g' \
  87. -e 's/src\/ggml-metal\.m/ggml-metal.m/g' \
  88. -e 's/src\/ggml-metal\.metal/ggml-metal.metal/g' \
  89. -e 's/src\/ggml-mpi\.h/ggml-mpi.h/g' \
  90. -e 's/src\/ggml-mpi\.c/ggml-mpi.c/g' \
  91. -e 's/src\/ggml-opencl\.cpp/ggml-opencl.cpp/g' \
  92. -e 's/src\/ggml-opencl\.h/ggml-opencl.h/g' \
  93. -e 's/src\/ggml-quants\.c/ggml-quants.c/g' \
  94. -e 's/src\/ggml-quants\.h/ggml-quants.h/g' \
  95. -e 's/include\/ggml\/ggml\.h/ggml.h/g' \
  96. -e 's/include\/ggml\/ggml-alloc\.h/ggml-alloc.h/g' \
  97. -e 's/include\/ggml\/ggml-backend\.h/ggml-backend.h/g' \
  98. -e 's/tests\/test-opt\.cpp/tests\/test-opt.cpp/g' \
  99. -e 's/tests\/test-grad0\.cpp/tests\/test-grad0.cpp/g' \
  100. -e 's/tests\/test-quantize-fns\.cpp/tests\/test-quantize-fns.cpp/g' \
  101. -e 's/tests\/test-quantize-perf\.cpp/tests\/test-quantize-perf.cpp/g' \
  102. -e 's/tests\/test-backend-ops\.cpp/tests\/test-backend-ops.cpp/g' \
  103. > ggml-src.patch.tmp
  104. mv ggml-src.patch.tmp ggml-src.patch
  105. git am ggml-src.patch
  106. rm -v $SRC_LLAMA/ggml-src.patch
  107. fi
  108. # update last commit
  109. cd $SRC_GGML
  110. git log -1 --format=%H > $SRC_LLAMA/scripts/sync-ggml.last
  111. echo "Done"
  112. exit 0