-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
198 lines (137 loc) · 5.61 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
#include Kokkos build vars
#include kokkos/kokkos/Makefile.kokkos
#CPU Compiler flags
CXX := g++
CPPFLAGS :=
CXXFLAGS := -O3 -std=c++11 -fopenmp
LDFLAGS :=
LDLIBS :=
#CUDA Compiler flags
NVCC := nvcc
NVCCFLAGS := -std=c++11
#Kokkos Compiler flags
#openacc flags
OPENACC_CXX := g++
OPENACC_CPPFLAGS :=
OPENACC_CXXFLAGS := -O3 -std=c++11 -fopenacc
LDFLAGS :=
LDLIBS :=
# Preliminary definitions
COMMON_SRC := $(wildcard common/*.cpp)
CPU_SRC := $(wildcard cpu/*.cpp)
MPI_SRC := $(wildcard mpi/*.cpp)
CUDA_SRC := $(wildcard cuda/*.cu)
KOKKOS_SRC := $(wildcard kokkos/*.cpp)
OPENACC_SRC := $(wildcard openacc/*.cpp)
VPATH := common/:cpu/:cuda/:kokkos/:openacc/
vpath %h common/ cpu/ mpi/ cuda/ kokkos/ openacc/
vpath %hpp common/ cpu/ mpi/ cuda/ kokkos/ openacc/
OBJ_DIR := obj/
COMMON_OBJ_DIR := obj/common/
CPU_OBJ_DIR := obj/cpu/
MPI_OBJ_DIR := obj/mpi/
CUDA_OBJ_DIR := obj/cuda/
KOKKOS_CPU_OBJ_DIR := obj/kokkos/cpu/
KOKKOS_CUDA_OBJ_DIR := obj/kokkos/cuda/
KOKKOS_UVM_OBJ_DIR := obj/kokkos/uvm/
OPENACC_OBJ_DIR := obj/openacc/
OBJ_DIRS = $(COMMON_OBJ_DIR) $(CPU_OBJ_DIR) $(MPI_OBJ_DIR) $(CUDA_OBJ_DIR) \
$(KOKKOS_CPU_OBJ_DIR) $(KOKKOS_CUDA_OBJ_DIR) $(KOKKOS_UVM_OBJ_DIR) \
$(OPENACC_OBJ_DIR)
CPU_OBJ := $(addprefix $(CPU_OBJ_DIR),$(notdir $(CPU_SRC:.cpp=.o))) \
$(addprefix $(CPU_OBJ_DIR),$(notdir $(COMMON_SRC:.cpp=.o)))
MPI_OBJ := $(addprefix $(MPI_OBJ_DIR),$(notdir $(MPI_SRC:.cpp=.o))) \
$(addprefix $(MPI_OBJ_DIR),$(notdir $(COMMON_SRC:.cpp=.o)))
CUDA_OBJ := $(addprefix $(CUDA_OBJ_DIR),$(notdir $(CUDA_SRC:.cu=.o))) \
$(addprefix $(CUDA_OBJ_DIR),$(notdir $(COMMON_SRC:.cpp=.o)))
KOKKOS_CPU_OBJ := $(addprefix $(KOKKOS_CPU_OBJ_DIR),$(notdir $(KOKKOS_SRC:.cpp=.o))) \
$(addprefix $(KOKKOS_CPU_OBJ_DIR),$(notdir $(COMMON_SRC:.cpp=.o)))
KOKKOS_CUDA_OBJ := $(addprefix $(KOKKOS_CUDA_OBJ_DIR),$(notdir $(KOKKOS_SRC:.cpp=.o))) \
$(addprefix $(KOKKOS_CUDA_OBJ_DIR),$(notdir $(COMMON_SRC:.cpp=.o)))
KOKKOS_UVM_OBJ := $(addprefix $(KOKKOS_UVM_OBJ_DIR),$(notdir $(KOKKOS_SRC:.cpp=.o))) \
$(addprefix $(KOKKOS_UVM_OBJ_DIR),$(notdir $(COMMON_SRC:.cpp=.o)))
OPENACC_OBJ := $(addprefix $(OPENACC_OBJ_DIR),$(notdir $(OPENACC_SRC:.cpp=.o))) \
$(addprefix $(OPENACC_OBJ_DIR),$(notdir $(COMMON_SRC:.cpp=.o)))
OBJS := $(COMMON_OBJ) $(CPU_OBJ) $(MPI_OBJ) $(CUDA_OBJ) $(KOKKOS_OBJ) $(OPENACC_OBJ)
BIN_DIR := bin/
CPU_BIN := $(BIN_DIR)testCPU
MPI_BIN := $(BIN_DIR)testMPI
CUDA_BIN := $(BIN_DIR)testCUDA
KOKKOS_CPU_BIN := $(BIN_DIR)testKokkosCPU
KOKKOS_CUDA_BIN := $(BIN_DIR)testKokkosCUDA
KOKKOS_UVM_BIN := $(BIN_DIR)testKokkosUVM
OPENACC_BIN := $(BIN_DIR)testOpenACC
BINS := $(CPU_BIN) $(CUDA_BIN) $(KOKKOS_CPU_BIN) $(KOKKOS_CUDA_BIN)
#$(OPENACC_BIN)
# Generally useful targets
.PHONY : all clean cpu mpi cuda kokkosCPU kokkosCUDA kokkosUVM openacc
.PHONY : debug-CPU debug-mpi debug-cuda debug-kokkosCPU debug-kokkosCUDA debug-kokkosUVM debug-openacc
#all : dirs cpu cuda kokkosCPU kokkosCUDA
#Can't compile everything at once
cpu : dirs $(CPU_BIN)
mpi : dirs $(MPI_BIN)
cuda : dirs $(CUDA_BIN)
ifneq (,$(findstring kokkosCPU,$(MAKECMDGOALS)))
include kokkos/kokkosCPU/Makefile.kokkos
endif
ifneq (,$(findstring kokkosCUDA,$(MAKECMDGOALS)))
include kokkos/kokkosCUDA/Makefile.kokkos
endif
ifneq (,$(findstring kokkosUVM,$(MAKECMDGOALS)))
include kokkos/kokkosUVM/Makefile.kokkos
endif
kokkosCPU : KOKKOS_CXX := g++
kokkosCPU : dirs $(KOKKOS_CPU_BIN)
kokkosCUDA : KOKKOS_CXX := $(HOME)/sources/kokkos/bin/nvcc_wrapper
kokkosCUDA : dirs $(KOKKOS_CUDA_BIN)
kokkosUVM : KOKKOS_CXX = $(HOME)/sources/kokkos/bin/nvcc_wrapper
kokkosUVM : dirs $(KOKKOS_UVM_BIN)
openacc : dirs $(OPENACC_BIN)
debug-cpu : CXXFLAGS := $(CXXFLAGS) -g -DDEBUG
debug-cpu : cpu
debug-cuda : NVCCFLAGS := $(NVCCFLAGS) -g -DDEBUG
debug-cuda : cuda
debug-kokkosCPU : KOKKOS_CXXFLAGS := $(KOKKOS_CXXFLAGS) -g -DDEBUG
debug-kokkosCPU : kokkosCPU
debug-kokkosCUDA : KOKKOS_CXXFLAGS := $(KOKKOS_CXXFLAGS) -g -DDEBUG
debug-kokkosCUDA : kokkosCUDA
debug-kokkosUVM : KOKKOS_CXXFLAGS := $(KOKKOS_CXXFLAGS) -g -DDEBUG
debug-kokkosUVM : kokkosUVM
debug-openacc : OPENACC_CXXFLAGS := $(OPENACC_CXXFLAGS) -g -DDEBUG
debug-openacc : openacc
objs : dirs $(OBJS)
dirs : $(BIN_DIR) $(OBJ_DIRS)
$(OBJ_DIRS):
mkdir -p $(BIN_DIR) $(OBJ_DIRS)
# Link objects into executable
$(CPU_BIN) : $(CPU_OBJ)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $(CPU_OBJ) $(COMMON_OBJ) $(LDLIBS)
$(MPI_BIN) : $(MPI_OBJ)
$(MPICXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $(MPI_OBJ) $(COMMON_OBJ) $(LDLIBS)
$(CUDA_BIN) : $(CUDA_OBJ)
nvcc $(NVCCFLAGS) -o $@ $(CUDA_OBJ) $(LDFLAGS) $(LDLIBS)
$(KOKKOS_CPU_BIN) : $(KOKKOS_CPU_OBJ)
$(KOKKOS_CXX) $(KOKKOS_FLAGS) -o $@ $(KOKKOS_CPU_OBJ) $(KOKKOS_LDFLAGS) $(LDLIBS) $(KOKKOS_LIBS)
$(KOKKOS_CUDA_BIN) : $(KOKKOS_CUDA_OBJ)
$(KOKKOS_CXX) $(KOKKOS_FLAGS) -o $@ $(KOKKOS_CUDA_OBJ) $(KOKKOS_LDFLAGS) $(LDLIBS) $(KOKKOS_LIBS)
$(KOKKOS_UVM_BIN) : $(KOKKOS_UVM_OBJ)
$(KOKKOS_CXX) $(KOKKOS_FLAGS) -o $@ $(KOKKOS_UVM_OBJ) $(KOKKOS_LDFLAGS) $(LDLIBS) $(KOKKOS_LIBS)
$(OPENACC_BIN) : $(OPENACC_OBJ)
$(OPENACC_CXX) $(OPENACC_CXXFLAGS) -o $@ $(OPENACC_OBJ) $(OPENACC_LDFLAGS) $(OPENACC_LDLIBS)
# Create objects from source files
$(CPU_OBJ_DIR)%.o : %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
$(CUDA_OBJ_DIR)%.o : %.cu
$(NVCC) $(NVCCFLAGS) -c $< -o $@
$(KOKKOS_CPU_OBJ_DIR)%.o : %.cpp
$(KOKKOS_CXX) $(KOKKOS_CXXFLAGS) -c $< -o $@
$(KOKKOS_CUDA_OBJ_DIR)%.o : %.cpp
$(KOKKOS_CXX) $(KOKKOS_CXXFLAGS) -c $< -o $@
$(KOKKOS_UVM_OBJ_DIR)%.o : %.cpp
$(KOKKOS_CXX) $(KOKKOS_CXXFLAGS) -c $< -o $@
$(OPENACC_OBJ_DIR)%.o : %.cpp
$(OPENACC_CXX) $(OPENACC_CPPFLAGS) $(OPENACC_CXXFLAGS) -c $< -o $@
# Cleanup
clean :
rm -rf $(OBJ_DIR)*
rm -rf $(BIN_DIR)*