-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
178 lines (142 loc) · 5.91 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
# @Author: Julien Vial-Detambel <l3ninj>
# @Date: 2018-06-12T11:58:18+01:00
# @Email: julien.vial-detambel@epitech.eu
# @Project: CUDA-Based Simulator of Quantum Systems
# @Filename: Makefile
# @Last modified by: l3ninj
# @Last modified time: 2018-08-21T20:59:18+02:00
# @License: MIT License
CXX?= g++
# Maccro that defines the c++ compiler we will use.
OPTIFLAGS= -g3
CXXFLAGS= -Wextra -Wall -std=c++14 $(OPTIFLAGS) -MD
# Maccro that defines the Nvidia's compiler we will use.
NVCC= nvcc
# Maccro that contains how the temporary objects and repositories will be deleted.
# E.g. here we will call the 'rm' linux command with 'rf' as options.
RM= rm -rf
# Maccro that contains the final executable name of the project.
NAME= quSim
# Maccro that contains where the *.cpp source files are located.
SDIR= src
# Maccro that contains where the *.cu source files are located.
CUSDIR= cuda_src
# Maccro that contains the repository's name where objects compiled from *.cpp
# sources files will be stored.
ODIR= obj
# Maccro that contains the repository's name where objects compiled from *.cu
# sources files will be stored.
CUODIR= cuda_obj
# Maccro that contains a list of all *.cu source files that will be compiled
# with 'NVCC' maccro.
CUSRC= QCUDA.cu \
QCUDA_struct.cu \
QCUDA_utils.cu \
GPUExecutor.cu \
GPUProperties.cu \
CUDADimensions.cu \
ExecutorManager.cu \
QCUDAOperations.cu
# Maccro that contains a list of all *.cpp source files that will be compiled
# with 'CXX' maccro.
SRC= Parser/FloatExprAst.cpp \
Parser/ASTGenerator.cpp \
Parser/CircuitBuilder/CXBuilder.cpp \
Parser/CircuitBuilder/MeasureBuilder.cpp \
Parser/CircuitBuilder/RegisterDeclarationBuilder.cpp \
Parser/CircuitBuilder/UBuilder.cpp \
Parser/CircuitBuilder/UserDefinedGateBuilder.cpp \
Parser/CircuitBuilder/IncludeBuilder.cpp \
Parser/CircuitBuilder/ResetBuilder.cpp \
Parser/CircuitBuilder/BarrierBuilder.cpp \
Parser/CircuitBuilder/ConditionalStatementBuilder.cpp \
Parser/CircuitBuilder/CircuitBuilder.cpp \
Parser/CircuitBuilder/CircuitBuilderUtils.cpp \
Parser/FloatExpressionEvaluator.cpp \
TaskScheduling/TaskGraph.cpp \
TaskScheduling/BasicStateStore.cpp \
TaskScheduling/BasicTaskScheduler.cpp \
TaskScheduling/CircuitToTaskGraphConverter.cpp \
TaskScheduling/BasicMeasurementResultsTree.cpp \
Worker/Worker.cpp \
Worker/Simulator.cpp \
Worker/Measurer.cpp \
Circuit.cpp \
CircuitPrinter.cpp \
CircuitCompressor.cpp \
Matrix.cpp \
CPUExecutor.cpp \
utils.cpp \
main.cpp
$(ODIR)/Parser/ASTGenerator.o: CXXFLAGS:=$(filter-out $(OPTIFLAGS),$(CXXFLAGS))
# Maccro that contains the default include repository with all *.hpp headers.
INC= -Iinclude -I/usr/include/boost
# Maccro that contains all the entries of CUDA's headers.
CUINC= -Icuda_include -I$(CUDA_HOME)/samples/common/inc
# Maccro that combines both includes.
BOTHINC= $(INC) $(CUINC)
# Below we have different types of flags related to NVCC compiler.
# 'NVCCFLAGS' and 'NVCCFLAGS_LINK' are the flags that will be used
# when the architecture of the project doesn't involve any kind of
# dependecies resolution. I.e. when "device" codes are defined
# in files where they are initially called.
NVCCFLAGS= -std=c++14 -arch=sm_61
NVCCFLAGS_LINK= -std=c++14 -arch=sm_61
# 'NVCCFLAGS_COMPILE' and 'NVCCFLAGS_DLINK' have the opposite behaviour
# of the two maccros above. Indeed, those Maccros will be used when the
# architecture of the project involves definition of 'device' codes outside
# of files where they are initially called. Therefore to avoid any file with
# a lot of lines of codes, we will mostly use those maccros.
# LINK: https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#using-separate-compilation-in-cuda
NVCCFLAGS_COMPILE= -std=c++14 -arch=sm_61 --device-c
NVCCFLAGS_DLINK= -std=c++14 -arch=sm_61 --device-link
# This maccro is related to 'NVCCFLAGS_COMPILE' and 'NVCCFLAGS_DLINK' maccros.
# Indeed,this maccro contains the name of the object that will be built thanks
# to those maccros (dlink.o), and where it will be stored (see 'CUODIR' maccro).
DLINKOBJ= $(CUODIR)/dlink.o
# objects from .cpp source files.
_OBJS= $(SRC:.cpp=.o)
OBJS= $(patsubst %,$(ODIR)/%,$(_OBJS))
# objects from .cu source files.
_CUOBJS= $(CUSRC:.cu=.o)
CUOBJS= $(patsubst %,$(CUODIR)/%,$(_CUOBJS))
# Maccro that contains all the dynamic libraries that will be linked
# to the created objects in order to get our executable.
LDIR= -L$(CUDA_HOME)/lib64 -lcuda -lcudart -lboost_system -lboost_filesystem -lboost_program_options
# Default rule that will be called when the user types 'make'.
# Here, it will create 'ODIR' and 'CUODIR' repositories and call the 'NAME' rule.
all: $(ODIR) $(CUODIR) $(NAME)
# Rule that creates the 'ODIR' directory.
$(ODIR):
mkdir $(ODIR)
mkdir $(ODIR)/Parser
mkdir $(ODIR)/Worker
mkdir $(ODIR)/Parser/CircuitBuilder
mkdir $(ODIR)/TaskScheduling
# Rule that creates for each *.cpp file a *.o file,
# with the specified compilation line (see line 103).
$(ODIR)/%.o: $(SDIR)/%.cpp
$(CXX) $(CXXFLAGS) $(BOTHINC) -o $@ -c $<
# Rule that creates the 'CUODIR' directory.
$(CUODIR):
mkdir $(CUODIR)
# Rule that creates for each *.cu file a *.o file,
# with the specified compilation line (see line 112).
$(CUODIR)/%.o: $(CUSDIR)/%.cu
$(NVCC) $(BOTHINC) $(NVCCFLAGS_COMPILE) -o $@ -c $<
# Main rule that performs the compilation of each source file (see line 116),
# and links all the compiled objects with specific links (see lines 117 and 118).
$(NAME): $(OBJS) $(CUOBJS)
$(NVCC) $(NVCCFLAGS_DLINK) -o $(DLINKOBJ) $(CUOBJS) $(LDIR)
$(CXX) -o $(NAME) $(OBJS) $(CUOBJS) $(DLINKOBJ) $(LDIR)
# Rule that deletes the 'ODIR' and 'CUODIR' repositories.
clean:
$(RM) $(ODIR) $(CUODIR)
# Rule that calls the 'clean' rule, and deletes the created executable.
fclean: clean
$(RM) $(NAME)
# Rule that respectively calls the 'fclean' and 'all' rules.
re: fclean all
# Specific rule that checks the Makefile's cycle by testing all the specified rules.
.PHONY: all clean fclean re
-include $(OBJS:.o=.d)