Skip to content

Commit

Permalink
MKL compile update to remove full mkl pack dependency for blas=mkl (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlinluo authored and piiswrong committed Feb 16, 2017
1 parent 5e9f4e3 commit 0fc54d3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 45 deletions.
8 changes: 4 additions & 4 deletions MKL_README.md
Expand Up @@ -12,7 +12,7 @@ This README shows the user how to setup and install MKL2017 library with mxnet.

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.

1.2 By default, USE_BLAS=atlas, MKLML_ROOT=/usr/local, MKL2017_ML will be used
1.2 By default, MKLML_ROOT=/usr/local, MKL2017_ML will be used

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

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

1.3 If setting USE_BLAS=mkl

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

1.3.2 do not use MKL2017 and MKL2017_ML at the same time
1.4 MKL version compatibility

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.
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.

2. Run 'make -jX'

Expand Down
20 changes: 8 additions & 12 deletions Makefile
Expand Up @@ -22,8 +22,16 @@ ifneq ($(USE_OPENMP), 1)
export NO_OPENMP = 1
endif


# use customized config file
include $(config)

ifeq ($(USE_MKL2017), 1)
RETURN_STRING=$(shell ./prepare_mkl.sh $(MKLML_ROOT))
MKLROOT=$(firstword $(RETURN_STRING))
export USE_MKLML=$(lastword $(RETURN_STRING))
endif

include mshadow/make/mshadow.mk
include $(DMLC_CORE)/make/dmlc.mk

Expand Down Expand Up @@ -85,18 +93,6 @@ ifeq ($(USE_MKL2017_EXPERIMENTAL), 1)
else
CFLAGS += -DMKL_EXPERIMENTAL=0
endif
ifneq ($(USE_BLAS), mkl)
ICC_ON=0
RETURN_STRING=$(shell ./prepare_mkl.sh $(ICC_ON) $(MKLML_ROOT))
MKLROOT=$(firstword $(RETURN_STRING))
MKL_LDFLAGS=-l$(word 2, $(RETURN_STRING))
MKL_EXTERNAL=$(lastword $(RETURN_STRING))
ifeq ($(MKL_EXTERNAL), 1)
MKL_LDFLAGS+=-Wl,-rpath,$(MKLROOT)/lib
CFLAGS += -I$(MKLROOT)/include
LDFLAGS += -Wl,--as-needed -L$(MKLROOT)/lib/ -liomp5 -lmklml_intel
endif
endif
endif

ifeq ($(USE_CUDNN), 1)
Expand Down
4 changes: 3 additions & 1 deletion make/config.mk
Expand Up @@ -105,9 +105,11 @@ endif
# to environment variable
USE_INTEL_PATH = NONE

# If use MKL, choose static link automatically to allow python wrapper
# If use MKL only for BLAS, choose static link automatically to allow python wrapper
ifeq ($(USE_MKL2017), 0)
ifeq ($(USE_BLAS), mkl)
USE_STATIC_MKL = 1
endif
else
USE_STATIC_MKL = NONE
endif
Expand Down
38 changes: 11 additions & 27 deletions prepare_mkl.sh
Expand Up @@ -36,19 +36,6 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
FindLibrary()
{
case "$1" in
intel|1)
LOCALMKL=`find $HOME_MKL -name libmklml_intel.so` # name of MKL SDL lib
;;
*)
LOCALMKL=`find $HOME_MKL -name libmklml_gnu.so` # name of MKL SDL lib
;;
esac

}

GetVersionName()
{
VERSION_LINE=0
Expand All @@ -62,12 +49,12 @@ echo $VERSION_LINE # Return Version Line
}

# MKL
HOME_MKL=$2
HOME_MKL=$1
if [ ! -d "$HOME_MKL" ]; then
mkdir $HOME_MKL
fi
MXNET_ROOT=`dirname $0`
OMP=0
USE_MKLML=0
VERSION_MATCH=20170210
ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170209.tgz
MKL_CONTENT_DIR=`echo $ARCHIVE_BASENAME | rev | cut -d "." -f 2- | rev`
Expand All @@ -77,7 +64,7 @@ reg='^[0-9]+$'
VERSION_LINE=`GetVersionName $MKLROOT`
#echo $VERSION_LINE
# Check if MKLROOT is set if positive then set one will be used..
if [ -z $MKLROOT ] || [ $VERSION_LINE -lt $VERSION_MATCH ]; then
if [ -z $MKLROOT ]; then
# ..if MKLROOT is not set then check if we have MKL downloaded in proper version
VERSION_LINE=`GetVersionName $HOME_MKL`
#echo $VERSION_LINE
Expand All @@ -89,19 +76,16 @@ if [ -z $MKLROOT ] || [ $VERSION_LINE -lt $VERSION_MATCH ]; then
yes | cp -rf $MXNET_ROOT/$MKL_CONTENT_DIR/* $HOME_MKL
rm -rf $MXNET_ROOT/$MKL_CONTENT_DIR
fi
FindLibrary $1
#echo $LOCALMKL
MKLROOT=`echo $LOCALMKL | sed -e 's/lib.*$//'`
MKLLIB=`find $HOME_MKL -name libmklml_gnu.so`
MKLROOT=`echo $MKLLIB | sed -e 's/lib.*$//'`
fi

# Check what MKL lib we have in MKLROOT
if [ -z `find $MKLROOT -name libmkl_rt.so -print -quit` ]; then
LIBRARIES=`basename $LOCALMKL | sed -e 's/^.*lib//' | sed -e 's/\.so.*$//'`
OMP=1
else
LIBRARIES="mkl_rt"
fi

if [ -z `find $MKLROOT -name libmklml_gnu.so -print -quit` ]; then
USE_MKLML=0
elif [ -z `find $MKLROOT -name libmkl_core.so -print -quit` ]; then
USE_MKLML=1
fi

# return value to calling script (Makefile,cmake)
echo $MKLROOT $LIBRARIES $OMP
echo $MKLROOT $USE_MKLML

0 comments on commit 0fc54d3

Please sign in to comment.