Skip to content

Commit ee72eaf

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

File tree

4 files changed

+27
-48
lines changed

4 files changed

+27
-48
lines changed

BLIS.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 43 deletions
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

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ ifdef LLAMA_OPENBLAS
123123
endif
124124
endif
125125
ifdef LLAMA_BLIS
126-
CFLAGS += -DGGML_USE_OPENBLAS -DGGML_USE_BLIS -I/usr/local/include/blis -I/usr/include/blis
126+
CFLAGS += -DGGML_USE_OPENBLAS -I/usr/local/include/blis -I/usr/include/blis
127127
LDFLAGS += -lblis -L/usr/local/lib
128128
endif
129129
ifdef LLAMA_CUBLAS

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ The main goal of `llama.cpp` is to run the LLaMA model using 4-bit integer quant
5656
- Mixed F16 / F32 precision
5757
- 4-bit, 5-bit and 8-bit integer quantization support
5858
- Runs on the CPU
59-
- OpenBLAS support
59+
- 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
6060
- cuBLAS and CLBlast support
61-
- BLIS support (cblas wrapper)
6261

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

282281
- BLIS
283282

284283
Check [BLIS.md](BLIS.md) for more information.
285284

285+
- Intel MKL
286+
287+
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:
288+
289+
```bash
290+
mkdir build
291+
cd build
292+
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=Intel10_64lp -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
293+
cmake --build . -config Release
294+
```
295+
286296
- cuBLAS
287297

288298
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)