sync.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # Set the source directory
  3. src_dir=$1
  4. # Set the destination directory (current directory)
  5. dst_dir="."
  6. # llama.cpp
  7. cp $src_dir/unicode.cpp $dst_dir/unicode.cpp
  8. cp $src_dir/unicode.h $dst_dir/unicode.h
  9. cp $src_dir/unicode-data.cpp $dst_dir/unicode-data.cpp
  10. cp $src_dir/unicode-data.h $dst_dir/unicode-data.h
  11. cp $src_dir/llama.cpp $dst_dir/llama.cpp
  12. cp $src_dir/llama.h $dst_dir/llama.h
  13. cp $src_dir/sgemm.cpp $dst_dir/sgemm.cpp
  14. cp $src_dir/sgemm.h $dst_dir/sgemm.h
  15. # ggml
  16. cp $src_dir/ggml.c $dst_dir/ggml.c
  17. cp $src_dir/ggml.h $dst_dir/ggml.h
  18. cp $src_dir/ggml-quants.c $dst_dir/ggml-quants.c
  19. cp $src_dir/ggml-quants.h $dst_dir/ggml-quants.h
  20. cp $src_dir/ggml-metal.metal $dst_dir/ggml-metal.metal
  21. cp $src_dir/ggml-metal.h $dst_dir/ggml-metal.h
  22. cp $src_dir/ggml-metal.m $dst_dir/ggml-metal.m
  23. cp $src_dir/ggml-impl.h $dst_dir/ggml-impl.h
  24. cp $src_dir/ggml-cuda.h $dst_dir/ggml-cuda.h
  25. cp $src_dir/ggml-cuda.cu $dst_dir/ggml-cuda.cu
  26. cp $src_dir/ggml-common.h $dst_dir/ggml-common.h
  27. cp $src_dir/ggml-backend.h $dst_dir/ggml-backend.h
  28. cp $src_dir/ggml-backend.c $dst_dir/ggml-backend.c
  29. cp $src_dir/ggml-backend-impl.h $dst_dir/ggml-backend-impl.h
  30. cp $src_dir/ggml-alloc.h $dst_dir/ggml-alloc.h
  31. cp $src_dir/ggml-alloc.c $dst_dir/ggml-alloc.c
  32. # ggml-cuda
  33. mkdir -p $dst_dir/ggml-cuda
  34. cp $src_dir/ggml-cuda/*.cu $dst_dir/ggml-cuda/
  35. cp $src_dir/ggml-cuda/*.cuh $dst_dir/ggml-cuda/
  36. # apply patches
  37. for patch in patches/*.patch; do
  38. git apply "$patch"
  39. done
  40. # add license
  41. sha1=$(git -C $src_dir rev-parse @)
  42. tempdir=$(mktemp)
  43. cleanup() {
  44. rm -f $tempdir
  45. }
  46. trap cleanup 0
  47. cat <<EOF | sed 's/ *$//' >$tempdir
  48. /**
  49. * llama.cpp - git $sha1
  50. *
  51. $(sed 's/^/ * /' <$src_dir/LICENSE)
  52. */
  53. EOF
  54. for IN in $dst_dir/*.{c,h,cpp,m,metal,cu}; do
  55. if [[ "$IN" == *"sgemm.cpp" || "$IN" == *"sgemm.h" ]]; then
  56. continue
  57. fi
  58. TMP=$(mktemp)
  59. cat $tempdir $IN >$TMP
  60. mv $TMP $IN
  61. done
  62. # ggml-metal
  63. sed -i '' '1s;^;//go:build darwin,arm64\n\n;' ggml-metal.m
  64. sed -e '/#include "ggml-common.h"/r ggml-common.h' -e '/#include "ggml-common.h"/d' < ggml-metal.metal > temp.metal
  65. TEMP_ASSEMBLY=$(mktemp)
  66. echo ".section __DATA, __ggml_metallib" > $TEMP_ASSEMBLY
  67. echo ".globl _ggml_metallib_start" >> $TEMP_ASSEMBLY
  68. echo "_ggml_metallib_start:" >> $TEMP_ASSEMBLY
  69. echo ".incbin \"temp.metal\"" >> $TEMP_ASSEMBLY
  70. echo ".globl _ggml_metallib_end" >> $TEMP_ASSEMBLY
  71. echo "_ggml_metallib_end:" >> $TEMP_ASSEMBLY
  72. as -mmacosx-version-min=11.3 $TEMP_ASSEMBLY -o ggml-metal.o
  73. rm -f $TEMP_ASSEMBLY
  74. rm -rf temp.metal