forked from cp2k/dbcsr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
441 lines (368 loc) · 14.4 KB
/
Makefile
File metadata and controls
441 lines (368 loc) · 14.4 KB
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#
SHELL = /bin/sh
#
# the home dir is taken from the current directory
#
DBCSRHOME ?= $(CURDIR)
MAKEFILE := $(DBCSRHOME)/Makefile
DOXYGENDIR := $(DBCSRHOME)/doc
BINDIR := $(DBCSRHOME)/bin
LIBDIR ?= $(DBCSRHOME)/lib
OBJDIR ?= $(DBCSRHOME)/obj
PRETTYOBJDIR := $(OBJDIR)/prettified
DOXIFYOBJDIR := $(OBJDIR)/doxified
TOOLSRC := $(DBCSRHOME)/tools
FYPPEXE ?= $(TOOLSRC)/build_utils/fypp/bin/fypp
SRCDIR := $(DBCSRHOME)/src
TESTSDIR := $(DBCSRHOME)/tests
EXAMPLESDIR := $(DBCSRHOME)/examples
PREFIX ?= $(DBCSRHOME)/install
INCLUDEMAKE ?= $(DBCSRHOME)/Makefile.inc
NPROCS ?= 1
# Default Target ============================================================
LIBNAME := dbcsr
LIBRARY := lib$(LIBNAME)
default_target: $(LIBRARY)
# Read the configuration ====================================================
MODDEPS = "lower"
include $(INCLUDEMAKE)
# Read the version ==========================================================
include $(DBCSRHOME)/VERSION
ifeq ($(DATE),)
DATE = "Development Version"
endif
# Set the compute version and NVFLAGS =======================================
ifeq ($(GPUVER),K20X)
ARCH_NUMBER = 35
else ifeq ($(GPUVER),K40)
ARCH_NUMBER = 35
else ifeq ($(GPUVER),K80)
ARCH_NUMBER = 37
else ifeq ($(GPUVER),P100)
ARCH_NUMBER = 60
else ifeq ($(GPUVER),) # Default to the newest GPU
ARCH_NUMBER = 60
else
$(error GPUVER not recognized)
endif
ifneq ($(ARCH_NUMBER),)
NVFLAGS += -arch sm_$(ARCH_NUMBER)
endif
# Test programs =========================================================
include $(TESTSDIR)/Makefile.inc
BIN_TESTS := $(sort $(addprefix $(TESTSDIR)/, $(SRC_TESTS)))
# Set the configuration ============================================
# the only binaries for the moment are the tests
BIN_FILES := $(BIN_TESTS)
BIN_NAMES := $(basename $(notdir $(BIN_FILES)))
#
ifneq ($(LD_SHARED),)
ARCHIVE_EXT := .so
else
ARCHIVE_EXT := .a
endif
# Declare PHONY targets =====================================================
.PHONY : $(BIN_NAMES) \
dirs makedep \
default_target $(LIBRARY) all \
toolversions \
doxify doxifyclean \
pretty prettyclean doxygen/clean doxygen \
install clean realclean help \
version test
# Discover files and directories ============================================
ALL_SRC_DIRS := $(shell find $(SRCDIR) -type d | awk '{printf("%s:",$$1)}')
ALL_SRC_DIRS += $(TESTSDIR)
LIBCUSMM_DIR := $(shell cd $(SRCDIR) ; find . -type d -name "libcusmm")
LIBCUSMM_ABS_DIR := $(shell find $(SRCDIR) -type d -name "libcusmm")
ALL_PKG_FILES := $(shell find $(SRCDIR) -name "PACKAGE")
OBJ_SRC_FILES = $(shell cd $(SRCDIR); find . ! -name "dbcsr_api_c.F" -name "*.F")
OBJ_SRC_FILES += $(shell cd $(SRCDIR); find . -name "*.c")
OBJ_SRC_FILES += $(shell cd $(SRCDIR); find . ! -name "libcusmm.cpp" ! -name "parameters_utils_for_py.cpp" -name "*.cpp")
ifneq ($(NVCC),)
OBJ_SRC_FILES += $(shell cd $(SRCDIR); find . ! -name "tune_*_exe*_part*.cu" ! -name "tune_*_exe*_main*.cu" -name "*.cu")
OBJ_SRC_FILES += $(LIBCUSMM_DIR)/libcusmm.cpp
endif
ifneq ($(CINT),)
OBJ_SRC_FILES += ./dbcsr_api_c.F
PUBLICHEADERS += $(SRCDIR)/dbcsr.h
PUBLICHEADERS += $(SRCDIR)/dbcsr_c.h
PUBLICHEADERS += $(SRCDIR)/DistBCSR.hpp
endif
# OBJECTS used for pretty and doxify
ALL_OBJECTS := $(addsuffix .o, $(basename $(notdir $(OBJ_SRC_FILES))))
ALL_OBJECTS += $(addsuffix .o, $(basename $(notdir $(shell cd $(TESTSDIR); find . -name "*.F"))))
ALL_OBJECTS += $(addsuffix .o, $(basename $(notdir $(shell cd $(TESTSDIR); find . -name "*.c"))))
ALL_OBJECTS += $(addsuffix .o, $(basename $(notdir $(shell cd $(TESTSDIR); find . -name "*.cpp"))))
ALL_OBJECTS += $(addsuffix .o, $(basename $(notdir $(shell cd $(TESTSDIR); find . -name "*.cu"))))
# Included files used by Fypp preprocessor and standard includes
INCLUDED_SRC_FILES := $(filter-out base_uses.f90, $(notdir $(shell find $(SRCDIR) -name "*.f90")))
INCLUDED_SRC_FILES += $(notdir $(shell find $(TESTSDIR) -name "*.f90"))
# Include also source files which won't compile into an object file
ALL_SRC_FILES = $(strip $(subst $(NULL) .,$(NULL) $(SRCDIR),$(NULL) $(OBJ_SRC_FILES)))
ALL_SRC_FILES += $(filter-out base_uses.f90, $(shell find $(SRCDIR) -name "*.f90"))
ALL_SRC_FILES += $(shell find $(SRCDIR) -name "*.h")
ALL_SRC_FILES += $(shell find $(SRCDIR) -name "*.hpp")
# stage 1: create dirs and run makedep.py.
# Afterwards, call make recursively again with -C $(OBJDIR) and INCLUDE_DEPS=true
ifeq ($(INCLUDE_DEPS),)
$(LIBRARY): dirs makedep
@+$(MAKE) --no-print-directory -C $(OBJDIR) -f $(MAKEFILE) $(LIBDIR)/$(LIBRARY)$(ARCHIVE_EXT) INCLUDE_DEPS=true DBCSRHOME=$(DBCSRHOME)
$(BIN_NAMES): $(LIBRARY)
@+$(MAKE) --no-print-directory -C $(OBJDIR) -f $(MAKEFILE) $@ INCLUDE_DEPS=true DBCSRHOME=$(DBCSRHOME)
all: $(LIBRARY)
@+$(MAKE) --no-print-directory -C $(OBJDIR) -f $(MAKEFILE) all INCLUDE_DEPS=true DBCSRHOME=$(DBCSRHOME)
dirs:
@mkdir -p $(OBJDIR)
@mkdir -p $(LIBDIR)
version:
@echo "DCBSR Version: "$(MAJOR)"."$(MINOR)"."$(PATCH)" ("$(DATE)")"
OTHER_HELP += "version : Print DBCSR version"
toolversions:
ifneq ($(FC),)
@echo "=========== FC ==========="
ifeq (Cray,$(shell $(CC) -V 2>&1 | head -n1 | cut -d' ' -f1))
$(FC) -V
else ifeq (IBM,$(shell $(CC) -qversion 2>&1 | head -n1 | cut -d' ' -f1))
$(FC) -qversion
else
$(FC) --version
endif
endif
ifneq ($(CC),)
@echo "=========== CC ==========="
ifeq (Cray,$(shell $(CC) -V 2>&1 | head -n1 | cut -d' ' -f1))
$(CC) -V
else ifeq (IBM,$(shell $(CC) -qversion 2>&1 | head -n1 | cut -d' ' -f1))
$(CC) -qversion
else
$(CC) --version
endif
endif
ifneq ($(NVCC),)
@echo "========== NVCC =========="
$(NVCC) --version
@echo ""
endif
ifneq ($(AR),)
@echo "=========== AR ==========="
$(firstword $(AR)) V
@echo ""
endif
@echo "========== Make =========="
$(MAKE) --version
@echo ""
@echo "========= Python ========="
/usr/bin/env python --version
OTHER_HELP += "toolversions : Print versions of build tools"
else
# stage 2: Include $(OBJDIR)/all.dep, expand target all, and get list of dependencies.
all: $(foreach e, $(BIN_NAMES), $(e))
ifeq ($(BIN_NAME),)
$(BIN_NAMES):
@mkdir -p $(BINDIR)
@+$(MAKE) --no-print-directory -C $(OBJDIR) -f $(MAKEFILE) $(BINDIR)/$@.x INCLUDE_DEPS=true BIN_NAME=$@ BIN_DEPS="$(BIN_DEPS)" DBCSRHOME=$(DBCSRHOME)
else
# stage 3: Perform actual build.
$(BIN_NAME).o: $(BIN_DEPS)
$(BINDIR)/%.x: %.o $(LIBDIR)/$(LIBRARY)$(ARCHIVE_EXT)
$(LD) $(LDFLAGS) -L$(LIBDIR) -o $@ $< $(BIN_DEPS) -l$(LIBNAME) $(LIBS)
endif
endif
# extract help text from doxygen "\brief"-tag
help:
@echo "=================== Default ===================="
@echo -e "$(LIBRARY) Build DBCSR library"
@echo ""
@echo "=================== Binaries ===================="
@echo "all Builds all executables"
@for i in $(BIN_FILES); do \
basename $$i | sed 's/^\(.*\)\..*/\1/' | awk '{printf "%-29s", $$1}'; \
grep "brief" $$i | head -n 1 | sed 's/^.*\\brief\s*//'; \
done
@echo ""
@echo "===================== Tools ====================="
@printf "%s\n" $(TOOL_HELP) | awk -F ':' '{printf "%-28s%s\n", $$1, $$2}'
@echo ""
@echo "================= Other Targets ================="
@printf "%s\n" $(OTHER_HELP) | awk -F ':' '{printf "%-28s%s\n", $$1, $$2}'
@echo "help Print this help text"
ifeq ($(INCLUDE_DEPS),)
install: $(LIBRARY)
@echo "Remove any previous installation directory"
@rm -rf $(PREFIX)
@echo "Copying files ..."
@mkdir -p $(PREFIX)
@mkdir -p $(PREFIX)/lib
@mkdir -p $(PREFIX)/include
@echo -n " ... library ..."
@cp $(LIBDIR)/$(LIBRARY)$(ARCHIVE_EXT) $(PREFIX)/lib
@echo " done."
@+$(MAKE) --no-print-directory -C $(OBJDIR) -f $(MAKEFILE) install INCLUDE_DEPS=true DBCSRHOME=$(DBCSRHOME)
@echo "... installation done at $(PREFIX)."
else
install:
@echo -n " ... modules ..."
@if [[ -n "$(wildcard $(addprefix $(OBJDIR)/, $(PUBLICFILES:.F=.mod)))" ]] ; then \
cp $(addprefix $(OBJDIR)/, $(PUBLICFILES:.F=.mod)) $(PREFIX)/include ; \
echo " done." ; \
else echo " no modules were installed!" ; fi
@echo -n " ... headers ..."
@if [[ -n "$(PUBLICHEADERS)" ]] ; then \
cp $(PUBLICHEADERS) $(PREFIX)/include ; \
echo " done." ; \
else echo " no headers were installed!" ; fi
endif
OTHER_HELP += "install : Install the library and modules under PREFIX=<directory> (default $(PREFIX))"
test:
@export OMP_NUM_THREADS=2 ; \
for test in $(UNITTESTS); do \
mpirun -np $(NPROCS) $(BINDIR)/$$test.x || exit 1; \
done
@export OMP_NUM_THREADS=2 ; \
for input in $(PERFTESTS); do \
mpirun -np $(NPROCS) $(BINDIR)/dbcsr_performance_driver.x $$input || exit 1; \
done
OTHER_HELP += "test : Run the unittests available in tests/"
clean:
rm -rf $(OBJDIR)
rm -f $(LIBCUSMM_ABS_DIR)/parameters.h $(LIBCUSMM_ABS_DIR)/cusmm_kernels.h $(LIBCUSMM_ABS_DIR)/*.so
OTHER_HELP += "clean : Remove intermediate object and mod files, but not the libraries and executables"
#
# delete the intermediate files, the programs and libraries and anything that might be in the objdir or libdir directory
# Use this if you want to fully rebuild an executable (for a given compiler)
#
realclean: clean doxygen/clean
rm -rf $(BINDIR) $(LIBDIR) $(PREFIX)
rm -rf `find $(DBCSRHOME) -name "*.pyc"`
rm -rf `find $(DBCSRHOME) -name "*.callgraph"`
OTHER_HELP += "realclean : Remove all files"
# Prettyfier stuff ==========================================================
vpath %.pretty $(PRETTYOBJDIR)
pretty: $(addprefix $(PRETTYOBJDIR)/, $(ALL_OBJECTS:.o=.pretty)) $(addprefix $(PRETTYOBJDIR)/, $(INCLUDED_SRC_FILES:.f90=.pretty_included))
TOOL_HELP += "pretty : Reformat all source files in a pretty way"
prettyclean:
-rm -rf $(PRETTYOBJDIR)
TOOL_HELP += "prettyclean : Remove prettify marker files"
$(PRETTYOBJDIR)/%.pretty: %.F $(DOXIFYOBJDIR)/%.doxified
@mkdir -p $(PRETTYOBJDIR)
cd $(dir $<); $(TOOLSRC)/prettify/prettify.py --do-backup --backup-dir=$(PRETTYOBJDIR) --src-dir=$(SRCDIR) $(notdir $<)
@touch $@
$(PRETTYOBJDIR)/%.pretty_included: %.f90 $(DOXIFYOBJDIR)/%.doxified_included
@mkdir -p $(PRETTYOBJDIR)
cd $(dir $<); $(TOOLSRC)/prettify/prettify.py --do-backup --backup-dir=$(PRETTYOBJDIR) --src-dir=$(SRCDIR) $(notdir $<)
@touch $@
$(PRETTYOBJDIR)/%.pretty: %.c $(DOXIFYOBJDIR)/%.doxified
# TODO: call indent here?
@mkdir -p $(PRETTYOBJDIR)
@touch $@
$(PRETTYOBJDIR)/%.pretty: %.cpp $(DOXIFYOBJDIR)/%.doxified
# TODO: call indent here?
@mkdir -p $(PRETTYOBJDIR)
@touch $@
$(PRETTYOBJDIR)/%.pretty: %.cu $(DOXIFYOBJDIR)/%.doxified
# TODO: call indent here?
@mkdir -p $(PRETTYOBJDIR)
@touch $@
# Doxyifier stuff ===========================================================
vpath %.doxified $(DOXIFYOBJDIR)
doxify: $(addprefix $(DOXIFYOBJDIR)/, $(ALL_OBJECTS:.o=.doxified)) $(addprefix $(DOXIFYOBJDIR)/, $(INCLUDED_SRC_FILES:.f90=.doxified_included))
TOOL_HELP += "doxify : Autogenerate doxygen headers for subroutines"
doxifyclean:
-rm -rf $(DOXIFYOBJDIR)
TOOL_HELP += "doxifyclean : Remove doxify marker files"
$(DOXIFYOBJDIR)/%.doxified: %.F
$(TOOLSRC)/doxify/doxify.sh $<
@mkdir -p $(DOXIFYOBJDIR)
@touch $@
$(DOXIFYOBJDIR)/%.doxified_included: %.f90
$(TOOLSRC)/doxify/doxify.sh $<
@mkdir -p $(DOXIFYOBJDIR)
@touch $@
$(DOXIFYOBJDIR)/%.doxified: %.c
@mkdir -p $(DOXIFYOBJDIR)
@touch $@
$(DOXIFYOBJDIR)/%.doxified: %.cpp
@mkdir -p $(DOXIFYOBJDIR)
@touch $@
$(DOXIFYOBJDIR)/%.doxified: %.cu
@mkdir -p $(DOXIFYOBJDIR)
@touch $@
# doxygen stuff =============================================================
doxygen/clean:
-rm -rf $(DOXYGENDIR)
TOOL_HELP += "doxygen/clean : Remove the generated doxygen documentation"
# Automatic source code documentation using Doxygen
# Prerequisites:
# - stable doxygen release 1.5.4 (Oct. 27, 2007)
# - graphviz (2.16.1)
# - webdot (2.16)
#
doxygen: doxygen/clean
@mkdir -p $(DOXYGENDIR)
@mkdir -p $(DOXYGENDIR)/html
@echo "<html><body>Sorry, the Doxygen documentation is currently being updated. Please try again in a few minutes.</body></html>" > $(DOXYGENDIR)/html/index.html
cp $(ALL_SRC_FILES) $(DOXYGENDIR)
@for i in $(DOXYGENDIR)/*.F ; do mv $${i} $${i%%.*}.f90; done ;
@cat $(TOOLSRC)/doxify/Doxyfile.template > $(DOXYGENDIR)/Doxyfile
cd $(DOXYGENDIR); doxygen ./Doxyfile 2>&1 | tee ./html/doxygen.out
TOOL_HELP += "doxygen : Generate the doxygen documentation"
# Libcusmm stuff ============================================================
$(LIBCUSMM_ABS_DIR)/parameters.h: $(LIBCUSMM_ABS_DIR)/generate_parameters.py $(wildcard $(LIBCUSMM_ABS_DIR)/parameters_*.txt)
cd $(LIBCUSMM_ABS_DIR); ./generate_parameters.py --gpu_version=$(GPUVER)
$(LIBCUSMM_ABS_DIR)/cusmm_kernels.h: $(LIBCUSMM_ABS_DIR)/generate_kernels.py $(wildcard $(LIBCUSMM_ABS_DIR)/kernels/*.h)
cd $(LIBCUSMM_ABS_DIR); ./generate_kernels.py
# automatic dependency generation ===========================================
MAKEDEPMODE = "normal"
ifeq ($(HACKDEP),yes)
MAKEDEPMODE = "hackdep"
endif
# this happens on stage 1
makedep: $(ALL_SRC_FILES) $(ALL_PKG_FILES) dirs
ifeq ($(LD_SHARED),)
@echo "Removing stale archives ... "
@$(TOOLSRC)/build_utils/check_archives.py $(firstword $(AR)) $(SRCDIR) $(LIBDIR)
endif
@echo "Resolving dependencies ... "
@$(TOOLSRC)/build_utils/makedep.py $(OBJDIR)/all.dep dbcsr $(MODDEPS) $(MAKEDEPMODE) $(ARCHIVE_EXT) $(SRCDIR) $(OBJ_SRC_FILES)
# on stage 2, load the rules generated by makedep.py
ifeq ($(INCLUDE_DEPS), true)
include $(OBJDIR)/all.dep
endif
# ================= Stuff need for compiling (stage 2) ======================
# These rules are executed in a recursive call to make -C $(OBJDIR)
# The change of $(CURDIR) allows to find targets without abs paths and vpaths.
### Slave rules ###
vpath %.F $(ALL_SRC_DIRS)
vpath %.h $(ALL_SRC_DIRS)
vpath %.hpp $(ALL_SRC_DIRS)
vpath %.f90 $(ALL_SRC_DIRS)
vpath %.cu $(ALL_SRC_DIRS)
vpath %.c $(ALL_SRC_DIRS)
vpath %.cpp $(ALL_SRC_DIRS)
# $(FCLOGPIPE) can be used to store compiler output, e.g. warnings, for each F-file separately.
# This is used e.g. by the convention checker.
FYPPFLAGS ?= -n
%.o %.mod: %.F
@rm -f $*.mod
$(FYPPEXE) $(FYPPFLAGS) $< $*.F90
$(FC) -c $(FCFLAGS) -D__SHORT_FILE__="\"$(notdir $<)\"" -I'$(dir $<)' -I'$(SRCDIR)' $*.F90 $(FCLOGPIPE)
%.o: %.c
$(CC) -c $(CFLAGS) $<
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $<
libcusmm.o: libcusmm.cpp parameters.h cusmm_kernels.h
$(CXX) -c $(CXXFLAGS) -DARCH_NUMBER=$(ARCH_NUMBER) $<
%.o: %.cu
$(NVCC) -c $(NVFLAGS) -I'$(SRCDIR)' $<
libcusmm_benchmark.o: libcusmm_benchmark.cu parameters.h
$(NVCC) -c $(NVFLAGS) -I'$(SRCDIR)' $<
$(LIBDIR)/%:
ifneq ($(LD_SHARED),)
@echo "Creating shared library $@"
@$(LD_SHARED) -o $(@:.a=.so) $^
else
@echo "Updating archive $@"
@$(AR) $@ $?
endif
#EOF