2023-11-29 19:00:37 +00:00
|
|
|
#!/bin/bash
|
2023-11-14 01:20:34 +00:00
|
|
|
# This script is intended to run inside the go generate
|
2024-01-04 17:40:15 +00:00
|
|
|
# working directory must be ./llm/generate/
|
2023-11-14 01:20:34 +00:00
|
|
|
|
|
|
|
# TODO - add hardening to detect missing tools (cmake, etc.)
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
set -o pipefail
|
|
|
|
echo "Starting darwin generate script"
|
|
|
|
source $(dirname $0)/gen_common.sh
|
|
|
|
init_vars
|
2024-01-13 00:28:00 +00:00
|
|
|
git_module_setup
|
|
|
|
apply_patches
|
|
|
|
|
2024-01-20 00:24:11 +00:00
|
|
|
sign() {
|
|
|
|
if [ -n "$APPLE_IDENTITY" ]; then
|
|
|
|
codesign -f --timestamp --deep --options=runtime --sign "$APPLE_IDENTITY" --identifier ai.ollama.ollama $1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-01-23 00:25:56 +00:00
|
|
|
COMMON_DARWIN_DEFS="-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_SYSTEM_NAME=Darwin"
|
2024-01-13 00:28:00 +00:00
|
|
|
|
2023-11-14 01:20:34 +00:00
|
|
|
case "${GOARCH}" in
|
2023-12-22 17:51:53 +00:00
|
|
|
"amd64")
|
2024-01-13 00:28:00 +00:00
|
|
|
COMMON_CPU_DEFS="${COMMON_DARWIN_DEFS} -DCMAKE_SYSTEM_PROCESSOR=${ARCH} -DCMAKE_OSX_ARCHITECTURES=${ARCH} -DLLAMA_METAL=off -DLLAMA_NATIVE=off"
|
|
|
|
|
|
|
|
#
|
|
|
|
# CPU first for the default library, set up as lowest common denominator for maximum compatibility (including Rosetta)
|
|
|
|
#
|
2024-01-23 00:25:56 +00:00
|
|
|
CMAKE_DEFS="${COMMON_CPU_DEFS} -DLLAMA_ACCELERATE=off -DLLAMA_AVX=off -DLLAMA_AVX2=off -DLLAMA_AVX512=off -DLLAMA_FMA=off -DLLAMA_F16C=off ${CMAKE_DEFS}"
|
2024-01-13 00:28:00 +00:00
|
|
|
BUILD_DIR="${LLAMACPP_DIR}/build/darwin/${ARCH}/cpu"
|
|
|
|
echo "Building LCD CPU"
|
|
|
|
build
|
2024-01-20 00:24:11 +00:00
|
|
|
sign ${LLAMACPP_DIR}/build/darwin/${ARCH}/cpu/lib/libext_server.dylib
|
2024-01-13 00:28:00 +00:00
|
|
|
compress_libs
|
|
|
|
|
|
|
|
#
|
|
|
|
# ~2011 CPU Dynamic library with more capabilities turned on to optimize performance
|
|
|
|
# Approximately 400% faster than LCD on same CPU
|
|
|
|
#
|
|
|
|
init_vars
|
2024-01-23 00:25:56 +00:00
|
|
|
CMAKE_DEFS="${COMMON_CPU_DEFS} -DLLAMA_ACCELERATE=off -DLLAMA_AVX=on -DLLAMA_AVX2=off -DLLAMA_AVX512=off -DLLAMA_FMA=off -DLLAMA_F16C=off ${CMAKE_DEFS}"
|
2024-01-13 00:28:00 +00:00
|
|
|
BUILD_DIR="${LLAMACPP_DIR}/build/darwin/${ARCH}/cpu_avx"
|
|
|
|
echo "Building AVX CPU"
|
|
|
|
build
|
2024-01-20 00:24:11 +00:00
|
|
|
sign ${LLAMACPP_DIR}/build/darwin/${ARCH}/cpu_avx/lib/libext_server.dylib
|
2024-01-13 00:28:00 +00:00
|
|
|
compress_libs
|
|
|
|
|
|
|
|
#
|
|
|
|
# ~2013 CPU Dynamic library
|
|
|
|
# Approximately 10% faster than AVX on same CPU
|
|
|
|
#
|
|
|
|
init_vars
|
2024-01-23 00:25:56 +00:00
|
|
|
CMAKE_DEFS="${COMMON_CPU_DEFS} -DLLAMA_ACCELERATE=on -DLLAMA_AVX=on -DLLAMA_AVX2=on -DLLAMA_AVX512=off -DLLAMA_FMA=on -DLLAMA_F16C=on ${CMAKE_DEFS}"
|
2024-01-13 00:28:00 +00:00
|
|
|
BUILD_DIR="${LLAMACPP_DIR}/build/darwin/${ARCH}/cpu_avx2"
|
|
|
|
echo "Building AVX2 CPU"
|
2024-01-23 00:25:56 +00:00
|
|
|
EXTRA_LIBS="${EXTRA_LIBS} -framework Accelerate -framework Foundation"
|
2024-01-13 00:28:00 +00:00
|
|
|
build
|
2024-01-20 00:24:11 +00:00
|
|
|
sign ${LLAMACPP_DIR}/build/darwin/${ARCH}/cpu_avx2/lib/libext_server.dylib
|
2024-01-13 00:28:00 +00:00
|
|
|
compress_libs
|
2023-12-22 17:51:53 +00:00
|
|
|
;;
|
|
|
|
"arm64")
|
2024-01-23 00:25:56 +00:00
|
|
|
CMAKE_DEFS="${COMMON_DARWIN_DEFS} -DLLAMA_ACCELERATE=on -DCMAKE_SYSTEM_PROCESSOR=${ARCH} -DCMAKE_OSX_ARCHITECTURES=${ARCH} -DLLAMA_METAL=on ${CMAKE_DEFS}"
|
2024-01-13 00:28:00 +00:00
|
|
|
BUILD_DIR="${LLAMACPP_DIR}/build/darwin/${ARCH}/metal"
|
|
|
|
EXTRA_LIBS="${EXTRA_LIBS} -framework Accelerate -framework Foundation -framework Metal -framework MetalKit -framework MetalPerformanceShaders"
|
|
|
|
build
|
2024-01-20 00:24:11 +00:00
|
|
|
sign ${LLAMACPP_DIR}/build/darwin/${ARCH}/metal/lib/libext_server.dylib
|
2024-01-13 00:28:00 +00:00
|
|
|
compress_libs
|
2023-12-22 17:51:53 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "GOARCH must be set"
|
|
|
|
echo "this script is meant to be run from within go generate"
|
|
|
|
exit 1
|
|
|
|
;;
|
2023-11-14 01:20:34 +00:00
|
|
|
esac
|
|
|
|
|
2023-12-22 17:51:53 +00:00
|
|
|
cleanup
|