ggerganov / llama.cpp

LLM inference in C/C++
MIT License
65.81k stars 9.45k forks source link

Bug: Could NOT find BLAS (missing: BLAS_LIBRARIES) #7708

Closed vt-alt closed 2 months ago

vt-alt commented 4 months ago

What happened?

When building package for ALT Linux I found that with -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS OpenBLAS support is still not built.

Name and Version

Version b3012

What operating system are you seeing the problem on?

Linux

Relevant log output

-- Could NOT find BLAS (missing: BLAS_LIBRARIES)
CMake Warning at CMakeLists.txt:374 (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 think this is because of this code:~

    set(BLA_VENDOR ${LLAMA_BLAS_VENDOR})
    find_package(BLAS)

~Instead of setting BLAS_VENDOR.~

~There also other instances for setting BLA_ variables,~ but I am not sure this is not intended since I'm not into BLAS.

vt-alt commented 4 months ago

OK I was incorrect guessing it was because of BLA_VENDOR (and setting BLA_VEDOR is a correct thing to do). With this patch applied

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c5add823..5c12ff2d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -300,7 +300,7 @@ if (LLAMA_BLAS)
         set(BLA_STATIC ON)
     endif()
     if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
-        set(BLA_SIZEOF_INTEGER 8)
+        set(BLAS_SIZEOF_INTEGER 8)
     endif()

     set(BLA_VENDOR ${LLAMA_BLAS_VENDOR})

OpenBLAS is now detected (perhaps correctly):

-- Looking for sgemm_
-- Looking for sgemm_ - found
-- Found BLAS: /usr/lib64/libopenblas.so
-- BLAS found, Libraries: /usr/lib64/libopenblas.so
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Checking for module 'openblas64'
--   No package 'openblas64' found
-- Checking for module 'openblas'
--   Found openblas, version 0.3.27
-- BLAS found, Includes: /usr/include/openblas

Maybe we have incorrect libopenblas-devel package - I will investigate further.

vt-alt commented 4 months ago

Findings update. We have default build for OpenBLAS, which is LP64, having int size 32-bit.

https://github.com/OpenMathLib/OpenBLAS/blob/develop/docs/distributing.md

The LP64 (32-bit integer) interface is the default build, and has well-established C and Fortran APIs as determined by the reference (Netlib) BLAS and LAPACK libraries.

Setting harcoded BLA_SIZEOF_INTEGER to 8 you force cmake to find only ILP64 build, which we don't have.

CMake allows setting BLA_SIZEOF_INTEGER to ANY and it will search for any type of lib, Or just don't set it and it will do the same.

https://cmake.org/cmake/help/latest/module/FindBLAS.html#input-variables

Conclusion: So I'd suggest you set it to ANY or do not set BLA_SIZEOF_INTEGER at all. (Of course if your code is compatible with it.)

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.

FranzKafkaYu commented 2 months ago

I am using the llama,cpp latest version and I encountered this problem with Ubuntu20,Cmake version:3.22.0,I want to use it in Android Virtual Machine(x86_64),I have noticed that the variable BLA_SIZEOF_INTEGER has been unset:

if (GGML_BLAS)
    if (GGML_STATIC)
        set(BLA_STATIC ON)
    endif()
    #if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
    #    set(BLA_SIZEOF_INTEGER 8)                                       
    #endif()

    set(BLA_VENDOR ${GGML_BLAS_VENDOR})
    find_package(BLAS)

while I still can't build,I have installed OpenBLAS related libraries,list below:

libopenblas-base/focal-updates,now 0.3.8+ds-1ubuntu0.20.04.1 amd64 [installed]
libopenblas-dev/focal-updates,now 0.3.8+ds-1ubuntu0.20.04.1 amd64 [installed]
libopenblas-pthread-dev/focal-updates,now 0.3.8+ds-1ubuntu0.20.04.1 amd64 [installed,automatic]
libopenblas0-pthread/focal-updates,now 0.3.8+ds-1ubuntu0.20.04.1 amd64 [installed,automatic]
libopenblas0/focal-updates,now 0.3.8+ds-1ubuntu0.20.04.1 amd64 [installed,automatic]

I don't know why it can't find these packages,just keep trying.

vt-alt commented 2 months ago

This bug is obsoleted. @FranzKafkaYu Also they renamed definitions now you should pass -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS instead of -DLLAMA_BLAS....

FranzKafkaYu commented 2 months ago

This bug is obsoleted. @FranzKafkaYu Also they renamed definitions now you should pass -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS instead of -DLLAMA_BLAS....

yeah,I know it.And here is my build configuration:

cmake -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86_64 -DANDROID_PLATFORM=latest  -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS