From 9095d136e8d499d4c28b84aa31542533e93e2498 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 30 Nov 2023 02:31:37 -0500 Subject: [PATCH 1/2] Make Metal the default on OSX, simplify osx-specific code, and fix the file copy error. --- Makefile | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 193510fc4362..25b515aa3d08 100644 --- a/Makefile +++ b/Makefile @@ -68,12 +68,20 @@ ifndef UNAME_S UNAME_S := $(shell uname -s) endif -ifeq ($(UNAME_S),Darwin) +ifeq ($(OS),Darwin) CGO_LDFLAGS += -lcblas -framework Accelerate -ifneq ($(BUILD_TYPE),metal) - # explicit disable metal if on Darwin and metal is disabled - CMAKE_ARGS+=-DLLAMA_METAL=OFF -endif + ifeq ($(OSX_SIGNING_IDENTITY),) + OSX_SIGNING_IDENTITY := $(shell security find-identity -v -p codesigning | grep '"' | head -n 1 | sed -E 's/.*"(.*)"/\1/') + endif + + # on OSX, if BUILD_TYPE is blank, we should default to use Metal + ifeq ($(BUILD_TYPE),) + BUILD_TYPE=metal + else ifneq ($(BUILD_TYPE),metal) + # explicit disable metal if on Darwin and any other value is explicitly passed. + CMAKE_ARGS+=-DLLAMA_METAL=OFF + endif + endif endif ifeq ($(BUILD_TYPE),openblas) @@ -106,12 +114,6 @@ ifeq ($(BUILD_TYPE),clblas) CGO_LDFLAGS+=-lOpenCL -lclblast endif -ifeq ($(OS),Darwin) - ifeq ($(OSX_SIGNING_IDENTITY),) - OSX_SIGNING_IDENTITY := $(shell security find-identity -v -p codesigning | grep '"' | head -n 1 | sed -E 's/.*"(.*)"/\1/') - endif -endif - # glibc-static or glibc-devel-static required ifeq ($(STATIC),true) LD_FLAGS=-linkmode external -extldflags -static @@ -411,9 +413,9 @@ backend-assets/grpc/llama: backend-assets/grpc sources/go-llama/libbinding.a $(GOCMD) mod edit -replace github.com/go-skynet/go-llama.cpp=$(shell pwd)/sources/go-llama CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/sources/go-llama LIBRARY_PATH=$(shell pwd)/sources/go-llama \ $(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/llama ./backend/go/llm/llama/ -# TODO: every binary should have its own folder instead, so can have different metal implementations +# TODO: every binary should have its own folder instead, so can have different implementations ifeq ($(BUILD_TYPE),metal) - cp go-llama/build/bin/ggml-metal.metal backend-assets/grpc/ + cp backend/cpp/llama/llama.cpp/ggml-metal.metal backend-assets/grpc/ endif ## BACKEND CPP LLAMA START From 1ac3800a691bda978de2293caa3896afe72ead4e Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 30 Nov 2023 02:35:39 -0500 Subject: [PATCH 2/2] fix endif / comment --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 25b515aa3d08..6c6accd1e139 100644 --- a/Makefile +++ b/Makefile @@ -77,10 +77,9 @@ ifeq ($(OS),Darwin) # on OSX, if BUILD_TYPE is blank, we should default to use Metal ifeq ($(BUILD_TYPE),) BUILD_TYPE=metal + # disable metal if on Darwin and any other value is explicitly passed. else ifneq ($(BUILD_TYPE),metal) - # explicit disable metal if on Darwin and any other value is explicitly passed. - CMAKE_ARGS+=-DLLAMA_METAL=OFF - endif + CMAKE_ARGS+=-DLLAMA_METAL=OFF endif endif