]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
cmake : support for CPU BLAS build via Intel MKL (#2024)
authorslashlib <redacted>
Tue, 9 Apr 2024 15:32:46 +0000 (18:32 +0300)
committerGitHub <redacted>
Tue, 9 Apr 2024 15:32:46 +0000 (18:32 +0300)
CMakeLists.txt
README.md

index db0862454cec461bccf37ad503e2dff38b51ec52..a3c2639939e6e8922830dd56b2b338db6acfa9b6 100644 (file)
@@ -82,6 +82,7 @@ else()
     option(WHISPER_CUBLAS                "whisper: support for CUDA (deprecated)"             OFF)
     option(WHISPER_HIPBLAS               "whisper: support for hipBLAS"                       OFF)
     option(WHISPER_CLBLAST               "whisper: use CLBlast"                               OFF)
+    option(WHISPER_MKL                   "whisper: use Intel Math Kernel Library (MKL)"       OFF)
     option(WHISPER_SYCL                  "whisper: use SYCL"                                  OFF)
     option(WHISPER_SYCL_F16              "whisper: use 16 bit floats for sycl calculations"   OFF)
 endif()
@@ -296,6 +297,13 @@ if (WHISPER_BLAS)
     endif ()
 endif ()
 
+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()
+
 if (WHISPER_CUBLAS)
     message(WARNING "WHISPER_CUBLAS is deprecated and will be removed in the future.\nUse WHISPER_CUDA instead")
     set(WHISPER_CUDA ON)
@@ -630,6 +638,10 @@ if (WHISPER_OPENVINO)
     target_link_libraries(${TARGET} PRIVATE whisper.openvino)
 endif()
 
+if (WHISPER_MKL)
+    target_link_libraries(${TARGET} PUBLIC MKL::MKL)
+endif()
+
 if (MSVC)
     target_link_libraries(${TARGET} PRIVATE ${WHISPER_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT})
 
index 96a8dd7b2c1bfc5ad0e2db7f57d416c8bf1436b7..6b6ea673c39ab658d95703c0f96a81fe602d934f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -455,6 +455,21 @@ make clean
 WHISPER_OPENBLAS=1 make -j
 ```
 
+## BLAS CPU support via Intel MKL
+
+Encoder processing can be accelerated on the CPU via the BLAS compatible interface of Intel's Math Kernel Library.
+First, make sure you have installed Intel's MKL runtime and development packages: https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-download.html
+
+Now build `whisper.cpp` with Intel MKL BLAS support:
+
+```
+source /opt/intel/oneapi/setvars.sh
+mkdir build
+cd build
+cmake -DWHISPER_MKL=ON ..
+WHISPER_MKL=1 make -j
+```
+
 ## Docker
 
 ### Prerequisites