Skip to content

make : find include dir for OpenBLAS header file - #1795

Closed
katsu560 wants to merge 1 commit into
ggml-org:masterfrom
katsu560:cmake-inc
Closed

katsu560 wants to merge 1 commit into
ggml-org:masterfrom
katsu560:cmake-inc

Conversation

@katsu560

Copy link
Copy Markdown
Contributor

Hi, Gerganov. Thank you for sharing awesome thing.
Latest source meets following compile error on Linux environment.

[ 16%] Building C object CMakeFiles/ggml.dir/ggml.c.o
/home/user/github/llama.cpp/llama.cpp/ggml.c:156:10: fatal error: cblas.h: No such file or directory
  156 | #include <cblas.h>
      |          ^~~~~~~~~
compilation terminated.
CMakeFiles/ggml.dir/build.make:75: recipe for target 'CMakeFiles/ggml.dir/ggml.c.o' failed
make[3]: *** [CMakeFiles/ggml.dir/ggml.c.o] Error 1
CMakeFiles/Makefile2:359: recipe for target 'CMakeFiles/ggml.dir/all' failed
make[2]: *** [CMakeFiles/ggml.dir/all] Error 2

Because BLAS cmake package can't find include header directory.
I added some code to CMakeLists.txt to resolve above issue.

Please confirm my pull-request.
Thanks.

@grencez

grencez commented Jun 11, 2023 •

Copy link
Copy Markdown
Contributor

You added this before in #992 and it was removed in #1536, but I'm not sure why. find_package(BLAS) doesn't populate a variable called BLAS_INCLUDE_DIRS at all, so I think PR makes sense again.

@zenixls2

zenixls2 commented Jun 12, 2023 •

Copy link
Copy Markdown
Contributor

The way that I use BLAS_INCLUDE_DIRS here is to allow users to assign the path using -DBLAS_INCLUDE_DIRS={path}.
In ubuntu, the package's include path for OpenBlas is in /usr/include/x86_64-linux-gnu/openblas-openmp/ and the ENV for OpenBLAS_HOME may not be a good naming for me (sounds like somewhere that might also include the shared/static lib)

A better way might be to provide a custom FindBlas cmake that appends the cflags from pkg-config directly, what do you think?

@zenixls2

Copy link
Copy Markdown
Contributor

@katsu560 does this patch works on your system?

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 19cd42d..b6c1fd3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -158,8 +158,27 @@ if (LLAMA_BLAS)
     if ($(CMAKE_VERSION) VERSION_GREATER_EQUAL 3.22)
         set(BLA_SIZEOF_INTEGER 8)
     endif()
+    find_package(PkgConfig REQUIRED)
+    if (${LLAMA_BLAS_VENDOR} MATCHES "Generic")
+        pkg_check_modules(DepBLAS REQUIRED blas)
+        if (DepBLAS_FOUND)
+            set(BLAS_INCLUDE_DIRS ${DepBLAS_INCLUDE_DIRS})
+        endif()
+    elseif (${LLAMA_BLAS_VENDOR} MATCHES "OpenBLAS")
+        pkg_check_modules(DepBLAS REQUIRED openblas)
+        if (DepBLAS_FOUND)
+            set(BLAS_INCLUDE_DIRS ${DepBLAS_INCLUDE_DIRS})
+        endif()
+    elseif (${LLAMA_BLAS_VENDOR} MATCHES "FLAME")
+        pkg_check_modules(DepBLAS REQUIRED blis)
+        if (DepBLAS_FOUND)
+            set(BLAS_INCLUDE_DIRS ${DepBLAS_INCLUDE_DIRS})
+        endif()
+    endif()
+
     set(BLA_VENDOR ${LLAMA_BLAS_VENDOR})
     find_package(BLAS)

@ggerganov

Copy link
Copy Markdown
Member

Decided to merge #1830 instead of this one.
Please reopen if problem still persists

@ggerganov ggerganov closed this Jun 15, 2023
@katsu560

Copy link
Copy Markdown
Contributor Author

Hi grencez, zenixls2 and Gerganov.
Thank you for your comments and sorry for my late comments.

Yes, the zenixls2' s patch works good on my system.
My system is Ubuntu 18.04 on WSL on Windows 10 with cmake 3.23.1 , self compiled OpenBLAS installed with openblas.pc.
Thanks again.

But, Gerganov's latest code #1830 doesn't works for me.
It can't find include file.

-- Found BLAS: /usr/local/lib/libopenblas.a;-pthread
-- BLAS found, Libraries: /usr/local/lib/libopenblas.a;-pthread
-- BLAS found, Includes: BLAS_INCLUDE_DIRS-NOTFOUND
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- x86 detected
-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
/home/user/github/llama.cpp/llama.cpp/BLAS_INCLUDE_DIRS
   used as include directory in directory /home/user/github/llama.cpp/llama.cpp

So, I think that it is necessary zenixls2's patch.

@katsu560

Copy link
Copy Markdown
Contributor Author

@zenixls2
Could you do pull request with your patch?

@zenixls2

Copy link
Copy Markdown
Contributor

Sure. Thanks for the confirmation.

@ggerganov

Copy link
Copy Markdown
Member

@katsu560

Did 13fe9d2 fix your issues?

@zenixls2

Copy link
Copy Markdown
Contributor

@ggerganov i think he answered in #1886

@katsu560

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants