@@ -159,23 +159,59 @@ if (LLAMA_BLAS)
159159 if ($(CMAKE_VERSION ) VERSION_GREATER_EQUAL 3.22)
160160 set (BLA_SIZEOF_INTEGER 8)
161161 endif ()
162+
162163 set (BLA_VENDOR ${LLAMA_BLAS_VENDOR} )
163164 find_package (BLAS)
165+
164166 if (BLAS_FOUND)
165167 message (STATUS "BLAS found, Libraries: ${BLAS_LIBRARIES} " )
166168
167- # BLAS_INCLUDE_DIRS is missing in FindBLAS.cmake.
168- # see https://gitlab.kitware.com/cmake/cmake/-/issues/20268
169- find_path (BLAS_INCLUDE_DIRS
170- NAMES cblas.h
171- HINTS
172- /usr/include
173- /usr/local/include
174- /usr/include /openblas
175- )
169+ if ("${BLAS_INCLUDE_DIRS} " STREQUAL "" )
170+ # BLAS_INCLUDE_DIRS is missing in FindBLAS.cmake.
171+ # see https://gitlab.kitware.com/cmake/cmake/-/issues/20268
172+ find_package (PkgConfig REQUIRED)
173+ if (${LLAMA_BLAS_VENDOR} MATCHES "Generic" )
174+ pkg_check_modules(DepBLAS REQUIRED blas)
175+ elseif (${LLAMA_BLAS_VENDOR} MATCHES "OpenBLAS" )
176+ pkg_check_modules(DepBLAS REQUIRED openblas)
177+ elseif (${LLAMA_BLAS_VENDOR} MATCHES "FLAME" )
178+ pkg_check_modules(DepBLAS REQUIRED blis)
179+ elseif (${LLAMA_BLAS_VENDOR} MATCHES "ATLAS" )
180+ pkg_check_modules(DepBLAS REQUIRED blas-atlas)
181+ elseif (${LLAMA_BLAS_VENDOR} MATCHES "FlexiBLAS" )
182+ pkg_check_modules(DepBLAS REQUIRED flexiblas_api)
183+ elseif (${LLAMA_BLAS_VENDOR} MATCHES "Intel" )
184+ # all Intel* libraries share the same include path
185+ pkg_check_modules(DepBLAS REQUIRED mkl-sdl)
186+ elseif (${LLAMA_BLAS_VENDOR} MATCHES "NVHPC" )
187+ # this doesn't provide pkg-config
188+ # suggest to assign BLAS_INCLUDE_DIRS on your own
189+ if ("${NVHPC_VERSION} " STREQUAL "" )
190+ message (WARNING "Better to set NVHPC_VERSION" )
191+ else ()
192+ set (DepBLAS_FOUND ON )
193+ set (DepBLAS_INCLUDE_DIRS "/opt/nvidia/hpc_sdk/${CMAKE_SYSTEM_NAME} _${CMAKE_SYSTEM_PROCESSOR} /${NVHPC_VERSION} /math_libs/include" )
194+ endif ()
195+ endif ()
196+ if (DepBLAS_FOUND)
197+ set (BLAS_INCLUDE_DIRS ${DepBLAS_INCLUDE_DIRS} )
198+ else ()
199+ message (WARNING "BLAS_INCLUDE_DIRS neither been provided nor been automatically"
200+ " detected by pkgconfig, trying to find cblas.h from possible paths..." )
201+ find_path (BLAS_INCLUDE_DIRS
202+ NAMES cblas.h
203+ HINTS
204+ /usr/include
205+ /usr/local/include
206+ /usr/include /openblas
207+ /opt/homebrew/opt/openblas/include
208+ /usr/local/opt/openblas/include
209+ /usr/include /x86_64-linux-gnu/openblas/include
210+ )
211+ endif ()
212+ endif ()
176213
177214 message (STATUS "BLAS found, Includes: ${BLAS_INCLUDE_DIRS} " )
178-
179215 add_compile_options (${BLAS_LINKER_FLAGS} )
180216 add_compile_definitions (GGML_USE_OPENBLAS)
181217 set (LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} ${BLAS_LIBRARIES} )
0 commit comments