-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
164 lines (114 loc) · 3.58 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
-include local.mk
include mkglue/cuda.mk
PREFIX ?= /usr/local
O ?= build
PROG=${O}/saga
SONAME=libsaga.so.0
PKG_CONFIG ?= pkg-config
CPPFLAGS += -g -Og -Wall -Werror -I. -I$(O) -Isrc -fPIC
CXXFLAGS += --std=c++17 -march=native -Wno-terminate
CXXFLAGS += -Wno-deprecated-declarations
LDFLAGS += -lpthread
###########################################
# Lib
SRCS-lib += \
src/util.cpp \
src/tensor.cpp \
src/graph.cpp \
src/node.cpp \
src/engine.cpp \
src/ui/tui.cpp \
src/ui/nui.cpp \
src/pub.cpp \
###########################################
# Dnnl
HAVE_DNNL ?= no
SRCS-lib-$(HAVE_DNNL) += \
src/dnnl/dnnl.cpp \
src/dnnl/dnnl_tensor.cpp \
CPPFLAGS-$(HAVE_DNNL) += -I${DNNL_PATH}/include
LDFLAGS-$(HAVE_DNNL) += -L${DNNL_PATH}/lib -ldnnl
###########################################
# Cuda
NVCCFLAGS := --std=c++14 -O2 -g -I. -arch compute_70
SRCS-lib-$(HAVE_CUDA) += \
src/cuda/cuda_common.cpp \
src/cuda/cuda_program.cpp \
src/cuda/cuda_analysis.cpp \
src/cuda/cuda_dnn.cpp \
src/cuda/cuda_optimizer.cpp \
src/cuda/cuda_tensor.cpp \
src/cuda/cuda_kernels.cu \
CPPFLAGS += ${CUDA_CPPFLAGS}
LDFLAGS += ${CUDA_LDFLAGS}
LDFLAGS-$(HAVE_CUDA) += -lcudnn -lcublas
###########################################
# Onnx & Protobuf
HAVE_PROTOBUF := $(subst 0,yes,$(shell $(PKG_CONFIG) protobuf; echo $$?))
SRCS-lib-$(HAVE_PROTOBUF) += src/onnx.cpp onnx/onnx.proto3
PKGS-$(HAVE_PROTOBUF) += protobuf
###########################################
# Program
SRCS-prog += \
main.cpp \
test/mnist.cpp \
test/cifar.cpp \
test/minimal.cpp \
test/test_classifier.cpp \
test/test_ops.cpp \
test/test_fc.cpp \
test/test_conv.cpp \
test/test_mp.cpp \
test/test_jpeg_decoder.cpp \
test/test_resnode.cpp \
test/test_aliasing.cpp \
SRCS-prog-$(HAVE_PROTOBUF) += test/test_onnx.cpp
ifeq '$(shell $(PKG_CONFIG) sqlite3 ; echo $$?)' '0'
CPPFLAGS += -DHAVE_SQLITE
LDFLAGS += -lsqlite3
endif
###########################################
SRCS += $(SRCS-lib) $(SRCS-lib-yes)
CPPFLAGS += $(CPPFLAGS-yes)
LDFLAGS += $(LDFLAGS-yes)
CPPFLAGS += $(shell ${PKG_CONFIG} --cflags ${PKGS} ${PKGS-yes} 2>/dev/null)
LDFLAGS += $(shell ${PKG_CONFIG} --libs ${PKGS} ${PKGS-yes} 2>/dev/null)
OBJS := ${SRCS:%.cpp=${O}/%.o}
OBJS := ${OBJS:%.proto3=${O}/%.proto3.o}
OBJS := ${OBJS:%.cu=${O}/%.o}
OBJS-prog := ${SRCS-prog:%.cpp=${O}/%.o} ${SRCS-prog-yes:%.cpp=${O}/%.o}
DEPS := ${OBJS:%.o=%.d} ${OBJS-prog:%.o=%.d}
SRCDEPS := $(patsubst %,$(O)/%.pb.cc,$(filter %.proto3,$(SRCS)))
ALLDEPS += Makefile
${PROG}: ${OBJS} ${OBJS-prog} ${ALLDEPS}
@mkdir -p $(dir $@)
${CXX} -o $@ ${OBJS} ${OBJS-prog} ${LDFLAGS}
${O}/${SONAME}: ${OBJS} ${ALLDEPS}
@mkdir -p $(dir $@)
${CXX} -shared -Wl,-soname,${SONAME} -Wl,--no-undefined -o $@ ${OBJS} ${LDFLAGS}
strip --strip-all --discard-all $@
solib: ${O}/${SONAME}
${O}/%.o: %.cu ${ALLDEPS}
@mkdir -p $(dir $@)
${NVCC} ${NVCCFLAGS} -o $@ -c $<
${NVCC} -M ${NVCCFLAGS} -o ${@:%.o=%.d} -c $<
@sed -itmp "s:^$(notdir $@) :$@ :" ${@:%.o=%.d}
${O}/%.o: %.cpp ${ALLDEPS} | $(SRCDEPS)
@mkdir -p $(dir $@)
${CXX} -MD -MP ${CPPFLAGS} ${CXXFLAGS} -o $@ -c $<
${O}/%.o: ${O}/%.pb.cc ${ALLDEPS}
@mkdir -p $(dir $@)
${CXX} -MD -MP ${CPPFLAGS} ${CXXFLAGS} -o $@ -c $<
${O}/%.proto3.pb.cc: %.proto3 ${ALLDEPS}
@mkdir -p $(dir $@)
protoc --cpp_out=$(O) $<
clean:
rm -rf "${O}" "${PROG}"
install: ${O}/${SONAME}
@mkdir -p "${PREFIX}/include/" "${PREFIX}/lib/"
cp saga.hpp "${PREFIX}/include/saga.hpp"
cp "${O}/${SONAME}" "${PREFIX}/lib/"
ln -srf "${PREFIX}/lib/${SONAME}" "${PREFIX}/lib/libsaga.so"
if [ "x`id -u $$USER`" = "x0" ]; then ldconfig ; fi
-include ${DEPS}
.PRECIOUS: ${O}/%.proto3.pb.cc