-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMakefile
221 lines (186 loc) · 5.6 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#Variables that users can change
# Can be no, 0 or 1
MEMORYDEBUG = no
# Can be 0 or 1
DEBUG = 0
OPENCL = 0
LOWP = 0
PENRYN = 0
SANDYBRIDGE = 0
HASWELL = 0
USEBLAS = 0
ONNX = 0
#Can be no, 4 or 5 (version)
CUDNN = no
QSML = noma
#Or write its path like here:
#QSML=/opt/Qualcomm/QSML-0.15.2/linux/arm32/lp64/gcc-4.8/
LIBPROTOBUFPATH=/usr/local/lib
CUDAPATH=/usr/local/cuda
CUDAPATH2=/usr/local/cuda/targets/aarch64-linux
OPENBLASPATH=/opt/OpenBLAS/lib
#End of variables users can change
UNAME_M := $(shell uname -m)
UNAME_S := $(shell uname -s)
CFLAGS = -Wall -c -fPIC
CXXFLAGS = -Wall -c -fPIC -std=c++11
LIBS = -lm
CC = gcc
CXX = g++
VPATH = modules cudnn OpenBLAS-stripped opencl lowp lowp/gemmlowp/eight_bit_int_gemm \
OpenBLAS-stripped/generic
LIBOBJS = thload.o thbasic.o thapi.o SpatialConvolutionMM.o SpatialMaxPooling.o Threshold.o \
View.o SoftMax.o Linear.o Dropout.o SpatialZeroPadding.o Reshape.o SpatialConvolution.o \
Normalize.o SpatialFullConvolution.o SpatialMaxUnpooling.o SpatialBatchNormalization.o \
SpatialAveragePooling.o Sequential.o Concat.o ConcatTable.o JoinTable.o CAddTable.o \
PReLU.o pytorch.o LogSoftMax.o Slice.o Cmax.o Sigmoid.o Tanh.o Upsample.o
ifeq ($(UNAME_S),Darwin)
CFLAGS += -DACCELERATE
USEBLAS = 1
else
CFLAGS += -fopenmp
CPPFLAGS += -fopenmp
LDFLAGS += -fopenmp
endif
ifneq ($(USEBLAS),1)
LIBOBJS += sgemm.o sger.o sgemv.o gemm_beta.o gemv_t.o copy.o
#ARM 32 bit
ifneq ($(filter arm%,$(UNAME_M)),)
CFLAGS += -DARM -D__NEON__ -mcpu=cortex-a9 -mfpu=neon -DHAVEFP16 -mfp16-format=ieee
ifneq ($(QSML),no)
CFLAGS += -DUSEQSML -I$(QSML)/include
LDFLAGS += -L$(QSML)/libs -lQSML
endif
LIBOBJS += axpy_vfp.o sgemm_kernel_4x4_vfpv3.o sgemm_ncopy_4_vfp.o sgemm_tcopy_4_vfp.o
VPATH += OpenBLAS-stripped/arm
endif
#ARM 64 bit
ifneq ($(filter aarc%,$(UNAME_M)),)
CFLAGS += -DARM -DHAVEFP16
ifneq ($(QSML),no)
CFLAGS += -DUSEQSML -I$(QSML)/include
LDFLAGS += -L$(QSML)/libs -lQSML
endif
CUFLAGS += -DHAVEHALF --gpu-architecture=compute_53
LIBOBJS += axpy.o sgemm_kernel_4x4.o gemm_ncopy_4.o gemm_tcopy_4.o
VPATH += OpenBLAS-stripped/arm64
endif
#Intel 64 bit
ifneq ($(filter x86_64%,$(UNAME_M)),)
ifeq ($(PENRYN)$(SANDYBRIDGE)$(HASWELL),000)
PENRYN=1
endif
CFLAGS += -DX86_64
CPPFLAGS += -DX86_64
LIBOBJS += axpy_sse.o
ifeq ($(PENRYN),1)
CFLAGS += -DPENRYN
CPPFLAGS += -DPENRYN
LIBOBJS += gemm_kernel_8x4_penryn.o gemm_ncopy_8.o gemm_tcopy_8.o gemm_ncopy_4_penryn.o gemm_tcopy_4_penryn.o
endif
ifeq ($(SANDYBRIDGE),1)
CFLAGS += -DSANDYBRIDGE
CPPFLAGS += -DSANDYBRIDGE
LIBOBJS += sgemm_kernel_16x4_sandy.o gemm_ncopy_16.o gemm_tcopy_16.o gemm_ncopy_4.o gemm_tcopy_4.o
endif
ifeq ($(HASWELL),1)
CFLAGS += -DHASWELL
CPPFLAGS += -DHASWELL
LIBOBJS += sgemm_kernel_16x4_haswell.o gemm_ncopy_16.o gemm_tcopy_16.o gemm_ncopy_4.o gemm_tcopy_4.o
endif
VPATH += OpenBLAS-stripped/x86_64
endif
else #USEBLAS
CFLAGS += -DUSEBLAS
ifeq ($(UNAME_S),Darwin)
LIBS += -framework Accelerate
else
LIBS += -L$(OPENBLASPATH) -lopenblas
endif
#ARM 32 bit
ifneq ($(filter arm%,$(UNAME_M)),)
CFLAGS += -DARM -D__NEON__ -mcpu=cortex-a9 -mfpu=neon -DHAVEFP16 -mfp16-format=ieee
endif
#ARM 64 bit
ifneq ($(filter aarc%,$(UNAME_M)),)
CFLAGS += -DARM -DHAVEFP16
CUFLAGS += -DHAVEHALF --gpu-architecture=compute_53
endif
#Intel 64 bit
ifneq ($(filter x86_64%,$(UNAME_M)),)
CFLAGS += -DX86_64
CPPFLAGS += -DX86_64
endif
endif #USEBLAS
#Memory leaks debugging
ifneq ($(MEMORYDEBUG),no)
LIBOBJS += memorydebug.o
CFLAGS += -DMEMORYDEBUG=$(MEMORYDEBUG)
CPPFLAGS += -DMEMORYDEBUG=$(MEMORYDEBUG)
endif
#Debug or release compilation
ifeq ($(DEBUG),1)
CFLAGS += -g
CUFLAGS += -g
CPPFLAGS += -g
ASFLAGS += -g
else
CFLAGS += -O3
CUFLAGS += -O3
CPPFLAGS += -O3
endif
#CUDNN
ifeq ($(CUDNN),$(filter $(CUDNN),4 5))
LIBOBJS += cudnn_basic.o cudnn_SpatialConvolution.o cunn_SpatialMaxPooling.o cudnn_Threshold.o \
cudnn_SoftMax.o cudnn_copy.o cunn_SpatialMaxUnpooling.o cudnn_SpatialBatchNormalization.o \
cunn_SpatialFullConvolution.o
CFLAGS += -DCUDNN -I$(CUDAPATH)/include -I$(CUDAPATH2)/include
LIBS += -L$(CUDAPATH2)/lib -L$(CUDAPATH2)/lib -lcudart -lcudnn -lcublas
ifeq ($(CUDNN),5)
CFLAGS += -DCUDNN5
endif
endif
#OpenCL
ifeq ($(OPENCL),1)
LIBOBJS += opencl_basic.o opencl_SpatialConvolution.o opencl_SpatialMaxPooling.o \
opencl_Threshold.o opencl_SoftMax.o opencl_img.o
CFLAGS += -DOPENCL
LIBS += -lOpenCL
endif
#Lowp
ifeq ($(LOWP),1)
LIBOBJS += lowp_basic.o lowp_SpatialConvolution.o lowp_SpatialMaxPooling.o \
lowp_Threshold.o lowp_SoftMax.o gemm8.o eight_bit_int_gemm.o
CFLAGS += -DLOWP
endif
ifeq ($(ONNX),1)
LIBOBJS += onnx.pb.o onnx.o
CFLAGS += -DONNX
CPPFLAGS += -DONNX
LIBS += -L$(LIBPROTOBUFPATH) -lprotobuf
endif
all : libthnets.so libthnets.a thnets-test
onnx.pb.cc: onnx.proto
protoc onnx.proto --cpp_out=.
*.o: thnets.h
.c.o:
$(CC) $(CFLAGS) $<
%.o: %.cu
nvcc -c -Xcompiler -fPIC $(CUFLAGS) -DCUDNN $<
libthnets.so: $(LIBOBJS)
$(CXX) -o $@ $(LIBOBJS) -shared $(LDFLAGS) $(LIBS)
libthnets.a: $(LIBOBJS)
$(AR) rcs $@ $(LIBOBJS)
thnets-test: $(LIBOBJS) thnets-test.o images.o
$(CC) -o $@ thnets-test.o images.o libthnets.so $(LDFLAGS) $(LIBS)
clean :
rm -f *.o libthnets.so test onnx.pb.*
install:
cp libthnets.so libthnets.a /usr/local/lib
cp thnets.h thvector.h /usr/local/include
cp thnets-test /usr/local/bin
ldconfig
uninstall:
rm -f /usr/local/lib/libthnets.so /usr/local/lib/libthnets.a
rm -f /usr/local/include/thnets.h /usr/local/include/thvector.h
rm -f /usr/local/bin/thnets-test