2023-11-29 19:00:37 +00:00
|
|
|
#!/bin/bash
|
2024-04-09 22:57:45 +00:00
|
|
|
# This script is intended to run inside the go generate
|
|
|
|
# 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
|
2024-08-09 14:21:40 +00:00
|
|
|
compress_pids=""
|
2023-11-14 01:20:34 +00:00
|
|
|
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-09-04 01:12:39 +00:00
|
|
|
COMMON_DARWIN_DEFS="-DBUILD_SHARED_LIBS=off -DCMAKE_OSX_DEPLOYMENT_TARGET=11.3 -DGGML_METAL_MACOSX_VERSION_MIN=11.3 -DCMAKE_SYSTEM_NAME=Darwin -DGGML_METAL_EMBED_LIBRARY=on -DGGML_OPENMP=off"
|
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-07-05 17:25:58 +00:00
|
|
|
COMMON_CPU_DEFS="${COMMON_DARWIN_DEFS} -DCMAKE_SYSTEM_PROCESSOR=${ARCH} -DCMAKE_OSX_ARCHITECTURES=${ARCH} -DGGML_METAL=off -DGGML_NATIVE=off"
|
2024-01-13 00:28:00 +00:00
|
|
|
|
2024-03-14 17:24:13 +00:00
|
|
|
# Static build for linking into the Go binary
|
|
|
|
init_vars
|
|
|
|
CMAKE_TARGETS="--target llama --target ggml"
|
2024-07-06 01:48:31 +00:00
|
|
|
CMAKE_DEFS="${COMMON_CPU_DEFS} -DGGML_BLAS=off -DGGML_ACCELERATE=off -DGGML_AVX=off -DGGML_AVX2=off -DGGML_AVX512=off -DGGML_FMA=off -DGGML_F16C=off ${CMAKE_DEFS}"
|
2024-03-14 17:24:13 +00:00
|
|
|
BUILD_DIR="../build/darwin/${ARCH}_static"
|
|
|
|
echo "Building static library"
|
|
|
|
build
|
|
|
|
|
2024-05-31 04:43:15 +00:00
|
|
|
if [ -z "$OLLAMA_SKIP_CPU_GENERATE" ]; then
|
|
|
|
#
|
|
|
|
# CPU first for the default library, set up as lowest common denominator for maximum compatibility (including Rosetta)
|
|
|
|
#
|
|
|
|
init_vars
|
2024-07-05 17:25:58 +00:00
|
|
|
CMAKE_DEFS="${COMMON_CPU_DEFS} -DGGML_ACCELERATE=off -DGGML_BLAS=off -DGGML_AVX=off -DGGML_AVX2=off -DGGML_AVX512=off -DGGML_FMA=off -DGGML_F16C=off ${CMAKE_DEFS}"
|
2024-05-31 04:43:15 +00:00
|
|
|
BUILD_DIR="../build/darwin/${ARCH}/cpu"
|
|
|
|
echo "Building LCD CPU"
|
|
|
|
build
|
|
|
|
sign ${BUILD_DIR}/bin/ollama_llama_server
|
|
|
|
compress
|
2024-03-14 17:24:13 +00:00
|
|
|
|
2024-05-31 04:43:15 +00:00
|
|
|
#
|
|
|
|
# ~2011 CPU Dynamic library with more capabilities turned on to optimize performance
|
|
|
|
# Approximately 400% faster than LCD on same CPU
|
|
|
|
#
|
|
|
|
init_vars
|
2024-07-05 17:25:58 +00:00
|
|
|
CMAKE_DEFS="${COMMON_CPU_DEFS} -DGGML_ACCELERATE=off -DGGML_BLAS=off -DGGML_AVX=on -DGGML_AVX2=off -DGGML_AVX512=off -DGGML_FMA=off -DGGML_F16C=off ${CMAKE_DEFS}"
|
2024-05-31 04:43:15 +00:00
|
|
|
BUILD_DIR="../build/darwin/${ARCH}/cpu_avx"
|
|
|
|
echo "Building AVX CPU"
|
|
|
|
build
|
|
|
|
sign ${BUILD_DIR}/bin/ollama_llama_server
|
|
|
|
compress
|
2024-01-13 00:28:00 +00:00
|
|
|
|
2024-05-31 04:43:15 +00:00
|
|
|
#
|
|
|
|
# ~2013 CPU Dynamic library
|
|
|
|
# Approximately 10% faster than AVX on same CPU
|
|
|
|
#
|
|
|
|
init_vars
|
2024-07-05 17:25:58 +00:00
|
|
|
CMAKE_DEFS="${COMMON_CPU_DEFS} -DGGML_ACCELERATE=on -DGGML_BLAS=off -DGGML_AVX=on -DGGML_AVX2=on -DGGML_AVX512=off -DGGML_FMA=on -DGGML_F16C=on ${CMAKE_DEFS}"
|
2024-05-31 04:43:15 +00:00
|
|
|
BUILD_DIR="../build/darwin/${ARCH}/cpu_avx2"
|
|
|
|
echo "Building AVX2 CPU"
|
|
|
|
EXTRA_LIBS="${EXTRA_LIBS} -framework Accelerate -framework Foundation"
|
|
|
|
build
|
|
|
|
sign ${BUILD_DIR}/bin/ollama_llama_server
|
|
|
|
compress
|
|
|
|
fi
|
2023-12-22 17:51:53 +00:00
|
|
|
;;
|
|
|
|
"arm64")
|
2024-03-14 17:24:13 +00:00
|
|
|
|
|
|
|
# Static build for linking into the Go binary
|
|
|
|
init_vars
|
|
|
|
CMAKE_TARGETS="--target llama --target ggml"
|
2024-07-06 02:42:42 +00:00
|
|
|
CMAKE_DEFS="${COMMON_DARWIN_DEFS} -DCMAKE_OSX_DEPLOYMENT_TARGET=11.3 -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_SYSTEM_PROCESSOR=${ARCH} -DCMAKE_OSX_ARCHITECTURES=${ARCH} ${CMAKE_DEFS}"
|
2024-03-14 17:24:13 +00:00
|
|
|
BUILD_DIR="../build/darwin/${ARCH}_static"
|
|
|
|
echo "Building static library"
|
|
|
|
build
|
|
|
|
|
2024-05-31 04:43:15 +00:00
|
|
|
if [ -z "$OLLAMA_SKIP_METAL_GENERATE" ]; then
|
|
|
|
init_vars
|
2024-07-05 17:25:58 +00:00
|
|
|
CMAKE_DEFS="${COMMON_DARWIN_DEFS} -DCMAKE_SYSTEM_PROCESSOR=${ARCH} -DCMAKE_OSX_ARCHITECTURES=${ARCH} ${CMAKE_DEFS}"
|
2024-05-31 04:43:15 +00:00
|
|
|
BUILD_DIR="../build/darwin/${ARCH}/metal"
|
|
|
|
EXTRA_LIBS="${EXTRA_LIBS} -framework Accelerate -framework Foundation -framework Metal -framework MetalKit -framework MetalPerformanceShaders"
|
|
|
|
build
|
|
|
|
sign ${BUILD_DIR}/bin/ollama_llama_server
|
|
|
|
compress
|
|
|
|
fi
|
2023-12-22 17:51:53 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "GOARCH must be set"
|
2024-04-09 22:57:45 +00:00
|
|
|
echo "this script is meant to be run from within go generate"
|
2023-12-22 17:51:53 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
2023-11-14 01:20:34 +00:00
|
|
|
esac
|
|
|
|
|
2023-12-22 17:51:53 +00:00
|
|
|
cleanup
|
2024-08-09 14:21:40 +00:00
|
|
|
wait_for_compress
|
2024-04-09 22:57:45 +00:00
|
|
|
echo "go generate completed. LLM runners: $(cd ${BUILD_DIR}/..; echo *)"
|