fix ggml-metal.m

This commit is contained in:
jmorganca 2024-05-18 23:31:41 -07:00
parent beb847b40f
commit dfd8f34806
2 changed files with 16 additions and 15 deletions

View File

@ -1,3 +1,5 @@
//go:build darwin,arm64
/**
* llama.cpp - git 059031b8c40e1f4ba60586842c5b1ed3ddf61842
*
@ -24,7 +26,6 @@
* SOFTWARE.
*/
//go:build darwin,arm64
#import "ggml-metal.h"
#import "ggml-backend-impl.h"

View File

@ -39,20 +39,6 @@ mkdir -p $dst_dir/ggml-cuda
cp $src_dir/ggml-cuda/*.cu $dst_dir/ggml-cuda/
cp $src_dir/ggml-cuda/*.cuh $dst_dir/ggml-cuda/
# ggml-metal
sed -i '' '1s;^;//go:build darwin,arm64\n;' ggml-metal.m
sed -e '/#include "ggml-common.h"/r ggml-common.h' -e '/#include "ggml-common.h"/d' < ggml-metal.metal > temp.metal
TEMP_ASSEMBLY=$(mktemp)
echo ".section __DATA, __ggml_metallib" > $TEMP_ASSEMBLY
echo ".globl _ggml_metallib_start" >> $TEMP_ASSEMBLY
echo "_ggml_metallib_start:" >> $TEMP_ASSEMBLY
echo ".incbin \"temp.metal\"" >> $TEMP_ASSEMBLY
echo ".globl _ggml_metallib_end" >> $TEMP_ASSEMBLY
echo "_ggml_metallib_end:" >> $TEMP_ASSEMBLY
as -mmacosx-version-min=11.3 $TEMP_ASSEMBLY -o ggml-metal.o
rm -f $TEMP_ASSEMBLY
rm -rf temp.metal
# apply patches
for patch in patches/*.patch; do
git apply "$patch"
@ -84,3 +70,17 @@ for IN in $dst_dir/*.{c,h,cpp,m,metal,cu}; do
cat $tempdir $IN >$TMP
mv $TMP $IN
done
# ggml-metal
sed -i '' '1s;^;//go:build darwin,arm64\n\n;' ggml-metal.m
sed -e '/#include "ggml-common.h"/r ggml-common.h' -e '/#include "ggml-common.h"/d' < ggml-metal.metal > temp.metal
TEMP_ASSEMBLY=$(mktemp)
echo ".section __DATA, __ggml_metallib" > $TEMP_ASSEMBLY
echo ".globl _ggml_metallib_start" >> $TEMP_ASSEMBLY
echo "_ggml_metallib_start:" >> $TEMP_ASSEMBLY
echo ".incbin \"temp.metal\"" >> $TEMP_ASSEMBLY
echo ".globl _ggml_metallib_end" >> $TEMP_ASSEMBLY
echo "_ggml_metallib_end:" >> $TEMP_ASSEMBLY
as -mmacosx-version-min=11.3 $TEMP_ASSEMBLY -o ggml-metal.o
rm -f $TEMP_ASSEMBLY
rm -rf temp.metal