Upgrade to MKL DNN 0.18 RC

This commit is contained in:
AG Ramesh 2019-02-28 19:44:47 -08:00
parent 7db477e1a1
commit c5947c7bb9
5 changed files with 67 additions and 35 deletions

View File

@ -73,8 +73,8 @@ class MklAddNOp : public OpKernel {
"Inputs to operation ", this->name(), " of type ", "Inputs to operation ", this->name(), " of type ",
this->type_string(), this->type_string(),
" must have the same size and shape. Input 0: ", " must have the same size and shape. Input 0: ",
src1_shape.DebugString(), src1_shape.DebugString(), " != input 1: ",
" != input 1: ", src2_shape.DebugString())); src2_shape.DebugString()));
} }
if (!input1_in_mkl_format && src1_dims_size == 0) { if (!input1_in_mkl_format && src1_dims_size == 0) {
@ -101,7 +101,7 @@ class MklAddNOp : public OpKernel {
} }
} }
std::vector<double> coeff(2, 1.0); const std::vector<float> coeff(2, 1.0f);
MklDnnData<T> src1(&cpu_engine); MklDnnData<T> src1(&cpu_engine);
MklDnnData<T> src2(&cpu_engine); MklDnnData<T> src2(&cpu_engine);
MklDnnData<T> dst(&cpu_engine); MklDnnData<T> dst(&cpu_engine);
@ -242,9 +242,9 @@ class MklAddNOp : public OpKernel {
net.push_back(sum(sum_pd, inputs, dst.GetOpMem())); net.push_back(sum(sum_pd, inputs, dst.GetOpMem()));
stream(stream::kind::eager).submit(net).wait(); stream(stream::kind::eager).submit(net).wait();
} catch (mkldnn::error& e) { } catch (mkldnn::error& e) {
string error_msg = "Status: " + std::to_string(e.status) + string error_msg = "Status: " + std::to_string(e.status) + ", message: " +
", message: " + string(e.message) + ", in file " + string(e.message) + ", in file " + string(__FILE__) +
string(__FILE__) + ":" + std::to_string(__LINE__); ":" + std::to_string(__LINE__);
OP_REQUIRES_OK( OP_REQUIRES_OK(
ctx, errors::Aborted("Operation received an exception:", error_msg)); ctx, errors::Aborted("Operation received an exception:", error_msg));
} }

View File

