-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile.inc
165 lines (138 loc) · 4.57 KB
/
Makefile.inc
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
#########################
## Library Directories ##
########################
# This FMM library
FMMTL_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
KERNEL_DIR = $(FMMTL_DIR)kernel
# External libraries
THRUST_DIR = /usr/local/cuda/include
# Optional libraries
# Only needed if using CUDA
CUDA_PATH = /usr/local/cuda
####################
## Makefile Setup ##
####################
# Get the host-name if empty
ifeq ($(host-name),)
host-name := $(shell hostname)
endif
# Get the kernel-name if empty
ifeq ($(kernel-name),)
kernel-name := $(shell uname -s)
endif
# Get the arch-name if empty
ifeq ($(arch-name),)
arch-name := $(shell uname -p)
endif
# Define the C++ compiler to use
CXX := $(shell which g++) -std=c++11
# Check the version number of CXX
CXX_VERSION_LT_48 := $(shell expr `$(CXX) -dumpversion | cut -f1,2 -d.` \< 4.8)
ifeq ($(CXX_VERSION_LT_48),1)
$(error Makefile using g++ v$(shell $(CXX) -dumpversion), please use >= v4.8)
endif
# Check for CUDA compiler
USE_NVCC := $(shell which nvcc)
NVCC := $(USE_NVCC) -std=c++11 -ccbin=g++-4.8 #$(shell which g++)
# Dependency directory and flags
DEPSDIR := $(shell mkdir -p .deps; echo .deps)
# MD: Dependency as side-effect of compilation
# MF: File for output
# MP: Include phony targets
DEPSFILE = $(DEPSDIR)/$(notdir $*.d)
DEPSFLAGS = -MD -MF $(DEPSFILE) #-MP
# Define any directories containing header files
# To include directories use -Ipath/to/files
INCLUDES += -I. -I$(THRUST_DIR) -I$(FMMTL_DIR) -I$(KERNEL_DIR)
# Define cxx compile flags
CXXFLAGS = -fopenmp -funroll-loops -O3 -Wall -Wextra -Wno-unused-local-typedefs
# Define nvcc compile flags TODO: Detect and generate appropriate sm_XX
NVCCFLAGS := -arch=sm_70 -O3 --compiler-options "$(CXXFLAGS)" -Xcompiler -Wno-unused-parameter #-Xptxas="-v"
# Define any directories containing libraries
# To include directories use -Lpath/to/files
LDFLAGS +=
# Define any libraries to link into executable
# To link in libraries (libXXX.so or libXXX.a) use -lXXX
LDLIBS +=
######################
## Makefile Options ##
######################
ifeq ($(NDEBUG),1)
CXXFLAGS += -DNDEBUG
NVCCFLAGS += -DNDEBUG
endif
ifeq ($(FMMTL_NDEBUG),1)
CXXFLAGS += -DFMMTL_NDEBUG
endif
ifeq ($(DEBUG),1)
CXXFLAGS += -DFMMTL_DEBUG -g -fno-inline
endif
ifeq ($(PROFILE),1)
CXXFLAGS += -g -pg
endif
ifeq ($(LOG),1)
CXXFLAGS += -DFMMTL_LOGGING
endif
ifeq ($(NO_CUDA),1)
USE_NVCC :=
endif
# Set up for CUDA if available
ifeq ($(USE_NVCC),) # NVCC is not available
else # NVCC is available
CXXFLAGS += -DFMMTL_WITH_CUDA
# Use cuda lib64 if it exists, else cuda lib
ifneq ($(wildcard $(CUDA_PATH)/lib64/.*),)
LDFLAGS += -L$(CUDA_PATH)/lib64
else
LDFLAGS += -L$(CUDA_PATH)/lib
endif
LDLIBS += -lcudart
endif
####################
## Makefile Rules ##
####################
# Suffix replacement rules
# $^: the name of the prereqs of the rule
# $<: the name of the first prereq of the rule
# $@: the name of the target of the rule
.SUFFIXES: # Delete the default suffixes
.SUFFIXES: .hpp .cpp .kern .kern.cpp .kern.cu .o # Define our suffix list
# 'make' - default rule
all: $(EXEC)
# Default rule for creating an exec of $(EXEC) from a .o file
$(EXEC): % : %.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
# Default rule for creating a .o file from a .cpp file
%.o: %.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEPSFLAGS) -c -o $@ $<
# Default rule for creating a .o file from a .cu file
%.o: %.cu
$(NVCC) $(NVCCFLAGS) $(INCLUDES) -c -o $@ $<
@$(NVCC) $(NVCCFLAGS) $(INCLUDES) -M -o $(DEPSFILE) $<
# Default rule for creating a .o file from a .kern.cpp file
%.o: %.kern.cpp
$(CXX) -DFMMTL_KERNEL $(CXXFLAGS) $(INCLUDES) $(DEPSFLAGS) -c -o $@ $<
# Default rule for creating a .o file from a .kern.cu file
%.o: %.kern.cu
$(NVCC) -DFMMTL_KERNEL $(NVCCFLAGS) $(INCLUDES) -c -o $@ $<
@$(NVCC) -DFMMTL_KERNEL $(NVCCFLAGS) $(INCLUDES) -M -o $(DEPSFILE) $<
@sed -i -e "1s,.*.kern.o,$@," $(DEPSFILE) # Fix dep file file.o -> /path/file.o
# Default rule for creating a .o file from a .kern file
%.o: %.kern
ifeq ($(USE_NVCC),) # NVCC isn't available
ln -s $< $(<:%.kern=%.kern.cpp)
@$(MAKE) --no-print-directory $@
else # NVCC is availble
ln -s $< $(<:%.kern=%.kern.cu)
@$(MAKE) --no-print-directory $@
endif
# 'make clean' - deletes all .o and temp files, exec, and dependency file
clean:
-$(RM) *.o $(KERNEL_DIR)/*.o
-$(RM) $(EXEC)
find $(KERNEL_DIR) -maxdepth 1 -type l -delete
$(RM) -r $(DEPSDIR)
# Define rules that do not actually generate the corresponding file
.PHONY: clean all
# Include the dependency files
-include $(wildcard $(DEPSDIR)/*.d)