This repository has been archived by the owner on Oct 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 172
/
CMakeLists.txt
145 lines (127 loc) · 5.18 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
cmake_minimum_required(VERSION 2.8)
function(find_cudnn)
set(CUDNN_ROOT "" CACHE PATH "cuDNN root path")
find_path(CUDNN_INCLUDE_DIRS cudnn.h
PATHS ${CUDNN_ROOT}
${CUDNN_ROOT}/include
DOC "cuDNN include path")
find_library(CUDNN_LIBRARIES NAMES libcudnn.so
PATHS ${CUDNN_ROOT}
${CUDNN_ROOT}/lib
${CUDNN_ROOT}/lib64
DOC "cuDNN library path")
if(CUDNN_INCLUDE_DIRS AND CUDNN_LIBRARIES)
set(CUDNN_FOUND TRUE PARENT_SCOPE)
message(STATUS "Found cuDNN (include: ${CUDNN_INCLUDE_DIRS}, library: ${CUDNN_LIBRARIES})")
mark_as_advanced(CUDNN_INCLUDE_DIRS CUDNN_LIBRARIES)
else()
MESSAGE(FATAL_ERROR "Failed to find cuDNN in path: ${CUDNN_ROOT}")
endif()
endfunction()
function(find_blas)
set(BLAS_ROOT "" CACHE PATH "BLAS root path")
find_path(CBLAS_INCLUDE_DIRS cblas.h
PATHS ${BLAS_ROOT}
${BLAS_ROOT}/include
DOC "BLAS include path")
find_library(CBLAS_LIBRARIES NAMES libcblas.so
PATHS ${BLAS_ROOT}
${BLAS_ROOT}/lib
${BLAS_ROOT}/lib64
DOC "BLAS library path")
if(CBLAS_INCLUDE_DIRS AND CBLAS_LIBRARIES)
set(CBLAS_FOUND TRUE PARENT_SCOPE)
message(STATUS "Found BLAS (include: ${CBLAS_INCLUDE_DIRS}, library: ${CBLAS_LIBRARIES})")
mark_as_advanced(CBLAS_INCLUDE_DIRS CBLAS_LIBRARIES)
else()
MESSAGE(FATAL_ERROR "Failed to find BLAS in path: ${BLAS_ROOT}. If you are using other BLAS than cBLAS, please link your .so into libcblas.so.")
endif()
endfunction()
function(find_ps)
set(PS_ROOT "" CACHE PATH "minervaps root path")
find_library(PS_LIBRARIES NAMES libminervaps.a
PATHS ${PS_ROOT}/build
DOC "PS library path")
if(PS_LIBRARIES)
set(PS_FOUND TRUE PARENT_SCOPE)
message(STATUS "Found PS (library: ${PS_LIBRARIES})")
mark_as_advanced(PS_LIBRARIES)
else()
MESSAGE(FATAL_ERROR "Failed to find PS in path: ${PS_ROOT}. Make sure you have built ps with 'make minerva'.")
endif()
endfunction()
project(Minerva)
option(BUILD_CXX_APPS "build C++ applications" OFF)
option(BUILD_TESTS "build all unittests" OFF)
option(BUILD_CPU_ONLY "build cpu-only version" OFF)
option(BUILD_WITH_PS "build with parameter server support" OFF)
option(BUILD_WITH_BLAS "build with BLAS library for CPU" OFF)
message(STATUS "cmake generator: ${CMAKE_GENERATOR}")
message(STATUS "cmake build tool: ${CMAKE_BUILD_TOOL}")
message(STATUS "cmake build type: ${CMAKE_BUILD_TYPE}")
############################################# compiler flags
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" SUPPORTS_CXX11)
check_cxx_compiler_flag("-flto" SUPPORTS_LTO)
check_cxx_compiler_flag("-mssse3" SUPPORTS_MSSSE3)
check_cxx_compiler_flag("-ftree-vectorize" SUPPORTS_VECTORIZE)
set(COMPILER_FLAGS "-Wall -fPIC -march=native")
set(GENERAL_FLAGS_DEBUG "${COMPILER_FLAGS} -O0 -g")
set(GENERAL_FLAGS_RELEASE "${COMPILER_FLAGS} -O2 -mtune=native -mssse3")
set(CMAKE_CXX_FLAGS_DEBUG "${GENERAL_FLAGS_DEBUG} -std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "${GENERAL_FLAGS_RELEASE} -std=c++11 -DNDEBUG")
############################################# find packages
set(CORE_DEPS "")
find_package(Threads REQUIRED)
set(CORE_DEPS ${CORE_DEPS} ${CMAKE_THREAD_LIBS_INIT})
if (BUILD_CPU_ONLY)
message(STATUS "build cpu-only version; cuda is not enabled!")
else(BUILD_CPU_ONLY)
set(CUDA_TOOLKIT_ROOT_DIR ${CUDA_ROOT})
find_package(CUDA)
if (CUDA_FOUND)
if (CUDA_VERSION_MAJOR LESS 6)
message(FATAL_ERROR "Need CUDA 6 for uniform addressing")
endif (CUDA_VERSION_MAJOR LESS 6)
include_directories(SYSTEM ${CUDA_INCLUDE_DIRS})
add_definitions(-DHAS_CUDA)
string(REPLACE " " "\\\",\\\"" CUDA_CONCAT_DEBUG "${GENERAL_FLAGS_DEBUG}")
string(REPLACE " " "\\\",\\\"" CUDA_CONCAT_RELEASE "${GENERAL_FLAGS_RELEASE}")
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
set(CUDA_NVCC_FLAGS_DEBUG "-G -Xcompiler \\\"${CUDA_CONCAT_DEBUG}\\\"")
set(CUDA_NVCC_FLAGS_RELEASE "-Xcompiler \\\"${CUDA_CONCAT_RELEASE}\\\"")
set(CUDA_NVCC_FLAGS "-arch sm_35")
find_cudnn()
include_directories(SYSTEM ${CUDNN_INCLUDE_DIRS})
else ()
message(FATAL_ERROR "CUDA enabled but not found")
endif ()
endif(BUILD_CPU_ONLY)
############################################# third party libraries
add_subdirectory(third_party)
include_directories(SYSTEM ${THIRD_INCLUDE_PATH})
set(CORE_DEPS ${CORE_DEPS} ${THIRD_LIBS})
############################################# macros
if(BUILD_WITH_PS)
add_definitions(-DHAS_PS)
find_ps()
message(STATUS "PS enabled, forcing BUILD_TESTS to 0")
set(BUILD_TESTS 0)
endif()
if(BUILD_WITH_BLAS)
add_definitions(-DHAS_CBLAS)
find_blas()
include_directories(SYSTEM ${CBLAS_INCLUDE_DIRS})
endif()
message(STATUS "build C++ applications -- ${BUILD_CXX_APPS}")
message(STATUS "build unit tests -- ${BUILD_TESTS}")
message(STATUS "build cpu-only version -- ${BUILD_CPU_ONLY}")
message(STATUS "build with parameter server support -- ${BUILD_WITH_PS}")
message(STATUS "build with BLAS library for CPU -- ${BUILD_WITH_BLAS}")
add_subdirectory(minerva)
if(BUILD_CXX_APPS)
add_subdirectory(apps)
endif()
if(BUILD_TESTS)
add_subdirectory(tests)
endif()