|
74 | 74 | option(WHISPER_BLAS "whisper: use BLAS libraries" OFF)
|
75 | 75 | option(WHISPER_BLAS_VENDOR "whisper: BLAS library vendor" Generic)
|
76 | 76 | option(WHISPER_OPENBLAS "whisper: prefer OpenBLAS" OFF)
|
| 77 | + option(WHISPER_OPENBLAS_INTERFACE64 "whisper: use OpenBLAS w/ 64-bit interface" OFF) |
77 | 78 | option(WHISPER_CUDA "whisper: support for CUDA" OFF)
|
78 | 79 | option(WHISPER_CUBLAS "whisper: support for CUDA (deprecated)" OFF)
|
79 | 80 | option(WHISPER_HIPBLAS "whisper: support for hipBLAS" OFF)
|
@@ -207,30 +208,82 @@ endif()
|
207 | 208 | if (WHISPER_OPENBLAS)
|
208 | 209 | set(WHISPER_BLAS_VENDOR "OpenBLAS")
|
209 | 210 | set(WHISPER_BLAS ON)
|
| 211 | + # BLA_PKGCONFIG_BLAS is supported since CMake 3.25. |
| 212 | + # FindBLAS.cmake pkg-config logic seems incomplete, because when |
| 213 | + # BLA_SIZEOF_INTEGER is 8, then it should search for blas64 instead of blas. |
| 214 | + # blas.pc/blas64.pc are not always provided, so let's be more specific |
| 215 | + # and go with openblas.pc/openblas64.pc if WHISPER_OPENBLAS is on. |
| 216 | + if (WHISPER_OPENBLAS_INTERFACE64) |
| 217 | + set(WHISPER_BLAS_LIB "openblas64") |
| 218 | + else () |
| 219 | + set(WHISPER_BLAS_LIB "openblas") |
| 220 | + endif () |
| 221 | + set(BLA_PKGCONFIG_BLAS ${WHISPER_BLAS_LIB}) |
| 222 | + # OpenBLAS prebuilt libraries for Windows do not have "64" suffix in filename. |
| 223 | + # (But .pc file has "64" suffix in filename for USE_64BITINT=1 Windows build.) |
| 224 | + if (MSVC) |
| 225 | + set(WHISPER_BLAS_LIB "openblas") |
| 226 | + endif () |
210 | 227 | endif()
|
211 | 228 |
|
212 | 229 | if (WHISPER_BLAS)
|
213 |
| - if (WIN32) |
214 |
| - if(DEFINED ENV{OPENBLAS_PATH}) |
215 |
| - set(BLAS_LIBRARIES $ENV{OPENBLAS_PATH}/lib/libopenblas.dll.a) |
216 |
| - message(STATUS "Libraries ${BLAS_LIBRARIES}") |
217 |
| - set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_USE_OPENBLAS) |
218 |
| - include_directories($ENV{OPENBLAS_PATH}/include) |
219 |
| - set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} ${BLAS_LIBRARIES}) |
| 230 | + if (NOT "$ENV{OPENBLAS_PATH}" STREQUAL "") |
| 231 | + if (WHISPER_STATIC) |
| 232 | + set(WHISPER_BLAS_LIB_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX}) |
| 233 | + set(WHISPER_BLAS_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX}) |
220 | 234 | else ()
|
221 |
| - message(FATAL_ERROR "BLAS library was not found. Environment variable OPENBLAS_PATH not defined.") |
| 235 | + if (CMAKE_IMPORT_LIBRARY_SUFFIX) |
| 236 | + set(WHISPER_BLAS_LIB_PREFIX ${CMAKE_IMPORT_LIBRARY_PREFIX}) |
| 237 | + set(WHISPER_BLAS_LIB_SUFFIX ${CMAKE_IMPORT_LIBRARY_SUFFIX}) |
| 238 | + else () |
| 239 | + set(WHISPER_BLAS_LIB_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX}) |
| 240 | + set(WHISPER_BLAS_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| 241 | + endif () |
| 242 | + endif () |
| 243 | + # OpenBLAS prebuilt libraries hardcode "lib" prefix in filename even on Windows |
| 244 | + if (WHISPER_OPENBLAS) |
| 245 | + set(WHISPER_BLAS_LIB_PREFIX "lib") |
222 | 246 | endif ()
|
| 247 | + message(STATUS "BLAS compatible library path provided") |
| 248 | + set(BLAS_LIBRARIES "$ENV{OPENBLAS_PATH}/lib/${WHISPER_BLAS_LIB_PREFIX}${WHISPER_BLAS_LIB}${WHISPER_BLAS_LIB_SUFFIX}") |
| 249 | + message(STATUS "Libraries ${BLAS_LIBRARIES}") |
| 250 | + set(BLAS_INCLUDE_DIRS "$ENV{OPENBLAS_PATH}/include") |
| 251 | + message(STATUS "Include dirs ${BLAS_INCLUDE_DIRS}") |
| 252 | + if (NOT EXISTS "${BLAS_LIBRARIES}") |
| 253 | + message(FATAL_ERROR "BLAS library was not found. Environment variable OPENBLAS_PATH misdefined.") |
| 254 | + endif () |
| 255 | + set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_USE_OPENBLAS) |
| 256 | + include_directories(${BLAS_INCLUDE_DIRS}) |
| 257 | + set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} ${BLAS_LIBRARIES}) |
223 | 258 | else ()
|
224 |
| - set(BLA_STATIC 1) |
| 259 | + if (WHISPER_STATIC) |
| 260 | + # FindBLAS.cmake pkg-config logic seems incomplete, because when |
| 261 | + # BLA_STATIC is on, then it should use pkg_check_modules_static |
| 262 | + # instead of pkg_check_modules. |
| 263 | + # Some manual variable overriding may be necessary if you don't |
| 264 | + # achieve desired results. |
| 265 | + set(BLA_STATIC 1) |
| 266 | + endif () |
225 | 267 | set(BLA_VENDOR ${WHISPER_BLAS_VENDOR})
|
226 |
| - set(BLA_SIZEOF_INTEGER 8) |
| 268 | + if (WHISPER_OPENBLAS_INTERFACE64) |
| 269 | + set(BLA_SIZEOF_INTEGER 8) |
| 270 | + else () |
| 271 | + set(BLA_SIZEOF_INTEGER 4) |
| 272 | + endif() |
227 | 273 | set(BLA_PREFER_PKGCONFIG 1)
|
228 | 274 | find_package(BLAS)
|
229 | 275 |
|
230 | 276 | if(BLAS_FOUND)
|
231 | 277 | message(STATUS "BLAS compatible library found")
|
232 | 278 | message(STATUS "Libraries ${BLAS_LIBRARIES}")
|
233 |
| - find_path(BLAS_INCLUDE_DIRS cblas.h /usr/include/openblas /usr/local/include/openblas $ENV{BLAS_HOME}/include) |
| 279 | + if (NOT DEFINED BLAS_INCLUDE_DIRS) |
| 280 | + if (PKGC_BLAS_FOUND) |
| 281 | + set(BLAS_INCLUDE_DIRS "${PKGC_BLAS_INCLUDE_DIRS}") |
| 282 | + else () |
| 283 | + find_path(BLAS_INCLUDE_DIRS cblas.h /usr/include/openblas) |
| 284 | + endif() |
| 285 | + endif() |
| 286 | + message(STATUS "Include dirs ${BLAS_INCLUDE_DIRS}") |
234 | 287 | set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_USE_OPENBLAS)
|
235 | 288 | include_directories(${BLAS_INCLUDE_DIRS})
|
236 | 289 | set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} ${BLAS_LIBRARIES})
|
|
0 commit comments