From 8d7278b8ac3361716f8472c901a25776436d8bf8 Mon Sep 17 00:00:00 2001 From: David Thorpe Date: Fri, 6 Jan 2023 17:02:37 +0100 Subject: [PATCH] Updated makefiles to set FMA flag on optionally, for xeon E5 on Darwin --- CMakeLists.txt | 8 ++++++-- Makefile | 5 ++++- bindings/go/Makefile | 6 ++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50de993..5233459 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.19) +cmake_minimum_required (VERSION 3.18) project(whisper.cpp VERSION 1.0.4) @@ -53,6 +53,7 @@ if (APPLE) option(WHISPER_NO_ACCELERATE "whisper: disable Accelerate framework" OFF) option(WHISPER_NO_AVX "whisper: disable AVX" OFF) option(WHISPER_NO_AVX2 "whisper: disable AVX2" OFF) + option(WHISPER_NO_FMA "whisper: disable FMA" OFF) else() option(WHISPER_SUPPORT_OPENBLAS "whisper: support for OpenBLAS" OFF) endif() @@ -166,7 +167,10 @@ else() if(NOT WHISPER_NO_AVX2) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2") endif() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma -mf16c") + if(NOT WHISPER_NO_FMA) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma") + endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mf16c") endif() endif() endif() diff --git a/Makefile b/Makefile index 0fc1768..a46b7ab 100644 --- a/Makefile +++ b/Makefile @@ -58,8 +58,11 @@ endif # feel free to update the Makefile for your architecture and send a pull request or issue ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686)) ifeq ($(UNAME_S),Darwin) - CFLAGS += -mfma -mf16c + CFLAGS += -mf16c AVX1_M := $(shell sysctl machdep.cpu.features) + ifneq (,$(findstring FMA,$(AVX1_M))) + CFLAGS += -mfma + endif ifneq (,$(findstring AVX1.0,$(AVX1_M))) CFLAGS += -mavx endif diff --git a/bindings/go/Makefile b/bindings/go/Makefile index 567713c..6be2979 100644 --- a/bindings/go/Makefile +++ b/bindings/go/Makefile @@ -1,16 +1,14 @@ -CMAKE := $(shell which cmake) BUILD_DIR := build MODELS_DIR := models EXAMPLES_DIR := $(wildcard examples/*) INCLUDE_PATH := $(abspath ../..) -LIBRARY_PATH := $(abspath ${BUILD_DIR}) +LIBRARY_PATH := $(abspath ../..) all: clean whisper examples whisper: mkdir @echo Build whisper - @${CMAKE} -S ../.. -B ${BUILD_DIR} -D BUILD_SHARED_LIBS=off -D WHISPER_NO_AVX2=on - @${CMAKE} --build ${BUILD_DIR} --target whisper + @${MAKE} -C ../.. libwhisper.a test: model-small whisper modtidy @C_INCLUDE_PATH=${INCLUDE_PATH} LIBRARY_PATH=${LIBRARY_PATH} go test -v .