Skip to content

Commit 956ef86

Browse files
authored
cmake : support for CPU BLAS build via Intel MKL (ggml-org#2024)
1 parent 671b4bd commit 956ef86

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ else()
8282
option(WHISPER_CUBLAS "whisper: support for CUDA (deprecated)" OFF)
8383
option(WHISPER_HIPBLAS "whisper: support for hipBLAS" OFF)
8484
option(WHISPER_CLBLAST "whisper: use CLBlast" OFF)
85+
option(WHISPER_MKL "whisper: use Intel Math Kernel Library (MKL)" OFF)
8586
option(WHISPER_SYCL "whisper: use SYCL" OFF)
8687
option(WHISPER_SYCL_F16 "whisper: use 16 bit floats for sycl calculations" OFF)
8788
endif()
@@ -296,6 +297,13 @@ if (WHISPER_BLAS)
296297
endif ()
297298
endif ()
298299

300+
if (WHISPER_MKL)
301+
find_package(MKL CONFIG REQUIRED PATHS $ENV{MKLROOT})
302+
message(STATUS "Imported oneMKL targets: ${MKL_IMPORTED_TARGETS}")
303+
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_USE_OPENBLAS)
304+
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_BLAS_USE_MKL)
305+
endif()
306+
299307
if (WHISPER_CUBLAS)
300308
message(WARNING "WHISPER_CUBLAS is deprecated and will be removed in the future.\nUse WHISPER_CUDA instead")
301309
set(WHISPER_CUDA ON)
@@ -630,6 +638,10 @@ if (WHISPER_OPENVINO)
630638
target_link_libraries(${TARGET} PRIVATE whisper.openvino)
631639
endif()
632640

641+
if (WHISPER_MKL)
642+
target_link_libraries(${TARGET} PUBLIC MKL::MKL)
643+
endif()
644+
633645
if (MSVC)
634646
target_link_libraries(${TARGET} PRIVATE ${WHISPER_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT})
635647

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,21 @@ make clean
455455
WHISPER_OPENBLAS=1 make -j
456456
```
457457

458+
## BLAS CPU support via Intel MKL
459+
460+
Encoder processing can be accelerated on the CPU via the BLAS compatible interface of Intel's Math Kernel Library.
461+
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
462+
463+
Now build `whisper.cpp` with Intel MKL BLAS support:
464+
465+
```
466+
source /opt/intel/oneapi/setvars.sh
467+
mkdir build
468+
cd build
469+
cmake -DWHISPER_MKL=ON ..
470+
WHISPER_MKL=1 make -j
471+
```
472+
458473
## Docker
459474

460475
### Prerequisites

0 commit comments

Comments
 (0)