Spaces:
Running
Running
build : update make / cmake
Browse files- .gitignore +1 -0
- CMakeLists.txt +87 -87
- Makefile +38 -27
.gitignore
CHANGED
|
@@ -10,6 +10,7 @@
|
|
| 10 |
/CMakeSettings.json
|
| 11 |
|
| 12 |
build/
|
|
|
|
| 13 |
build-coreml/
|
| 14 |
build-em/
|
| 15 |
build-debug/
|
|
|
|
| 10 |
/CMakeSettings.json
|
| 11 |
|
| 12 |
build/
|
| 13 |
+
build-blas/
|
| 14 |
build-coreml/
|
| 15 |
build-em/
|
| 16 |
build-debug/
|
CMakeLists.txt
CHANGED
|
@@ -80,11 +80,10 @@ if (APPLE)
|
|
| 80 |
option(WHISPER_COREML "whisper: enable Core ML framework" OFF)
|
| 81 |
option(WHISPER_COREML_ALLOW_FALLBACK "whisper: allow non-CoreML fallback" OFF)
|
| 82 |
option(WHISPER_METAL_EMBED_LIBRARY "whisper: embed Metal library" OFF)
|
|
|
|
|
|
|
|
|
|
| 83 |
else()
|
| 84 |
-
option(WHISPER_BLAS "whisper: use BLAS libraries" OFF)
|
| 85 |
-
option(WHISPER_BLAS_VENDOR "whisper: BLAS library vendor" Generic)
|
| 86 |
-
option(WHISPER_OPENBLAS "whisper: prefer OpenBLAS" OFF)
|
| 87 |
-
option(WHISPER_OPENBLAS_INTERFACE64 "whisper: use OpenBLAS w/ 64-bit interface" OFF)
|
| 88 |
option(WHISPER_CUDA "whisper: support for CUDA" OFF)
|
| 89 |
option(WHISPER_CUDA_FA_ALL_QUANTS "whisper: compile all quants for FlashAttention" OFF)
|
| 90 |
option(WHISPER_CUBLAS "whisper: support for CUDA (deprecated)" OFF)
|
|
@@ -93,6 +92,9 @@ else()
|
|
| 93 |
option(WHISPER_MKL "whisper: use Intel Math Kernel Library (MKL)" OFF)
|
| 94 |
option(WHISPER_SYCL "whisper: use SYCL" OFF)
|
| 95 |
option(WHISPER_SYCL_F16 "whisper: use 16 bit floats for sycl calculations" OFF)
|
|
|
|
|
|
|
|
|
|
| 96 |
endif()
|
| 97 |
|
| 98 |
option(WHISPER_PERF "whisper: enable perf timings" OFF)
|
|
@@ -246,93 +248,90 @@ if (APPLE)
|
|
| 246 |
endif()
|
| 247 |
endif()
|
| 248 |
|
| 249 |
-
if (WHISPER_OPENBLAS)
|
| 250 |
-
set(WHISPER_BLAS_VENDOR "OpenBLAS")
|
| 251 |
-
set(WHISPER_BLAS ON)
|
| 252 |
-
# BLA_PKGCONFIG_BLAS is supported since CMake 3.25.
|
| 253 |
-
# FindBLAS.cmake pkg-config logic seems incomplete, because when
|
| 254 |
-
# BLA_SIZEOF_INTEGER is 8, then it should search for blas64 instead of blas.
|
| 255 |
-
# blas.pc/blas64.pc are not always provided, so let's be more specific
|
| 256 |
-
# and go with openblas.pc/openblas64.pc if WHISPER_OPENBLAS is on.
|
| 257 |
-
if (WHISPER_OPENBLAS_INTERFACE64)
|
| 258 |
-
set(WHISPER_BLAS_LIB "openblas64")
|
| 259 |
-
else ()
|
| 260 |
-
set(WHISPER_BLAS_LIB "openblas")
|
| 261 |
-
endif ()
|
| 262 |
-
set(BLA_PKGCONFIG_BLAS ${WHISPER_BLAS_LIB})
|
| 263 |
-
# OpenBLAS prebuilt libraries for Windows do not have "64" suffix in filename.
|
| 264 |
-
# (But .pc file has "64" suffix in filename for USE_64BITINT=1 Windows build.)
|
| 265 |
-
if (MSVC)
|
| 266 |
-
set(WHISPER_BLAS_LIB "openblas")
|
| 267 |
-
endif ()
|
| 268 |
-
endif()
|
| 269 |
-
|
| 270 |
if (WHISPER_BLAS)
|
| 271 |
-
if (
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
endif()
|
| 314 |
-
set(BLA_PREFER_PKGCONFIG 1)
|
| 315 |
-
find_package(BLAS)
|
| 316 |
-
|
| 317 |
-
if(BLAS_FOUND)
|
| 318 |
-
message(STATUS "BLAS compatible library found")
|
| 319 |
-
message(STATUS "Libraries ${BLAS_LIBRARIES}")
|
| 320 |
-
if (NOT DEFINED BLAS_INCLUDE_DIRS)
|
| 321 |
-
if (PKGC_BLAS_FOUND)
|
| 322 |
-
set(BLAS_INCLUDE_DIRS "${PKGC_BLAS_INCLUDE_DIRS}")
|
| 323 |
-
else ()
|
| 324 |
-
find_path(BLAS_INCLUDE_DIRS cblas.h /usr/include/openblas)
|
| 325 |
endif()
|
| 326 |
endif()
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
endif()
|
| 334 |
-
|
| 335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
if (WHISPER_MKL)
|
| 338 |
find_package(MKL CONFIG REQUIRED PATHS $ENV{MKLROOT})
|
|
@@ -712,6 +711,7 @@ add_library(${TARGET}
|
|
| 712 |
${GGML_SOURCES_CUDA}
|
| 713 |
${GGML_SOURCES_SYCL} ${GGML_HEADERS_SYCL}
|
| 714 |
${GGML_SOURCES_ROCM} ${GGML_HEADERS_ROCM}
|
|
|
|
| 715 |
whisper.h
|
| 716 |
whisper.cpp
|
| 717 |
)
|
|
|
|
| 80 |
option(WHISPER_COREML "whisper: enable Core ML framework" OFF)
|
| 81 |
option(WHISPER_COREML_ALLOW_FALLBACK "whisper: allow non-CoreML fallback" OFF)
|
| 82 |
option(WHISPER_METAL_EMBED_LIBRARY "whisper: embed Metal library" OFF)
|
| 83 |
+
option(WHISPER_BLAS "whisper: use BLAS" ON)
|
| 84 |
+
set (WHISPER_BLAS_VENDOR "Apple" CACHE STRING
|
| 85 |
+
"whisper: BLAS library vendor")
|
| 86 |
else()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
option(WHISPER_CUDA "whisper: support for CUDA" OFF)
|
| 88 |
option(WHISPER_CUDA_FA_ALL_QUANTS "whisper: compile all quants for FlashAttention" OFF)
|
| 89 |
option(WHISPER_CUBLAS "whisper: support for CUDA (deprecated)" OFF)
|
|
|
|
| 92 |
option(WHISPER_MKL "whisper: use Intel Math Kernel Library (MKL)" OFF)
|
| 93 |
option(WHISPER_SYCL "whisper: use SYCL" OFF)
|
| 94 |
option(WHISPER_SYCL_F16 "whisper: use 16 bit floats for sycl calculations" OFF)
|
| 95 |
+
option(WHISPER_BLAS "whisper: use BLAS" OFF)
|
| 96 |
+
set (WHISPER_BLAS_VENDOR "Generic" CACHE STRING
|
| 97 |
+
"whisper: BLAS library vendor")
|
| 98 |
endif()
|
| 99 |
|
| 100 |
option(WHISPER_PERF "whisper: enable perf timings" OFF)
|
|
|
|
| 248 |
endif()
|
| 249 |
endif()
|
| 250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
if (WHISPER_BLAS)
|
| 252 |
+
if (WHISPER_STATIC)
|
| 253 |
+
set(BLA_STATIC ON)
|
| 254 |
+
endif()
|
| 255 |
+
#if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
|
| 256 |
+
# set(BLA_SIZEOF_INTEGER 8)
|
| 257 |
+
#endif()
|
| 258 |
+
|
| 259 |
+
set(BLA_VENDOR ${WHISPER_BLAS_VENDOR})
|
| 260 |
+
find_package(BLAS)
|
| 261 |
+
|
| 262 |
+
if (BLAS_FOUND)
|
| 263 |
+
message(STATUS "BLAS found, Libraries: ${BLAS_LIBRARIES}")
|
| 264 |
+
|
| 265 |
+
if (("${BLAS_INCLUDE_DIRS}" STREQUAL "") AND NOT (${WHISPER_BLAS_VENDOR} MATCHES "Apple"))
|
| 266 |
+
# BLAS_INCLUDE_DIRS is missing in FindBLAS.cmake.
|
| 267 |
+
# see https://gitlab.kitware.com/cmake/cmake/-/issues/20268
|
| 268 |
+
find_package(PkgConfig REQUIRED)
|
| 269 |
+
if (${WHISPER_BLAS_VENDOR} MATCHES "Generic")
|
| 270 |
+
pkg_check_modules(DepBLAS REQUIRED blas)
|
| 271 |
+
elseif (${WHISPER_BLAS_VENDOR} MATCHES "OpenBLAS")
|
| 272 |
+
# As of openblas v0.3.22, the 64-bit is named openblas64.pc
|
| 273 |
+
pkg_check_modules(DepBLAS openblas64)
|
| 274 |
+
if (NOT DepBLAS_FOUND)
|
| 275 |
+
pkg_check_modules(DepBLAS REQUIRED openblas)
|
| 276 |
+
endif()
|
| 277 |
+
elseif (${WHISPER_BLAS_VENDOR} MATCHES "FLAME")
|
| 278 |
+
pkg_check_modules(DepBLAS REQUIRED blis)
|
| 279 |
+
elseif (${WHISPER_BLAS_VENDOR} MATCHES "ATLAS")
|
| 280 |
+
pkg_check_modules(DepBLAS REQUIRED blas-atlas)
|
| 281 |
+
elseif (${WHISPER_BLAS_VENDOR} MATCHES "FlexiBLAS")
|
| 282 |
+
pkg_check_modules(DepBLAS REQUIRED flexiblas_api)
|
| 283 |
+
elseif (${WHISPER_BLAS_VENDOR} MATCHES "Intel")
|
| 284 |
+
# all Intel* libraries share the same include path
|
| 285 |
+
pkg_check_modules(DepBLAS REQUIRED mkl-sdl)
|
| 286 |
+
elseif (${WHISPER_BLAS_VENDOR} MATCHES "NVHPC")
|
| 287 |
+
# this doesn't provide pkg-config
|
| 288 |
+
# suggest to assign BLAS_INCLUDE_DIRS on your own
|
| 289 |
+
if ("${NVHPC_VERSION}" STREQUAL "")
|
| 290 |
+
message(WARNING "Better to set NVHPC_VERSION")
|
| 291 |
+
else()
|
| 292 |
+
set(DepBLAS_FOUND ON)
|
| 293 |
+
set(DepBLAS_INCLUDE_DIRS "/opt/nvidia/hpc_sdk/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR}/${NVHPC_VERSION}/math_libs/include")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
endif()
|
| 295 |
endif()
|
| 296 |
+
if (DepBLAS_FOUND)
|
| 297 |
+
set(BLAS_INCLUDE_DIRS ${DepBLAS_INCLUDE_DIRS})
|
| 298 |
+
else()
|
| 299 |
+
message(WARNING "BLAS_INCLUDE_DIRS neither been provided nor been automatically"
|
| 300 |
+
" detected by pkgconfig, trying to find cblas.h from possible paths...")
|
| 301 |
+
find_path(BLAS_INCLUDE_DIRS
|
| 302 |
+
NAMES cblas.h
|
| 303 |
+
HINTS
|
| 304 |
+
/usr/include
|
| 305 |
+
/usr/local/include
|
| 306 |
+
/usr/include/openblas
|
| 307 |
+
/opt/homebrew/opt/openblas/include
|
| 308 |
+
/usr/local/opt/openblas/include
|
| 309 |
+
/usr/include/x86_64-linux-gnu/openblas/include
|
| 310 |
+
)
|
| 311 |
+
endif()
|
| 312 |
endif()
|
| 313 |
+
|
| 314 |
+
message(STATUS "BLAS found, Includes: ${BLAS_INCLUDE_DIRS}")
|
| 315 |
+
|
| 316 |
+
add_compile_options(${BLAS_LINKER_FLAGS})
|
| 317 |
+
|
| 318 |
+
add_compile_definitions(GGML_USE_BLAS)
|
| 319 |
+
|
| 320 |
+
if (${BLAS_INCLUDE_DIRS} MATCHES "mkl" AND (${WHISPER_BLAS_VENDOR} MATCHES "Generic" OR ${WHISPER_BLAS_VENDOR} MATCHES "Intel"))
|
| 321 |
+
add_compile_definitions(GGML_BLAS_USE_MKL)
|
| 322 |
+
endif()
|
| 323 |
+
|
| 324 |
+
set(GGML_HEADERS_BLAS ggml-blas.h)
|
| 325 |
+
set(GGML_SOURCES_BLAS ggml-blas.cpp)
|
| 326 |
+
|
| 327 |
+
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} ${BLAS_LIBRARIES})
|
| 328 |
+
set(WHISPER_EXTRA_INCLUDES ${WHISPER_EXTRA_INCLUDES} ${BLAS_INCLUDE_DIRS})
|
| 329 |
+
else()
|
| 330 |
+
message(WARNING "BLAS not found, please refer to "
|
| 331 |
+
"https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors"
|
| 332 |
+
" to set correct WHISPER_BLAS_VENDOR")
|
| 333 |
+
endif()
|
| 334 |
+
endif()
|
| 335 |
|
| 336 |
if (WHISPER_MKL)
|
| 337 |
find_package(MKL CONFIG REQUIRED PATHS $ENV{MKLROOT})
|
|
|
|
| 711 |
${GGML_SOURCES_CUDA}
|
| 712 |
${GGML_SOURCES_SYCL} ${GGML_HEADERS_SYCL}
|
| 713 |
${GGML_SOURCES_ROCM} ${GGML_HEADERS_ROCM}
|
| 714 |
+
${GGML_SOURCES_BLAS} ${GGML_HEADERS_BLAS}
|
| 715 |
whisper.h
|
| 716 |
whisper.cpp
|
| 717 |
)
|
Makefile
CHANGED
|
@@ -35,6 +35,8 @@ CXXV := $(shell $(CXX) --version | head -n 1)
|
|
| 35 |
# Mac OS + Arm can report x86_64
|
| 36 |
# ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789
|
| 37 |
ifeq ($(UNAME_S),Darwin)
|
|
|
|
|
|
|
| 38 |
ifneq ($(UNAME_P),arm)
|
| 39 |
SYSCTL_M := $(shell sysctl -n hw.optional.arm64)
|
| 40 |
ifeq ($(SYSCTL_M),1)
|
|
@@ -222,10 +224,14 @@ endif
|
|
| 222 |
ifndef WHISPER_NO_ACCELERATE
|
| 223 |
# Mac M1 - include Accelerate framework
|
| 224 |
ifeq ($(UNAME_S),Darwin)
|
| 225 |
-
CFLAGS
|
| 226 |
-
CFLAGS
|
| 227 |
-
CFLAGS
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
endif
|
| 230 |
endif
|
| 231 |
|
|
@@ -248,29 +254,31 @@ ifndef WHISPER_NO_METAL
|
|
| 248 |
endif
|
| 249 |
endif
|
| 250 |
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
|
|
|
|
|
|
| 274 |
|
| 275 |
ifdef WHISPER_CUBLAS
|
| 276 |
# 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
|
|
| 402 |
ggml-quants.o: ggml-quants.c ggml.h ggml-quants.h
|
| 403 |
$(CC) $(CFLAGS) -c $< -o $@
|
| 404 |
|
|
|
|
|
|
|
|
|
|
| 405 |
WHISPER_OBJ += ggml.o ggml-alloc.o ggml-backend.o ggml-quants.o
|
| 406 |
|
| 407 |
whisper.o: whisper.cpp whisper.h whisper-mel.hpp ggml.h ggml-cuda.h
|
|
|
|
| 35 |
# Mac OS + Arm can report x86_64
|
| 36 |
# ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789
|
| 37 |
ifeq ($(UNAME_S),Darwin)
|
| 38 |
+
WHISPER_NO_OPENMP := 1
|
| 39 |
+
|
| 40 |
ifneq ($(UNAME_P),arm)
|
| 41 |
SYSCTL_M := $(shell sysctl -n hw.optional.arm64)
|
| 42 |
ifeq ($(SYSCTL_M),1)
|
|
|
|
| 224 |
ifndef WHISPER_NO_ACCELERATE
|
| 225 |
# Mac M1 - include Accelerate framework
|
| 226 |
ifeq ($(UNAME_S),Darwin)
|
| 227 |
+
CFLAGS += -DGGML_USE_ACCELERATE -DGGML_USE_BLAS
|
| 228 |
+
CFLAGS += -DACCELERATE_NEW_LAPACK
|
| 229 |
+
CFLAGS += -DACCELERATE_LAPACK_ILP64
|
| 230 |
+
CXXFLAGS += -DGGML_USE_ACCELERATE -DGGML_USE_BLAS
|
| 231 |
+
CXXFLAGS += -DACCELERATE_NEW_LAPACK
|
| 232 |
+
CXXFLAGS += -DACCELERATE_LAPACK_ILP64
|
| 233 |
+
LDFLAGS += -framework Accelerate
|
| 234 |
+
WHISPER_OBJ += ggml-blas.o
|
| 235 |
endif
|
| 236 |
endif
|
| 237 |
|
|
|
|
| 254 |
endif
|
| 255 |
endif
|
| 256 |
|
| 257 |
+
ifndef WHISPER_NO_OPENMP
|
| 258 |
+
CXXFLAGS += -DGGML_USE_OPENMP
|
| 259 |
+
CFLAGS += -fopenmp
|
| 260 |
+
CXXFLAGS += -fopenmp
|
| 261 |
+
endif # WHISPER_NO_OPENMP
|
| 262 |
+
|
| 263 |
+
ifdef WHISPER_OPENBLAS
|
| 264 |
+
CXXFLAGS += -DGGML_USE_BLAS $(shell pkg-config --cflags-only-I openblas)
|
| 265 |
+
CFLAGS += $(shell pkg-config --cflags-only-other openblas)
|
| 266 |
+
LDFLAGS += $(shell pkg-config --libs openblas)
|
| 267 |
+
WHISPER_OBJ += ggml-blas.o
|
| 268 |
+
endif # WHISPER_OPENBLAS
|
| 269 |
+
|
| 270 |
+
ifdef WHISPER_OPENBLAS64
|
| 271 |
+
CXXFLAGS += -DGGML_USE_BLAS $(shell pkg-config --cflags-only-I openblas64)
|
| 272 |
+
CFLAGS += $(shell pkg-config --cflags-only-other openblas64)
|
| 273 |
+
LDFLAGS += $(shell pkg-config --libs openblas64)
|
| 274 |
+
WHISPER_OBJ += ggml-blas.o
|
| 275 |
+
endif # WHISPER_OPENBLAS64
|
| 276 |
+
|
| 277 |
+
ifdef WHISPER_BLIS
|
| 278 |
+
CXXFLAGS += -DGGML_USE_BLAS -I/usr/local/include/blis -I/usr/include/blis
|
| 279 |
+
LDFLAGS += -lblis -L/usr/local/lib
|
| 280 |
+
WHISPER_OBJ += ggml-blas.o
|
| 281 |
+
endif # WHISPER_BLIS
|
| 282 |
|
| 283 |
ifdef WHISPER_CUBLAS
|
| 284 |
# WHISPER_CUBLAS is deprecated and will be removed in the future
|
|
|
|
| 410 |
ggml-quants.o: ggml-quants.c ggml.h ggml-quants.h
|
| 411 |
$(CC) $(CFLAGS) -c $< -o $@
|
| 412 |
|
| 413 |
+
ggml-blas.o: ggml-blas.cpp ggml-blas.h
|
| 414 |
+
$(CXX) $(CXXFLAGS) -c $< -o $@
|
| 415 |
+
|
| 416 |
WHISPER_OBJ += ggml.o ggml-alloc.o ggml-backend.o ggml-quants.o
|
| 417 |
|
| 418 |
whisper.o: whisper.cpp whisper.h whisper-mel.hpp ggml.h ggml-cuda.h
|