-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
219 lines (165 loc) · 6.03 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
LIB_NAME := HyWall
ifndef PARALLEL
PARALLEL := MPI
endif
ifndef ALLOW_DEBUG_EXT
ALLOW_DEBUG_EXT := 0
endif
ifndef OPTLEVEL
OPTLEVEL := 0
endif
ifndef CUDA_ENABLE
CUDA_ENABLE := 0
endif
ifndef PROBLEM_DIMENSION
PROBLEM_DIMENSION := 2
endif
ifndef DEBUG_LEVEL
DEBUG_LEVEL := 0
endif
ifndef BITCART_SOURCE_PATH
BITCART_SOURCE_PATH := THEREISNOBASEPATHFORHYWALLINSTALL
endif
WM_BASEIDIR = $(shell pwd)
WM_SRC_DIR := ${WM_BASEIDIR}/src
WM_LIB_DIR := ${WM_BASEIDIR}/lib
WM_OBJ_DIR := ${WM_BASEIDIR}/obj
WM_HDR_DIR := ${WM_BASEIDIR}/include
WM_PRP_DIR := ${WM_BASEIDIR}/maketools
WM_DOC_DIR := ${WM_BASEIDIR}/docs
WM_FRT_DIR := ${WM_BASEIDIR}/fortran
WM_TST_DIR := ${WM_BASEIDIR}/testing
PREPROCESSOR := ${WM_PRP_DIR}/hyWallPreProcess.py
POSTPROCESSOR := ${WM_PRP_DIR}/hyWallPostProcess.py
WM_IFLAGS := -I${WM_HDR_DIR}
export WMLIB_INCLUDE_CONFIG=-I${WM_HDR_DIR} -I${BITCART_SRC}/navier_stokes_newest -L${WM_LIB_DIR} -l${LIB_NAME}
SRC_FILES_HYBRID := $(wildcard ${WM_SRC_DIR}/hybrid/*.cpp)
SRC_FILES_HOST := $(wildcard ${WM_SRC_DIR}/host/*.cpp)
SRC_FILES_CUDA := $(wildcard ${WM_SRC_DIR}/cuda/*.cu)
HDR_FILES_HYBRID := $(wildcard ${WM_SRC_DIR}/hybrid/*.h)
HDR_FILES_HOST := $(wildcard ${WM_SRC_DIR}/host/*.h)
HDR_FILES_CUDA := $(wildcard ${WM_SRC_DIR}/cuda/*.h)
HEADER_FILES := ${HDR_FILES_HYBRID}
HEADER_FILES += ${HDR_FILES_HOST}
HEADER_FILES += ${HDR_FILES_CUDA}
OBJ_FILES_HYBRID_HOST := $(patsubst ${WM_SRC_DIR}/numerics/%.cpp,$(WM_OBJ_DIR)/%.o,$(SRC_FILES_HYBRID))
OBJ_FILES_HYBRID_DEVICE := $(patsubst ${WM_SRC_DIR}/numerics/%.cpp,$(WM_OBJ_DIR)/K_%.o,$(SRC_FILES_HYBRID))
OBJ_FILES_HOST := $(patsubst ${WM_SRC_DIR}/host/%.cpp,$(WM_OBJ_DIR)/%.o,$(SRC_FILES_HOST))
OBJ_FILES_CUDA := $(patsubst ${WM_SRC_DIR}/kernel/%.cu,$(WM_OBJ_DIR)/%.o,$(SRC_FILES_CUDA))
TARGET := ${WM_LIB_DIR}/lib${LIB_NAME}.a
PY_EXE := $(shell which python3)
CC_HOST := mpicxx
CC_DEVICE := nvcc -ccbin=mpicxx
ifneq (${PARALLEL}, MPI)
CC_HOST := g++
CC_DEVICE := none
endif
CU_O_TARGET_NAME := ${WM_OBJ_DIR}/CU_dlink.o
ifeq (${CUDA_ENABLE}, 1)
LINK_STEP := link_step
CU_O_TARGET := ${CU_O_TARGET_NAME}
LCUDA := -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lcudadevrt -lcudart
else
LINK_STEP :=
OBJ_FILES_HYBRID_DEVICE :=
CUDA_ENABLE := 0
OBJ_FILES_CUDA :=
CU_O_TARGET :=
LCUDA :=
endif
COMPILE_TIME_OPT += -DCUDA_ENABLE=${CUDA_ENABLE}
COMPILE_TIME_OPT += -DDEBUG_LEVEL=${DEBUG_LEVEL}
COMPILE_TIME_OPT += -DALLOW_DEBUG_EXT=${ALLOW_DEBUG_EXT}
COMPILE_TIME_OPT += -DPARALLEL=${PARALLEL}
COMPILE_TIME_OPT += -DMAX_BUFFERS=1024
DEVICE_FLAGS := -O${OPTLEVEL} -x cu -rdc=true -Xcompiler -fPIC ${COMPILE_TIME_OPT} -dc
DEVICE_DLINK_FLAGS := -Xcompiler -fPIC -rdc=true -dlink
HOST_FLAGS := -O${OPTLEVEL} -Wno-unknown-pragmas -fPIC -fpermissive -std=c++11 -c ${LCUDA}
export CUDA_ENABLE
LZLIB :=
ifeq (${ALLOW_DEBUG_EXT}, 1)
LZLIB := -lz
endif
DO_CLEAN :=
ifeq (1, ${CUDA_ENABLE})
ifeq (,$(wildcard ${CU_O_TARGET_NAME}))
DO_CLEAN := clean
endif
endif
ifeq (0, ${CUDA_ENABLE})
ifneq (,$(wildcard ${CU_O_TARGET_NAME}))
DO_CLEAN := clean
endif
endif
OBJ_FILES_HYBRID_HOST := $(patsubst ${WM_SRC_DIR}/hybrid/%.cpp,$(WM_OBJ_DIR)/%.o,$(SRC_FILES_HYBRID))
OBJ_FILES_HYBRID_DEVICE := $(patsubst ${WM_SRC_DIR}/hybrid/%.cpp,$(WM_OBJ_DIR)/K_%.o,$(SRC_FILES_HYBRID))
OBJ_FILES_HOST := $(patsubst ${WM_SRC_DIR}/host/%.cpp,$(WM_OBJ_DIR)/%.o,$(SRC_FILES_HOST))
OBJ_FILES_CUDA := $(patsubst ${WM_SRC_DIR}/cuda/%.cu,$(WM_OBJ_DIR)/%.o,$(SRC_FILES_CUDA))
ifeq (0, ${CUDA_ENABLE})
OBJ_FILES_CUDA :=
OBJ_FILES_HYBRID_DEVICE :=
endif
LIB_OBJECTS := ${OBJ_FILES_HOST} ${OBJ_FILES_HYBRID_HOST} ${OBJ_FILES_CUDA} ${OBJ_FILES_HYBRID_DEVICE} ${CU_O_TARGET}
LIB_SOURCES := ${HEADER_FILES} ${SRC_FILES_HYBRID} ${SRC_FILES_HOST} ${SRC_FILES_CUDA}
export HWPP_OUT=${WM_HDR_DIR}/HWPP.hpp
export FORCE_NO_CLEAN=1
ifndef STATIC_LIB
STATIC_LIB := 1
endif
final_target := final_dynamic
ifeq (${STATIC_LIB},1)
final_target := final_static
endif
.PHONY: final preprocess postprocess
postprocess: final
${PY_EXE} ${POSTPROCESSOR}
final: ${final_target}
final_dynamic: ${DO_CLEAN} setup preprocess ${OBJ_FILES_HYBRID_HOST} ${OBJ_FILES_HOST} ${OBJ_FILES_HYBRID_DEVICE} ${OBJ_FILES_CUDA} ${LINK_STEP}
${CC_HOST} -fPIC -shared ${LIB_OBJECTS} ${WM_IFLAGS} ${COMPILE_TIME_OPT} ${LZLIB} ${LCUDA} -o ${TARGET}
final_static: ${DO_CLEAN} setup preprocess ${OBJ_FILES_HYBRID_HOST} ${OBJ_FILES_HOST} ${OBJ_FILES_HYBRID_DEVICE} ${OBJ_FILES_CUDA} ${LINK_STEP}
ar rcs ${TARGET} ${LIB_OBJECTS}
preprocess:
${PY_EXE} ${PREPROCESSOR} ${LIB_SOURCES}
${OBJ_FILES_HYBRID_DEVICE}: ${WM_OBJ_DIR}/K_%.o : ${WM_SRC_DIR}/hybrid/%.cpp
${CC_DEVICE} ${DEVICE_FLAGS} ${COMPILE_TIME_OPT} ${WM_IFLAGS} $< -o $@
${OBJ_FILES_HYBRID_HOST}: ${WM_OBJ_DIR}/%.o : ${WM_SRC_DIR}/hybrid/%.cpp
${CC_HOST} ${HOST_FLAGS} ${COMPILE_TIME_OPT} ${WM_IFLAGS} $< -o $@
${OBJ_FILES_HOST}: ${WM_OBJ_DIR}/%.o : ${WM_SRC_DIR}/host/%.cpp
${CC_HOST} ${HOST_FLAGS} ${COMPILE_TIME_OPT} ${WM_IFLAGS} $< -o $@
${LINK_STEP}:
${CC_DEVICE} ${DEVICE_DLINK_FLAGS} ${COMPILE_TIME_OPT} ${OBJ_FILES_HYBRID_DEVICE} ${OBJ_FILES_CUDA} -o ${CU_O_TARGET} -lcudadevrt
${OBJ_FILES_CUDA}: ${WM_OBJ_DIR}/%.o : ${WM_SRC_DIR}/cuda/%.cu
${CC_DEVICE} ${DEVICE_FLAGS} ${COMPILE_TIME_OPT} ${WM_IFLAGS} $< -o $@
syslink:
ln -sf ${TARGET} ${LINK_LOCATION}
setup:
-rm -r ${WM_HDR_DIR}
mkdir -p ${WM_LIB_DIR}
mkdir -p ${WM_OBJ_DIR}
mkdir -p ${WM_HDR_DIR}
@for hdr in ${HEADER_FILES} ; do \
ln -sf $${hdr} -t ${WM_HDR_DIR};\
done
test: final
@for fldr in testing/* ; do \
${MAKE} -C $${fldr} -f makefile -s test || exit 1; \
done
clean:
for fldr in testing/* ; do \
${MAKE} -C $${fldr} -f makefile clean ; \
done
-rm -r ${WM_LIB_DIR}
-rm -r ${WM_OBJ_DIR}
-rm -r ${WM_HDR_DIR}
subs.build:
@for fldr in sub/* ; do \
${MAKE} -C $${fldr} -f makefile || exit 1; \
done
subs.clean:
@for fldr in sub/* ; do \
${MAKE} -C $${fldr} -f makefile clean || exit 1; \
done
subs.test:
@for fldr in sub/* ; do \
${MAKE} -C $${fldr} -f makefile test || exit 1; \
done