From: apcameron Date: Sat, 27 May 2023 13:48:33 +0000 (+0100) Subject: ggml : add CLBLAST support (#197) X-Git-Tag: upstream/0.0.1642~1429 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=72dbb51c0900dcb10c4efbf18deb7b4b440d6ad4;p=pkg%2Fggml%2Fsources%2Fggml ggml : add CLBLAST support (#197) Enable support for the RISCV architecture This addresses https://github.com/ggerganov/ggml/issues/129 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e46d55e..6c76cdb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/README.md b/README.md index 1cf38403..0b965157 100644 --- 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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26f14b1f..4c663934 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 . diff --git a/src/ggml.c b/src/ggml.c index 14972464..07ea92a5 100644 --- a/src/ggml.c +++ b/src/ggml.c @@ -186,10 +186,12 @@ typedef double ggml_float; #if defined(_MSC_VER) || defined(__MINGW32__) #include #else +#if !defined(__riscv) #include #endif #endif #endif +#endif #ifdef __F16C__