Skip to content

Commit b47879b

Browse files
committed
scripts : add sync-ggml-am.sh
1 parent 951010f commit b47879b

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

scripts/sync-ggml-am.sh

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

scripts/sync-ggml.last

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
76e7f47b69e8334384dc718480c496dafbd47999

0 commit comments

Comments
 (0)