This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MKL2017 implemented layers integration to improve IA perf. on mxnet (#…
…3581) * Add MKL2017 memory struct support and mklconv into mxnet * fix cuda compile problem Signed-off-by: Lingyan <lingyan.guo@intel.com> * remove mkldnnchunk from memory and add all necessary file for compile * add mkl pooling * add mkl relu support * add mkl lrn * add mkl batch norm * add mkl concat * add mkl elementwise sum * add mkl fc * disable USE_MKL2017 by default Signed-off-by: Lingyan <lingyan.guo@intel.com> * revert mkl for sgemm Signed-off-by: Lingyan <lingyan.guo@intel.com> * add fix mkl path script & README Signed-off-by: Lingyan <lingyan.guo@intel.com> * use prepare_mkl.sh to download mkl Signed-off-by: Lingyan <lingyan.guo@intel.com> * Update for download failed for MKL Signed-off-by: Lingyan <lingyan.guo@intel.com> * add step to avoid mkl lib missing when excute python script Signed-off-by: Lingyan <lingyan.guo@intel.com> * update python install to sudo Signed-off-by: Lingyan <lingyan.guo@intel.com> * rollback padding change in pooling-inh.h Since mxnet update the new inception-bn model do not need to add padding patch to use old model Signed-off-by: Lingyan <lingyan.guo@intel.com> * correct pooling formula * minor change for pooling-inl.h * support new pooling_convention for converter * add MKL support in dropout * fix concat unit test issue since MKL concat don't support cross minbatch * disable external mkl if USE_BLAS is mkl Signed-off-by: Lingyan <lingyan.guo@intel.com> * fix compile error when mkl is disable Signed-off-by: Lingyan <lingyan.guo@intel.com> * remove debug msg and fix lint * remove MKL_DEBUG by default
- Loading branch information
1 parent
ae3b210
commit 8e1e7f0
Showing
33 changed files
with
4,301 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# MKL2017 PLUGIN | ||
|
||
MKL2017 is one INTEL released library to accelerate Deep Neural Network (DNN) applications on Intel architecture. | ||
This README shows user how to setup and install MKL2017 library with mxnet. | ||
|
||
|
||
## Build/Install Instructions: | ||
``` | ||
Download MKL: | ||
``` | ||
|
||
## Build/Install MxNet | ||
1. Enable USE_MKL2017=1 in make/config.mk | ||
1.1 USE_BLAS should be atlas by default | ||
1.2 if need USE_BLAS to be mkl, please Navigate here - https://registrationcenter.intel.com/en/forms/?productid=2558&licensetype=2 to do a full MKL installation | ||
2. Run 'make -jX' | ||
2.1 Makefile will execute "prepare_mkl.sh" to download the mkl under root folder.e.g. <MXNET ROOTDIR> /mklml_lnx_2017.0.0.20160801 | ||
2.2 if download failed because of proxy setting, please do it manually before make | ||
2.2.1 wget https://github.com/intel/caffe/releases/download/self_containted_MKLGOLD/mklml_lnx_2017.0.0.20160801.tgz | ||
2.2.2 tar zxvf mklml_lnx_2017.0.0.20160801.tgz | ||
|
||
3. Navigate into the python directory | ||
4. Run 'sudo python setup.py install' | ||
5. Before excute python scipt, need to set LD_LIBRARY_PATH | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<MXNET ROOTDIR>/mklml_lnx_2017.0.0.20160801/lib | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************* | ||
* Copyright 2016 Intel Corporation | ||
* | ||
* Licensed 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. | ||
* | ||
* \file mkl_memory.cc | ||
* \brief | ||
* \author lingyan.guo@intel.com | ||
* zhenlin.luo@intel.com | ||
* | ||
*******************************************************************************/ | ||
#ifndef MXNET_MKL_MEMORY_H_ | ||
#define MXNET_MKL_MEMORY_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <memory> | ||
|
||
|
||
namespace mxnet { | ||
// Base class | ||
struct PrvMemDescr { | ||
virtual void convert_from_prv(void* cpu_ptr) = 0; | ||
virtual void convert_to_prv(void* cpu_ptr) = 0; | ||
virtual void convert_from_other(std::shared_ptr<PrvMemDescr> other) = 0; | ||
virtual void* prv_ptr() = 0; | ||
// returns true for matching layouts | ||
virtual bool layout_compare(std::shared_ptr<PrvMemDescr> other) = 0; | ||
virtual size_t prv_count() = 0; | ||
virtual size_t prv_size() = 0; | ||
// This might help using prv_ptr_ by different accelerators/engines | ||
enum PrvDescrType { | ||
PRV_DESCR_MKL2017, | ||
PRV_DESCR_MKLDNN | ||
}; | ||
virtual PrvDescrType get_descr_type() = 0; | ||
}; | ||
|
||
struct MKLMemHolder { | ||
public: | ||
virtual std::shared_ptr<PrvMemDescr> get_prv_descriptor() = 0; | ||
}; | ||
|
||
} // namespace mxnet | ||
#endif // MXNET_MKL_MEMORY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/bin/bash | ||
# set -ex | ||
# | ||
# All modification made by Intel Corporation: © 2016 Intel Corporation | ||
# | ||
# All contributions by the University of California: | ||
# Copyright (c) 2014, 2015, The Regents of the University of California (Regents) | ||
# All rights reserved. | ||
# | ||
# All other contributions: | ||
# Copyright (c) 2014, 2015, the respective contributors | ||
# All rights reserved. | ||
# For the list of contributors go to https://github.com/BVLC/caffe/blob/master/CONTRIBUTORS.md | ||
# | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of Intel Corporation nor the names of its contributors | ||
# may be used to endorse or promote products derived from this software | ||
# without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# 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 $DST -name libmklml_intel.so` # name of MKL SDL lib | ||
;; | ||
*) | ||
LOCALMKL=`find $DST -name libmklml_gnu.so` # name of MKL SDL lib | ||
;; | ||
esac | ||
|
||
} | ||
|
||
GetVersionName() | ||
{ | ||
VERSION_LINE=0 | ||
if [ $1 ]; then | ||
VERSION_LINE=`grep __INTEL_MKL_BUILD_DATE $1/include/mkl_version.h 2>/dev/null | sed -e 's/.* //'` | ||
fi | ||
if [ -z $VERSION_LINE ]; then | ||
VERSION_LINE=0 | ||
fi | ||
echo $VERSION_LINE # Return Version Line | ||
} | ||
|
||
# MKL | ||
DST=`dirname $0` | ||
OMP=0 | ||
VERSION_MATCH=20160706 | ||
ARCHIVE_BASENAME=mklml_lnx_2017.0.0.20160801.tgz | ||
MKL_CONTENT_DIR=`echo $ARCHIVE_BASENAME | rev | cut -d "." -f 2- | rev` | ||
GITHUB_RELEASE_TAG=self_containted_MKLGOLD | ||
MKLURL="https://github.com/intel/caffe/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME" | ||
# there are diffrent MKL lib to be used for GCC and for ICC | ||
reg='^[0-9]+$' | ||
VERSION_LINE=`GetVersionName $MKLROOT` | ||
# Check if MKLROOT is set if positive then set one will be used.. | ||
if [ -z $MKLROOT ] || [ $VERSION_LINE -lt $VERSION_MATCH ]; then | ||
# ..if MKLROOT is not set then check if we have MKL downloaded in proper version | ||
VERSION_LINE=`GetVersionName $DST/$MKL_CONTENT_DIR` | ||
if [ $VERSION_LINE -lt $VERSION_MATCH ] ; then | ||
#...If it is not then downloaded and unpacked | ||
wget --no-check-certificate -P $DST $MKLURL -O $DST/$ARCHIVE_BASENAME | ||
tar -xzf $DST/$ARCHIVE_BASENAME -C $DST | ||
fi | ||
FindLibrary $1 | ||
MKLROOT=$PWD/`echo $LOCALMKL | 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 | ||
|
||
|
||
# return value to calling script (Makefile,cmake) | ||
echo $MKLROOT $LIBRARIES $OMP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.