From 8501fb2e59e15aa05e571a043bd1c68e6eea5445 Mon Sep 17 00:00:00 2001 From: lijiahao Date: Thu, 25 Jul 2024 18:05:09 +0800 Subject: [PATCH] Fix compilation on metal --- CMakeLists.txt | 24 +++++++++++++++--------- chatglm.cpp | 4 ---- chatglm.h | 4 ++++ chatglm_cpp/__init__.py | 2 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18b547b..ab73f42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,8 @@ if (CHATGLM_ENABLE_PYBIND) endif () # third-party libraries + +# ggml if (GGML_CUDA) add_compile_definitions(GGML_USE_CUDA) enable_language(CUDA) @@ -42,9 +44,19 @@ if (GGML_CUDA) set(CMAKE_CUDA_ARCHITECTURES ${CUDA_ARCH_LIST} CACHE STRING "") endif () +if (GGML_METAL) + add_compile_definitions(GGML_USE_METAL) + set(GGML_METAL_EMBED_LIBRARY ON CACHE BOOL "" FORCE) +endif () + +if (GGML_PERF) + add_compile_definitions(GGML_PERF) +endif () + include_directories(third_party/ggml/include/ggml third_party/ggml/src) add_subdirectory(third_party/ggml) +# sentencepiece set(SPM_ENABLE_SHARED OFF CACHE BOOL "chatglm: disable sentencepiece shared libraries by default") set(SPM_ENABLE_TCMALLOC OFF CACHE BOOL "chatglm: disable tcmalloc by default") include_directories(third_party/sentencepiece/src) @@ -52,23 +64,17 @@ add_subdirectory(third_party/sentencepiece) include_directories(third_party/sentencepiece/third_party/protobuf-lite) +# absl set(ABSL_ENABLE_INSTALL ON CACHE BOOL "" FORCE) set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE) add_subdirectory(third_party/abseil-cpp) +# re2 add_subdirectory(third_party/re2) +# stb include_directories(third_party/stb) -if (GGML_METAL) - add_compile_definitions(GGML_USE_METAL) - configure_file(third_party/ggml/src/ggml-metal.metal ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ggml-metal.metal COPYONLY) -endif () - -if (GGML_PERF) - add_compile_definitions(GGML_PERF) -endif () - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) file(GLOB CPP_SOURCES diff --git a/chatglm.cpp b/chatglm.cpp index c9f943b..7779083 100644 --- a/chatglm.cpp +++ b/chatglm.cpp @@ -48,10 +48,6 @@ #include #endif -#ifdef GGML_USE_METAL -#include -#endif - namespace chatglm { static std::string shape_to_string(ggml_tensor *tensor) { diff --git a/chatglm.h b/chatglm.h index bc91024..ebda6b9 100644 --- a/chatglm.h +++ b/chatglm.h @@ -9,6 +9,10 @@ #include #include +#ifdef GGML_USE_METAL +#include +#endif + namespace chatglm { // ===== common ===== diff --git a/chatglm_cpp/__init__.py b/chatglm_cpp/__init__.py index 209bf24..73d3302 100644 --- a/chatglm_cpp/__init__.py +++ b/chatglm_cpp/__init__.py @@ -6,7 +6,7 @@ import chatglm_cpp._C as _C from chatglm_cpp._C import ChatMessage, Image -__version__ = "0.4.1" +__version__ = "0.4.2" @dataclass