Skip to content

Commit 0fc54d3

Browse files
zhenlinluopiiswrong
authored andcommitted
MKL compile update to remove full mkl pack dependency for blas=mkl (apache#5036)
1 parent 5e9f4e3 commit 0fc54d3

File tree

5 files changed

+27
-45
lines changed

5 files changed

+27
-45
lines changed

MKL_README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This README shows the user how to setup and install MKL2017 library with mxnet.
1212

1313
1.1 By default, MKL_2017_EXPRIEMENTAL=0. If setting MKL_2017_EXPRIEMENTAL=1, MKL buffer will be created and transferred between layers to achiever much higher performance.
1414

15-
1.2 By default, USE_BLAS=atlas, MKLML_ROOT=/usr/local, MKL2017_ML will be used
15+
1.2 By default, MKLML_ROOT=/usr/local, MKL2017_ML will be used
1616

1717
1.2.1 when excute make, Makefile will execute "prepare_mkl.sh" to download the MKL2017_ML library under <MKLML_ROOT>
1818

@@ -28,11 +28,11 @@ This README shows the user how to setup and install MKL2017 library with mxnet.
2828

2929
1.3 If setting USE_BLAS=mkl
3030

31-
1.3.1 please navigate here to do a full MKL installation: https://registrationcenter.intel.com/en/forms/?productid=2558&licensetype=2
31+
1.3.1 mshadow can also utilize mkl blas function in mklml package
3232

33-
1.3.2 do not use MKL2017 and MKL2017_ML at the same time
33+
1.4 MKL version compatibility
3434

35-
1.3.2.1 Do not execute MKL2017 compilervars.sh or mklvars.sh script before MxNet compilation. Otherwise, MKL2017 may conflict with MKL2017_ML and MxNet may not be compiled.
35+
1.3.2.1 If you already have MKL installed and MKLROOT being set in your system, by default, it will not attempt to download the latest mklml package unless you unset MKLROOT.
3636

3737
2. Run 'make -jX'
3838

Makefile

+8-12
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ ifneq ($(USE_OPENMP), 1)
2222
export NO_OPENMP = 1
2323
endif
2424

25+
2526
# use customized config file
2627
include $(config)
28+
29+
ifeq ($(USE_MKL2017), 1)
30+
RETURN_STRING=$(shell ./prepare_mkl.sh $(MKLML_ROOT))
31+
MKLROOT=$(firstword $(RETURN_STRING))
32+
export USE_MKLML=$(lastword $(RETURN_STRING))
33+
endif
34+
2735
include mshadow/make/mshadow.mk
2836
include $(DMLC_CORE)/make/dmlc.mk
2937

@@ -85,18 +93,6 @@ ifeq ($(USE_MKL2017_EXPERIMENTAL), 1)
8593
else
8694
CFLAGS += -DMKL_EXPERIMENTAL=0
8795
endif
88-
ifneq ($(USE_BLAS), mkl)
89-
ICC_ON=0
90-
RETURN_STRING=$(shell ./prepare_mkl.sh $(ICC_ON) $(MKLML_ROOT))
91-
MKLROOT=$(firstword $(RETURN_STRING))
92-
MKL_LDFLAGS=-l$(word 2, $(RETURN_STRING))
93-
MKL_EXTERNAL=$(lastword $(RETURN_STRING))
94-
ifeq ($(MKL_EXTERNAL), 1)
95-
MKL_LDFLAGS+=-Wl,-rpath,$(MKLROOT)/lib
96-
CFLAGS += -I$(MKLROOT)/include
97-
LDFLAGS += -Wl,--as-needed -L$(MKLROOT)/lib/ -liomp5 -lmklml_intel
98-
endif
99-
endif
10096
endif
10197

10298
ifeq ($(USE_CUDNN), 1)

make/config.mk

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ endif
105105
# to environment variable
106106
USE_INTEL_PATH = NONE
107107

108-
# If use MKL, choose static link automatically to allow python wrapper
108+
# If use MKL only for BLAS, choose static link automatically to allow python wrapper
109+
ifeq ($(USE_MKL2017), 0)
109110
ifeq ($(USE_BLAS), mkl)
110111
USE_STATIC_MKL = 1
112+
endif
111113
else
112114
USE_STATIC_MKL = NONE
113115
endif

prepare_mkl.sh

+11-27
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,6 @@
3636
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3737
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838
#
39-
FindLibrary()
40-
{
41-
case "$1" in
42-
intel|1)
43-
LOCALMKL=`find $HOME_MKL -name libmklml_intel.so` # name of MKL SDL lib
44-
;;
45-
*)
46-
LOCALMKL=`find $HOME_MKL -name libmklml_gnu.so` # name of MKL SDL lib
47-
;;
48-
esac
49-
50-
}
51-
5239
GetVersionName()
5340
{
5441
VERSION_LINE=0
@@ -62,12 +49,12 @@ echo $VERSION_LINE # Return Version Line
6249
}
6350

6451
# MKL
65-
HOME_MKL=$2
52+
HOME_MKL=$1
6653
if [ ! -d "$HOME_MKL" ]; then
6754
mkdir $HOME_MKL
6855
fi
6956
MXNET_ROOT=`dirname $0`
70-
OMP=0
57+
USE_MKLML=0
7158
VERSION_MATCH=20170210
7259
ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170209.tgz
7360
MKL_CONTENT_DIR=`echo $ARCHIVE_BASENAME | rev | cut -d "." -f 2- | rev`
@@ -77,7 +64,7 @@ reg='^[0-9]+$'
7764
VERSION_LINE=`GetVersionName $MKLROOT`
7865
#echo $VERSION_LINE
7966
# Check if MKLROOT is set if positive then set one will be used..
80-
if [ -z $MKLROOT ] || [ $VERSION_LINE -lt $VERSION_MATCH ]; then
67+
if [ -z $MKLROOT ]; then
8168
# ..if MKLROOT is not set then check if we have MKL downloaded in proper version
8269
VERSION_LINE=`GetVersionName $HOME_MKL`
8370
#echo $VERSION_LINE
@@ -89,19 +76,16 @@ if [ -z $MKLROOT ] || [ $VERSION_LINE -lt $VERSION_MATCH ]; then
8976
yes | cp -rf $MXNET_ROOT/$MKL_CONTENT_DIR/* $HOME_MKL
9077
rm -rf $MXNET_ROOT/$MKL_CONTENT_DIR
9178
fi
92-
FindLibrary $1
93-
#echo $LOCALMKL
94-
MKLROOT=`echo $LOCALMKL | sed -e 's/lib.*$//'`
79+
MKLLIB=`find $HOME_MKL -name libmklml_gnu.so`
80+
MKLROOT=`echo $MKLLIB | sed -e 's/lib.*$//'`
9581
fi
9682

9783
# Check what MKL lib we have in MKLROOT
98-
if [ -z `find $MKLROOT -name libmkl_rt.so -print -quit` ]; then
99-
LIBRARIES=`basename $LOCALMKL | sed -e 's/^.*lib//' | sed -e 's/\.so.*$//'`
100-
OMP=1
101-
else
102-
LIBRARIES="mkl_rt"
103-
fi
104-
84+
if [ -z `find $MKLROOT -name libmklml_gnu.so -print -quit` ]; then
85+
USE_MKLML=0
86+
elif [ -z `find $MKLROOT -name libmkl_core.so -print -quit` ]; then
87+
USE_MKLML=1
88+
fi
10589

10690
# return value to calling script (Makefile,cmake)
107-
echo $MKLROOT $LIBRARIES $OMP
91+
echo $MKLROOT $USE_MKLML

0 commit comments

Comments
 (0)