-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
106 lines (76 loc) · 3.02 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
# Use Prefix to define the home folder of the source code.
# It can be different from the folder in which you want to compile and run the mesh generator.
# In the current directory ./ you only need to have the main.cu and this Makefile
GEN = /usr
#MPI = /usr/local/openmpi-4.1.1
CUDA = /usr/local/cuda-11.2
GPU_ARCHITECTURE = 70
ifeq ($(ARCH),CPU)
gpu_usage=0
endif
ifeq ($(ARCH),)
ARCH=GPU
gpu_usage=1
endif
ifeq ($(ARCH),GPU)
gpu_usage=1
endif
SRC=./src/
OBJ=./obj/
# Define compiler and optimizer's flags
FLAG_GPU = -Darch=$(gpu_usage)
FLAG_ARCH = -Dcapability=$(GPU_ARCHITECTURE)
LIBS = -lm
FLAG2 = --use_fast_math
MAT = -ftz=true -prec-div=false
FLAG1 = -arch 'compute_$(GPU_ARCHITECTURE)' -code 'sm_$(GPU_ARCHITECTURE)'
INC = -I$(CUDA)/include -I$(GEN)/include $(GLB)
#INC += -I$(MPI)/include
LIB = -L$(CUDA)/lib64 -L$(GEN)/lib -lc -lstdc++ -lcuda -lcudart -lcudadevrt
#LIB += -L$(MPI)/lib
NVCC = nvcc $(DBG) $(CPPFLAGS) -lineinfo -rdc=true #
MAXREG = # --maxrregcount=82 --ptxas-options=-v
ifeq ($(DBG),)
NVCC += -O5 -mcmodel=large -forward-unknown-to-host-compiler -mcmodel=large
endif
CC = $(NVCC)
CFLAGS = $(INC) $(LIB)
TARGET = ns
MPICC = mpic++ -mcmodel=large $(CPPFLAGS)
ifeq ($(DBG),)
MPICC += -O5
endif
# List of objects
OBJ_SRC = $(OBJ)main.o $(OBJ)comm.o $(OBJ)init.o
OBJ_CUDA= $(OBJ)cuda_utils.o $(OBJ)cuda_math.o $(OBJ)cuda_main.o $(OBJ)cuda_rhs.o $(OBJ)calc_stress.o $(OBJ)sponge.o
OBJ_LINK= $(OBJ)cuda_link.o
OBJECTS = $(OBJ_SRC) $(OBJ_CUDA) $(OBJ_LINK)
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(MPICC) $(CFLAGS) $(FLAG_GPU) $(FLAG_ARCH) -o $(TARGET) $(OBJECTS) $(LIBS) -lcudart -lcudadevrt
#MPIC++ compilation src files
$(OBJ)main.o: $(SRC)main.cpp
$(MPICC) $(FLAG_GPU) -std=c++11 $(FLAG_ARCH) -c $(SRC)main.cpp $(CFLAGS) -o $(OBJ)main.o
$(OBJ)comm.o: $(SRC)comm.cpp
$(MPICC) $(FLAG_GPU) -std=c++11 $(FLAG_ARCH) -c $(SRC)comm.cpp $(CFLAGS) -o $(OBJ)comm.o
$(OBJ)init.o: $(SRC)init.cpp
$(MPICC) $(FLAG_GPU) -std=c++11 $(FLAG_ARCH) -c $(SRC)init.cpp $(CFLAGS) -o $(OBJ)init.o
#NVCC compilation src files (with link)
#compiling step (OBJ_CUDA)
$(OBJ)cuda_main.o: $(SRC)cuda_main.cu
$(NVCC) -c $(FLAG1) $(FLAG_ARCH) $(CFLAGS) $(SRC)cuda_main.cu $(FLAG2) -o $(OBJ)cuda_main.o
$(OBJ)calc_stress.o: $(SRC)calc_stress.cu
$(NVCC) -c $(FLAG1) $(FLAG_ARCH) $(CFLAGS) $(SRC)calc_stress.cu $(FLAG2) -o $(OBJ)calc_stress.o
$(OBJ)cuda_rhs.o: $(SRC)cuda_rhs.cu
$(NVCC) -c $(MAXREG) $(FLAG1) $(FLAG_ARCH) $(CFLAGS) $(SRC)cuda_rhs.cu $(FLAG2) -o $(OBJ)cuda_rhs.o
$(OBJ)cuda_math.o: $(SRC)cuda_math.cu
$(NVCC) -c $(FLAG1) $(FLAG_ARCH) $(CFLAGS) $(SRC)cuda_math.cu $(FLAG2) -o $(OBJ)cuda_math.o
$(OBJ)cuda_utils.o: $(SRC)cuda_utils.cu
$(NVCC) -c $(FLAG1) $(FLAG_ARCH) $(CFLAGS) $(SRC)cuda_utils.cu $(FLAG2) -o $(OBJ)cuda_utils.o
$(OBJ)sponge.o: $(SRC)sponge.cu
$(NVCC) -c $(FLAG1) $(FLAG_ARCH) $(CFLAGS) $(SRC)sponge.cu $(FLAG2) -o $(OBJ)sponge.o
#linking step (OBJ_LINK)
$(OBJ)cuda_link.o: $(OBJ_CUDA)
$(NVCC) -dlink $(FLAG1) $(FLAG_ARCH) $(CFLAGS) $(OBJ_CUDA) $(FLAG2) -o $(OBJ)cuda_link.o
clean:
rm -rf $(TARGET) $(OBJ)*.o