forked from MagmaDNN/magmadnn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
317 lines (231 loc) · 7.87 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
cmake_minimum_required(VERSION 3.9)
project(MagmaDNN LANGUAGES C CXX VERSION 1.0.0 DESCRIPTION "A simple deep learning framework in C++")
# include(CheckSymbolExists)
include(CheckFunctionExists)
include(ExternalProject)
########################################
# Compiling options
set(default_build_type "RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Using default build type '${default_build_type}' because none was specified")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build (Debug, Release, MinSizeRel, RelWithDebInfo)" FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
########################################
# MagmaDNN options
option(MAGMADNN_ENABLE_CUDA "Enable use of CUDA library and compilation of CUDA kernel" OFF)
option(MAGMADNN_ENABLE_MPI "Enable distributed memory routines using MPI" OFF)
option(MAGMADNN_ENABLE_OMP "Enable parallelization using OpenMP library" OFF)
option(MAGMADNN_ENABLE_MKLDNN "Enable use of MKLDNN library" OFF)
option(MAGMADNN_BUILD_MKLDNN "Enable build of MKLDNN from source" OFF)
option(MAGMADNN_BUILD_DOC "Generate documentation" OFF)
option(MAGMADNN_BUILD_EXAMPLES "Build MagmaDNN examples" ON)
option(MAGMADNN_BUILD_TESTS "Generate build files for unit tests" OFF)
option(MAGMADNN_BUILD_SHARED_LIBS "Build shared (.so, .dylib, .dll) libraries" ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(MAGMADNN_HAVE_CUDA FALSE)
set(MAGMADNN_HAVE_OMP FALSE)
add_definitions(-DMAGMADNN_CMAKE_BUILD)
########################################
# BLAS
set(LBLAS "" CACHE STRING "BLAS library")
# If LBLAS not set, use environement variable
if(LBLAS)
set(BLAS_LIBRARIES ${LBLAS})
elseif(DEFINED ENV{BLAS_LIB})
set(BLAS_LIBRARIES $ENV{BLAS_LIB})
endif()
if(DEFINED BLAS_LIBRARIES)
message(STATUS "BLAS libraries: ${BLAS_LIBRARIES}")
set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
check_function_exists("dgemm" BLAS_FOUND)
unset(CMAKE_REQUIRED_LIBRARIES)
if(NOT BLAS_FOUND)
message(ERROR "User supplied BLAS is NOT working")
endif()
else()
find_package(BLAS)
endif()
if(BLAS_FOUND)
set(LIBS ${LIBS} ${BLAS_LIBRARIES})
else()
message(FATAL_ERROR "BLAS NOT found")
endif (BLAS_FOUND)
########################################
# LAPACK
set(LLAPACK "" CACHE STRING "LAPACK library")
# If LBLAS not set, use environement variable
if(LLAPACK)
set(LAPACK_LIBRARIES ${LLAPACK})
elseif(DEFINED ENV{LAPACK_LIB})
set(LAPACK_LIBRARIES $ENV{LAPACK_LIB})
endif()
if(DEFINED LAPACK_LIBRARIES)
set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
check_function_exists("dpotrf" LAPACK_FOUND)
unset(CMAKE_REQUIRED_LIBRARIES)
if(NOT LAPACK_FOUND)
message(ERROR "User supplied LAPACK is NOT working")
endif()
else()
find_package(LAPACK)
endif()
if (LAPACK_FOUND)
set(LIBS ${LIBS} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
else()
message(FATAL_ERROR "LAPACK library NOT found")
endif (LAPACK_FOUND)
########################################
# CUDA
if (MAGMADNN_ENABLE_CUDA)
include(CheckLanguage)
check_language(CUDA)
enable_language(CUDA)
# CUDA headers directory
set(CUDA_INCLUDE_DIRS ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
message(STATUS "CUDA include directories: ${CUDA_INCLUDE_DIRS}")
# Find cudart library
find_library(CUDA_RUNTIME_LIBS_DYNAMIC cudart
HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
# find_library(CUDA_RUNTIME_LIBS_STATIC cudart_static
# HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
set(CUDA_RUNTIME_LIBS "${CUDA_RUNTIME_LIBS_DYNAMIC}" CACHE STRING "Path to a library" FORCE)
# set(CUDA_RUNTIME_LIBS "${CUDA_RUNTIME_LIBS_STATIC}" CACHE STRING "Path to a library" FORCE)
message(STATUS "CUDA runtime library: ${CUDA_RUNTIME_LIBS}")
set(LIBS ${LIBS} ${CUDA_RUNTIME_LIBS})
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_EXTENSIONS OFF)
add_definitions(-DHAVE_CUDA)
add_definitions(-D_HAS_CUDA_)
add_definitions(-DMAGMADNN_HAVE_CUDA)
set(MAGMADNN_HAVE_CUDA TRUE)
set(MAGMADNN_NVCC_ARCHS "60;61;70;75" CACHE STRING "The SM architectures to build code for.")
# Set NVCC arguments
foreach(ARCH ${MAGMADNN_NVCC_ARCHS})
string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_${ARCH},code=sm_${ARCH}")
endforeach()
########################################
# Find cuBLAS library
find_library(CUBLAS cublas
HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
message(STATUS "cuBLAS: ${CUBLAS}")
set(LIBS ${LIBS} ${CUBLAS})
########################################
# Find Magma library
set(MAGMA_DIR "" CACHE STRING "Magam install directory")
# message(STATUS "ENV{MAGMA_DIR}: $ENV{MAGMA_DIR}")
if(DEFINED ENV{MAGMA_DIR})
set(MAGMA_DIR $ENV{MAGMA_DIR})
# message(STATUS "Magma directory: ${MAGMA_DIR}")
elseif(DEFINED ENV{MAGMADIR})
set(MAGMA_DIR $ENV{MAGMADIR})
endif()
find_library(MAGMA_LIBRARIES magma
HINTS ${MAGMA_DIR} /usr/local/magma
PATH_SUFFIXES lib)
find_path(MAGMA_INCLUDE_DIRS magma.h
HINTS ${MAGMA_DIR} /usr/local/magma
PATH_SUFFIXES include)
# find_library(MAGMA)
if (MAGMA_LIBRARIES)
set(MAGMA_FOUND TRUE)
else ()
SET(MAGMA_FOUND FALSE)
endif ()
if(MAGMA_FOUND)
message(STATUS "Magma include directories: ${MAGMA_INCLUDE_DIRS}")
else()
message(FATAL_ERROR " Magma NOT found")
endif()
set(LIBS ${LIBS} ${MAGMA_LIBRARIES})
########################################
# Find cuDNN library
set(CUDNN_DIR "" CACHE STRING "cuDNN install directory")
find_library(CUDNN_LIBRARIES cudnn
HINTS ${CUDNN_DIR}
PATH_SUFFIXES lib64)
find_path(CUDNN_INCLUDE_DIRS cudnn.h
HINTS ${CUDNN_DIR}
PATH_SUFFIXES include)
if (CUDNN_LIBRARIES)
set(CUDNN_FOUND TRUE)
else ()
SET(CUDNN_FOUND FALSE)
endif ()
if(CUDNN_FOUND)
message(STATUS "cuDNN libraries: ${CUDNN_LIBRARIES}")
message(STATUS "cuDNN include directories: ${CUDNN_INCLUDE_DIRS}")
else()
message(FATAL_ERROR " cuDNN NOT found")
endif()
set(LIBS ${LIBS} ${CUDNN_LIBRARIES})
endif()
########################################
# OpenMP
if (MAGMADNN_ENABLE_OMP)
find_package(OpenMP REQUIRED)
if (OPENMP_FOUND)
add_definitions(-DHAVE_OMP)
add_definitions(-DMAGMADNN_HAVE_OMP)
set(MAGMADNN_HAVE_OMP TRUE)
endif()
endif()
########################################
# MKLDNN
if (MAGMADNN_ENABLE_MKLDNN)
# add_definitions(-D MAGMADNN_HAVE_MKLDNN)
set(MAGMADNN_HAVE_MKLDNN TRUE)
if (MAGMADNN_BUILD_MKLDNN)
include(cmake/mkldnn.cmake)
else()
find_library(ONEDNN_LIBRARIES mkldnn)
if (ONEDNN_LIBRARIES)
set(ONEDNN_FOUND TRUE)
else ()
SET(ONEDNN_FOUND FALSE)
endif ()
if(ONEDNN_FOUND)
message(STATUS "oneDNN libraries: ${ONEDNN_LIBRARIES}")
else()
message(FATAL_ERROR " oneDNN NOT found")
endif()
set(LIBS ${LIBS} ${ONEDNN_LIBRARIES})
endif()
endif()
########################################
# MPI
if (MAGMADNN_ENABLE_MPI)
find_package(MPI REQUIRED)
add_definitions(-D MAGMADNN_HAVE_MPI)
set(MAGMADNN_HAVE_MPI TRUE)
message(STATUS "MPI C++ libraries: ${MPI_CXX_LIBRARIES}")
set(LIBS ${LIBS} ${MPI_CXX_LIBRARIES})
endif()
########################################
# Configuration file
configure_file(
${MagmaDNN_SOURCE_DIR}/include/magmadnn/config.h.in
${MagmaDNN_BINARY_DIR}/include/magmadnn/config.h
@ONLY)
########################################
# Load CMake helpers
include(cmake/build_helpers.cmake)
include(cmake/install_helpers.cmake)
if(MAGMADNN_BUILD_TESTS)
include(cmake/create_test.cmake)
endif()
########################################
# Subdirectories
add_subdirectory(src)
if(MAGMADNN_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(MAGMADNN_BUILD_TESTS)
enable_testing()
include(CTest)
add_subdirectory(testing)
endif()
magmadnn_install()