mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-29 08:41:22 +00:00 
			
		
		
		
	cmake : add auto detection of BLAS_INCLUDE_DIRS (#1886)
This commit is contained in:
		| @@ -159,23 +159,59 @@ if (LLAMA_BLAS) | |||||||
|     if ($(CMAKE_VERSION) VERSION_GREATER_EQUAL 3.22) |     if ($(CMAKE_VERSION) VERSION_GREATER_EQUAL 3.22) | ||||||
|         set(BLA_SIZEOF_INTEGER 8) |         set(BLA_SIZEOF_INTEGER 8) | ||||||
|     endif() |     endif() | ||||||
|  |  | ||||||
|     set(BLA_VENDOR ${LLAMA_BLAS_VENDOR}) |     set(BLA_VENDOR ${LLAMA_BLAS_VENDOR}) | ||||||
|     find_package(BLAS) |     find_package(BLAS) | ||||||
|  |  | ||||||
|     if (BLAS_FOUND) |     if (BLAS_FOUND) | ||||||
|         message(STATUS "BLAS found, Libraries: ${BLAS_LIBRARIES}") |         message(STATUS "BLAS found, Libraries: ${BLAS_LIBRARIES}") | ||||||
|  |  | ||||||
|         # BLAS_INCLUDE_DIRS is missing in FindBLAS.cmake. |         if ("${BLAS_INCLUDE_DIRS}" STREQUAL "") | ||||||
|         # see https://gitlab.kitware.com/cmake/cmake/-/issues/20268 |             # BLAS_INCLUDE_DIRS is missing in FindBLAS.cmake. | ||||||
|         find_path(BLAS_INCLUDE_DIRS |             # see https://gitlab.kitware.com/cmake/cmake/-/issues/20268 | ||||||
|             NAMES cblas.h |             find_package(PkgConfig REQUIRED) | ||||||
|             HINTS |             if (${LLAMA_BLAS_VENDOR} MATCHES "Generic") | ||||||
|                 /usr/include |                 pkg_check_modules(DepBLAS REQUIRED blas) | ||||||
|                 /usr/local/include |             elseif (${LLAMA_BLAS_VENDOR} MATCHES "OpenBLAS") | ||||||
|                 /usr/include/openblas |                 pkg_check_modules(DepBLAS REQUIRED openblas) | ||||||
|         ) |             elseif (${LLAMA_BLAS_VENDOR} MATCHES "FLAME") | ||||||
|  |                 pkg_check_modules(DepBLAS REQUIRED blis) | ||||||
|  |             elseif (${LLAMA_BLAS_VENDOR} MATCHES "ATLAS") | ||||||
|  |                 pkg_check_modules(DepBLAS REQUIRED blas-atlas) | ||||||
|  |             elseif (${LLAMA_BLAS_VENDOR} MATCHES "FlexiBLAS") | ||||||
|  |                 pkg_check_modules(DepBLAS REQUIRED flexiblas_api) | ||||||
|  |             elseif (${LLAMA_BLAS_VENDOR} MATCHES "Intel") | ||||||
|  |                 # all Intel* libraries share the same include path | ||||||
|  |                 pkg_check_modules(DepBLAS REQUIRED mkl-sdl) | ||||||
|  |             elseif (${LLAMA_BLAS_VENDOR} MATCHES "NVHPC") | ||||||
|  |                 # this doesn't provide pkg-config | ||||||
|  |                 # suggest to assign BLAS_INCLUDE_DIRS on your own | ||||||
|  |                 if ("${NVHPC_VERSION}" STREQUAL "") | ||||||
|  |                     message(WARNING "Better to set NVHPC_VERSION") | ||||||
|  |                 else() | ||||||
|  |                     set(DepBLAS_FOUND ON) | ||||||
|  |                     set(DepBLAS_INCLUDE_DIRS "/opt/nvidia/hpc_sdk/${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR}/${NVHPC_VERSION}/math_libs/include") | ||||||
|  |                 endif() | ||||||
|  |             endif() | ||||||
|  |             if (DepBLAS_FOUND) | ||||||
|  |                 set(BLAS_INCLUDE_DIRS ${DepBLAS_INCLUDE_DIRS}) | ||||||
|  |             else() | ||||||
|  |                 message(WARNING "BLAS_INCLUDE_DIRS neither been provided nor been automatically" | ||||||
|  |                 " detected by pkgconfig, trying to find cblas.h from possible paths...") | ||||||
|  |                 find_path(BLAS_INCLUDE_DIRS | ||||||
|  |                     NAMES cblas.h | ||||||
|  |                     HINTS | ||||||
|  |                         /usr/include | ||||||
|  |                         /usr/local/include | ||||||
|  |                         /usr/include/openblas | ||||||
|  |                         /opt/homebrew/opt/openblas/include | ||||||
|  |                         /usr/local/opt/openblas/include | ||||||
|  |                         /usr/include/x86_64-linux-gnu/openblas/include | ||||||
|  |                 ) | ||||||
|  |             endif() | ||||||
|  |         endif() | ||||||
|  |  | ||||||
|         message(STATUS "BLAS found, Includes: ${BLAS_INCLUDE_DIRS}") |         message(STATUS "BLAS found, Includes: ${BLAS_INCLUDE_DIRS}") | ||||||
|  |  | ||||||
|         add_compile_options(${BLAS_LINKER_FLAGS}) |         add_compile_options(${BLAS_LINKER_FLAGS}) | ||||||
|         add_compile_definitions(GGML_USE_OPENBLAS) |         add_compile_definitions(GGML_USE_OPENBLAS) | ||||||
|         set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} ${BLAS_LIBRARIES}) |         set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} ${BLAS_LIBRARIES}) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zenix
					Zenix