-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmakefile
235 lines (185 loc) · 5.19 KB
/
makefile
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
# This makefile can build and install the magmadnn library
# include any user-defined compile options (pre-sets)
include make.inc
# compilers for c++ and cu
CXX ?= g++
NVCC ?= nvcc
#MKLDNN flag
USE_MKLDNN ?= 0
# CUDA flag
TRY_CUDA ?= 1
# locations of cuda and magma installations
CUDADIR ?= /usr/local/cuda
# Location of cuDNN library
CUDNN_INC_DIR ?=
CUDNN_LIB_DIR ?=
MAGMADIR ?= /usr/local/magma
BLASDIR ?= /usr/local/openblas
BLASINC ?= $(BLASDIR)/include
BLASLIB_PATH ?= $(BLASDIR)/lib
BLASLIB ?= openblas
# Distributed memory version
USE_MPI ?= 0
# where to install magmadnn (make must have sudo access if prefix is root privileged)
prefix ?= /usr/local/magmadnn
# headers needed for library compilation
INC := -I./include -I$(BLASINC)
# Add cuDNN include directory
ifneq ($(CUDNN_INC_DIR),)
INC += -I$(CUDNN_INC_DIR)
endif
# libs to link with
LIBDIRS := -L$(BLASLIB_PATH)
LIBS = -l$(BLASLIB)
# Add cuDNN lib directory
ifneq ($(CUDNN_LIB_DIR),)
LIBDIRS += -L$(CUDNN_LIB_DIR)
endif
ifeq ($(USE_MKLDNN),1)
MKLDNN_MACRO = -DMAGMADNN_HAVE_MKLDNN
LIBS += -lmkldnn
endif
USE_CUDA = 0
ifeq ($(TRY_CUDA),1)
# use nvcc to determine if we should compile for gpu or not
GPU_TARGET ?= Kepler
ifneq ($(shell which nvcc),)
include make.device
CUDA_MACRO = -DMAGMADNN_HAVE_CUDA -D_HAS_CUDA_
INC += -I$(CUDADIR)/include -I$(MAGMADIR)/include
LIBDIRS += -L$(CUDADIR)/lib64 -L$(MAGMADIR)/lib
LIBS += -lcudart -lcudnn -lmagma
USE_CUDA=1
endif
endif
# individual flags for compilation
OPTIMIZATION_LEVEL ?= -O3
WARNINGS ?= -Wall
FPIC ?= -fPIC
CXX_VERSION ?= -std=c++11
DEBUG ?= 0
PROFILE_FLAGS ?=
# this flag dictates whether to use openmp or not for some CPU code
# set it to false by default
USE_OPENMP ?= 0
ifeq ($(USE_OPENMP),1)
OPENMP_FLAGS = -fopenmp -D_USE_OPENMP_
endif
# set optimization to Og for debugging
ifeq ($(DEBUG),1)
OPTIMIZATION_LEVEL = -O0
endif
# the entire flags for compilation
CXXFLAGS := $(OPTIMIZATION_LEVEL) $(WARNINGS) $(CXX_VERSION) $(CUDA_MACRO) $(MKLDNN_MACRO) $(FPIC) -MMD $(OPENMP_FLAGS) $(PROFILE_FLAGS)
NVCCFLAGS := $(CXX_VERSION) $(OPTIMIZATION_LEVEL) -Xcompiler "$(CXXFLAGS)" $(NV_SM) $(NV_COMP)
LD_FLAGS := $(LIBDIRS) $(LIBS)
# include -g for debugging
ifeq ($(DEBUG),1)
CXXFLAGS += -g -DDEBUG
NVCCFLAGS += -g -DDEBUG
endif
# make these available to child makefiles
export CXX
export NVCC
export INC
export LD_FLAGS
export prefix
export CUDADIR
export MAGMADIR
export OPTIMIZATION_LEVEL
export WARNINGS
export CXX_VERSION
export CUDA_MACRO
export USE_CUDA
export CXXFLAGS
export NVCCFLAGS
export LIBDIRS
export LIBS
export USE_MPI
export USE_MKLDNN
# default extension for object files
o_ext ?= o
# where are the source files (files that need to be compiled) found
TARGET_DIRS ?= src
all: $(TARGET_DIRS)
# step into source directories and use their makefiles
$(TARGET_DIRS):
@echo "==== Building Sources ===="
ifeq ($(USE_CUDA),1)
@echo "CUDA installation found. Building GPU/CPU."
else
@echo "(X) CUDA installation not found. Building CPU-only."
endif
$(MAKE) -C $@
@echo
# collect all the object files from the source directories (deepest: src/compute/*/*.cpp)
OBJ_FILES = $(wildcard $(TARGET_DIRS)/*.$(o_ext) $(TARGET_DIRS)/*/*.$(o_ext) $(TARGET_DIRS)/*/*/*.$(o_ext))
# collect dependency files (.d)
DEP_FILES = $(wildcard $(TARGET_DIRS)/*.d $(TARGET_DIRS)/*/*.d $(TARGET_DIRS)/*/*/*.d)
# MAKE THE LIB FILES
LIB_DIR ?= lib
# archiver and flags
ARCH ?= ar
ARCH_FLAGS ?= cr
RANLIB ?= ranlib
RANLIB_FLAGS ?=
# set EXT to .dylib and FLAG to -dynamiclib for MAC OS
LIBSHARED_EXT ?= .so
LIBSHARED_FLAG ?= -shared
libstatic := $(LIB_DIR)/libmagmadnn.a
libshared := $(LIB_DIR)/libmagmadnn$(LIBSHARED_EXT)
lib: $(TARGET_DIRS) static shared
static: $(libstatic)
shared: $(libshared)
$(libstatic):
@echo "==== building static lib ===="
mkdir -p $(LIB_DIR)
$(ARCH) $(ARCH_FLAGS) $@ $(OBJ_FILES)
$(RANLIB) $(RANLIB_FLAGS) $@
@echo
# MacOS specific install information
ostype = ${shell echo $${OSTYPE}}
ifneq ($(findstring darwin, ${ostype}),)
$(libshared): LIBSHARED_FLAG += -install_name $(prefix)/lib/$(notdir $(libshared))
endif
$(libshared):
@echo "==== building shared lib ===="
mkdir -p $(LIB_DIR)
$(CXX) $(LIBSHARED_FLAG) $(FPIC) -o $@ $(OBJ_FILES) -L./lib $(LD_FLAGS)
@echo
# make the testers
TESTING_DIR ?= testing
testing:
@echo "==== building testing sources ===="
# step into the testing directories and call their makefiles
$(MAKE) -C $(TESTING_DIR)
@echo
# make the examples
EXAMPLE_DIR ?= examples
examples:
@echo "==== building examples ===="
# step into example directory and use its makefile
$(MAKE) -C $(EXAMPLE_DIR)
@echo
# build the library first, then link the lib together.
# install copies the newly made libs into prefix
install: lib
@echo "==== installing libs ===="
mkdir -p $(prefix)
mkdir -p $(prefix)/include
mkdir -p $(prefix)/lib
cp -r ./include/* $(prefix)/include
cp $(libstatic) $(prefix)/lib
cp $(libshared) $(prefix)/lib
@echo
# build the docs files and the refman.pdf
# DOCS_DIR ?= docs
# docs:
# ifneq ($(shell which doxygen),)
# doxygen doxygen.config
# $(MAKE) -C $(DOCS_DIR)/latex
# endif
# TODO: change to call clean on subdirectory makefiles
clean:
rm $(OBJ_FILES) $(DEP_FILES)
.PHONY: $(TARGET_DIRS) $(libstatic) $(libshared) $(TESTING_DIR) $(EXAMPLE_DIR) $(DOCS_DIR)