Skip to content

Commit

Permalink
Tidy up opensouce mkl build.
Browse files Browse the repository at this point in the history
Closes tensorflow#11212

PiperOrigin-RevId: 162713588
  • Loading branch information
gunan authored and tensorflower-gardener committed Jul 21, 2017
1 parent 602632b commit 133705c
Show file tree
Hide file tree
Showing 24 changed files with 300 additions and 139 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ node_modules
/.tf_configure.bazelrc
/bazel-*
/bazel_pip
/third_party/eigen3/mkl_include
/third_party/mkl/*
/tools/python_bin_path.sh
/tools/git/gen
/pip_test
Expand Down
77 changes: 4 additions & 73 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -217,84 +217,15 @@ done
OSNAME=`uname -s`

if [ "$TF_NEED_MKL" == "1" ]; then # TF_NEED_MKL
while [ "$TF_DOWNLOAD_MKL" == "" ]; do
fromuser=""
read -p "Do you wish to download MKL LIB from the web? [Y/n] " INPUT
fromuser="1"
case $INPUT in
[Yy]* ) TF_DOWNLOAD_MKL=1;;
[Nn]* ) TF_DOWNLOAD_MKL=0;;
"" ) TF_DOWNLOAD_MKL=1;;
* ) echo "Invalid selection: " $INPUT; exit 1;;
esac
done

if [[ "$TF_DOWNLOAD_MKL" == "1" ]]; then
DST=`dirname $0`
ARCHIVE_BASENAME=mklml_lnx_2018.0.20170425.tgz
GITHUB_RELEASE_TAG=v0.7
MKLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME"
if ! [ -e "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" ]; then
curl -fSsL -o "${DST}/third_party/mkl/${ARCHIVE_BASENAME}" "${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}')))"`

else
default_mkl_path=/opt/intel/mklml
fromuser=""
if [ -z "$MKL_INSTALL_PATH" ]; then
read -p "Please specify the location where MKL is installed. [Default is $default_mkl_path]: " MKL_INSTALL_PATH
fromuser="1"
fi
if [ -z "$MKL_INSTALL_PATH" ]; then
MKL_INSTALL_PATH=$default_mkl_path
fi
# Result returned from "read" will be used unexpanded. That make "~" unusable.
# Going through one more level of expansion to handle that.
MKL_INSTALL_PATH=`${PYTHON_BIN_PATH} -c "import os; print(os.path.realpath(os.path.expanduser('${MKL_INSTALL_PATH}')))"`
fi

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?
write_to_bazelrc 'build:mkl --define with_mkl_support=true'
write_to_bazelrc 'build:mkl -c opt'
write_to_bazelrc 'build:mkl --copt="-DEIGEN_USE_VML"'
echo "Add \"--config=mkl\" to your bazel command to build with MKL support."
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
loc=$(locate -e libdl.so.2 | sed -n 1p)
ln -sf $loc third_party/mkl/libdl.so.2
elif [ -e "$MKL_INSTALL_PATH/${MKL_RT_LIB_PATH}" ]; then
ln -sf $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} third_party/mkl/
ln -sf $MKL_INSTALL_PATH/${MKL_RT_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
loc=$(locate -e libdl.so.2 | sed -n 1p)
ln -sf $loc third_party/mkl/libdl.so.2
else
echo "ERROR: $MKL_INSTALL_PATH/${MKL_ML_LIB_PATH} nor $MKL_INSTALL_PATH/${MKL_RT_LIB_PATH} exists";
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
## End MKL setup

Expand Down
2 changes: 1 addition & 1 deletion tensorflow/core/common_runtime/mkl_cpu_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License.
#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/platform/mem.h"

#include "third_party/mkl/include/i_malloc.h"
#include "i_malloc.h"

namespace tensorflow {

Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_concat_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ limitations under the License.
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/types.h"

#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"
#include "tensorflow/core/util/mkl_util.h"

namespace tensorflow {
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_conv_grad_bias_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ limitations under the License.
#include "tensorflow/core/util/work_sharder.h"

#include "tensorflow/core/util/mkl_util.h"
#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"

namespace tensorflow {

Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_conv_grad_filter_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ limitations under the License.
#include "tensorflow/core/util/work_sharder.h"

#include "tensorflow/core/util/mkl_util.h"
#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"

namespace tensorflow {

Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_conv_grad_input_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ limitations under the License.
#include "tensorflow/core/util/tensor_format.h"
#include "tensorflow/core/util/use_cudnn.h"
#include "tensorflow/core/util/work_sharder.h"
#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"

namespace tensorflow {

Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_conv_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ limitations under the License.
#include "tensorflow/core/util/tensor_format.h"

#include "tensorflow/core/util/mkl_util.h"
#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"

namespace tensorflow {

Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_fused_batch_norm_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ limitations under the License.
#include "tensorflow/core/framework/tensor_types.h"
#include "tensorflow/core/util/tensor_format.h"

#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"
#include "tensorflow/core/util/mkl_util.h"

// TODO(inteltf) Address comments from PR 8968.
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_identity_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ limitations under the License.
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/logging.h"

#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"
#include "tensorflow/core/util/mkl_util.h"

namespace tensorflow {
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_lrn_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ limitations under the License.
#include "tensorflow/core/util/mkl_util.h"
#include "tensorflow/core/util/tensor_format.h"
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"

#if !defined(IS_MOBILE_PLATFORM)
#include "tensorflow/core/util/work_sharder.h"
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/core/kernels/mkl_matmul_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.

#if defined(INTEL_MKL)

#include "third_party/mkl/include/mkl_cblas.h"
#include "mkl_cblas.h"
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/register_types.h"
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_relu_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ limitations under the License.

#include "tensorflow/core/platform/default/logging.h"
#include "tensorflow/core/util/mkl_util.h"
#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"

namespace tensorflow {

Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_reshape_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ limitations under the License.
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/logging.h"

#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"
#include "tensorflow/core/util/mkl_util.h"

namespace tensorflow {
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/mkl_tfconv_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ limitations under the License.
#include "tensorflow/core/util/tensor_format.h"

#include "tensorflow/core/util/mkl_util.h"
#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"

namespace tensorflow {
typedef Eigen::ThreadPoolDevice CPUDevice;
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/core/kernels/mkl_transpose_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
#ifdef INTEL_MKL
#define EIGEN_USE_THREADS

#include "third_party/mkl/include/mkl_trans.h"
#include "mkl_trans.h"
#include "tensorflow/core/kernels/transpose_functor.h"
#include "tensorflow/core/kernels/transpose_op.h"

Expand Down
8 changes: 4 additions & 4 deletions tensorflow/core/util/mkl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ limitations under the License.
#include <string>
#include <vector>

#include "third_party/mkl/include/mkl_dnn.h"
#include "third_party/mkl/include/mkl_dnn_types.h"
#include "third_party/mkl/include/mkl_service.h"
#include "third_party/mkl/include/mkl_trans.h"
#include "mkl_dnn.h"
#include "mkl_dnn_types.h"
#include "mkl_service.h"
#include "mkl_trans.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/util/tensor_format.h"
Expand Down
11 changes: 9 additions & 2 deletions tensorflow/tools/lib_package/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package(default_visibility = ["//visibility:private"])

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("//third_party/mkl:build_defs.bzl", "if_mkl")

genrule(
name = "libtensorflow_proto",
Expand Down Expand Up @@ -104,7 +105,10 @@ genrule(
"@protobuf//:LICENSE",
"@snappy//:COPYING",
"@zlib_archive//:zlib.h",
],
] + if_mkl([
"//third_party/mkl:LICENSE",
"@mkl//:LICENSE",
]),
outs = ["include/tensorflow/c/LICENSE"],
cmd = "$(location :concat_licenses.sh) $(SRCS) >$@",
tools = [":concat_licenses.sh"],
Expand Down Expand Up @@ -135,7 +139,10 @@ genrule(
"@protobuf//:LICENSE",
"@snappy//:COPYING",
"@zlib_archive//:zlib.h",
],
] + if_mkl([
"//third_party/mkl:LICENSE",
"@mkl//:LICENSE",
]),
outs = ["include/tensorflow/jni/LICENSE"],
cmd = "$(location :concat_licenses.sh) $(SRCS) >$@",
tools = [":concat_licenses.sh"],
Expand Down
5 changes: 4 additions & 1 deletion tensorflow/tools/pip_package/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ filegroup(
"@snappy//:COPYING",
"@zlib_archive//:zlib.h",
"@org_python_pypi_backports_weakref//:LICENSE",
] + if_not_windows([
] + if_mkl([
"//third_party/mkl:LICENSE",
"@mkl//:LICENSE",
]) + if_not_windows([
"@nccl_archive//:LICENSE.txt",
]) + tf_additional_license_deps(),
)
Expand Down
41 changes: 14 additions & 27 deletions tensorflow/tools/pip_package/build_pip_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,6 @@ function main() {
bazel-bin/tensorflow/tools/pip_package/simple_console_for_window_unzip/runfiles \
"${TMPDIR}/external"
RUNFILES=bazel-bin/tensorflow/tools/pip_package/simple_console_for_window_unzip/runfiles/org_tensorflow
elif [ ! -d bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow ]; then
# Really old (0.2.1-) runfiles, without workspace name.
cp -R \
bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/tensorflow \
"${TMPDIR}"
mkdir "${TMPDIR}/external"
cp_external \
bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/external \
"${TMPDIR}/external"
RUNFILES=bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles
# Copy MKL libs over so they can be loaded at runtime
if [ -d bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/_solib_k8/_U_S_Sthird_Uparty_Smkl_Cintel_Ubinary_Ublob___Uthird_Uparty_Smkl ]; then
mkdir "${TMPDIR}/_solib_k8"
cp -R \
bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/_solib_k8/_U_S_Sthird_Uparty_Smkl_Cintel_Ubinary_Ublob___Uthird_Uparty_Smkl \
"${TMPDIR}/_solib_k8"
fi
else
if [ -d bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/external ]; then
# Old-style runfiles structure (--legacy_external_runfiles).
Expand All @@ -107,11 +90,13 @@ function main() {
bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/external \
"${TMPDIR}/external"
# Copy MKL libs over so they can be loaded at runtime
if [ -d bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/_solib_k8/_U_S_Sthird_Uparty_Smkl_Cintel_Ubinary_Ublob___Uthird_Uparty_Smkl ]; then
mkdir "${TMPDIR}/_solib_k8"
cp -R \
bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/_solib_k8/_U_S_Sthird_Uparty_Smkl_Cintel_Ubinary_Ublob___Uthird_Uparty_Smkl \
"${TMPDIR}/_solib_k8"
so_lib_dir="bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/_solib_k8"
if [ -d ${so_lib_dir} ]; then
mkl_so_dir=$(ls ${so_lib_dir} | grep mkl)
if [ $? -eq 0 ]; then
mkdir "${TMPDIR}/_solib_k8"
cp -R ${so_lib_dir}/${mkl_so_dir} "${TMPDIR}/_solib_k8"
fi
fi
else
# New-style runfiles structure (--nolegacy_external_runfiles).
Expand All @@ -124,11 +109,13 @@ function main() {
bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles \
"${TMPDIR}/external"
# Copy MKL libs over so they can be loaded at runtime
if [ -d bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/_solib_k8/_U_S_Sthird_Uparty_Smkl_Cintel_Ubinary_Ublob___Uthird_Uparty_Smkl ]; then
mkdir "${TMPDIR}/_solib_k8"
cp -R \
bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/_solib_k8/_U_S_Sthird_Uparty_Smkl_Cintel_Ubinary_Ublob___Uthird_Uparty_Smkl \
"${TMPDIR}/_solib_k8"
so_lib_dir="bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/_solib_k8"
if [ -d ${so_lib_dir} ]; then
mkl_so_dir=$(ls ${so_lib_dir} | grep mkl)
if [ $? -eq 0 ]; then
mkdir "${TMPDIR}/_solib_k8"
cp -R ${so_lib_dir}/${mkl_so_dir} "${TMPDIR}/_solib_k8"
fi
fi
fi
RUNFILES=bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow
Expand Down
11 changes: 11 additions & 0 deletions tensorflow/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ def tf_workspace(path_prefix="", tf_repo_name=""):
actual = "@libxsmm_archive//third_party:xsmm_avx",
)

native.new_http_archive(
name = "mkl",
urls = [
"http://mirror.bazel.build/github.com/01org/mkl-dnn/releases/download/v0.7/mklml_lnx_2018.0.20170425.tgz",
"https://github.com/01org/mkl-dnn/releases/download/v0.7/mklml_lnx_2018.0.20170425.tgz",
],
sha256 = "3cc2501fb209e1fd0960a5f61c919438f9619c68a644dcebf0fdf69b07460c57",
strip_prefix = "mklml_lnx_2018.0.20170425",
build_file = str(Label("//third_party/mkl:mkl.BUILD")),
)

native.new_http_archive(
name = "ortools_archive",
urls = [
Expand Down
Loading

0 comments on commit 133705c

Please sign in to comment.