Merge pull request #30186 from Intel-tensorflow:mkldnn-1.0-integration
PiperOrigin-RevId: 257253393
This commit is contained in:
commit
8e7014bcac
1
.bazelrc
1
.bazelrc
@ -40,6 +40,7 @@ build:mkl -c opt
|
||||
# This config option is used to enable MKL-DNN open source library only,
|
||||
# without depending on MKL binary version.
|
||||
build:mkl_open_source_only --define=build_with_mkl_dnn_only=true
|
||||
build:mkl_open_source_only --define=build_with_mkl_dnn_v1_only=true
|
||||
build:mkl_open_source_only --define=build_with_mkl=true --define=enable_mkl=true
|
||||
build:mkl_open_source_only --define=tensorflow_mkldnn_contraction_kernel=0
|
||||
|
||||
|
@ -44,6 +44,7 @@ load(
|
||||
load(
|
||||
"//third_party/mkl_dnn:build_defs.bzl",
|
||||
"if_mkl_open_source_only",
|
||||
"if_mkl_v1_open_source_only",
|
||||
)
|
||||
load(
|
||||
"//third_party/ngraph:build_defs.bzl",
|
||||
@ -291,6 +292,7 @@ def tf_copts(android_optimization_level_override = "-O2", is_external = False):
|
||||
if_tensorrt(["-DGOOGLE_TENSORRT=1"]) +
|
||||
if_mkl(["-DINTEL_MKL=1", "-DEIGEN_USE_VML"]) +
|
||||
if_mkl_open_source_only(["-DINTEL_MKL_DNN_ONLY"]) +
|
||||
if_mkl_v1_open_source_only(["-DENABLE_MKLDNN_V1"]) +
|
||||
if_enable_mkl(["-DENABLE_MKL"]) +
|
||||
if_ngraph(["-DINTEL_NGRAPH=1"]) +
|
||||
if_mkl_lnx_x64(["-fopenmp"]) +
|
||||
|
@ -141,6 +141,17 @@ def tf_repositories(path_prefix = "", tf_repo_name = ""):
|
||||
],
|
||||
)
|
||||
|
||||
tf_http_archive(
|
||||
name = "mkl_dnn_v1",
|
||||
build_file = clean_dep("//third_party/mkl_dnn:mkldnn.BUILD"),
|
||||
sha256 = "fcc2d951f7170eade0cfdd0d8d1d58e3e7785bd326bca6555f3722f8cba71811",
|
||||
strip_prefix = "mkl-dnn-1.0-pc2",
|
||||
urls = [
|
||||
"http://mirror.tensorflow.org/github.com/intel/mkl-dnn/archive/v1.0-pc2.tar.gz",
|
||||
"https://github.com/intel/mkl-dnn/archive/v1.0-pc2.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
tf_http_archive(
|
||||
name = "com_google_absl",
|
||||
build_file = clean_dep("//third_party:com_google_absl.BUILD"),
|
||||
|
1
third_party/mkl/build_defs.bzl
vendored
1
third_party/mkl/build_defs.bzl
vendored
@ -107,6 +107,7 @@ def mkl_deps():
|
||||
"""
|
||||
return select({
|
||||
str(Label("//third_party/mkl_dnn:build_with_mkl_dnn_only")): ["@mkl_dnn"],
|
||||
str(Label("//third_party/mkl_dnn:build_with_mkl_dnn_v1_only")): ["@mkl_dnn_v1//:mkl_dnn"],
|
||||
str(Label("//third_party/mkl:build_with_mkl_ml_only")): ["//third_party/mkl:intel_binary_blob"],
|
||||
str(Label("//third_party/mkl:build_with_mkl")): [
|
||||
"//third_party/mkl:intel_binary_blob",
|
||||
|
9
third_party/mkl_dnn/BUILD
vendored
9
third_party/mkl_dnn/BUILD
vendored
@ -10,3 +10,12 @@ config_setting(
|
||||
},
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "build_with_mkl_dnn_v1_only",
|
||||
define_values = {
|
||||
"build_with_mkl": "true",
|
||||
"build_with_mkl_dnn_v1_only": "true",
|
||||
},
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
26
third_party/mkl_dnn/build_defs.bzl
vendored
26
third_party/mkl_dnn/build_defs.bzl
vendored
@ -1,13 +1,31 @@
|
||||
def if_mkl_open_source_only(if_true, if_false = []):
|
||||
"""Shorthand for select()'ing on whether we're building with
|
||||
MKL-DNN open source lib only, without depending on MKL binary form.
|
||||
"""Returns `if_true` if MKL-DNN v0.x is used.
|
||||
|
||||
Shorthand for select()'ing on whether we're building with
|
||||
MKL-DNN v0.x open source library only, without depending on MKL binary form.
|
||||
|
||||
Returns a select statement which evaluates to if_true if we're building
|
||||
with MKL-DNN open source lib only. Otherwise,
|
||||
the select statement evaluates to if_false.
|
||||
with MKL-DNN v0.x open source library only. Otherwise, the select statement
|
||||
evaluates to if_false.
|
||||
|
||||
"""
|
||||
return select({
|
||||
str(Label("//third_party/mkl_dnn:build_with_mkl_dnn_only")): if_true,
|
||||
"//conditions:default": if_false,
|
||||
})
|
||||
|
||||
def if_mkl_v1_open_source_only(if_true, if_false = []):
|
||||
"""Returns `if_true` if MKL-DNN v1.x is used.
|
||||
|
||||
Shorthand for select()'ing on whether we're building with
|
||||
MKL-DNN v1.x open source library only, without depending on MKL binary form.
|
||||
|
||||
Returns a select statement which evaluates to if_true if we're building
|
||||
with MKL-DNN v1.x open source library only. Otherwise, the
|
||||
select statement evaluates to if_false.
|
||||
|
||||
"""
|
||||
return select({
|
||||
str(Label("//third_party/mkl_dnn:build_with_mkl_dnn_v1_only")): if_true,
|
||||
"//conditions:default": if_false,
|
||||
})
|
||||
|
20
third_party/mkl_dnn/mkldnn.BUILD
vendored
20
third_party/mkl_dnn/mkldnn.BUILD
vendored
@ -3,6 +3,7 @@ exports_files(["LICENSE"])
|
||||
load(
|
||||
"@org_tensorflow//third_party/mkl_dnn:build_defs.bzl",
|
||||
"if_mkl_open_source_only",
|
||||
"if_mkl_v1_open_source_only",
|
||||
)
|
||||
load(
|
||||
"@org_tensorflow//third_party:common.bzl",
|
||||
@ -17,6 +18,16 @@ config_setting(
|
||||
},
|
||||
)
|
||||
|
||||
template_rule(
|
||||
name = "mkldnn_config_h",
|
||||
src = "include/mkldnn_config.h.in",
|
||||
out = "include/mkldnn_config.h",
|
||||
substitutions = {
|
||||
"#cmakedefine MKLDNN_CPU_BACKEND MKLDNN_BACKEND_${MKLDNN_CPU_BACKEND}": "#define MKLDNN_CPU_BACKEND MKLDNN_BACKEND_NATIVE",
|
||||
"#cmakedefine MKLDNN_GPU_BACKEND MKLDNN_BACKEND_${MKLDNN_GPU_BACKEND}": "#define MKLDNN_GPU_BACKEND MKLDNN_BACKEND_NONE",
|
||||
},
|
||||
)
|
||||
|
||||
# Create the file mkldnn_version.h with MKL-DNN version numbers.
|
||||
# Currently, the version numbers are hard coded here. If MKL-DNN is upgraded then
|
||||
# the version numbers have to be updated manually. The version numbers can be
|
||||
@ -24,6 +35,8 @@ config_setting(
|
||||
# set to "version_major.version_minor.version_patch". The git hash version can
|
||||
# be set to NA.
|
||||
# TODO(agramesh1) Automatically get the version numbers from CMakeLists.txt.
|
||||
# TODO(bhavanis): MKL-DNN minor version needs to be updated for MKL-DNN v1.x.
|
||||
# The current version numbers will work only if MKL-DNN v0.18 is used.
|
||||
|
||||
template_rule(
|
||||
name = "mkldnn_version_h",
|
||||
@ -53,6 +66,10 @@ cc_library(
|
||||
"src/cpu/rnn/*.cpp",
|
||||
"src/cpu/rnn/*.hpp",
|
||||
"src/cpu/xbyak/*.h",
|
||||
]) + if_mkl_v1_open_source_only([
|
||||
":mkldnn_config_h",
|
||||
"src/cpu/jit_utils/jit_utils.cpp",
|
||||
"src/cpu/jit_utils/jit_utils.hpp",
|
||||
]) + [":mkldnn_version_h"],
|
||||
hdrs = glob(["include/*"]),
|
||||
copts = [
|
||||
@ -62,6 +79,9 @@ cc_library(
|
||||
] + if_mkl_open_source_only([
|
||||
"-UUSE_MKL",
|
||||
"-UUSE_CBLAS",
|
||||
]) + if_mkl_v1_open_source_only([
|
||||
"-UUSE_MKL",
|
||||
"-UUSE_CBLAS",
|
||||
]) + select({
|
||||
"@org_tensorflow//tensorflow:linux_x86_64": [
|
||||
"-fopenmp", # only works with gcc
|
||||
|
Loading…
Reference in New Issue
Block a user