build : update make / cmake

This commit is contained in:
Georgi Gerganov
2024-06-16 19:10:20 +03:00
parent 4a6e6e8b30
commit 5181494e9f
3 changed files with 125 additions and 113 deletions

View File

@@ -35,6 +35,8 @@ CXXV := $(shell $(CXX) --version | head -n 1)
# Mac OS + Arm can report x86_64
# ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789
ifeq ($(UNAME_S),Darwin)
WHISPER_NO_OPENMP := 1
ifneq ($(UNAME_P),arm)
SYSCTL_M := $(shell sysctl -n hw.optional.arm64)
ifeq ($(SYSCTL_M),1)
@@ -222,10 +224,14 @@ endif
ifndef WHISPER_NO_ACCELERATE
# Mac M1 - include Accelerate framework
ifeq ($(UNAME_S),Darwin)
CFLAGS += -DGGML_USE_ACCELERATE
CFLAGS += -DACCELERATE_NEW_LAPACK
CFLAGS += -DACCELERATE_LAPACK_ILP64
LDFLAGS += -framework Accelerate
CFLAGS += -DGGML_USE_ACCELERATE -DGGML_USE_BLAS
CFLAGS += -DACCELERATE_NEW_LAPACK
CFLAGS += -DACCELERATE_LAPACK_ILP64
CXXFLAGS += -DGGML_USE_ACCELERATE -DGGML_USE_BLAS
CXXFLAGS += -DACCELERATE_NEW_LAPACK
CXXFLAGS += -DACCELERATE_LAPACK_ILP64
LDFLAGS += -framework Accelerate
WHISPER_OBJ += ggml-blas.o
endif
endif
@@ -248,29 +254,31 @@ ifndef WHISPER_NO_METAL
endif
endif
ifneq ($(filter-out 0,$(WHISPER_OPENBLAS)),) # OpenBLAS
WHISPER_OPENBLAS_INTERFACE64 ?= 0 # use 32-bit interface by default
ifneq ($(filter-out 0,$(WHISPER_OPENBLAS_INTERFACE64)),)
WHISPER_BLAS_LIB := openblas64
else
WHISPER_BLAS_LIB := openblas
endif
ifneq ($(OPENBLAS_PATH),)
WHISPER_BLAS_CFLAGS := -I$(OPENBLAS_PATH)/include
WHISPER_BLAS_LDFLAGS := -L$(OPENBLAS_PATH)/lib -l$(WHISPER_BLAS_LIB)
else
WHISPER_BLAS_LIB_PC_EXISTS := $(shell pkg-config --exists $(WHISPER_BLAS_LIB) && echo 1)
ifneq ($(filter-out 0,$(WHISPER_BLAS_LIB_PC_EXISTS)),)
WHISPER_BLAS_CFLAGS := $(shell pkg-config --cflags $(WHISPER_BLAS_LIB))
WHISPER_BLAS_LDFLAGS := $(shell pkg-config --libs $(WHISPER_BLAS_LIB))
else
WHISPER_BLAS_CFLAGS := -I/usr/include/openblas
WHISPER_BLAS_LDFLAGS := -l$(WHISPER_BLAS_LIB)
endif
endif
CFLAGS += $(WHISPER_BLAS_CFLAGS) -DGGML_USE_OPENBLAS
LDFLAGS += $(WHISPER_BLAS_LDFLAGS)
endif
ifndef WHISPER_NO_OPENMP
CXXFLAGS += -DGGML_USE_OPENMP
CFLAGS += -fopenmp
CXXFLAGS += -fopenmp
endif # WHISPER_NO_OPENMP
ifdef WHISPER_OPENBLAS
CXXFLAGS += -DGGML_USE_BLAS $(shell pkg-config --cflags-only-I openblas)
CFLAGS += $(shell pkg-config --cflags-only-other openblas)
LDFLAGS += $(shell pkg-config --libs openblas)
WHISPER_OBJ += ggml-blas.o
endif # WHISPER_OPENBLAS
ifdef WHISPER_OPENBLAS64
CXXFLAGS += -DGGML_USE_BLAS $(shell pkg-config --cflags-only-I openblas64)
CFLAGS += $(shell pkg-config --cflags-only-other openblas64)
LDFLAGS += $(shell pkg-config --libs openblas64)
WHISPER_OBJ += ggml-blas.o
endif # WHISPER_OPENBLAS64
ifdef WHISPER_BLIS
CXXFLAGS += -DGGML_USE_BLAS -I/usr/local/include/blis -I/usr/include/blis
LDFLAGS += -lblis -L/usr/local/lib
WHISPER_OBJ += ggml-blas.o
endif # WHISPER_BLIS
ifdef WHISPER_CUBLAS
# WHISPER_CUBLAS is deprecated and will be removed in the future
@@ -402,6 +410,9 @@ ggml-backend.o: ggml-backend.c ggml.h ggml-backend.h
ggml-quants.o: ggml-quants.c ggml.h ggml-quants.h
$(CC) $(CFLAGS) -c $< -o $@
ggml-blas.o: ggml-blas.cpp ggml-blas.h
$(CXX) $(CXXFLAGS) -c $< -o $@
WHISPER_OBJ += ggml.o ggml-alloc.o ggml-backend.o ggml-quants.o
whisper.o: whisper.cpp whisper.h whisper-mel.hpp ggml.h ggml-cuda.h