2023-09-15 09:18:18 +00:00
cmake_minimum_required ( VERSION 3.5 )
2022-12-17 17:52:42 +00:00
2024-04-09 15:23:33 +00:00
# Allow for the creation of solution folders.
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
2024-05-27 07:35:09 +00:00
project ( whisper.cpp VERSION 1.6.2 )
2024-03-04 19:17:48 +00:00
set ( SOVERSION 1 )
2022-10-07 20:53:12 +00:00
2023-01-05 19:22:48 +00:00
# Add path to modules
2023-01-05 19:40:59 +00:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" )
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } /bin )
2022-10-07 20:53:12 +00:00
if ( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
set ( WHISPER_STANDALONE ON )
2023-01-05 19:22:48 +00:00
include ( GitVars )
include ( BuildTypes )
2022-11-07 18:50:24 +00:00
# configure project version
if ( EXISTS "${CMAKE_SOURCE_DIR}/bindings/ios/Makefile-tmpl" )
configure_file ( ${ CMAKE_SOURCE_DIR } /bindings/ios/Makefile-tmpl ${ CMAKE_SOURCE_DIR } /bindings/ios/Makefile @ONLY )
endif ( )
2022-12-12 18:17:27 +00:00
configure_file ( ${ CMAKE_SOURCE_DIR } /bindings/javascript/package-tmpl.json ${ CMAKE_SOURCE_DIR } /bindings/javascript/package.json @ONLY )
2022-10-07 20:53:12 +00:00
else ( )
set ( WHISPER_STANDALONE OFF )
endif ( )
2022-10-22 10:07:59 +00:00
if ( EMSCRIPTEN )
set ( BUILD_SHARED_LIBS_DEFAULT OFF )
option ( WHISPER_WASM_SINGLE_FILE "whisper: embed WASM inside the generated whisper.js" ON )
else ( )
if ( MINGW )
set ( BUILD_SHARED_LIBS_DEFAULT OFF )
else ( )
set ( BUILD_SHARED_LIBS_DEFAULT ON )
endif ( )
endif ( )
2022-10-07 20:53:12 +00:00
# options
2023-09-15 09:18:18 +00:00
if ( APPLE )
set ( WHISPER_METAL_DEFAULT ON )
else ( )
set ( WHISPER_METAL_DEFAULT OFF )
endif ( )
2023-04-29 07:55:24 +00:00
option ( BUILD_SHARED_LIBS "whisper: build shared libs" ${ BUILD_SHARED_LIBS_DEFAULT } )
2022-10-22 10:07:59 +00:00
2023-04-29 07:55:24 +00:00
option ( WHISPER_ALL_WARNINGS "whisper: enable all compiler warnings" ON )
option ( WHISPER_ALL_WARNINGS_3RD_PARTY "whisper: enable all compiler warnings in 3rd party libs" OFF )
2022-10-07 20:53:12 +00:00
2023-04-29 07:55:24 +00:00
option ( WHISPER_SANITIZE_THREAD "whisper: enable thread sanitizer" OFF )
option ( WHISPER_SANITIZE_ADDRESS "whisper: enable address sanitizer" OFF )
option ( WHISPER_SANITIZE_UNDEFINED "whisper: enable undefined sanitizer" OFF )
2022-10-07 20:53:12 +00:00
2023-04-29 07:55:24 +00:00
option ( WHISPER_BUILD_TESTS "whisper: build tests" ${ WHISPER_STANDALONE } )
option ( WHISPER_BUILD_EXAMPLES "whisper: build examples" ${ WHISPER_STANDALONE } )
2022-10-07 20:53:12 +00:00
2023-04-30 09:14:33 +00:00
option ( WHISPER_SDL2 "whisper: support for libSDL2" OFF )
2022-10-07 20:53:12 +00:00
2024-05-21 15:31:41 +00:00
if ( CMAKE_SYSTEM_NAME MATCHES "Linux" )
option ( WHISPER_FFMPEG "whisper: support building and linking with ffmpeg libs (avcodec, swresample, ...)" OFF )
endif ( )
2024-04-15 17:02:09 +00:00
option ( WHISPER_NO_AVX "whisper: disable AVX" OFF )
option ( WHISPER_NO_AVX2 "whisper: disable AVX2" OFF )
option ( WHISPER_NO_AVX512 "whisper: disable AVX512" ON )
option ( WHISPER_NO_AVX512_VBMI "whisper: disable AVX512-VBMI" ON )
option ( WHISPER_NO_AVX512_VNNI "whisper: disable AVX512-VNNI" ON )
option ( WHISPER_NO_FMA "whisper: disable FMA" OFF )
option ( WHISPER_NO_F16C "whisper: disable F16c" OFF )
2023-05-04 16:31:04 +00:00
2023-07-04 12:56:11 +00:00
option ( WHISPER_OPENVINO "whisper: support for OpenVINO" OFF )
2022-10-27 15:31:49 +00:00
if ( APPLE )
2023-04-29 07:55:24 +00:00
option ( WHISPER_NO_ACCELERATE "whisper: disable Accelerate framework" OFF )
2023-09-15 09:18:18 +00:00
option ( WHISPER_METAL "whisper: use Metal" ${ WHISPER_METAL_DEFAULT } )
option ( WHISPER_METAL_NDEBUG "whisper: disable Metal debugging" OFF )
2023-05-04 16:31:04 +00:00
option ( WHISPER_COREML "whisper: enable Core ML framework" OFF )
option ( WHISPER_COREML_ALLOW_FALLBACK "whisper: allow non-CoreML fallback" OFF )
2024-02-11 14:41:41 +00:00
option ( WHISPER_METAL_EMBED_LIBRARY "whisper: embed Metal library" OFF )
2022-10-27 15:31:49 +00:00
else ( )
2024-02-23 07:22:24 +00:00
option ( WHISPER_BLAS "whisper: use BLAS libraries" OFF )
option ( WHISPER_BLAS_VENDOR "whisper: BLAS library vendor" Generic )
option ( WHISPER_OPENBLAS "whisper: prefer OpenBLAS" OFF )
build : use pkg-config for OpenBLAS (#1778)
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.
Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled. Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N). make is not CMake.
By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.
If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.
If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`). If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.
Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.
* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.
Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.
By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.
Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.
Get rid of supporting BLAS_HOME environment variable. If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.
* make / cmake : use OpenBLAS with 32-bit interface by default.
OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.
* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)
* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)
Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
2024-03-29 13:53:26 +00:00
option ( WHISPER_OPENBLAS_INTERFACE64 "whisper: use OpenBLAS w/ 64-bit interface" OFF )
2024-03-27 16:55:10 +00:00
option ( WHISPER_CUDA "whisper: support for CUDA" OFF )
2024-06-16 10:07:43 +00:00
option ( WHISPER_CUDA_FA_ALL_QUANTS "whisper: compile all quants for FlashAttention" OFF )
2024-03-27 16:55:10 +00:00
option ( WHISPER_CUBLAS "whisper: support for CUDA (deprecated)" OFF )
2024-02-23 07:22:24 +00:00
option ( WHISPER_HIPBLAS "whisper: support for hipBLAS" OFF )
option ( WHISPER_CLBLAST "whisper: use CLBlast" OFF )
2024-04-09 15:32:46 +00:00
option ( WHISPER_MKL "whisper: use Intel Math Kernel Library (MKL)" OFF )
2024-02-23 07:22:24 +00:00
option ( WHISPER_SYCL "whisper: use SYCL" OFF )
option ( WHISPER_SYCL_F16 "whisper: use 16 bit floats for sycl calculations" OFF )
2022-10-27 15:31:49 +00:00
endif ( )
2023-04-29 07:55:24 +00:00
option ( WHISPER_PERF "whisper: enable perf timings" OFF )
2022-10-18 15:51:59 +00:00
2022-10-07 20:53:12 +00:00
# sanitizers
2022-10-11 17:57:52 +00:00
if ( NOT MSVC )
if ( WHISPER_SANITIZE_THREAD )
2022-10-25 16:13:08 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread" )
2022-10-11 17:57:52 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread" )
endif ( )
2022-10-07 20:53:12 +00:00
2022-10-11 17:57:52 +00:00
if ( WHISPER_SANITIZE_ADDRESS )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer" )
endif ( )
2022-10-07 20:53:12 +00:00
2022-10-11 17:57:52 +00:00
if ( WHISPER_SANITIZE_UNDEFINED )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined" )
endif ( )
2022-10-07 20:53:12 +00:00
endif ( )
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
# dependencies
find_package ( Threads REQUIRED )
2024-02-23 07:22:24 +00:00
#compile flag sycl
if ( WHISPER_SYCL )
set ( CMAKE_CXX_STANDARD 17 )
else ( )
set ( CMAKE_CXX_STANDARD 11 )
endif ( )
2024-05-21 15:31:41 +00:00
if ( WHISPER_FFMPEG )
# As of cmake 3.27, there is no official cmake support for FindFFmpeg.
# Consequnelty we added a FindFFmpeg.cmake script the cmake subfolder:
# whisper.cpp does not need the full ffmpeg libs, just AVFORMAT AVCODEC AVUTIL SWRESAMPLE
# libswresample performs highly optimized audio resampling, rematrixing and sample format conversion operations
# libavcodec provides a generic encoding/decoding framework and contains multiple decoders and encoders for audio, video and subtitle streams, and several bitstream filters.
# libavformat provides a generic framework for multiplexing and demultiplexing (muxing and demuxing) audio, video and subtitle streams.
find_package ( FFmpeg REQUIRED )
if ( NOT ${ FFMPEG_FOUND } )
message ( FATAL_ERROR "Cannot find ffmpeg libs/headers" )
endif ( )
message ( STATUS "Found ffmpeg libs: ${FFMPEG_LIBRARIES}" )
message ( STATUS "Found ffmpeg headers in: ${FFMPEG_INCLUDE_DIRS}" )
message ( STATUS "ffmpeg definitions: ${FFMPEG_DEFINITIONS}" )
message ( STATUS "Found avformat ${AVFORMAT_VERSION}" )
include_directories ( ${ FFMPEG_INCLUDE_DIRS } )
add_compile_definitions ( WHISPER_FFMPEG )
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } ${ FFMPEG_LIBRARIES } )
endif ( )
2023-04-15 10:21:27 +00:00
# on APPLE
if ( APPLE )
# include Accelerate framework
if ( NOT WHISPER_NO_ACCELERATE )
find_library ( ACCELERATE_FRAMEWORK Accelerate )
if ( ACCELERATE_FRAMEWORK )
message ( STATUS "Accelerate framework found" )
2022-10-18 15:51:59 +00:00
2023-04-15 10:21:27 +00:00
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } ${ ACCELERATE_FRAMEWORK } )
2024-02-19 12:44:46 +00:00
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DGGML_USE_ACCELERATE -DACCELERATE_NEW_LAPACK -DACCELERATE_LAPACK_ILP64 )
2023-04-15 10:21:27 +00:00
else ( )
2023-10-07 19:01:18 +00:00
message ( FATAL_ERROR "Accelerate framework not found" )
2023-04-15 10:21:27 +00:00
endif ( )
endif ( )
2023-09-15 09:18:18 +00:00
if ( WHISPER_METAL )
find_library ( FOUNDATION_LIBRARY Foundation REQUIRED )
find_library ( METAL_FRAMEWORK Metal REQUIRED )
find_library ( METALKIT_FRAMEWORK MetalKit REQUIRED )
if ( METAL_FRAMEWORK )
message ( STATUS "Metal framework found" )
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS }
$ { F O U N D A T I O N _ L I B R A R Y }
$ { M E T A L _ F R A M E W O R K }
$ { M E T A L K I T _ F R A M E W O R K }
)
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DGGML_USE_METAL )
if ( WHISPER_METAL_NDEBUG )
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DGGML_METAL_NDEBUG )
endif ( )
else ( )
2023-10-07 19:01:18 +00:00
message ( FATAL_ERROR "Metal framework not found" )
2023-09-15 09:18:18 +00:00
endif ( )
set ( GGML_SOURCES_METAL ggml-metal.m ggml-metal.h )
2024-03-16 15:15:21 +00:00
# copy ggml-common.h and ggml-metal.metal to bin directory
configure_file ( ggml-common.h bin/ggml-common.h COPYONLY )
2023-09-15 09:18:18 +00:00
configure_file ( ggml-metal.metal bin/ggml-metal.metal COPYONLY )
2024-02-11 14:41:41 +00:00
if ( WHISPER_METAL_EMBED_LIBRARY )
enable_language ( ASM )
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DGGML_METAL_EMBED_LIBRARY )
2024-05-13 12:09:35 +00:00
set ( METALLIB_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal.metal" )
set ( COMMON_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/ggml-common.h" )
2024-02-11 14:41:41 +00:00
file ( MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/autogenerated" )
set ( EMBED_METALLIB_ASSEMBLY "${CMAKE_BINARY_DIR}/autogenerated/ggml-embed-metallib.s" )
2024-04-15 17:23:05 +00:00
set ( EMBED_METALLIB_SOURCE "${CMAKE_BINARY_DIR}/autogenerated/ggml-metal-combined.metal" )
add_custom_command (
O U T P U T $ { E M B E D _ M E T A L L I B _ S O U R C E }
C O M M A N D s e d - e " / ^ #include \\\"ggml-common.h\\\"/r ${COMMON_HEADER}" -e "/^#include \\\"ggml-common.h\\\"/d" ${METALLIB_SOURCE} > ${EMBED_METALLIB_SOURCE}
D E P E N D S $ { M E T A L L I B _ S O U R C E } $ { C O M M O N _ H E A D E R }
C O M M E N T " G e n e r a t i n g c o m b i n e d M e t a l l i b r a r y f o r e m b e d d i n g "
)
2024-02-11 14:41:41 +00:00
add_custom_command (
O U T P U T $ { E M B E D _ M E T A L L I B _ A S S E M B L Y }
C O M M A N D e c h o " . s e c t i o n _ _ D A T A , _ _ g g m l _ m e t a l l i b " > $ { E M B E D _ M E T A L L I B _ A S S E M B L Y }
C O M M A N D e c h o " . g l o b l _ g g m l _ m e t a l l i b _ s t a r t " > > $ { E M B E D _ M E T A L L I B _ A S S E M B L Y }
C O M M A N D e c h o " _ g g m l _ m e t a l l i b _ s t a r t : " > > $ { E M B E D _ M E T A L L I B _ A S S E M B L Y }
2024-04-15 17:23:05 +00:00
C O M M A N D e c h o " . i n c b i n \ \ \ " $ { E M B E D _ M E T A L L I B _ S O U R C E } \ \ \ " " > > $ { E M B E D _ M E T A L L I B _ A S S E M B L Y }
2024-02-11 14:41:41 +00:00
C O M M A N D e c h o " . g l o b l _ g g m l _ m e t a l l i b _ e n d " > > $ { E M B E D _ M E T A L L I B _ A S S E M B L Y }
C O M M A N D e c h o " _ g g m l _ m e t a l l i b _ e n d : " > > $ { E M B E D _ M E T A L L I B _ A S S E M B L Y }
2024-04-15 17:23:05 +00:00
D E P E N D S $ { E M B E D _ M E T A L L I B _ S O U R C E }
2024-02-11 14:41:41 +00:00
C O M M E N T " G e n e r a t e a s s e m b l y f o r e m b e d d e d M e t a l l i b r a r y "
)
set ( GGML_SOURCES_METAL ${ GGML_SOURCES_METAL } ${ EMBED_METALLIB_ASSEMBLY } )
endif ( )
2023-09-15 09:18:18 +00:00
endif ( )
2023-04-15 10:21:27 +00:00
if ( WHISPER_COREML )
find_library ( FOUNDATION_FRAMEWORK Foundation )
find_library ( COREML_FRAMEWORK CoreML )
if ( COREML_FRAMEWORK )
message ( STATUS "CoreML framework found" )
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DWHISPER_USE_COREML )
else ( )
2023-10-07 19:01:18 +00:00
message ( FATAL_ERROR "CoreML framework not found" )
2023-04-15 10:21:27 +00:00
endif ( )
2023-04-29 07:55:24 +00:00
if ( WHISPER_COREML_ALLOW_FALLBACK )
2023-05-08 18:08:09 +00:00
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DWHISPER_COREML_ALLOW_FALLBACK )
2023-04-29 07:55:24 +00:00
endif ( )
2022-10-18 15:51:59 +00:00
endif ( )
endif ( )
2023-04-30 09:14:33 +00:00
if ( WHISPER_OPENBLAS )
2023-05-20 18:23:45 +00:00
set ( WHISPER_BLAS_VENDOR "OpenBLAS" )
set ( WHISPER_BLAS ON )
build : use pkg-config for OpenBLAS (#1778)
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.
Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled. Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N). make is not CMake.
By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.
If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.
If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`). If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.
Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.
* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.
Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.
By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.
Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.
Get rid of supporting BLAS_HOME environment variable. If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.
* make / cmake : use OpenBLAS with 32-bit interface by default.
OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.
* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)
* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)
Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
2024-03-29 13:53:26 +00:00
# BLA_PKGCONFIG_BLAS is supported since CMake 3.25.
# FindBLAS.cmake pkg-config logic seems incomplete, because when
# BLA_SIZEOF_INTEGER is 8, then it should search for blas64 instead of blas.
# blas.pc/blas64.pc are not always provided, so let's be more specific
# and go with openblas.pc/openblas64.pc if WHISPER_OPENBLAS is on.
if ( WHISPER_OPENBLAS_INTERFACE64 )
set ( WHISPER_BLAS_LIB "openblas64" )
else ( )
set ( WHISPER_BLAS_LIB "openblas" )
endif ( )
set ( BLA_PKGCONFIG_BLAS ${ WHISPER_BLAS_LIB } )
# OpenBLAS prebuilt libraries for Windows do not have "64" suffix in filename.
# (But .pc file has "64" suffix in filename for USE_64BITINT=1 Windows build.)
if ( MSVC )
set ( WHISPER_BLAS_LIB "openblas" )
endif ( )
2023-05-20 18:23:45 +00:00
endif ( )
if ( WHISPER_BLAS )
build : use pkg-config for OpenBLAS (#1778)
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.
Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled. Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N). make is not CMake.
By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.
If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.
If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`). If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.
Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.
* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.
Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.
By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.
Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.
Get rid of supporting BLAS_HOME environment variable. If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.
* make / cmake : use OpenBLAS with 32-bit interface by default.
OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.
* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)
* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)
Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
2024-03-29 13:53:26 +00:00
if ( NOT "$ENV{OPENBLAS_PATH}" STREQUAL "" )
if ( WHISPER_STATIC )
set ( WHISPER_BLAS_LIB_PREFIX ${ CMAKE_STATIC_LIBRARY_PREFIX } )
set ( WHISPER_BLAS_LIB_SUFFIX ${ CMAKE_STATIC_LIBRARY_SUFFIX } )
2023-07-25 16:15:08 +00:00
else ( )
build : use pkg-config for OpenBLAS (#1778)
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.
Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled. Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N). make is not CMake.
By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.
If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.
If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`). If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.
Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.
* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.
Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.
By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.
Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.
Get rid of supporting BLAS_HOME environment variable. If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.
* make / cmake : use OpenBLAS with 32-bit interface by default.
OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.
* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)
* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)
Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
2024-03-29 13:53:26 +00:00
if ( CMAKE_IMPORT_LIBRARY_SUFFIX )
set ( WHISPER_BLAS_LIB_PREFIX ${ CMAKE_IMPORT_LIBRARY_PREFIX } )
set ( WHISPER_BLAS_LIB_SUFFIX ${ CMAKE_IMPORT_LIBRARY_SUFFIX } )
else ( )
set ( WHISPER_BLAS_LIB_PREFIX ${ CMAKE_SHARED_LIBRARY_PREFIX } )
set ( WHISPER_BLAS_LIB_SUFFIX ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
endif ( )
2023-07-25 16:15:08 +00:00
endif ( )
build : use pkg-config for OpenBLAS (#1778)
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.
Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled. Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N). make is not CMake.
By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.
If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.
If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`). If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.
Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.
* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.
Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.
By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.
Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.
Get rid of supporting BLAS_HOME environment variable. If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.
* make / cmake : use OpenBLAS with 32-bit interface by default.
OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.
* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)
* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)
Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
2024-03-29 13:53:26 +00:00
# OpenBLAS prebuilt libraries hardcode "lib" prefix in filename even on Windows
if ( WHISPER_OPENBLAS )
set ( WHISPER_BLAS_LIB_PREFIX "lib" )
endif ( )
message ( STATUS "BLAS compatible library path provided" )
set ( BLAS_LIBRARIES "$ENV{OPENBLAS_PATH}/lib/${WHISPER_BLAS_LIB_PREFIX}${WHISPER_BLAS_LIB}${WHISPER_BLAS_LIB_SUFFIX}" )
message ( STATUS "Libraries ${BLAS_LIBRARIES}" )
set ( BLAS_INCLUDE_DIRS "$ENV{OPENBLAS_PATH}/include" )
message ( STATUS "Include dirs ${BLAS_INCLUDE_DIRS}" )
if ( NOT EXISTS "${BLAS_LIBRARIES}" )
message ( FATAL_ERROR "BLAS library was not found. Environment variable OPENBLAS_PATH misdefined." )
endif ( )
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DGGML_USE_OPENBLAS )
include_directories ( ${ BLAS_INCLUDE_DIRS } )
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } ${ BLAS_LIBRARIES } )
2023-07-25 16:15:08 +00:00
else ( )
build : use pkg-config for OpenBLAS (#1778)
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.
Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled. Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N). make is not CMake.
By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.
If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.
If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`). If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.
Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.
* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.
Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.
By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.
Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.
Get rid of supporting BLAS_HOME environment variable. If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.
* make / cmake : use OpenBLAS with 32-bit interface by default.
OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.
* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)
* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)
Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
2024-03-29 13:53:26 +00:00
if ( WHISPER_STATIC )
# FindBLAS.cmake pkg-config logic seems incomplete, because when
# BLA_STATIC is on, then it should use pkg_check_modules_static
# instead of pkg_check_modules.
# Some manual variable overriding may be necessary if you don't
# achieve desired results.
set ( BLA_STATIC 1 )
endif ( )
2023-07-25 16:15:08 +00:00
set ( BLA_VENDOR ${ WHISPER_BLAS_VENDOR } )
build : use pkg-config for OpenBLAS (#1778)
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.
Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled. Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N). make is not CMake.
By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.
If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.
If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`). If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.
Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.
* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.
Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.
By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.
Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.
Get rid of supporting BLAS_HOME environment variable. If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.
* make / cmake : use OpenBLAS with 32-bit interface by default.
OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.
* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)
* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)
Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
2024-03-29 13:53:26 +00:00
if ( WHISPER_OPENBLAS_INTERFACE64 )
set ( BLA_SIZEOF_INTEGER 8 )
else ( )
set ( BLA_SIZEOF_INTEGER 4 )
endif ( )
2023-10-07 14:02:07 +00:00
set ( BLA_PREFER_PKGCONFIG 1 )
2023-07-25 16:15:08 +00:00
find_package ( BLAS )
if ( BLAS_FOUND )
message ( STATUS "BLAS compatible library found" )
message ( STATUS "Libraries ${BLAS_LIBRARIES}" )
build : use pkg-config for OpenBLAS (#1778)
* make : use pkg-config for finding CFLAGS & LDFLAGS needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with WHISPER_OPENBLAS=1 works out of the box.
Fix handling of WHISPER_OPENBLAS, so that empty value or 0 won't be
misinterpreted by make as enabled. Mind that it's not intended to
detect CMake false constants (OFF NO FALSE N). make is not CMake.
By default OpenBLAS with 64-bit interface is used, but that can be
changed with `WHISPER_OPENBLAS_INTERFACE64=0` if 32-bit one is desired.
If OpenBLAS headers and library are respectively in include/ and lib/
subdirectories of given path, then you can specify it, e.g.
`OPENBLAS_PATH=/usr/local/openblas`, and this will take precedence over
any pkg-config file.
If there is no pkg-config file (.pc) for OpenBLAS and OPENBLAS_PATH is
empty, then headers are assumed to be in /usr/include/openblas and
library as assumed to be called 'openblas64' (or 'openblas' if
`WHISPER_OPENBLAS_INTERFACE64=0`). If different headers location should
be used, then it can be done, e.g.
`WHISPER_BLAS_CFLAGS=-I/usr/local/include/openblas`.
If different library should be used, it can be specified, e.g.
`WHISPER_BLAS_LIB=openblasp64` (pthreads version as seen on Fedora), or
you can provide LDFLAGS needed to link with OpenBLAS directly:
`WHISPER_BLAS_LDFLAGS="-L/usr/local/lib/openblas -lopenblas64"`.
Current solution is flexible enough to handle most cases out there
without needlessly hardcoding possible OpenBLAS installation details.
* cmake : fix how pkg-config is used for finding include dirs and libraries needed by OpenBLAS
That way building on *nix like environments (including MSYS2 on Windows)
with -DWHISPER_OPENBLAS=ON should work out of the box as long as you
have CMake 3.25 or newer.
Make OPENBLAS_PATH environment variable supported not only on Windows.
It sets OpenBLAS include dir to ${OPENBLAS_PATH}/include and library to
${WHISPER_BLAS_LIB} (name without prefixes and suffixes) in
${OPENBLAS_PATH}/lib and avoids further package finding.
By default OpenBLAS with 64-bit interface is used (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas64`), but that can be changed with
`-DWHISPER_OPENBLAS_INTERFACE64=OFF` (equivalent to setting
`-DWHISPER_BLAS_LIB=openblas`) if 32-bit one is desired.
Turn on BLA_STATIC for FindBLAS only when WHISPER_STATIC is enabled.
BLA_STATIC may not work as expected for pkg-config based operation.
Get rid of supporting BLAS_HOME environment variable. If OPENBLAS_PATH
is insufficient in your case, there is no pkg-config file to rely on,
then you can manually specify include dir, e.g.
`-DBLAS_INCLUDE_DIRS=/usr/local/include/openblas`, and library, e.g.
`-DBLAS_LIBRARIES=/usr/local/lib/libopenblas.so`.
* make / cmake : use OpenBLAS with 32-bit interface by default.
OpenBLAS w/o INTERFACE64=1 vel USE_64BITINT=1 seems to be more common.
* cmake : hardcode "lib" prefix for OpenBLAS lib filename (even on Windows)
* cmake : hardcode OpenBLAS library name when building in MSVC (Windows)
Most *nix like environments (including MSYS2 on Windows) have OpenBLAS
packages that allow coexistence of OpenBLAS builds with 32-bit and
64-bit interface (w/o and w/ OPENBLAS_USE64BITINT defined) and they
differ by not having or having "64" suffix in their library filenames.
That's not the case for OpenBLAS prebuilt libraries for Windows.
2024-03-29 13:53:26 +00:00
if ( NOT DEFINED BLAS_INCLUDE_DIRS )
if ( PKGC_BLAS_FOUND )
set ( BLAS_INCLUDE_DIRS "${PKGC_BLAS_INCLUDE_DIRS}" )
else ( )
find_path ( BLAS_INCLUDE_DIRS cblas.h /usr/include/openblas )
endif ( )
endif ( )
message ( STATUS "Include dirs ${BLAS_INCLUDE_DIRS}" )
2023-07-25 16:15:08 +00:00
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DGGML_USE_OPENBLAS )
include_directories ( ${ BLAS_INCLUDE_DIRS } )
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } ${ BLAS_LIBRARIES } )
else ( )
2023-10-07 19:01:18 +00:00
message ( FATAL_ERROR "BLAS library was not found" )
2023-07-25 16:15:08 +00:00
endif ( )
endif ( )
2023-05-20 18:23:45 +00:00
endif ( )
2022-10-27 15:31:49 +00:00
2024-04-09 15:32:46 +00:00
if ( WHISPER_MKL )
find_package ( MKL CONFIG REQUIRED PATHS $ENV{ MKLROOT } )
message ( STATUS "Imported oneMKL targets: ${MKL_IMPORTED_TARGETS}" )
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DGGML_USE_OPENBLAS )
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DGGML_BLAS_USE_MKL )
endif ( )
2023-04-30 09:14:33 +00:00
if ( WHISPER_CUBLAS )
2024-03-27 16:55:10 +00:00
message ( WARNING "WHISPER_CUBLAS is deprecated and will be removed in the future.\nUse WHISPER_CUDA instead" )
set ( WHISPER_CUDA ON )
endif ( )
if ( WHISPER_CUDA )
2024-06-16 10:07:43 +00:00
cmake_minimum_required ( VERSION 3.18 ) # for CMAKE_CUDA_ARCHITECTURES
2023-04-30 09:14:33 +00:00
find_package ( CUDAToolkit )
if ( CUDAToolkit_FOUND )
message ( STATUS "cuBLAS found" )
2024-06-16 10:07:43 +00:00
if ( NOT DEFINED CMAKE_CUDA_ARCHITECTURES )
# 52 == lowest CUDA 12 standard
# 60 == f16 CUDA intrinsics
# 61 == integer CUDA intrinsics
# 70 == compute capability at which unrolling a loop in mul_mat_q kernels is faster
if ( WHISPER_CUDA_F16 OR WHISPER_CUDA_DMMV_F16 )
set ( CMAKE_CUDA_ARCHITECTURES "60;61;70" ) # needed for f16 CUDA intrinsics
else ( )
set ( CMAKE_CUDA_ARCHITECTURES "52;61;70" ) # lowest CUDA 12 standard + lowest for integer intrinsics
#set(CMAKE_CUDA_ARCHITECTURES "OFF") # use this to compile much faster, but only F16 models work
endif ( )
endif ( )
message ( STATUS "Using CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}" )
2023-04-30 09:14:33 +00:00
enable_language ( CUDA )
2024-03-27 16:55:10 +00:00
file ( GLOB GGML_SOURCES_CUDA "ggml-cuda/*.cu" )
list ( APPEND GGML_SOURCES_CUDA ggml-cuda.h )
list ( APPEND GGML_SOURCES_CUDA ggml-cuda.cu )
2023-04-30 09:14:33 +00:00
2024-06-16 10:07:43 +00:00
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-wmma*.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
file ( GLOB SRCS "ggml-cuda/template-instances/mmq*.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
if ( WHISPER_CUDA_FA_ALL_QUANTS )
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-vec*.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
add_compile_definitions ( GGML_CUDA_FA_ALL_QUANTS )
else ( )
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-vec*q4_0-q4_0.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-vec*q8_0-q8_0.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-vec*f16-f16.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
endif ( )
2024-03-27 16:55:10 +00:00
add_compile_definitions ( GGML_USE_CUDA )
2024-06-16 10:20:19 +00:00
add_compile_definitions ( GGML_CUDA_USE_GRAPHS )
2023-04-30 09:14:33 +00:00
if ( WHISPER_STATIC )
2023-12-29 09:30:47 +00:00
if ( WIN32 )
# As of 12.3.1 CUDA Tookit for Windows does not offer a static cublas library
2024-06-04 06:32:23 +00:00
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } CUDA::cudart_static CUDA::cublas CUDA::cublasLt CUDA::cufft )
2023-12-29 09:30:47 +00:00
else ( )
2024-06-04 06:32:23 +00:00
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } CUDA::cudart_static CUDA::cublas_static CUDA::cublasLt_static CUDA::cufft_static )
2023-12-29 09:30:47 +00:00
endif ( )
2023-04-30 09:14:33 +00:00
else ( )
2024-06-04 06:32:23 +00:00
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } CUDA::cudart CUDA::cublas CUDA::cublasLt CUDA::cufft )
2023-04-30 09:14:33 +00:00
endif ( )
2023-12-29 09:30:47 +00:00
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } CUDA::cuda_driver )
2023-04-30 09:14:33 +00:00
else ( )
2023-10-07 19:01:18 +00:00
message ( FATAL_ERROR "cuBLAS not found" )
2023-04-30 09:14:33 +00:00
endif ( )
endif ( )
2023-08-27 17:03:58 +00:00
if ( WHISPER_HIPBLAS )
list ( APPEND CMAKE_PREFIX_PATH /opt/rocm )
if ( NOT ${ CMAKE_C_COMPILER_ID } MATCHES "Clang" )
message ( WARNING "Only LLVM is supported for HIP, hint: CC=/opt/rocm/llvm/bin/clang" )
endif ( )
if ( NOT ${ CMAKE_CXX_COMPILER_ID } MATCHES "Clang" )
message ( WARNING "Only LLVM is supported for HIP, hint: CXX=/opt/rocm/llvm/bin/clang++" )
endif ( )
find_package ( hip )
find_package ( hipblas )
find_package ( rocblas )
if ( ${ hipblas_FOUND } AND ${ hip_FOUND } )
message ( STATUS "HIP and hipBLAS found" )
2024-05-13 12:18:43 +00:00
set ( GGML_HEADERS_ROCM "ggml-cuda.h" )
file ( GLOB GGML_SOURCES_ROCM "ggml-cuda/*.cu" )
list ( APPEND GGML_SOURCES_ROCM "ggml-cuda.cu" )
2024-06-16 10:07:43 +00:00
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-wmma*.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
file ( GLOB SRCS "ggml-cuda/template-instances/mmq*.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
if ( WHISPER_CUDA_FA_ALL_QUANTS )
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-vec*.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
add_compile_definitions ( GGML_CUDA_FA_ALL_QUANTS )
else ( )
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-vec*q4_0-q4_0.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-vec*q8_0-q8_0.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
file ( GLOB SRCS "ggml-cuda/template-instances/fattn-vec*f16-f16.cu" )
list ( APPEND GGML_SOURCES_CUDA ${ SRCS } )
endif ( )
2024-03-27 16:55:10 +00:00
add_compile_definitions ( GGML_USE_HIPBLAS GGML_USE_CUDA )
2023-08-27 17:03:58 +00:00
2024-05-13 12:18:43 +00:00
set_source_files_properties ( ${ GGML_SOURCES_ROCM } PROPERTIES LANGUAGE CXX )
2023-08-27 17:03:58 +00:00
if ( WHISPER_STATIC )
message ( FATAL_ERROR "Static linking not supported for HIP/ROCm" )
endif ( )
2024-05-13 12:18:43 +00:00
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } hip::device PUBLIC hip::host roc::rocblas roc::hipblas )
2023-08-27 17:03:58 +00:00
else ( )
2023-10-07 19:01:18 +00:00
message ( FATAL_ERROR "hipBLAS or HIP not found. Try setting CMAKE_PREFIX_PATH=/opt/rocm" )
2023-08-27 17:03:58 +00:00
endif ( )
endif ( )
2023-05-02 19:50:32 +00:00
if ( WHISPER_CLBLAST )
find_package ( CLBlast )
if ( CLBlast_FOUND )
message ( STATUS "CLBlast found" )
2023-09-15 09:18:18 +00:00
set ( GGML_SOURCES_OPENCL ggml-opencl.cpp ggml-opencl.h )
2023-05-02 19:50:32 +00:00
add_compile_definitions ( GGML_USE_CLBLAST )
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } clblast )
else ( )
2023-10-07 19:01:18 +00:00
message ( FATAL_ERROR "CLBlast not found" )
2023-05-02 19:50:32 +00:00
endif ( )
endif ( )
2023-07-04 12:56:11 +00:00
if ( WHISPER_OPENVINO )
find_package ( OpenVINO REQUIRED COMPONENTS Runtime )
endif ( )
2024-02-23 07:22:24 +00:00
if ( WHISPER_SYCL )
if ( NOT DEFINED ENV{ONEAPI_ROOT} )
message ( FATAL_ERROR "Not detect ENV {ONEAPI_ROOT}, please install oneAPI & source it, like: source /opt/intel/oneapi/setvars.sh" )
endif ( )
#todo: AOT
find_package ( IntelSYCL REQUIRED )
if ( WHISPER_SYCL_F16 )
add_compile_definitions ( GGML_SYCL_F16 )
endif ( )
add_compile_definitions ( GGML_USE_SYCL )
add_compile_options ( -I./ ) #include DPCT
add_compile_options ( -I/ ${ SYCL_INCLUDE_DIR } )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl -L${MKLROOT}/lib" )
set ( GGML_HEADERS_SYCL ggml-sycl.h )
set ( GGML_SOURCES_SYCL ggml-sycl.cpp )
set ( WHISPER_EXTRA_LIBS ${ WHISPER_EXTRA_LIBS } sycl OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread )
endif ( )
2022-10-08 06:00:59 +00:00
# compiler flags
2022-10-07 20:53:12 +00:00
if ( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
set ( CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE )
set_property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" )
endif ( )
if ( WHISPER_ALL_WARNINGS )
2022-10-11 17:57:52 +00:00
if ( NOT MSVC )
2022-10-07 20:53:12 +00:00
set ( CMAKE_C_FLAGS " ${ CMAKE_C_FLAGS } \
- W a l l \
- W e x t r a \
- W p e d a n t i c \
- W s h a d o w \
- W c a s t - q u a l \
- W s t r i c t - p r o t o t y p e s \
- W p o i n t e r - a r i t h \
2023-01-07 18:18:34 +00:00
- W n o - u n u s e d - f u n c t i o n \
2022-10-07 20:53:12 +00:00
" )
2022-12-19 18:45:08 +00:00
set ( CMAKE_CXX_FLAGS " ${ CMAKE_CXX_FLAGS } \
- W a l l \
- W e x t r a \
- W p e d a n t i c \
- W c a s t - q u a l \
" )
2022-10-07 20:53:12 +00:00
else ( )
2022-10-11 17:57:52 +00:00
# todo : msvc
2022-10-07 20:53:12 +00:00
endif ( )
endif ( )
2022-10-11 17:57:52 +00:00
if ( NOT MSVC )
2024-01-22 12:51:42 +00:00
# TODO: temporary disabled until we figure out ggml-metal.m
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=vla")
2022-10-11 17:57:52 +00:00
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-math-errno -ffinite-math-only -funsafe-math-optimizations")
endif ( )
2022-10-07 20:53:12 +00:00
message ( STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}" )
if ( ${ CMAKE_SYSTEM_PROCESSOR } MATCHES "arm" OR ${ CMAKE_SYSTEM_PROCESSOR } MATCHES "aarch64" )
message ( STATUS "ARM detected" )
2023-08-25 12:19:48 +00:00
elseif ( ${ CMAKE_SYSTEM_PROCESSOR } MATCHES "ppc64le" )
message ( STATUS "PowerPC detected" )
2022-10-07 20:53:12 +00:00
else ( )
message ( STATUS "x86 detected" )
2022-10-11 17:57:52 +00:00
if ( MSVC )
2023-07-26 15:57:25 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /utf-8" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8" )
2024-04-15 17:02:09 +00:00
if ( NOT WHISPER_NO_AVX512 )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX512" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:AVX512" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX512" )
# MSVC has no compile-time flags enabling specific
# AVX512 extensions, neither it defines the
# macros corresponding to the extensions.
# Do it manually.
if ( NOT WHISPER_NO_AVX512_VBMI )
add_compile_definitions ( $< $<COMPILE_LANGUAGE:C > :__AVX512VBMI__> )
add_compile_definitions ( $< $<COMPILE_LANGUAGE:CXX > :__AVX512VBMI__> )
endif ( )
if ( NOT WHISPER_NO_AVX512_VNNI )
add_compile_definitions ( $< $<COMPILE_LANGUAGE:C > :__AVX512VNNI__> )
add_compile_definitions ( $< $<COMPILE_LANGUAGE:CXX > :__AVX512VNNI__> )
endif ( )
elseif ( NOT WHISPER_NO_AVX2 )
2023-07-26 15:57:25 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:AVX2" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2" )
2024-04-15 17:02:09 +00:00
elseif ( NOT WHISPER_NO_AVX )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:AVX" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX" )
2023-07-26 15:57:25 +00:00
endif ( )
2022-10-11 17:57:52 +00:00
else ( )
2022-10-22 10:45:43 +00:00
if ( EMSCRIPTEN )
2024-01-02 16:50:04 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -s TOTAL_STACK=5242880" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -s TOTAL_STACK=5242880" )
2022-10-22 10:45:43 +00:00
else ( )
2023-08-19 18:39:03 +00:00
if ( NOT WHISPER_NO_AVX )
2022-11-11 16:10:01 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx" )
endif ( )
2023-08-19 18:39:03 +00:00
if ( NOT WHISPER_NO_AVX2 )
2022-11-11 16:10:01 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2" )
endif ( )
2024-04-15 17:02:09 +00:00
if ( NOT WHISPER_NO_AVX512 )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw" )
2024-05-08 15:32:43 +00:00
if ( NOT WHISPER_NO_AVX512_VBMI )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512vbmi" )
endif ( )
if ( NOT WHISPER_NO_AVX512_VNNI )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512vnni" )
endif ( )
2024-04-15 17:02:09 +00:00
endif ( )
2023-08-19 18:39:03 +00:00
if ( NOT WHISPER_NO_FMA )
2023-01-06 17:32:28 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma" )
endif ( )
2023-08-19 18:39:03 +00:00
if ( NOT WHISPER_NO_F16C )
2023-03-22 20:30:40 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mf16c" )
endif ( )
2022-10-22 10:45:43 +00:00
endif ( )
2022-10-11 17:57:52 +00:00
endif ( )
2022-10-07 20:53:12 +00:00
endif ( )
2023-09-08 14:58:14 +00:00
#
# POSIX conformance
#
2023-09-07 09:36:14 +00:00
# clock_gettime came in POSIX.1b (1993)
# CLOCK_MONOTONIC came in POSIX.1-2001 / SUSv3 as optional
# posix_memalign came in POSIX.1-2001 / SUSv3
# M_PI is an XSI extension since POSIX.1-2001 / SUSv3, came in XPG1 (1985)
add_compile_definitions ( _XOPEN_SOURCE=600 )
# Somehow in OpenBSD whenever POSIX conformance is specified
# some string functions rely on locale_t availability,
# which was introduced in POSIX.1-2008, forcing us to go higher
2023-09-08 11:50:03 +00:00
if ( CMAKE_SYSTEM_NAME MATCHES "OpenBSD" )
2023-09-07 09:36:14 +00:00
remove_definitions ( -D_XOPEN_SOURCE=600 )
add_compile_definitions ( _XOPEN_SOURCE=700 )
2023-09-08 11:50:03 +00:00
endif ( )
2023-09-07 09:36:14 +00:00
# Data types, macros and functions related to controlling CPU affinity
# are available on Linux through GNU extensions in libc
2023-09-08 11:50:03 +00:00
if ( CMAKE_SYSTEM_NAME MATCHES "Linux" )
2023-09-07 09:36:14 +00:00
add_compile_definitions ( _GNU_SOURCE )
2023-09-08 11:50:03 +00:00
endif ( )
2023-09-07 09:36:14 +00:00
# RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1,
# and on macOS its availability depends on enabling Darwin extensions
# similarly on DragonFly, enabling BSD extensions is necessary
2023-09-08 11:50:03 +00:00
if ( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
2023-09-07 09:36:14 +00:00
add_compile_definitions ( _DARWIN_C_SOURCE )
2023-09-08 11:50:03 +00:00
endif ( )
if ( CMAKE_SYSTEM_NAME MATCHES "DragonFly" )
2023-09-07 09:36:14 +00:00
add_compile_definitions ( _DARWIN_C_SOURCE )
2023-09-08 11:50:03 +00:00
endif ( )
2023-09-07 09:36:14 +00:00
# alloca is a non-standard interface that is not visible on BSDs when
# POSIX conformance is specified, but not all of them provide a clean way
# to enable it in such cases
2023-09-08 11:50:03 +00:00
if ( CMAKE_SYSTEM_NAME MATCHES "FreeBSD" )
2023-09-07 09:36:14 +00:00
add_compile_definitions ( __BSD_VISIBLE )
2023-09-08 11:50:03 +00:00
endif ( )
if ( CMAKE_SYSTEM_NAME MATCHES "NetBSD" )
2023-09-07 09:36:14 +00:00
add_compile_definitions ( _NETBSD_SOURCE )
2023-09-08 11:50:03 +00:00
endif ( )
if ( CMAKE_SYSTEM_NAME MATCHES "OpenBSD" )
2023-09-07 09:36:14 +00:00
add_compile_definitions ( _BSD_SOURCE )
2023-09-08 11:50:03 +00:00
endif ( )
2023-09-07 09:36:14 +00:00
2022-11-03 18:18:57 +00:00
if ( WHISPER_PERF )
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DGGML_PERF )
endif ( )
2023-04-15 10:21:27 +00:00
#
# whisper.coreml - Core ML support
#
if ( WHISPER_COREML )
set ( TARGET whisper.coreml )
add_library ( ${ TARGET }
c o r e m l / w h i s p e r - e n c o d e r . h
c o r e m l / w h i s p e r - e n c o d e r . m m
c o r e m l / w h i s p e r - e n c o d e r - i m p l . h
c o r e m l / w h i s p e r - e n c o d e r - i m p l . m
)
include ( DefaultTargetOptions )
target_include_directories ( ${ TARGET } PUBLIC
.
)
target_link_libraries ( ${ TARGET } PRIVATE ${ FOUNDATION_FRAMEWORK } ${ COREML_FRAMEWORK } )
set_target_properties ( ${ TARGET } PROPERTIES
C O M P I L E _ F L A G S " - f o b j c - a r c "
)
2024-04-09 15:23:33 +00:00
set_target_properties ( ${ TARGET } PROPERTIES FOLDER "libs" )
2023-04-15 10:21:27 +00:00
endif ( )
2023-07-04 12:56:11 +00:00
if ( WHISPER_OPENVINO )
set ( TARGET whisper.openvino )
add_library ( ${ TARGET } OBJECT
o p e n v i n o / w h i s p e r - o p e n v i n o - e n c o d e r . h
o p e n v i n o / w h i s p e r - o p e n v i n o - e n c o d e r . c p p
)
target_include_directories ( ${ TARGET } PUBLIC
.
)
set_property ( TARGET ${ TARGET } PROPERTY POSITION_INDEPENDENT_CODE ON )
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -DWHISPER_USE_OPENVINO )
target_link_libraries ( ${ TARGET } PRIVATE openvino::runtime )
2024-04-09 15:23:33 +00:00
set_target_properties ( ${ TARGET } PROPERTIES FOLDER "libs" )
2023-07-04 12:56:11 +00:00
endif ( )
2022-10-25 16:13:08 +00:00
#
2022-10-08 06:00:59 +00:00
# whisper - this is the main library of the project
2022-10-25 16:13:08 +00:00
#
2022-10-07 20:53:12 +00:00
set ( TARGET whisper )
2022-10-08 06:00:59 +00:00
add_library ( ${ TARGET }
2022-12-22 14:34:47 +00:00
g g m l . h
2022-10-07 21:21:16 +00:00
g g m l . c
2023-09-15 09:18:18 +00:00
g g m l - a l l o c . h
g g m l - a l l o c . c
2023-11-03 19:35:05 +00:00
g g m l - b a c k e n d . h
g g m l - b a c k e n d . c
g g m l - q u a n t s . h
g g m l - q u a n t s . c
2023-09-15 09:18:18 +00:00
$ { G G M L _ S O U R C E S _ M E T A L }
$ { G G M L _ S O U R C E S _ C U D A }
$ { G G M L _ S O U R C E S _ O P E N C L }
2024-05-13 12:18:43 +00:00
$ { G G M L _ S O U R C E S _ S Y C L } $ { G G M L _ H E A D E R S _ S Y C L }
$ { G G M L _ S O U R C E S _ R O C M } $ { G G M L _ H E A D E R S _ R O C M }
2022-12-22 14:34:47 +00:00
w h i s p e r . h
2022-10-07 20:53:12 +00:00
w h i s p e r . c p p
)
2024-06-04 06:32:23 +00:00
if ( WHISPER_CUDA )
target_sources ( ${ TARGET } PRIVATE whisper-mel-cuda.cu )
endif ( )
2024-05-13 12:18:43 +00:00
include_directories (
.
)
2024-03-04 19:17:48 +00:00
# Set the version numbers
set_target_properties ( whisper PROPERTIES
V E R S I O N $ { P R O J E C T _ V E R S I O N }
S O V E R S I O N $ { S O V E R S I O N }
)
2023-01-05 19:22:48 +00:00
include ( DefaultTargetOptions )
2022-10-07 20:53:12 +00:00
target_include_directories ( ${ TARGET } PUBLIC
.
)
2023-04-15 10:21:27 +00:00
if ( WHISPER_COREML )
target_link_libraries ( ${ TARGET } PRIVATE whisper.coreml )
endif ( )
2023-07-04 12:56:11 +00:00
if ( WHISPER_OPENVINO )
target_link_libraries ( ${ TARGET } PRIVATE whisper.openvino )
endif ( )
2024-04-09 15:32:46 +00:00
if ( WHISPER_MKL )
target_link_libraries ( ${ TARGET } PUBLIC MKL::MKL )
endif ( )
2022-10-27 09:59:02 +00:00
if ( MSVC )
2022-10-29 16:41:50 +00:00
target_link_libraries ( ${ TARGET } PRIVATE ${ WHISPER_EXTRA_LIBS } ${ CMAKE_THREAD_LIBS_INIT } )
set ( WHISPER_EXTRA_FLAGS ${ WHISPER_EXTRA_FLAGS } -D_CRT_SECURE_NO_WARNINGS )
2022-10-27 09:59:02 +00:00
else ( )
2022-10-29 16:41:50 +00:00
target_link_libraries ( ${ TARGET } PRIVATE m ${ WHISPER_EXTRA_LIBS } ${ CMAKE_THREAD_LIBS_INIT } )
2022-10-27 09:59:02 +00:00
endif ( )
2022-10-07 20:53:12 +00:00
if ( BUILD_SHARED_LIBS )
2024-01-22 13:02:35 +00:00
set_target_properties ( ${ TARGET } PROPERTIES POSITION_INDEPENDENT_CODE ON )
2022-10-07 20:53:12 +00:00
target_link_libraries ( ${ TARGET } PUBLIC
$ { C M A K E _ D L _ L I B S }
)
target_compile_definitions ( ${ TARGET } PUBLIC
W H I S P E R _ S H A R E D
2023-04-30 15:51:57 +00:00
G G M L _ S H A R E D
)
target_compile_definitions ( ${ TARGET } PRIVATE
W H I S P E R _ B U I L D
G G M L _ B U I L D
2022-10-07 20:53:12 +00:00
)
2023-09-15 09:18:18 +00:00
if ( WHISPER_METAL )
# TODO: I think this should make ggml-metal.m "see" the ggml-metal.metal file from the "bin" directory
# but for some reason it does not work here like it does in llama.cpp
set_target_properties ( ${ TARGET } PROPERTIES RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal.metal" )
endif ( )
2022-10-07 20:53:12 +00:00
endif ( )
2023-09-15 09:18:18 +00:00
if ( GGML_SOURCES_CUDA )
2023-04-30 09:14:33 +00:00
message ( STATUS "GGML CUDA sources found, configuring CUDA architecture" )
2023-12-21 13:44:04 +00:00
# Only configure gmml CUDA architectures is not globally set
if ( NOT DEFINED GGML_CUDA_ARCHITECTURES )
# Not overriden by user, so set defaults
set ( GGML_CUDA_ARCHITECTURES 52 61 70 )
endif ( )
message ( STATUS "GGML Configuring CUDA architectures ${GGML_CUDA_ARCHITECTURES}" )
set_property ( TARGET whisper PROPERTY CUDA_ARCHITECTURES ${ GGML_CUDA_ARCHITECTURES } )
2023-04-30 09:14:33 +00:00
set_property ( TARGET whisper PROPERTY CUDA_SELECT_NVCC_ARCH_FLAGS "Auto" )
endif ( )
2022-12-12 18:17:27 +00:00
if ( EMSCRIPTEN )
set_target_properties ( ${ TARGET } PROPERTIES COMPILE_FLAGS "-msimd128" )
endif ( )
2022-10-07 20:53:12 +00:00
target_compile_definitions ( ${ TARGET } PUBLIC
$ { W H I S P E R _ E X T R A _ F L A G S }
)
2023-11-28 13:41:49 +00:00
set_target_properties ( ${ TARGET } PROPERTIES PUBLIC_HEADER "ggml.h;whisper.h" )
2024-04-09 15:23:33 +00:00
set_target_properties ( ${ TARGET } PROPERTIES FOLDER "libs" )
2023-02-11 07:13:32 +00:00
2023-09-15 09:18:18 +00:00
include ( GNUInstallDirs )
2022-10-07 20:53:12 +00:00
install ( TARGETS ${ TARGET }
2023-09-15 09:18:18 +00:00
L I B R A R Y D E S T I N A T I O N l i b
A R C H I V E D E S T I N A T I O N l i b / s t a t i c
R U N T I M E D E S T I N A T I O N b i n
R E S O U R C E D E S T I N A T I O N b i n
2023-02-11 07:13:32 +00:00
P U B L I C _ H E A D E R D E S T I N A T I O N i n c l u d e
2022-10-07 20:53:12 +00:00
)
2022-10-25 16:13:08 +00:00
#
2022-10-22 10:07:59 +00:00
# bindings
2022-10-25 16:13:08 +00:00
#
2022-10-22 10:07:59 +00:00
add_subdirectory ( bindings )
2022-10-25 16:13:08 +00:00
#
2022-10-08 06:00:59 +00:00
# programs, examples and tests
2022-10-25 16:13:08 +00:00
#
2022-10-08 06:00:59 +00:00
2023-02-05 13:02:08 +00:00
if ( WHISPER_BUILD_TESTS AND NOT CMAKE_JS_VERSION )
2022-12-12 18:17:27 +00:00
enable_testing ( )
add_subdirectory ( tests )
2022-10-07 20:53:12 +00:00
endif ( )
2022-12-12 18:17:27 +00:00
if ( WHISPER_BUILD_EXAMPLES )
add_subdirectory ( examples )
endif ( )