Skip to content

Commit

Permalink
Fix compilation on metal
Browse files Browse the repository at this point in the history
  • Loading branch information
li-plus committed Jul 25, 2024
1 parent 0f7a8a9 commit 8501fb2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
24 changes: 15 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,33 +44,37 @@ 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)
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
Expand Down
4 changes: 0 additions & 4 deletions chatglm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
#include <ggml-cuda.h>
#endif

#ifdef GGML_USE_METAL
#include <ggml-metal.h>
#endif

namespace chatglm {

static std::string shape_to_string(ggml_tensor *tensor) {
Expand Down
4 changes: 4 additions & 0 deletions chatglm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <sstream>
#include <unordered_map>

#ifdef GGML_USE_METAL
#include <ggml-metal.h>
#endif

namespace chatglm {

// ===== common =====
Expand Down
2 changes: 1 addition & 1 deletion chatglm_cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8501fb2

Please sign in to comment.