-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
124 lines (99 loc) · 3.5 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
cmake_minimum_required(VERSION 3.20)
project(zhilight)
enable_language(C)
enable_language(CXX)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES "80;89")
endif()
enable_language(CUDA)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED True)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_CUDA_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 0)
set(CMAKE_BUILD_RPATH ${ORIGIN})
set(CMAKE_INSTALL_RPATH ${ORIGIN})
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/)
set(USE_STATIC_NCCL True)
message("CUDA Version: ${CMAKE_CUDA_COMPILER_TOOLKIT_VERSION}")
add_compile_options(
-Wno-deprecated-declarations
-Wno-narrowing
$<$<COMPILE_LANGUAGE:CUDA>:-Xcudafe="--diag_suppress=177,549">)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
set(PYTHON_VERSION ${Python_VERSION})
if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_LESS 12.0.0)
error("Require CUDA 12")
else()
message("Will link against CUDA 12 complied libraries")
endif()
option(WITH_TESTING "Compile zhilight with unit testing" ON)
if(WITH_TESTING)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import torch; \
print(int(torch._C._GLIBCXX_USE_CXX11_ABI))"
OUTPUT_VARIABLE PYTORCH_CXX_ABI
OUTPUT_STRIP_TRAILING_WHITESPACE
# COMMAND_ECHO STDERR
COMMAND_ERROR_IS_FATAL ANY)
list(APPEND CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=${PYTORCH_CXX_ABI}")
list(APPEND CMAKE_CUDA_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=${PYTORCH_CXX_ABI}")
message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")
endif()
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REPLACE "-DNDEBUG" "" CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELWITHDEBINFO}")
message(STATUS "CMAKE_INSTALL_RPATH: ${CMAKE_INSTALL_RPATH}")
include(bmengine)
add_subdirectory(3rd/bmengine)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import pybind11; \
print(pybind11.get_cmake_dir())"
OUTPUT_VARIABLE pybind11_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
find_package(pybind11 REQUIRED)
file(GLOB_RECURSE BACKEND_SOURCES
"src/*.cpp"
"src/*.cu"
)
list(FILTER BACKEND_SOURCES EXCLUDE REGEX "src/py_export/.*\\.cpp$")
list(FILTER BACKEND_SOURCES EXCLUDE REGEX "src/nn/tests/.*$")
add_library(backend STATIC ${BACKEND_SOURCES})
set_property(TARGET backend PROPERTY POSITION_INDEPENDENT_CODE ON)
file(GLOB FLASH_ATTN_LIB "${Python_SITELIB}/flash_attn*.so")
add_library(flash_attn SHARED IMPORTED)
set_property(TARGET flash_attn PROPERTY IMPORTED_LOCATION ${FLASH_ATTN_LIB})
target_include_directories(backend
PUBLIC "src"
PUBLIC "3rd/tensorrt_llm/"
PUBLIC "3rd/flash_decoding"
PUBLIC ${NCCL_INCLUDE_DIRS}
PUBLIC ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
PUBLIC ${Python_SITELIB}/torch/include
)
target_link_directories(backend
PUBLIC "3rd/tensorrt_llm/"
PUBLIC ${NCCL_LIBRARIES}
PUBLIC ${Python_SITELIB}/torch/lib
)
target_link_libraries(backend
PUBLIC bmengine
"-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
flash_attn
)
file(GLOB_RECURSE PYBIND_SOURCES "src/py_export/*.cpp")
pybind11_add_module(C ${PYBIND_SOURCES})
target_compile_definitions(C
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
target_link_libraries(C PRIVATE
bmengine
"-Wl,-Bsymbolic -Wl,-Bsymbolic-functions"
"pthread"
"backend"
)
if(WITH_TESTING)
add_subdirectory(tests/py_export_internal)
add_subdirectory(src/nn/tests)
endif()