Skip to content

Commit 5f22fec

Browse files
committed
feature: allow all BLA_VENDOR to be assigned in cmake arguments. align with whisper.cpp pr 927
1 parent 4cb20e5 commit 5f22fec

File tree

3 files changed

+26
-47
lines changed

3 files changed

+26
-47
lines changed

BLIS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CMake:
3939
```bash
4040
mkdir build
4141
cd build
42-
cmake -DLLAMA_BLIS=ON ..
42+
cmake -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=FLAME ..
4343
make -j
4444
```
4545

CMakeLists.txt

+12-43
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.12) # Don't bump this version for no reason
1+
cmake_minimum_required(VERSION 3.25) # Don't bump this version for no reason
22
project("llama.cpp" C CXX)
33

44
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -65,8 +65,8 @@ endif()
6565

6666
# 3rd party libs
6767
option(LLAMA_ACCELERATE "llama: enable Accelerate framework" ON)
68-
option(LLAMA_OPENBLAS "llama: use OpenBLAS" OFF)
69-
option(LLAMA_BLIS "llama: use blis" OFF)
68+
option(LLAMA_BLAS "llama: use BLAS" OFF)
69+
option(LLAMA_BLAS_VENDOR "llama: BLA_VENDOR from https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors" Generic)
7070
option(LLAMA_CUBLAS "llama: use cuBLAS" OFF)
7171
option(LLAMA_CLBLAST "llama: use CLBlast" OFF)
7272

@@ -146,57 +146,26 @@ if (APPLE AND LLAMA_ACCELERATE)
146146
endif()
147147
endif()
148148

149-
if (LLAMA_OPENBLAS)
149+
if (LLAMA_BLAS)
150150
if (LLAMA_STATIC)
151151
set(BLA_STATIC ON)
152152
endif()
153-
154-
set(BLA_VENDOR OpenBLAS)
153+
set(BLA_SIZEOF_INTEGRER 8)
154+
set(BLA_VENDOR ${LLAMA_BLAS_VENDOR})
155155
find_package(BLAS)
156156
if (BLAS_FOUND)
157-
message(STATUS "OpenBLAS found")
157+
message(STATUS "BLAS found, Libraries: ${BLAS_LIBRARIES}")
158158

159159
add_compile_definitions(GGML_USE_OPENBLAS)
160-
add_link_options(${BLAS_LIBRARIES})
161-
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} openblas)
162-
163-
# find header file
164-
set(OPENBLAS_INCLUDE_SEARCH_PATHS
165-
/usr/include
166-
/usr/include/openblas
167-
/usr/include/openblas-base
168-
/usr/local/include
169-
/usr/local/include/openblas
170-
/usr/local/include/openblas-base
171-
/opt/OpenBLAS/include
172-
$ENV{OpenBLAS_HOME}
173-
$ENV{OpenBLAS_HOME}/include
174-
)
175-
find_path(OPENBLAS_INC NAMES cblas.h PATHS ${OPENBLAS_INCLUDE_SEARCH_PATHS})
176-
add_compile_options(-I${OPENBLAS_INC})
160+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} ${BLAS_LIBRARIES})
161+
162+
message("${BLAS_LIBRARIES}")
163+
include_directories(${BLAS_INCLUDE_DIRS})
177164
else()
178-
message(WARNING "OpenBLAS not found")
165+
message(WARNING "BLAS not found, please refer to https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors to set correct LLAMA_BLAS_VENDOR")
179166
endif()
180167
endif()
181168

182-
if (LLAMA_BLIS)
183-
add_compile_definitions(GGML_USE_BLIS)
184-
# we don't directly call BLIS apis, use cblas wrapper instead
185-
add_compile_definitions(GGML_USE_OPENBLAS)
186-
set(BLIS_INCLUDE_SEARCH_PATHS
187-
/usr/include
188-
/usr/include/blis
189-
/usr/local/include
190-
/usr/local/include/blis
191-
$ENV{BLIS_HOME}
192-
$ENV{BLIS_HOME}/include
193-
)
194-
find_path(BLIS_INC NAMES blis.h PATHS ${BLIS_INCLUDE_SEARCH_PATHS})
195-
add_compile_definitions(BLIS_ENABLE_CBLAS)
196-
add_link_options(-lblis)
197-
add_compile_options(-I${BLIS_INC})
198-
endif()
199-
200169
if (LLAMA_CUBLAS)
201170
cmake_minimum_required(VERSION 3.17)
202171

README.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ The main goal of `llama.cpp` is to run the LLaMA model using 4-bit integer quant
5555
- Mixed F16 / F32 precision
5656
- 4-bit, 5-bit and 8-bit integer quantization support
5757
- Runs on the CPU
58-
- OpenBLAS support
58+
- Supports OpenBLAS/Apple BLAS/ARM Performance Lib/ATLAS/BLIS/Intel MKL/NVHPC/ACML/SCSL/SGIMATH and [more](https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors) in BLAS
5959
- cuBLAS and CLBlast support
60-
- BLIS support (cblas wrapper)
6160

6261
The original implementation of `llama.cpp` was [hacked in an evening](https://github.com/ggerganov/llama.cpp/issues/33#issuecomment-1465108022).
6362
Since then, the project has improved significantly thanks to many contributions. This project is for educational purposes and serves
@@ -273,14 +272,25 @@ Building the program with BLAS support may lead to some performance improvements
273272
```bash
274273
mkdir build
275274
cd build
276-
cmake .. -DLLAMA_OPENBLAS=ON
275+
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS
277276
cmake --build . --config Release
278277
```
279278

280279
- BLIS
281280

282281
Check [BLIS.md](BLIS.md) for more information.
283282

283+
- Intel MKL
284+
285+
By default, `LLAMA_BLAS_VENDOR` is set to `Generic`, so if you already sourced intel environment script and assign `-DLLAMA_BLAS=ON` in cmake, the mkl version of Blas will automatically been selected. You may also specify it by:
286+
287+
```bash
288+
mkdir build
289+
cd build
290+
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=Intel10_64lp -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
291+
cmake --build . -config Release
292+
```
293+
284294
- cuBLAS
285295

286296
This provides BLAS acceleration using the CUDA cores of your Nvidia GPU. Make sure to have the CUDA toolkit installed. You can download it from your Linux distro's package manager or from here: [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads).

0 commit comments

Comments
 (0)