-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
116 lines (94 loc) · 2.95 KB
/
CMakeLists.txt
File metadata and controls
116 lines (94 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
cmake_minimum_required(VERSION 3.19..4.0)
project(
Forward
VERSION 0.1
DESCRIPTION "A simple transformer inference engine"
LANGUAGES CXX CUDA
)
# Add cmake module path for our custom modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# Backend detection - can be overridden via -DBACKEND_CUDA=ON/OFF
if(APPLE)
option(BACKEND_METAL "Enable Metal backend" ON)
option(BACKEND_CUDA "Enable CUDA backend" OFF)
else()
option(BACKEND_CUDA "Enable CUDA backend" ON)
option(BACKEND_METAL "Enable Metal backend" OFF)
endif()
# Propagate backend flags as compile definitions
if(BACKEND_CUDA)
add_compile_definitions(BACKEND_CUDA)
message(STATUS "Backend: CUDA enabled")
else()
message(STATUS "Backend: CUDA disabled")
endif()
if(BACKEND_METAL)
add_compile_definitions(BACKEND_METAL)
message(STATUS "Backend: Metal enabled")
endif()
set(FETCHCONTENT_BASE_DIR "${CMAKE_SOURCE_DIR}/.cmake/fetchcontent")
set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
# msgpack in tokenizers_cpp is doing weird stuff
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
# Use ccache if available
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
message(STATUS "Using ccache: ${CCACHE_PROGRAM}")
endif()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_EXTENSIONS ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include(CTest)
find_package(Doxygen)
if(Doxygen_FOUND)
add_subdirectory(docs)
else()
message(STATUS "Doxygen not found, not building docs")
endif()
endif()
include(FetchContent)
# Declare all external dependencies in one place
FetchContent_Declare(
fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 12.1.0
)
FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.12.0
)
FetchContent_Declare(
safetensors_cpp
GIT_REPOSITORY https://github.com/syoyo/safetensors-cpp.git
GIT_TAG 10f7d8f
)
set(SAFETENSORS_CPP_CXX_EXCEPTIONS ON CACHE BOOL "" FORCE)
FetchContent_Declare(
tokenizers_cpp
GIT_REPOSITORY https://github.com/mlc-ai/tokenizers-cpp
GIT_TAG 55d53aa
)
# On NixOS with Clang, clangd uses a different resource-dir than clang++
# Set the correct resource-dir for all C++ compilation
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND DEFINED CLANG_RESOURCE_DIR AND NOT CLANG_RESOURCE_DIR STREQUAL "")
add_compile_options(-resource-dir=${CLANG_RESOURCE_DIR})
endif()
# Make dependencies available
FetchContent_MakeAvailable(fmtlib json safetensors_cpp tokenizers_cpp)
# compiled library code
add_subdirectory(src/tensor)
add_subdirectory(src/nn)
add_subdirectory(src/llama)
add_subdirectory(src/forward)
add_subdirectory(benchmarks)
# executable code
add_subdirectory(apps)
# testing only if this is the main app
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MODERN_CMAKE_BUILD_TESTING)
AND BUILD_TESTING)
add_subdirectory(tests)
endif()