forked from apache/mxnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
142 lines (116 loc) · 4.37 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
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
export MXNET_ROOT=`pwd`/..
export TPARTYDIR=`pwd`/../3rdparty
# Change this to path or specify in make command
ifndef OPENBLAS_ROOT
export OPENBLAS_ROOT=/usr/local/opt/openblas
endif
# Whether use minimum build without blas and SSE, this will make the library super slow
ifndef MIN
export MIN=0
DEFS=-DMSHADOW_USE_CBLAS=1
else
DEFS=-DMSHADOW_USE_CBLAS=0
endif
ifndef ANDROID
export ANDROID=0
else
DEFS+=-DMSHADOW_USE_SSE=0
endif
# Use locally installed emscripten if not specified
ifndef EMCC
EMCC=emcc
endif
ifndef DISABLE_OPENMP
DEFS+=-DDISABLE_OPENMP=1
endif
.PHONY: all clean
DEFS+=-DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_MKL=0 -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DDMLC_LOG_STACK_TRACE=0
DEFS+=-DMSHADOW_FORCE_STREAM -DMXNET_USE_OPENCV=0 -DMXNET_PREDICT_ONLY=1
CFLAGS=-std=c++11 -Wno-unknown-pragmas -Wall $(DEFS)
# if architecture of the CPU supports F16C instruction set, enable USE_F16C for fast fp16 computation on CPU
ifeq ($(USE_F16C), 1)
CFLAGS+=-mf16c
else
DEFS+=-DMSHADOW_USE_F16C=0
endif
ifneq ($(MIN), 1)
CFLAGS += -I${OPENBLAS_ROOT} -I${OPENBLAS_ROOT}/include
LDFLAGS+= -L${OPENBLAS_ROOT} -L${OPENBLAS_ROOT}/lib
# Define which blas is installed. Uses OpenBLAS by default.
ifeq ($(USE_BLAS), atlas)
LDFLAGS += -lcblas
else ifeq ($(USE_BLAS), blas)
LDFLAGS += -lblas
else
LDFLAGS += -lopenblas
endif
endif
all: android libmxnet_predict.a ${MXNET_ROOT}/lib/libmxnet_predict.so
nnvm.d:
./prep_nnvm.sh
dmlc.d: dmlc-minimum0.cc
${CXX} ${CFLAGS} -M -MT dmlc-minimum0.o \
-I ${TPARTYDIR}/dmlc-core/include \
-D__MIN__=$(MIN) $+ > dmlc.d
mxnet_predict0.d: mxnet_predict0.cc nnvm.d dmlc.d
${CXX} ${CFLAGS} -M -MT mxnet_predict0.o \
-I ${MXNET_ROOT}/ -I ${TPARTYDIR}/mshadow/ -I ${TPARTYDIR}/dmlc-core/include -I ${TPARTYDIR}/dmlc-core/src \
-I ${TPARTYDIR}/tvm/nnvm/include \
-I ${MXNET_ROOT}/3rdparty/dlpack/include \
-I ${MXNET_ROOT}/include \
-D__MIN__=$(MIN) mxnet_predict0.cc > mxnet_predict0.d
cat dmlc.d >> mxnet_predict0.d
cat nnvm.d >> mxnet_predict0.d
mxnet_predict-all.cc: mxnet_predict0.d dmlc-minimum0.cc nnvm.cc mxnet_predict0.cc
@echo "Generating amalgamation to " $@
python ./amalgamation.py $+ $@ $(MIN) $(ANDROID)
mxnet_predict-all.o: mxnet_predict-all.cc
${CXX} ${CFLAGS} -fPIC -o $@ -c $+
libmxnet_predict.a: mxnet_predict-all.o
ar rcs libmxnet_predict.a $+
jni_libmxnet_predict.o: mxnet_predict-all.cc jni/predictor.cc
${CXX} ${CFLAGS} -fPIC -o $@ -c jni/predictor.cc
jni_libmxnet_predict.so: jni_libmxnet_predict.o
${CXX} ${CFLAGS} -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
ifneq ($(ANDROID), 1)
android:
else
CFLAGS+= -mhard-float -D_NDK_MATH_NO_SOFTFP=1 -O3
LDFLAGS+= -Wl,--no-warn-mismatch -lm_hard
android: jni_libmxnet_predict.so
endif
libmxnet_predict.js: mxnet_predict-all.cc
${EMCC} -std=c++11 -O2 $(DEFS) -DMSHADOW_USE_SSE=0 -D__MXNET_JS__ -o $@ $+ \
-s EXPORTED_FUNCTIONS="['_MXPredCreate', \
'_MXPredGetOutputShape', \
'_MXPredSetInput', \
'_MXPredForward', \
'_MXPredPartialForward', \
'_MXPredGetOutput', \
'_MXPredFree', \
'_MXNDListCreate', \
'_MXNDListGet', \
'_MXNDListFree']" \
-s ALLOW_MEMORY_GROWTH=1
${MXNET_ROOT}/lib/libmxnet_predict.so: mxnet_predict-all.o
@mkdir -p ${MXNET_ROOT}/lib
${CXX} ${CFLAGS} -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
ls -alh $@
clean:
rm -f *.d *.o *.so *.a *.js *.js.mem mxnet_predict-all.cc nnvm.cc