-
Notifications
You must be signed in to change notification settings - Fork 130
/
CMakeLists.txt
284 lines (261 loc) · 9.65 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
cmake_minimum_required (VERSION 3.20)
project(tsnecuda)
set (CMAKE_PROJECT_VERSION 3)
set (CMAKE_PROJECT_VERSION_MAJOR 3)
set (CMAKE_PROJECT_VERSION_MINOR 0)
set (CMAKE_PROJECT_VERSION_PATCH 2)
set (CMAKE_PROJECT_VERSION_PATH 0)
set (CMAKE_SKIP_RULE_DEPENDENCY TRUE)
set (CMAKE_EXPORT_COMPILE_COMMANDS 1)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
enable_language(CUDA)
# Options
#-------------------------------------------------------------------------------
option(BUILD_PYTHON "Build python if ON" ON)
#-------------------------------------------------------------------------------
# Build Number Generation
#-------------------------------------------------------------------------------
SET(BUILD_NUMBER 0)
SET(VERSION_STRING "${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH}")
ADD_DEFINITIONS(-DBUILD_NUMBER=${BUILD_NUMBER})
ADD_DEFINITIONS(-DVERSION_STRING=${VERSION_STRING})
# src/exe/main.cu cannot inserting a three-part number (e.g. 3.0.0) in one go without throwing up
ADD_DEFINITIONS(-DVERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR})
ADD_DEFINITIONS(-DVERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR})
ADD_DEFINITIONS(-DVERSION_PATCH=${CMAKE_PROJECT_VERSION_PATCH})
#-------------------------------------------------------------------------------
# CXX Configuration
#-------------------------------------------------------------------------------
set(OPT_FLAGS
-std=c++14
-fopenmp
-mpopcnt
-msse4
-fPIC
-m64
-Wno-sign-compare
-g
-O3
-Wall
-Wextra
-DFINTEGER=int
)
string(REPLACE ";" " " CXX_FLAGS_STR "${CMAKE_CXX_FLAGS} ${OPT_FLAGS}")
set(CMAKE_CXX_FLAGS "${CXX_FLAGS_STR}")
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
#-------------------------------------------------------------------------------
# CUDA Configuration
#-------------------------------------------------------------------------------
find_package(CUDAToolkit REQUIRED)
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()
if(CUDAToolkit_VERSION_MAJOR EQUAL "10")
set(CUDA_ARCH
-gencode=arch=compute_30,code=sm_30
-gencode=arch=compute_35,code=sm_35
-gencode=arch=compute_37,code=sm_37
-gencode=arch=compute_50,code=sm_50
-gencode=arch=compute_52,code=sm_52
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61
-gencode=arch=compute_70,code=sm_70
-gencode=arch=compute_75,code=sm_75
)
elseif(CUDAToolkit_VERSION_MAJOR EQUAL "11" AND CUDAToolkit_VERSION_MINOR LESS "1")
set(CUDA_ARCH
-gencode=arch=compute_35,code=sm_35
-gencode=arch=compute_37,code=sm_37
-gencode=arch=compute_50,code=sm_50
-gencode=arch=compute_52,code=sm_52
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61
-gencode=arch=compute_70,code=sm_70
-gencode=arch=compute_75,code=sm_75
-gencode=arch=compute_80,code=sm_80
)
elseif(CUDAToolkit_VERSION_MAJOR EQUAL "11")
set(CUDA_ARCH
-gencode=arch=compute_35,code=sm_35
-gencode=arch=compute_37,code=sm_37
-gencode=arch=compute_50,code=sm_50
-gencode=arch=compute_52,code=sm_52
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61
-gencode=arch=compute_70,code=sm_70
-gencode=arch=compute_75,code=sm_75
-gencode=arch=compute_80,code=sm_80
-gencode=arch=compute_86,code=sm_86
)
elseif(CUDAToolkit_VERSION_MAJOR EQUAL "12")
set(CUDA_ARCH
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61
-gencode=arch=compute_70,code=sm_70
-gencode=arch=compute_75,code=sm_75
-gencode=arch=compute_80,code=sm_80
-gencode=arch=compute_86,code=sm_86
-gencode=arch=compute_87,code=sm_87
-gencode=arch=compute_89,code=sm_89
-gencode=arch=compute_90,code=sm_90
)
else()
set(CUDA_ARCH
-gencode=arch=compute_30,code=sm_30
-gencode=arch=compute_35,code=sm_35
-gencode=arch=compute_37,code=sm_37
-gencode=arch=compute_50,code=sm_50
-gencode=arch=compute_52,code=sm_52
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61
)
endif()
set(CUDA_OPTS
-O3
-g
-Xptxas '-dlcm=cg'
-Xcompiler '-O3'
-Xcompiler '-fPIC'
-Xcompiler '-fopenmp'
-Xcompiler '-msse4'
-Xcompiler '-m64'
-Xcompiler '-mpopcnt'
-Xcompiler '-g'
-Xlinker 'muldefs'
)
string (REPLACE ";" " " NVCC_FLAGS_STR "${CUDA_ARCH} ${CUDA_OPTS}")
set(CMAKE_CUDA_FLAGS "${NVCC_FLAGS_STR}")
# list(APPEND CUDA_NVCC_FLAGS "--compiler-options -fPIC")
#-------------------------------------------------------------------------------
# OpenMP configuration
#-------------------------------------------------------------------------------
find_package(OpenMP REQUIRED)
#-------------------------------------------------------------------------------
# GTEST Configuration
#-------------------------------------------------------------------------------
find_package(gflags REQUIRED)
# find_package(GLog REQUIRED)
find_package(GTest REQUIRED)
#-------------------------------------------------------------------------------
# ZMQ Configuration
#-------------------------------------------------------------------------------
find_package(ZMQ)
if(NOT ${ZMQ_FOUND})
ADD_DEFINITIONS(-DNO_ZMQ)
set(ZMQ_INCLUDE_DIR "")
set(ZMQ_LIBRARIES "")
message("-- Not building with ZMQ. Interactive visualization disabled. To build with ZMQ use -DWITH_ZMQ=ON")
endif()
#-------------------------------------------------------------------------------
# FAISS Configuration
#-------------------------------------------------------------------------------
find_package(FAISS REQUIRED)
if(NOT ${GPU_FAISS_FOUND})
message("-- GPU FAISS not installed. Please install FAISS for GPU.")
endif()
include_directories(${FAISS_INCLUDE_DIR})
# Project Setup
#-------------------------------------------------------------------------------
include_directories(
src/
src/include
${CUDA_INCLUDE_DIRS}
third_party/
third_party/cxxopts/include/
${ZMQ_INCLUDE_DIR}
)
link_directories(
${CUDA_LIBRARIES}
${CUDA_CUBLAS_LIBRARIES}
)
set(SOURCES
# Utils
src/util/data_utils.cu
src/util/debug_utils.cu
src/util/cuda_utils.cu
src/util/thrust_utils.cu
src/util/distance_utils.cu
src/util/math_utils.cu
src/util/matrix_broadcast_utils.cu
src/util/random_utils.cu
src/util/reduce_utils.cu
# Kernels
src/kernels/apply_forces.cu
src/kernels/attr_forces.cu
src/kernels/rep_forces.cu
src/kernels/perplexity_search.cu
src/kernels/nbodyfft.cu
# Method files
src/ext/pymodule_ext.cu
src/fit_tsne.cu
)
set(PYTHON_SOURCES
src/python/CHANGES.txt
src/python/LICENSE.txt
src/python/MANIFEST.in
src/python/MANIFEST
src/python/README.txt
src/python/setup.py
src/python/tsnecuda/__init__.py
src/python/tsnecuda/TSNE.py
src/python/tsnecuda/test/__init__.py
src/python/docs/FAQ.txt
)
add_library(tsnecuda SHARED ${SOURCES})
# set_property(TARGET tsnecuda PROPERTY POSITION_INDEPENDENT_CODE TRUE)
target_link_libraries(tsnecuda PRIVATE
gflags
gtest
CUDA::cudart
CUDA::cublas
# CUDA::cublasLt
CUDA::cufft
CUDA::cufftw
CUDA::cusparse
OpenMP::OpenMP_CXX
pthread
-Wl,--allow-multiple-definition
${ZMQ_LIBRARIES}
${FAISS_LIBRARIES}
)
# BLAS configuration
#-------------------------------------------------------------------------------
find_package(MKL)
if(MKL_FOUND)
target_link_libraries(tsnecuda PRIVATE ${MKL_LIBRARIES})
else()
find_package(BLAS REQUIRED)
target_link_libraries(tsnecuda PRIVATE ${BLAS_LIBRARIES})
find_package(LAPACK REQUIRED)
target_link_libraries(tsnecuda PRIVATE ${LAPACK_LIBRARIES})
endif()
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Main executable
#-------------------------------------------------------------------------------
add_executable(tsne src/exe/main.cu)
target_link_libraries(tsne tsnecuda)
#-------------------------------------------------------------------------------
# Python library copy and build
#-------------------------------------------------------------------------------
if(BUILD_PYTHON)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
add_custom_target(python_source_files ALL SOURCES ${PYTHON_SOURCES})
add_dependencies(python_source_files tsnecuda)
add_custom_command(TARGET python_source_files POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/src/python $<TARGET_FILE_DIR:tsnecuda>/python
)
add_custom_command(TARGET python_source_files POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:tsnecuda> $<TARGET_FILE_DIR:tsnecuda>/python/tsnecuda)
add_custom_target(write_version_string_to_python ALL SOURCES ${PYTHON_SOURCES})
# Write the version string
add_dependencies(write_version_string_to_python python_source_files)
add_custom_command(TARGET write_version_string_to_python POST_BUILD
COMMAND ${CMAKE_COMMAND} -DVERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR} -DVERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR} -DVERSION_PATCH=${CMAKE_PROJECT_VERSION_PATCH} -DBUILD_NUMBER=${BUILD_NUMBER} -P
${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_python_version_string.cmake)
else()
message("-- Not building python libraries. To build python libraries use -DBUILD_PYTHON=ON")
endif()