From 8f805dd74b28661b900bdbc55137684a31ca443a Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Mon, 16 Dec 2024 18:45:02 -0800 Subject: [PATCH] darwin: restore multiple runners for x86 (#8125) In 0.5.2 we simplified packaging to have avx only for macos x86. It looks like there may still be some non-AVX systems out there, so this puts back the prior logic of building no-AVX for the primary binary, and now 2 runners for avx and avx2. These will be packaged in the App bundle only, so the stand-alone binary will now be without AVX support on macos. On arm, we'll also see these runners reported as available in the log, but they're dormant and will never be used at runtime. --- Makefile | 2 -- macapp/forge.config.ts | 3 ++- runners/common.go | 1 + scripts/build_darwin.sh | 11 +++++++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 26dc418d222..383354ee907 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,9 @@ include make/cuda-v12-defs.make include make/rocm-defs.make ifeq ($(CUSTOM_CPU_FLAGS),) -ifneq ($(OS),darwin) ifeq ($(ARCH),amd64) RUNNER_TARGETS=cpu endif -endif # Without CUSTOM_CPU_FLAGS we default to build both v11 and v12 if present ifeq ($(OLLAMA_SKIP_CUDA_GENERATE),) ifneq ($(CUDA_11_COMPILER),) diff --git a/macapp/forge.config.ts b/macapp/forge.config.ts index 1000105390f..73ad23e8395 100644 --- a/macapp/forge.config.ts +++ b/macapp/forge.config.ts @@ -19,6 +19,7 @@ const config: ForgeConfig = { icon: './assets/icon.icns', extraResource: [ '../dist/ollama', + '../dist/darwin-amd64/lib', path.join(__dirname, './assets/iconTemplate.png'), path.join(__dirname, './assets/iconTemplate@2x.png'), path.join(__dirname, './assets/iconUpdateTemplate.png'), @@ -42,7 +43,7 @@ const config: ForgeConfig = { } : {}), osxUniversal: { - x64ArchFiles: '**/ollama', + x64ArchFiles: '**/ollama*', }, }, rebuildConfig: {}, diff --git a/runners/common.go b/runners/common.go index 287a6716a28..11279ed4402 100644 --- a/runners/common.go +++ b/runners/common.go @@ -72,6 +72,7 @@ func locateRunnersOnce() { paths := []string{ filepath.Join(filepath.Dir(exe), "llama", "build", runtime.GOOS+"-"+runtime.GOARCH, "runners"), filepath.Join(filepath.Dir(exe), envconfig.LibRelativeToExe(), "lib", "ollama", "runners"), + filepath.Join(filepath.Dir(exe), "lib", "ollama", "runners"), } for _, path := range paths { if _, err := os.Stat(path); err == nil { diff --git a/scripts/build_darwin.sh b/scripts/build_darwin.sh index 595c3ce7120..ae95afd9472 100755 --- a/scripts/build_darwin.sh +++ b/scripts/build_darwin.sh @@ -18,10 +18,18 @@ rm -rf llama/build dist/darwin-* echo "Building darwin arm64" GOOS=darwin ARCH=arm64 GOARCH=arm64 make -j 8 dist echo "Building darwin amd64 with AVX enabled" -GOOS=darwin ARCH=amd64 GOARCH=amd64 CUSTOM_CPU_FLAGS="avx" make -j 8 dist +GOOS=darwin ARCH=amd64 GOARCH=amd64 CUSTOM_CPU_FLAGS="avx" make -j 8 dist_exe +# Generate the universal ollama binary for stand-alone usage: metal + avx +lipo -create -output dist/ollama-darwin dist/darwin-arm64/bin/ollama dist/darwin-amd64/bin/ollama +echo "Building darwin amd64 with runners" +rm dist/darwin-amd64/bin/ollama +GOOS=darwin ARCH=amd64 GOARCH=amd64 make -j 8 dist +# Generate the universal ollama binary for the app bundle: metal + no-avx lipo -create -output dist/ollama dist/darwin-arm64/bin/ollama dist/darwin-amd64/bin/ollama + + if [ -n "$APPLE_IDENTITY" ]; then codesign --deep --force --options=runtime --sign "$APPLE_IDENTITY" --timestamp dist/ollama else @@ -48,5 +56,4 @@ ditto -c -k --keepParent dist/ollama dist/temp.zip if [ -n "$APPLE_IDENTITY" ]; then xcrun notarytool submit dist/temp.zip --wait --timeout 10m --apple-id $APPLE_ID --password $APPLE_PASSWORD --team-id $APPLE_TEAM_ID fi -mv dist/ollama dist/ollama-darwin rm -f dist/temp.zip