forked from modelscope/dash-infer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
210 lines (171 loc) · 6.43 KB
/
CMakeLists.txt
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
cmake_minimum_required(VERSION 3.20)
set(project_version_in_env $ENV{AS_RELEASE_VERSION})
# remove -rc1 like string in version name.
if ((NOT DEFINED project_version_in_env))
set(project_version_in_env "1.0.0")
endif()
string(REGEX REPLACE "-rc[0-9]+" "" STRIPED_VERSION_STRING ${project_version_in_env})
set(project_version_in_env ${STRIPED_VERSION_STRING})
message("Build AllSpark with version:${project_version_in_env}")
project(DashInfer LANGUAGES C CXX VERSION ${project_version_in_env})
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build,
options are: Debug/Release/RelWithDebInfo/MinSizeRel." FORCE)
endif()
set(CXX_STD "17" CACHE STRING "C++ standard")
set(CMAKE_VERBOSE_MAKEFILE ON)
message(STATUS "CMAKE_BUILD_TYPE:${CMAKE_BUILD_TYPE}")
set(ALLSPARK_CBLAS "MKL"
CACHE STRING "Blas library choice, MKL/BLIS/NONE")
set(RUNTIME_THREAD "OMP" CACHE STRING "cpu threading runtime")
set(CONFIG_HOST_CPU_TYPE "X86" CACHE STRING "host cpu type, like X86, ARMV9, etc.")
## x86 related option.
option(ENABLE_AVX2 "enable avx2" ON)
option(ENABLE_AVX512 "enable avx512" ON)
## ARM related option.
option(ENABLE_ARMCL "enable use of Arm Compute Library" OFF)
option(ENABLE_ARM_V84_V9 "enable v8.4-a or higher version of Arm instructions, such as sdot" OFF)
option(ENABLE_FP16 "build with fp16 mode" ON)
option(ENABLE_BF16 "build with bf16 mode" ON)
option(ENABLE_SPARSE "build with sparse mode" ON)
option(BUILD_PYTHON "build with python api" OFF)
option(BUILD_PACKAGE "build rpm or deb package" OFF)
option(MEM_CHECK "check memory" OFF)
option(LOCK_CHECK "check deadlock" OFF)
option(ENABLE_GLIBCXX11_ABI "build with cxx11 abi" ON)
#setting compiler flags
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD ${CXX_STD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type")
message(STATUS "CMAKE_CXX_FLAGS:${CMAKE_CXX_FLAGS} ALLSPARK_CBLAS:${ALLSPARK_CBLAS}")
if(ENABLE_AVX2)
list(APPEND ALLSPARK_DEFINITION "-DENABLE_AVX2")
endif()
if(ENABLE_AVX512)
list(APPEND ALLSPARK_DEFINITION "-DENABLE_AVX512")
endif()
if(ENABLE_ARM_V84_V9)
list(APPEND ALLSPARK_DEFINITION "-DENABLE_ARM_V84_V9")
if (ENABLE_BF16)
list(APPEND ALLSPARK_DEFINITION "-DENABLE_BF16")
endif()
endif()
if(ENABLE_GLIBCXX11_ABI)
if(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0))
message(FATAL_ERROR "gcc version < 5, ENABLE_GLIBCXX11_ABI should not be ON")
endif()
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
message("ENABLE_GLIBCXX11_ABI ${ENABLE_GLIBCXX11_ABI}")
else()
message("cxx11 abi is off")
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DALLSPARK_DEBUG_MODE)
endif()
include(cmake/CheckGit.cmake)
CheckGitSetup()
add_definitions(-DALLSPARK_VERSION_MAJOR="${PROJECT_VERSION_MAJOR}")
add_definitions(-DALLSPARK_VERSION_MINOR="${PROJECT_VERSION_MINOR}")
add_definitions(-DALLSPARK_VERSION_PATCH="${PROJECT_VERSION_PATCH}")
# 3rd dependency
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(Protobuf REQUIRED)
# thirdparth
set(INSTALL_LOCATION
${CMAKE_CURRENT_BINARY_DIR}/third_party/install/${CMAKE_BUILD_TYPE})
include(threading)
include(cpp-ipc)
if (ENABLE_ARMCL)
include(armcl)
endif()
include(AutoCCache)
include(dnnl)
include(cblas)
if(MEM_CHECK)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=address>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-omit-frame-pointer>)
endif()
if(LOCK_CHECK)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=thread>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-omit-frame-pointer>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fPIE>)
endif()
if (ENABLE_FP16)
list(APPEND ALLSPARK_DEFINITION "-DENABLE_FP16")
endif()
if (ENABLE_BF16)
list(APPEND ALLSPARK_DEFINITION "-DENABLE_BF16")
endif()
set(AS_MODEL_PROTO_FILE ${CMAKE_CURRENT_SOURCE_DIR}/csrc/proto/allspark.proto)
add_subdirectory(csrc)
if (BUILD_PYTHON)
add_subdirectory(python)
endif()
set(FILE_PATH "/etc/os-release")
file(STRINGS ${FILE_PATH} ID_LINE REGEX "^ID=.*$")
if(ID_LINE)
string(REGEX REPLACE "^ID=(.*)$" "\\1" OS_NAME ${ID_LINE})
# ~S~G~S~^~\
message(STATUS "The OS ID is: ${OS_NAME}")
else()
message(FATAL "No ID line found in file.")
endif()
string (REGEX MATCH "ubuntu" IS_UBUNTU ${OS_NAME})
if (BUILD_PACKAGE)
# config system arch
if(CONFIG_HOST_CPU_TYPE STREQUAL "ARM")
set(CPACK_SYSTEM_ARCHITECTURE "aarch64")
else()
set(CPACK_SYSTEM_ARCHITECTURE "x86_64")
endif()
set(CPACK_PACKAGE_DEVICE_NAME "cpu")
set(CPACK_PACKAGE_VENDOR "Alibaba")
set(CPACK_PACKAGE_NAME "DashInfer")
set(CPACK_PACKAGE_VERSION ${project_version_in_env})
set(CPACK_PACKAGE_VENDOR "Alibaba Tongyi")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "DashInfer AllSpark is a LLM inference engine.")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_DEVICE_NAME "cpu")
if(IS_UBUNTU)
message("build deb package.")
SET(CPACK_GENERATOR "DEB")
set(CPACK_SYSTEM_NAME "ubuntu")
SET(CPACK_THREADS 16)
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES
/.git
/dist
/.*build.*
/build
/\\\\.DS_Store
)
SET(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_ALL libraries headers)
set(CPACK_PACKAGING_INSTALL_PREFIX "")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Alibaba Tongyi") #required
INCLUDE(CPack)
else()
# only support centos like rpm system.
# rpm related settings.
set(CPACK_GENERATOR "RPM")
set(CPACK_SYSTEM_NAME "centos")
set(CPACK_RPM_PACKAGE_LICENSE "Apache2")
set(CPACK_RPM_PACKAGE_GROUP "DashInfer")
set(CPACK_RPM_COMPRESSION_TYPE "gzip")
set(CPACK_RPM_PACKAGE_SUMMARY "DashInfer")
set(CPACK_PACKAGING_INSTALL_PREFIX "")
set(CPACK_RPM_PACKAGE_RELOCATABLE ON)
INCLUDE(CPack)
endif()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_PACKAGE_DEVICE_NAME}.${CPACK_SYSTEM_NAME}.${CPACK_SYSTEM_ARCHITECTURE}")
endif()
#install
include(cmake/install.cmake)