forked from intel/caffe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.mkldnn
80 lines (65 loc) · 2.54 KB
/
Makefile.mkldnn
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
CAFFE_ROOTDIR := $(shell pwd)
MKLDNN_ROOTDIR := $(CAFFE_ROOTDIR)/external/mkldnn
MKLDNN_TMPDIR := $(MKLDNN_ROOTDIR)/tmp
MKLDNN_SRCDIR := $(MKLDNN_ROOTDIR)/src
MKLDNN_BUILDDIR := $(MKLDNN_ROOTDIR)/build
MKLDNN_INSTALLDIR := $(MKLDNN_ROOTDIR)/install
MKLDNN_COMMIT := `cat ${CAFFE_ROOTDIR}/mkldnn.commit`
MKLDNN_CXX := $(CXX)
MKLDNN_CC := $(CC)
RETURN_STRING=$(shell ./external/mkl/prepare_mkl.sh)
MKLROOT=$(firstword $(RETURN_STRING))
MKL_ROOTDIR := $(MKLROOT)
# We do this because earlier versions of CMake have problems with ccache
ifneq (,$(findstring ccache,$(CXX)))
MKLDNN_CXX := $(lastword $(CXX))
endif
ifneq (,$(findstring ccache,$(CC)))
MKLDNN_CC := $(lastword $(CC))
endif
MKLDNN_GITHUB := https://github.com/01org/mkl-dnn.git
MKLDNN_CMAKE_FLAGS += $(MKLDNN_SRCDIR) -DCMAKE_INSTALL_PREFIX=$(MKLDNN_INSTALLDIR) -DMKLROOT=${MKL_ROOTDIR} -B$(MKLDNN_BUILDDIR) -DCMAKE_CXX_COMPILER="$(MKLDNN_CXX)" -DCMAKE_C_COMPILER="$(MKLDNN_CC)"
# Disable MKLDNN download by customized setting
ifeq ($(DISABLE_MKLDNN_DOWNLOAD), 1)
disable_mkldnn_download_info:
@echo "MKLDNN download is disabled by customized setting! If MKLDNNROOT is not set in the ENV, may cause compile error in the following steps!"
mkldnn_download:
mkldnn_build:
else
disable_mkldnn_download_info:
@echo "MKLDNN download is enabled by customized setting!"
ifeq ("$(wildcard $(MKLDNN_INSTALLDIR)/include/mkldnn.hpp)", "")
mkldnn_download:
git clone --no-checkout $(MKLDNN_GITHUB) $(MKLDNN_TMPDIR)
rsync -a $(MKLDNN_TMPDIR)/ $(MKLDNN_SRCDIR) && rm -rf $(MKLDNN_TMPDIR)
cd $(MKLDNN_SRCDIR) && git reset --hard $(MKLDNN_COMMIT)
mkldnn_build: mkldnn_download
cmake $(MKLDNN_CMAKE_FLAGS)
make -C $(MKLDNN_BUILDDIR) -j$(shell cat /proc/cpuinfo |grep 'processor'|wc -l)
make -C $(MKLDNN_BUILDDIR) install
else
mkldnn_download:
mkldnn_build:
endif
endif
mkldnn_clean:
@rm -rf $(MKLDNN_SRCDIR) $(MKLDNN_BUILDDIR) $(MKLDNN_INSTALLDIR) $(MKLDNN_TMPDIR)
mkldnnroot_set:
$(eval CXXFLAGS += -DMKLDNN_SUPPORTED) \
$(eval INCLUDE_DIRS += $(MKLDNNROOT)/include)
$(eval MKLDNN_LDFLAGS += -lmkldnn -L$(MKLDNNROOT)/lib) \
$(eval MKLDNN_LDFLAGS += -Wl,-rpath,$(MKLDNNROOT)/lib) \
mkldnnroot_notset: mkldnn_build
$(eval CXXFLAGS += -DMKLDNN_SUPPORTED) \
$(eval INCLUDE_DIRS += $(MKLDNN_INSTALLDIR)/include) \
$(eval MKLDNN_LDFLAGS += -lmkldnn) \
$(eval MKLDNN_LDFLAGS += -L$(MKLDNN_INSTALLDIR)/lib -Wl,-rpath,${MKLDNN_INSTALLDIR}/lib)
ifneq ($(origin MKLDNNROOT), undefined)
ifdef MKLDNNROOT
mkldnn: mkldnnroot_set
mkldnn: disable_mkldnn_download_info
endif
else
mkldnn: mkldnnroot_notset
mkldnn: disable_mkldnn_download_info
endif