Skip to content

Commit

Permalink
Added Intel MKL graph optimization code and the ability to enable MKL…
Browse files Browse the repository at this point in the history
… when running configure. (tensorflow#6921)

* Added Intel MKL graph optimization code and the ability to enable MKL when running configure.

* Fixed inclusion of MKL into build files.

* Made changes to MKL graph optimization files based on review comments.

* Adding support for MKL matmul op

* Revert "Adding support for MKL matmul op"

This reverts commit 20d6cdd.

* Changes based on Vijay Vasudevan's comments

* Made format-related fixes to some build files.

* Setting the execute bit (755) for tensorflow/tools/pip_package/build_pip_package.sh
  • Loading branch information
mahmoud-abuzaina authored and rmlarsen committed Feb 3, 2017
1 parent 94f2229 commit 19d932f
Show file tree
Hide file tree
Showing 14 changed files with 1,220 additions and 3 deletions.
66 changes: 66 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,72 @@ while true; do
# Retry
done

## Set up MKL related environment settings
if false; then # Disable building with MKL for now
while [ "$TF_NEED_MKL" == "" ]; do
fromuser=""
read -p "Do you wish to build TensorFlow with MKL support? [y/N] " INPUT
fromuser="1"
case $INPUT in
[Yy]* ) echo "MKL support will be enabled for TensorFlow"; TF_NEED_MKL=1;;
[Nn]* ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
"" ) echo "No MKL support will be enabled for TensorFlow"; TF_NEED_MKL=0;;
* ) echo "Invalid selection: " $INPUT;;
esac
done

OSNAME=`uname -s`

if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
DST=`dirname $0`
ARCHIVE_BASENAME=mklml_lnx_2017.0.2.20170110.tgz
GITHUB_RELEASE_TAG=v0.3
MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
if ! [ -e "$DST/third_party/mkl/$ARCHIVE_BASENAME" ]; then
wget --no-check-certificate -P $DST/third_party/mkl/ $MKLURL
fi
tar -xzf $DST/third_party/mkl/$ARCHIVE_BASENAME -C $DST/third_party/mkl/
extracted_dir_name="${ARCHIVE_BASENAME%.*}"
MKL_INSTALL_PATH=$DST/third_party/mkl/$extracted_dir_name
MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`

if [ "$OSNAME" == "Linux" ]; then
# Full MKL configuration
MKL_RT_LIB_PATH="lib/intel64/libmkl_rt.so" #${TF_MKL_EXT}#TODO version?
MKL_RT_OMP_LIB_PATH="../compiler/lib/intel64/libiomp5.so" #TODO VERSION?

# MKL-ML configuration
MKL_ML_LIB_PATH="lib/libmklml_intel.so" #${TF_MKL_EXT}#TODO version?
MKL_ML_OMP_LIB_PATH="lib/libiomp5.so" #TODO VERSION?
elif [ "$OSNAME" == "Darwin" ]; then
echo "Darwin is unsupported yet";
exit 1
fi

if [ -e "$MKL_INSTALL_PATH/${MKL_ML_LIB_PATH}" ]; then
ln -sf $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} third_party/mkl/
ln -sf $MKL_INSTALL_PATH/${MKL_ML_OMP_LIB_PATH} third_party/mkl/
ln -sf $MKL_INSTALL_PATH/include third_party/mkl/
ln -sf $MKL_INSTALL_PATH/include third_party/eigen3/mkl_include
else
echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} does not exist";
exit 1
fi

if [ -z "$fromuser" ]; then
exit 1
fi

cat > third_party/mkl/mkl.config <<EOF
# MKL_INSTALL_PATH refers to the location of MKL root folder. The MKL header and library
# files can be either in this directory, or under include/ and lib64/
MKL_INSTALL_PATH=$MKL_INSTALL_PATH
EOF

fi # TF_NEED_MKL
################## MKL
fi # Disable building with MKL for now

## Set up architecture-dependent optimization flags.
if [ -z "$CC_OPT_FLAGS" ]; then
default_cc_opt_flags="-march=native"
Expand Down
14 changes: 14 additions & 0 deletions tensorflow/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ filegroup(
visibility = [":__subpackages__"],
)

load(
"//third_party/mkl:build_defs.bzl",
"if_mkl",
)

filegroup(
name = "intel_binary_blob",
data = if_mkl(
[
"//third_party/mkl:intel_binary_blob",
],
),
)

# -------------------------------------------
# New rules should be added above this target.
# -------------------------------------------
Expand Down
35 changes: 34 additions & 1 deletion tensorflow/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ load(
"tf_opts_nortti_if_android",
"cc_header_only_library",
)
load("//tensorflow:tensorflow.bzl", "tf_cc_test_mkl")
load("//tensorflow:tensorflow.bzl", "tf_cc_test_gpu")
load("//tensorflow:tensorflow.bzl", "tf_cc_tests_gpu")
load("//tensorflow:tensorflow.bzl", "tf_version_info_genrule")
Expand Down Expand Up @@ -111,7 +112,10 @@ load(
"//tensorflow/core:platform/default/build_config_root.bzl",
"tf_cuda_tests_tags",
)

load(
"//third_party/mkl:build_defs.bzl",
"if_mkl",
)
# -----------------------------------------------------------------------------
# Public targets

Expand Down Expand Up @@ -1854,6 +1858,35 @@ tf_cc_tests(
],
)

if_mkl(
tf_cc_test_mkl(
name = "mkl_related_tests",
size = "small",
srcs = ["graph/mkl_optimizer_merge_test.cc"],
linkstatic = tf_kernel_tests_linkstatic(),
deps = [
":core",
":core_cpu",
":core_cpu_internal",
":direct_session_internal",
":framework",
":framework_internal",
":lib",
":lib_internal",
":ops",
":protos_all_cc",
":test",
":test_main",
":testlib",
"//tensorflow/cc:cc_ops",
"//tensorflow/cc:scope",
"//tensorflow/cc:sendrecv_ops",
"//tensorflow/core/kernels:ops_util",
"//third_party/eigen3",
],
),
)

tf_cc_tests_gpu(
name = "gpu_related_tests",
size = "small",
Expand Down
Loading

0 comments on commit 19d932f

Please sign in to comment.