Added a config option to enable MKL-DNN v1.0.
This commit is contained in:
parent
13bef4c379
commit
48671af095
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",
|
||||
@ -292,6 +293,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"]) +
|
||||
|
@ -139,6 +139,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"],
|
||||
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"],
|
||||
)
|
||||
|
20
third_party/mkl_dnn/build_defs.bzl
vendored
20
third_party/mkl_dnn/build_defs.bzl
vendored
@ -1,13 +1,27 @@
|
||||
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.
|
||||
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 = []):
|
||||
"""Shorthand for select()'ing on whether we're building with MKL-DNN v1.x
|
||||
(and 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 v1.x (and 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_v1_only")): if_true,
|
||||
"//conditions:default": if_false,
|
||||
})
|
||||
|
90
third_party/mkl_dnn/mkldnn.BUILD
vendored
90
third_party/mkl_dnn/mkldnn.BUILD
vendored
@ -17,6 +17,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
|
||||
@ -37,6 +47,20 @@ template_rule(
|
||||
},
|
||||
)
|
||||
|
||||
# TODO(bhavanis): Once we automatically get version numbers from CMakeLists.txt,
|
||||
# the following template rule needs to be removed.
|
||||
template_rule(
|
||||
name = "mkldnn_v1_version_h",
|
||||
src = "include/mkldnn_version.h.in",
|
||||
out = "include/mkldnn_version.h",
|
||||
substitutions = {
|
||||
"@MKLDNN_VERSION_MAJOR@": "0",
|
||||
"@MKLDNN_VERSION_MINOR@": "95",
|
||||
"@MKLDNN_VERSION_PATCH@": "0",
|
||||
"@MKLDNN_VERSION_HASH@": "N/A",
|
||||
},
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "mkl_dnn",
|
||||
srcs = glob([
|
||||
@ -98,6 +122,72 @@ cc_library(
|
||||
}),
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "mkl_dnn_v1",
|
||||
srcs = glob([
|
||||
"src/common/*.cpp",
|
||||
"src/common/*.hpp",
|
||||
"src/cpu/*.cpp",
|
||||
"src/cpu/*.hpp",
|
||||
"src/cpu/gemm/*.cpp",
|
||||
"src/cpu/gemm/*.hpp",
|
||||
"src/cpu/gemm/f32/*.cpp",
|
||||
"src/cpu/gemm/f32/*.hpp",
|
||||
"src/cpu/gemm/s8x8s32/*.cpp",
|
||||
"src/cpu/gemm/s8x8s32/*.hpp",
|
||||
"src/cpu/jit_utils/*.cpp", # newly added
|
||||
"src/cpu/jit_utils/*.hpp", # newly added
|
||||
"src/cpu/rnn/*.cpp",
|
||||
"src/cpu/rnn/*.hpp",
|
||||
"src/cpu/xbyak/*.h",
|
||||
]) + [
|
||||
":mkldnn_v1_version_h", # newly added
|
||||
":mkldnn_config_h", # newly added
|
||||
],
|
||||
hdrs = glob(["include/*"]),
|
||||
copts = [
|
||||
"-fexceptions",
|
||||
"-DUSE_MKL",
|
||||
"-DUSE_CBLAS",
|
||||
] + if_mkl_open_source_only([
|
||||
"-UUSE_MKL",
|
||||
"-UUSE_CBLAS",
|
||||
]) + select({
|
||||
"@org_tensorflow//tensorflow:linux_x86_64": [
|
||||
"-fopenmp", # only works with gcc
|
||||
],
|
||||
# TODO(ibiryukov): enable openmp with clang by including libomp as a
|
||||
# dependency.
|
||||
":clang_linux_x86_64": [],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = [
|
||||
"include",
|
||||
"src",
|
||||
"src/common",
|
||||
"src/cpu",
|
||||
"src/cpu/gemm",
|
||||
"src/cpu/xbyak",
|
||||
],
|
||||
nocopts = "-fno-exceptions",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = select({
|
||||
"@org_tensorflow//tensorflow:linux_x86_64": [
|
||||
"@mkl_linux//:mkl_headers",
|
||||
"@mkl_linux//:mkl_libs_linux",
|
||||
],
|
||||
"@org_tensorflow//tensorflow:macos": [
|
||||
"@mkl_darwin//:mkl_headers",
|
||||
"@mkl_darwin//:mkl_libs_darwin",
|
||||
],
|
||||
"@org_tensorflow//tensorflow:windows": [
|
||||
"@mkl_windows//:mkl_headers",
|
||||
"@mkl_windows//:mkl_libs_windows",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "mkldnn_single_threaded",
|
||||
srcs = glob([
|
||||
|
Loading…
Reference in New Issue
Block a user