]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
ggml : add CLBLAST support (#197)
authorapcameron <redacted>
Sat, 27 May 2023 13:48:33 +0000 (14:48 +0100)
committerGitHub <redacted>
Sat, 27 May 2023 13:48:33 +0000 (16:48 +0300)
Enable support for the RISCV architecture

This addresses https://github.com/ggerganov/ggml/issues/129

CMakeLists.txt
README.md
src/CMakeLists.txt
src/ggml.c

index 2e46d55eaa640a7517b5d747cc5f1075f0d31e64..6c76cdb2008aab2fc33e756348a6bde4eca15644 100644 (file)
@@ -28,6 +28,7 @@ option(GGML_BUILD_EXAMPLES          "ggml: build examples" ${GGML_STANDALONE})
 option(GGML_PERF                    "ggml: enable perf timings"          OFF)
 option(GGML_NO_ACCELERATE           "ggml: disable Accelerate framework" OFF)
 option(GGML_OPENBLAS                "ggml: use OpenBLAS"                 OFF)
+option(GGML_CLBLAST                 "ggml: use clBLAST"                  OFF)
 option(GGML_CUBLAS                  "ggml: use cuBLAS"                   OFF)
 
 # sanitizers
index 1cf38403ef8c35a029460d2476657230e70aefeb..0b965157b6a78924b43f422da6179cb61275ea68 100644 (file)
--- a/README.md
+++ b/README.md
@@ -99,6 +99,12 @@ For more information, checkout the corresponding programs in the [examples](exam
 cmake -DGGML_CUBLAS=ON -DCMAKE_CUDA_COMPILER=/usr/local/cuda-12.1/bin/nvcc ..
 ```
 
+## Using clBLAST
+
+```bash
+cmake -DGGML_CLBLAST=ON ..
+```
+
 ## Resources
 
 - [GGML - Large Language Models for Everyone](https://github.com/rustformers/llm/blob/main/crates/ggml/README.md): a description of the GGML format provided by the maintainers of the `llm` Rust crate, which provides Rust bindings for GGML
index 26f14b1f5242e94058de4afdd944ac4d93e624d5..4c663934a3bffe0e9da94214a2b6f5332610152a 100644 (file)
@@ -157,6 +157,26 @@ if (GGML_OPENBLAS)
     endif()
 endif()
 
+if (GGML_CLBLAST)
+       set(CLBLAST_INCLUDE_SEARCH_PATHS
+        /usr/include
+        /usr/local/include
+           $ENV{CLBLAST_HOME}
+           $ENV{CLBLAST_HOME}/include
+        )
+       find_path(CLBLAST_INC NAMES cblast.h PATHS ${CLBLAST_INCLUDE_SEARCH_PATHS})
+       find_library(CLBLAST_LIB NAMES clblast)
+       if (CLBLAST_LIB)
+               message(STATUS "clBLAST found")
+
+               set(GGML_EXTRA_LIBS  ${GGML_EXTRA_LIBS}  ${CLBLAST_LIB})
+               set(GGML_OPENCL_SOURCES ggml-opencl.c ggml-opencl.h)
+               set(GGML_EXTRA_FLAGS ${GGML_EXTRA_FLAGS} -DGGML_USE_CLBLAST)
+               link_libraries("-Wl,--copy-dt-needed-entries")
+    else()
+        message(WARNING "clBLAST not found")
+    endif()
+endif()
 if (GGML_CUBLAS)
     cmake_minimum_required(VERSION 3.17)
 
@@ -189,7 +209,8 @@ endif()
 add_library(${TARGET}
     ggml.c
     ../include/ggml/ggml.h
-    ${GGML_CUDA_SOURCES})
+    ${GGML_CUDA_SOURCES}
+    ${GGML_OPENCL_SOURCES})
 
 target_include_directories(${TARGET} PUBLIC
     .
index 14972464b55e78a2e93349fa761c8c49eca1821d..07ea92a5836cfa2465038a9478bfe1ccb6b2abbc 100644 (file)
@@ -186,10 +186,12 @@ typedef double ggml_float;
 #if defined(_MSC_VER) || defined(__MINGW32__)
 #include <intrin.h>
 #else
+#if !defined(__riscv)
 #include <immintrin.h>
 #endif
 #endif
 #endif
+#endif
 
 #ifdef __F16C__