find_package(BLAS) does not find OpenBLAS

Hi,

I am using the llama.cpp project to evaluate LLMs. But on Windows I am running into a problem with CMake: The find_package(BLAS) invocation does not find OpenBLAS.

Steps to reproduce

  1. Unpack the fOpenBLAS-0.3.23-x64.zipf inside the projects ./build directory.

  2. Execute:

cmake `
    --debug-find `
    -DLLAMA_BLAS=ON `
    -DLLAMA_BLAS_VENDOR=OpenBLAS `
    ..

Debug Output

The file C:/llama.cpp/build/OpenBLAS/lib/libopenblas.lib does exist and the find_library method location should match.

See llama.cpp/CMakeLists.txt at master-0be54f7 · ggerganov/llama.cpp · GitHub for the implementation.

CMake Debug Log at C:/Users/CountZero/miniconda3/Lib/site-packages/cmake/data/share/cmake-3.26/Modules/FindBLAS.cmake:343 (find_library):
  find_library called with the following settings:

    VAR: BLAS_openblas_LIBRARY
    NAMES: "openblas"
    Documentation: Path to a library.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 0
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 0
      Search AppBundle First: 0
    CMAKE_FIND_USE_CMAKE_PATH: 1
    CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
    CMAKE_FIND_USE_INSTALL_PREFIX: 1

  find_library considered the following locations:

    C:/llama.cpp/build/()openblas(\.lib)

  The item was not found.

Call Stack (most recent call first):
  C:/Users/CountZero/miniconda3/Lib/site-packages/cmake/data/share/cmake-3.26/Modules/FindBLAS.cmake:775 (check_blas_libraries)
  CMakeLists.txt:173 (find_package)

-- Could NOT find BLAS (missing: BLAS_LIBRARIES)

The issue https://github.com/ggerganov/llama.cpp/issues/627 is related.

Is this a bug of CMake? Is there a workaround?

It looks like BLAS_ROOT should be set to ${LLAMA_BUILD_DIR}/OpenBLAS (or similar). Does that help?

Hi,

thank you for the advice.

I set the BLAS_ROOT variable:

cmake `
    -DBLAS_ROOT="${pathToOpenBLAS}" `
    -DLLAMA_BLAS=ON `
    -DLLAMA_BLAS_VENDOR=OpenBLAS `
    ..

And used the following values of $pathToOpenBLAS:

  1. ../../OpenBLAS
  2. ../../OpenBLAS/
  3. C:/absolute/path/to/OpenBLAS
  4. C:/absolute/path/to/OpenBLAS/

But the error message is still the same:

– Could NOT find BLAS (missing: BLAS_LIBRARIES)
CMake Warning at CMakeLists.txt:225 (message):
BLAS not found, please refer to
https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors
to set correct LLAMA_BLAS_VENDOR

So it sadly does not help.

Does --debug-find help figure out where CMake is looking at least?

@ben.boeckel Yes, setting the BLAS_ROOT variable to ../../OpenBLAS causes CMake to search at the right location:

CMake Debug Log at C:/Users/CountZero/miniconda3/Lib/site-packages/cmake/data/share/cmake-3.26/Modules/FindBLAS.cmake:343 (find_library):
  find_library called with the following settings:

    VAR: BLAS_openblas_LIBRARY
    NAMES: "openblas"
    Documentation: Path to a library.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 0
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 0
      Search AppBundle First: 0
    CMAKE_FIND_USE_CMAKE_PATH: 1
    CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
    CMAKE_FIND_USE_INSTALL_PREFIX: 1

  find_library considered the following locations:

    C:/absolute/path/to/OpenBLAS/lib/()openblas(\.lib)
    C:/absolute/path/to/OpenBLAS/()openblas(\.lib)
    [...]

But CMake still fails to “find” the OpenBLAS library:

[...]

  The item was not found.

Call Stack (most recent call first):
  C:/Users/CountZero/miniconda3/Lib/site-packages/cmake/data/share/cmake-3.26/Modules/FindBLAS.cmake:775 (check_blas_libraries)
  CMakeLists.txt:181 (find_package)


-- Could NOT find BLAS (missing: BLAS_LIBRARIES)
CMake Debug Log at CMakeLists.txt:181 (find_package):
  find_package considered the following paths for FindBLAS.cmake:

  The file was found at

    C:/Users/CountZero/miniconda3/Lib/site-packages/cmake/data/share/cmake-3.26/Modules/FindBLAS.cmake

  The module is considered not found due to BLAS_FOUND being FALSE.


CMake Warning at CMakeLists.txt:238 (message):
  BLAS not found, please refer to
  https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors
  to set correct LLAMA_BLAS_VENDOR

I am using the openblas-0.3.23-x64.zip from Release OpenBLAS 0.3.23 version · xianyi/OpenBLAS · GitHub.