@ -17,23 +17,22 @@ limitations under the License.
#ifdef INTEL_MKL #ifdef INTEL_MKL
#include "mkldnn.hpp" #include "mkldnn.hpp"
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
#include "tensorflow/core/framework/numeric_op.h" #include "tensorflow/core/framework/numeric_op.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/register_types.h"
#include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/util/mkl_util.h" #include "tensorflow/core/util/mkl_util.h"
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
using mkldnn::algorithm; using mkldnn::algorithm;
using mkldnn::eltwise_bounded_relu; using mkldnn::eltwise_bounded_relu;
using mkldnn::eltwise_elu; using mkldnn::eltwise_elu;
using mkldnn::eltwise_relu; using mkldnn::eltwise_relu;
using mkldnn::eltwise_tanh; using mkldnn::eltwise_tanh;
using mkldnn::eltwise_forward;
using mkldnn::memory; using mkldnn::memory;
using mkldnn::prop_kind; using mkldnn::prop_kind;
using mkldnn::relu_backward;
using mkldnn::relu_forward;
using mkldnn::stream; using mkldnn::stream;
namespace tensorflow { namespace tensorflow {
@ -531,9 +530,9 @@ class MklReluOpBase : public OpKernel {
// execute eltwise // execute eltwise
eltwise_fwd->Execute(src_data, dst_data); eltwise_fwd->Execute(src_data, dst_data);
} catch (mkldnn::error& e) { } catch (mkldnn::error& e) {
string error_msg = "Status: " + std::to_string(e.status) + string error_msg = "Status: " + std::to_string(e.status) + ", message: " +
", message: " + string(e.message) + ", in file " + string(e.message) + ", in file " + string(__FILE__) +
string(__FILE__) + ":" + std::to_string(__LINE__); ":" + std::to_string(__LINE__);
OP_REQUIRES_OK( OP_REQUIRES_OK(
context, context,
errors::Aborted("Operation received an exception:", error_msg)); errors::Aborted("Operation received an exception:", error_msg));
@ -542,7 +541,7 @@ class MklReluOpBase : public OpKernel {
private: private:
engine cpu_engine = engine(engine::cpu, 0); engine cpu_engine = engine(engine::cpu, 0);
std::shared_ptr<relu_forward::primitive_desc> relu_fwd_pd; std::shared_ptr<eltwise_forward::primitive_desc> relu_fwd_pd;
protected: protected:
float alpha_; float alpha_;
@ -699,9 +698,9 @@ class MklReluGradOpBase : public OpKernel {
// execute eltwise bwd // execute eltwise bwd
eltwise_bwd->Execute(src_data, diff_dst_data, diff_src_data); eltwise_bwd->Execute(src_data, diff_dst_data, diff_src_data);
} catch (mkldnn::error& e) { } catch (mkldnn::error& e) {
string error_msg = "Status: " + std::to_string(e.status) + string error_msg = "Status: " + std::to_string(e.status) + ", message: " +
", message: " + string(e.message) + ", in file " + string(e.message) + ", in file " + string(__FILE__) +
string(__FILE__) + ":" + std::to_string(__LINE__); ":" + std::to_string(__LINE__);
OP_REQUIRES_OK( OP_REQUIRES_OK(
context, context,
errors::Aborted("Operation received an exception:", error_msg)); errors::Aborted("Operation received an exception:", error_msg));
@ -710,7 +709,7 @@ class MklReluGradOpBase : public OpKernel {
private: private:
engine cpu_engine = engine(engine::cpu, 0); engine cpu_engine = engine(engine::cpu, 0);
std::shared_ptr<relu_forward::primitive_desc> relu_fwd_pd; std::shared_ptr<eltwise_forward::primitive_desc> relu_fwd_pd;
protected: protected:
float alpha_; float alpha_;

View File

@ -82,31 +82,31 @@ def tf_workspace(path_prefix = "", tf_repo_name = ""):
mkl_repository( mkl_repository(
name = "mkl_linux", name = "mkl_linux",
build_file = clean_dep("//third_party/mkl:mkl.BUILD"), build_file = clean_dep("//third_party/mkl:mkl.BUILD"),
sha256 = "f00dc3b142a5be399bdeebd7e7ea369545a35d4fb84c86f98b6b048d72685295", sha256 = "f84f92b047edad0467d68a925410b782e54eac9e7af61f4cc33d3d38b29bee5d",
strip_prefix = "mklml_lnx_2019.0.1.20180928", strip_prefix = "mklml_lnx_2019.0.3.20190125",
urls = [ urls = [
"https://mirror.bazel.build/github.com/intel/mkl-dnn/releases/download/v0.17-rc/mklml_lnx_2019.0.1.20180928.tgz", "https://mirror.bazel.build/github.com/intel/mkl-dnn/releases/download/v0.18-rc/mklml_lnx_2019.0.3.20190125.tgz",
"https://github.com/intel/mkl-dnn/releases/download/v0.17-rc/mklml_lnx_2019.0.1.20180928.tgz", "https://github.com/intel/mkl-dnn/releases/download/v0.18-rc/mklml_lnx_2019.0.3.20190125.tgz",
], ],
) )
mkl_repository( mkl_repository(
name = "mkl_windows", name = "mkl_windows",
build_file = clean_dep("//third_party/mkl:mkl.BUILD"), build_file = clean_dep("//third_party/mkl:mkl.BUILD"),
sha256 = "efef90b7b9613fab10f44c8ac4ff28db613a112c64ed94826d7e44df09c44b0b", sha256 = "8f968cdb175242f887efa9a6dbced76e65a584fbb35e5f5b05883a3584a2382a",
strip_prefix = "mklml_win_2019.0.1.20180928", strip_prefix = "mklml_win_2019.0.3.20190125",
urls = [ urls = [
"https://mirror.bazel.build/github.com/intel/mkl-dnn/releases/download/v0.17-rc/mklml_win_2019.0.1.20180928.zip", "https://mirror.bazel.build/github.com/intel/mkl-dnn/releases/download/v0.18-rc/mklml_win_2019.0.3.20190125.zip",
"https://github.com/intel/mkl-dnn/releases/download/v0.17-rc/mklml_win_2019.0.1.20180928.zip", "https://github.com/intel/mkl-dnn/releases/download/v0.18-rc/mklml_win_2019.0.3.20190125.zip",
], ],
) )
mkl_repository( mkl_repository(
name = "mkl_darwin", name = "mkl_darwin",
build_file = clean_dep("//third_party/mkl:mkl.BUILD"), build_file = clean_dep("//third_party/mkl:mkl.BUILD"),
sha256 = "83f02938a0c095274db7b8b7b694157abafa3837c5cbaef740440d466c86a477", sha256 = "60d6500f0e1a98f011324180fbf7a51a177f45494b4089e02867684d413c4293",
strip_prefix = "mklml_mac_2019.0.1.20180928", strip_prefix = "mklml_mac_2019.0.3.20190125",
urls = [ urls = [
"https://mirror.bazel.build/github.com/intel/mkl-dnn/releases/download/v0.17-rc/mklml_mac_2019.0.1.20180928.tgz", "https://mirror.bazel.build/github.com/intel/mkl-dnn/releases/download/v0.18-rc/mklml_mac_2019.0.3.20190125.tgz",
"https://github.com/intel/mkl-dnn/releases/download/v0.17-rc/mklml_mac_2019.0.1.20180928.tgz", "https://github.com/intel/mkl-dnn/releases/download/v0.18-rc/mklml_mac_2019.0.3.20190125.tgz",
], ],
) )
@ -114,14 +114,16 @@ def tf_workspace(path_prefix = "", tf_repo_name = ""):
print("path_prefix was specified to tf_workspace but is no longer used " + print("path_prefix was specified to tf_workspace but is no longer used " +
"and will be removed in the future.") "and will be removed in the future.")
# Important: If you are upgrading MKL DNN, then update the version numbers
# in third_party/mkl_dnn/mkldnn.BUILD.
tf_http_archive( tf_http_archive(
name = "mkl_dnn", name = "mkl_dnn",
build_file = clean_dep("//third_party/mkl_dnn:mkldnn.BUILD"), build_file = clean_dep("//third_party/mkl_dnn:mkldnn.BUILD"),
sha256 = "b100f57af4a2b59a3a37a1ba38f77b644d2107d758a1a7f4e51310063cd21e73", sha256 = "4d0522fc609b4194738dbbe14c8ee1546a2736b03886a07f498250cde53f38fb",
strip_prefix = "mkl-dnn-733fc908874c71a5285043931a1cf80aa923165c", strip_prefix = "mkl-dnn-bdd1c7be2cbc0b451d3541ab140742db67f17684",
urls = [ urls = [
"https://mirror.bazel.build/github.com/intel/mkl-dnn/archive/733fc908874c71a5285043931a1cf80aa923165c.tar.gz", "https://mirror.bazel.build/github.com/intel/mkl-dnn/archive/bdd1c7be2cbc0b451d3541ab140742db67f17684.tar.gz",
"https://github.com/intel/mkl-dnn/archive/733fc908874c71a5285043931a1cf80aa923165c.tar.gz", "https://github.com/intel/mkl-dnn/archive/bdd1c7be2cbc0b451d3541ab140742db67f17684.tar.gz",
], ],
) )

View File

@ -41,5 +41,6 @@ cc_library(
"lib/libiomp5md.lib", "lib/libiomp5md.lib",
"lib/mklml.lib", "lib/mklml.lib",
], ],
linkopts = ["/FORCE:MULTIPLE"],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )

View File

@ -4,6 +4,10 @@ load(
"@org_tensorflow//third_party/mkl_dnn:build_defs.bzl", "@org_tensorflow//third_party/mkl_dnn:build_defs.bzl",
"if_mkl_open_source_only", "if_mkl_open_source_only",
) )
load(
"@org_tensorflow//third_party:common.bzl",
"template_rule",
)
config_setting( config_setting(
name = "clang_linux_x86_64", name = "clang_linux_x86_64",
@ -13,6 +17,26 @@ config_setting(
}, },
) )
# Create the file mkldnn_version.h with MKL DNN version numbers.
# Currently, the version numbers are hard code here. If MKL DNN is upgraded then
# the version numbers have to be updated manually. The version numbers can be
# obtained from the PROJECT_VERSION settings in CMakeLists.txt. The variable is
# set to "version_major.version_minor.version_patch". The git hash version can
# be set to Unknown.
# TODO(agramesh1) Automatically get the version numbers from CMakeLists.txt.
template_rule(
name = "mkldnn_version_h",
src = "include/mkldnn_version.h.in",
out = "include/mkldnn_version.h",
substitutions = {
"@MKLDNN_VERSION_MAJOR@": "0",
"@MKLDNN_VERSION_MINOR@": "18",
"@MKLDNN_VERSION_PATCH@": "0",
"@MKLDNN_VERSION_HASH@": "N/A",
},
)
cc_library( cc_library(
name = "mkl_dnn", name = "mkl_dnn",
srcs = glob([ srcs = glob([
@ -22,8 +46,11 @@ cc_library(
"src/cpu/*.hpp", "src/cpu/*.hpp",
"src/cpu/gemm/*.cpp", "src/cpu/gemm/*.cpp",
"src/cpu/gemm/*.hpp", "src/cpu/gemm/*.hpp",
"src/cpu/gemm/f32/*.cpp",
"src/cpu/gemm/s8x8s32/*.cpp",
"src/cpu/rnn/*.cpp",
"src/cpu/xbyak/*.h", "src/cpu/xbyak/*.h",
]), ]) + [":mkldnn_version_h"],
hdrs = glob(["include/*"]), hdrs = glob(["include/*"]),
copts = [ copts = [
"-fexceptions", "-fexceptions",
@ -77,8 +104,11 @@ cc_library(
"src/cpu/*.hpp", "src/cpu/*.hpp",
"src/cpu/gemm/*.cpp", "src/cpu/gemm/*.cpp",
"src/cpu/gemm/*.hpp", "src/cpu/gemm/*.hpp",
"src/cpu/gemm/f32/*.cpp",
"src/cpu/gemm/s8x8s32/*.cpp",
"src/cpu/rnn/*.cpp",
"src/cpu/xbyak/*.h", "src/cpu/xbyak/*.h",
]), ]) + [":mkldnn_version_h"],
hdrs = glob(["include/*"]), hdrs = glob(["include/*"]),
copts = [ copts = [
"-fexceptions", "-fexceptions",