@@ -160,6 +160,9 @@ if [ "$host" == "Darwin" ]; then
160160 die $? " not ok - missing build tools, try \" $( advice " libtool" ) \" "
161161 quiet command -v curl
162162 die $? " not ok - missing curl, try \" $( advice " curl" ) \" "
163+ if ! brew list | grep libomp > /dev/null 2>&1 ; then
164+ die $? " not ok - missing libomp, try \" $( advice " libomp" ) \" "
165+ fi
163166fi
164167
165168if [ " $host " == " Linux" ]; then
@@ -286,6 +289,8 @@ function _build_cli {
286289 static_libs+=(" $BUILD_DIR /$arch -$platform /lib/libuv.a" )
287290 static_libs+=(" $BUILD_DIR /$arch -$platform /lib/libllama.a" )
288291 static_libs+=(" $BUILD_DIR /$arch -$platform /lib/libsocket-runtime.a" )
292+ elif [[ " $( uname -s) " == " Darwin" ]]; then
293+ cflags+=(" -fopenmp" )
289294 fi
290295
291296 libs=($( find " $root /build/$arch -$platform /lib$d /*" 2> /dev/null) )
@@ -818,7 +823,7 @@ function _compile_llama_metal {
818823 mkdir -p " $STAGING_DIR /build/"
819824 mkdir -p ../lib
820825
821- xcrun -sdk $sdk metal -O3 -c ggml-metal.metal -o ggml-metal.air
826+ xcrun -sdk $sdk metal -O3 -c ggml/src/ggml-metal/ggml -metal.metal -o ggml-metal.air
822827 xcrun -sdk $sdk metallib ggml-metal.air -o ../lib/default.metallib
823828 rm * .air
824829
@@ -893,15 +898,26 @@ function _compile_llama {
893898
894899 rm -f " $root /build/$( host_arch) -desktop/lib$d " /* .{so,la,dylib}*
895900 return
896- elif [ " $platform " == " iPhoneOS" ] || [ " $platform " == " iPhoneSimulator" ]; then
901+ # elif [ "$platform" == "iPhoneOS" ] || [ "$platform" == "iPhoneSimulator" ]; then
902+ elif [ " $platform " == " iPhoneOS" ]; then
897903 # https://github.com/ggerganov/llama.cpp/discussions/4508
898904
899905 local ar=" $( xcrun -sdk $sdk -find ar) "
900906 local cc=" $( xcrun -sdk $sdk -find clang) "
901907 local cxx=" $( xcrun -sdk $sdk -find clang++) "
902- local cflags=" --target=$target -apple-ios -isysroot $PLATFORMPATH /$platform .platform/Developer/SDKs/$platform$SDKVERSION .sdk -m$sdk -version-min=$SDKMINVERSION -DLLAMA_METAL_EMBED_LIBRARY=ON"
908+ local cflags=" --target=$target -apple-ios -isysroot $PLATFORMPATH /$platform .platform/Developer/SDKs/$platform$SDKVERSION .sdk -m$sdk -version-min=$SDKMINVERSION -DLLAMA_METAL_EMBED_LIBRARY=ON -DUSE_NEON_DOTPROD -march=armv8.2-a+dotprod"
909+
910+ export AR=" $ar "
911+ export CFLAGS=" $cflags "
912+ export CXXFLAGS=" $cflags "
913+ export CXX=" $cxx "
914+ export CC=" $cc "
915+ export SDKROOT=" $PLATFORMPATH /$platform .platform/Developer/SDKs/$platform$SDKVERSION .sdk"
903916
904- AR=" $ar " CFLAGS=" $cflags " CXXFLAGS=" $cflags " CXX=" $cxx " CC=" $cc " make libllama.a
917+ quiet cmake -S . -B build -DCMAKE_OSX_ARCHITECTURES=" $target " -DCMAKE_OSX_SYSROOT=" $SDKROOT " -DCMAKE_C_COMPILER=" $cc " -DCMAKE_CXX_COMPILER=" $cxx " -DCMAKE_INSTALL_PREFIX=" $BUILD_DIR /$target -$platform " -DLLAMA_NATIVE=OFF -DGGML_ARM_DOTPROD=ON ${cmake_args[@]} &&
918+ quiet cmake --build build &&
919+ quiet cmake --build build -- -j" $CPU_CORES " &&
920+ quiet cmake --install build
905921
906922 if [ ! $? = 0 ]; then
907923 die $? " not ok - Unable to compile libllama for '$platform '"
@@ -937,6 +953,7 @@ function _compile_llama {
937953 cd " $BUILD_DIR " || exit 1
938954 rm -f " $root /build/$target -$platform /lib$d " /* .{so,la,dylib}*
939955 echo " ok - built llama for $target -$platform "
956+ return 0
940957}
941958
942959function _compile_libuv {
@@ -1114,8 +1131,8 @@ if [[ "$(uname -s)" == "Darwin" ]] && [[ -z "$NO_IOS" ]]; then
11141131 quiet xcode-select -p
11151132 die $? " not ok - xcode needs to be installed from the mac app store: https://apps.apple.com/us/app/xcode/id497799835"
11161133
1117- SDKMINVERSION=" 8 .0"
1118- export IPHONEOS_DEPLOYMENT_TARGET=" 8 .0"
1134+ SDKMINVERSION=" 13 .0"
1135+ export IPHONEOS_DEPLOYMENT_TARGET=" 13 .0"
11191136
11201137 LIPO=$( xcrun -sdk iphoneos -find lipo)
11211138 PLATFORMPATH=" /Applications/Xcode.app/Contents/Developer/Platforms"
@@ -1126,11 +1143,11 @@ if [[ "$(uname -s)" == "Darwin" ]] && [[ -z "$NO_IOS" ]]; then
11261143 _compile_llama arm64 iPhoneOS & pids+=($! )
11271144
11281145 _compile_libuv x86_64 iPhoneSimulator & pids+=($! )
1129- _compile_llama x86_64 iPhoneSimulator & pids+=($! )
1146+ # _compile_llama x86_64 iPhoneSimulator & pids+=($!)
11301147
11311148 if [[ " $arch " = " arm64" ]]; then
11321149 _compile_libuv arm64 iPhoneSimulator & pids+=($! )
1133- _compile_llama arm64 iPhoneSimulator & pids+=($! )
1150+ # _compile_llama arm64 iPhoneSimulator & pids+=($!)
11341151 fi
11351152
11361153 for pid in " ${pids[@]} " ; do wait " $pid " ; done
0 commit comments