Apply MKL-{ML,DNN}-only config settings to dependencies, not just code.

Previously, specifying --define=using_mkl_dnn_only=true would cause
MKL-ML-dependent code to be #ifdef'd out, but dependencies on MKL-ML itself
would still be present. This change makes all library dependencies on MKL
properly select MKL-ML, MKL-DNN, or both, depending on the selected
configuration.

PiperOrigin-RevId: 208710102
This commit is contained in:
A. Unique TensorFlower 2018-08-14 14:10:20 -07:00 committed by TensorFlower Gardener
parent ab53f852b7
commit 7253bd04a4
10 changed files with 136 additions and 109 deletions

View File

@ -424,14 +424,14 @@ package_group(
load(
"//third_party/mkl:build_defs.bzl",
"if_mkl",
"if_mkl_ml",
)
filegroup(
name = "intel_binary_blob",
data = if_mkl(
data = if_mkl_ml(
[
"//third_party/mkl:intel_binary_blob",
"//third_party/intel_mkl_ml",
],
),
)

View File

@ -20,7 +20,7 @@ load("//tensorflow:tensorflow.bzl", "tf_cc_binary")
load("//tensorflow/compiler/xla:xla.bzl", "ORC_JIT_MEMORY_MAPPER_TARGETS")
load(
"//third_party/mkl:build_defs.bzl",
"if_mkl",
"mkl_deps",
)
# Filegroup used to collect source files for dependency checking.
@ -498,10 +498,7 @@ cc_library(
"//tensorflow/core:framework_lite",
"//tensorflow/core/kernels:eigen_helpers",
"//third_party/eigen3",
] + if_mkl([
"@mkl_dnn",
"//third_party/mkl:intel_binary_blob",
]),
] + mkl_deps(),
)
cc_library(
@ -555,10 +552,7 @@ cc_library(
"//tensorflow/compiler/xla:executable_run_options",
"//tensorflow/core:framework_lite",
"//third_party/eigen3",
] + if_mkl([
"//third_party/mkl:intel_binary_blob",
"@mkl_dnn",
]),
] + mkl_deps(),
)
cc_library(

View File

@ -149,6 +149,7 @@ load("@io_bazel_rules_closure//closure:defs.bzl", "closure_proto_library")
load(
"//third_party/mkl:build_defs.bzl",
"if_mkl",
"mkl_deps",
)
exports_files(["ops/ops.pbtxt"])
@ -2514,12 +2515,7 @@ tf_cuda_library(
] + if_static(
extra_deps = ["@protobuf_archive//:protobuf"],
otherwise = ["@protobuf_archive//:protobuf_headers"],
) + if_mkl(
[
"//third_party/mkl:intel_binary_blob",
"@mkl_dnn",
],
),
) + mkl_deps(),
alwayslink = 1,
)
@ -2800,12 +2796,7 @@ tf_cuda_library(
":protos_all_cc",
"//third_party/eigen3",
"//tensorflow/core/grappler:grappler_item",
] + if_mkl(
[
"//third_party/mkl:intel_binary_blob",
"@mkl_dnn",
],
),
] + mkl_deps(),
alwayslink = 1,
)
@ -2845,12 +2836,7 @@ tf_cuda_library(
"//tensorflow/core/grappler/optimizers:meta_optimizer",
"//third_party/eigen3",
"//tensorflow/core/kernels:required",
] + if_mkl(
[
"//third_party/mkl:intel_binary_blob",
"@mkl_dnn",
],
) + tf_additional_core_deps() + if_static([":core_cpu_impl"]),
] + mkl_deps() + tf_additional_core_deps() + if_static([":core_cpu_impl"]),
alwayslink = 1,
)
@ -3857,11 +3843,7 @@ tf_cuda_only_cc_test(
":test",
":test_main",
"//third_party/eigen3",
] + if_mkl(
[
"//third_party/mkl:intel_binary_blob",
],
),
] + mkl_deps(),
)
tf_cc_test_gpu(

View File

@ -52,6 +52,8 @@ load(
load(
"//third_party/mkl:build_defs.bzl",
"if_mkl",
"if_mkl_ml",
"mkl_deps",
)
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda")
@ -909,10 +911,7 @@ if_mkl(
"transpose_op.cc",
],
hdrs = ["transpose_op.h"],
deps = ARRAY_DEPS + if_mkl([
"//third_party/mkl:intel_binary_blob",
"@mkl_dnn",
]),
deps = ARRAY_DEPS + mkl_deps(),
)],
[tf_kernel_library(
name = "transpose_op",
@ -2875,7 +2874,7 @@ tf_kernel_library(
tf_kernel_library(
name = "batch_matmul_op",
srcs = [] + if_mkl([
srcs = if_mkl_ml([
"mkl_batch_matmul_op.cc",
]),
# <prefix>*impl.h are excluded by default from the CPU build, add explicitly.
@ -2884,8 +2883,8 @@ tf_kernel_library(
# to avoid long compiling time. See https://github.com/tensorflow/tensorflow/issues/10521
copts = if_override_eigen_strong_inline(["/DEIGEN_STRONG_INLINE=inline"]),
prefix = "batch_matmul_op",
deps = MATH_DEPS + if_mkl([
"//third_party/mkl:intel_binary_blob",
deps = MATH_DEPS + if_mkl_ml([
"//third_party/intel_mkl_ml",
]),
)
@ -2967,10 +2966,7 @@ tf_kernel_library(
"@libxsmm_archive//:xsmm_avx",
],
"//conditions:default": [],
}) + if_mkl([
"//third_party/mkl:intel_binary_blob",
"@mkl_dnn",
]) + if_cuda([
}) + mkl_deps() + if_cuda([
"//tensorflow/core/platform/default/build_config:cublas_plugin",
]),
)
@ -6160,8 +6156,7 @@ tf_mkl_kernel_library(
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"//tensorflow/core:nn_ops_op_lib",
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
] + mkl_deps(),
)
tf_mkl_kernel_library(
@ -6175,8 +6170,7 @@ tf_mkl_kernel_library(
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"//tensorflow/core:nn_ops_op_lib",
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
] + mkl_deps(),
)
tf_mkl_kernel_library(
@ -6191,8 +6185,7 @@ tf_mkl_kernel_library(
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"//tensorflow/core:nn_ops_op_lib",
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
] + mkl_deps(),
)
tf_mkl_kernel_library(
@ -6211,8 +6204,7 @@ tf_mkl_kernel_library(
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"//tensorflow/core:nn_ops_op_lib",
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
] + mkl_deps(),
)
tf_mkl_kernel_library(
@ -6227,8 +6219,7 @@ tf_mkl_kernel_library(
"//tensorflow/core:lib_internal",
"//tensorflow/core:nn_ops_op_lib",
"//third_party/eigen3",
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
] + mkl_deps(),
)
tf_mkl_kernel_library(
@ -6243,56 +6234,43 @@ tf_mkl_kernel_library(
"//tensorflow/core:lib_internal",
"//tensorflow/core:nn_ops_op_lib",
"//third_party/eigen3",
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
] + mkl_deps(),
)
tf_mkl_kernel_library(
name = "mkl_fused_batch_norm_op",
srcs = ["mkl_fused_batch_norm_op.cc"],
deps = NN_DEPS + [
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
deps = NN_DEPS + mkl_deps(),
)
tf_mkl_kernel_library(
name = "mkl_aggregate_ops",
prefix = "mkl_aggregate_ops",
deps = MATH_DEPS + [
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
deps = MATH_DEPS + mkl_deps(),
)
tf_mkl_kernel_library(
name = "mkl_concat_op",
prefix = "mkl_concat_op",
deps = ARRAY_DEPS + [
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
deps = ARRAY_DEPS + mkl_deps(),
)
tf_mkl_kernel_library(
name = "mkl_reshape_op",
prefix = "mkl_reshape_op",
deps = ARRAY_DEPS + [
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
deps = ARRAY_DEPS + mkl_deps(),
)
tf_mkl_kernel_library(
name = "mkl_identity_op",
prefix = "mkl_identity_op",
deps = ARRAY_DEPS + [
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
deps = ARRAY_DEPS + mkl_deps(),
)
tf_mkl_kernel_library(
name = "mkl_lrn_op",
prefix = "mkl_lrn_op",
deps = NN_DEPS + [
"//third_party/mkl:intel_binary_blob",
] + if_mkl(["@mkl_dnn"]),
deps = NN_DEPS + mkl_deps(),
)
tf_mkl_kernel_library(
@ -6303,10 +6281,7 @@ tf_mkl_kernel_library(
"cwise_ops_gradients.h",
],
prefix = "mkl_cwise_ops_common",
deps = NN_DEPS + [
"cwise_op",
"//third_party/mkl:intel_binary_blob",
],
deps = NN_DEPS + mkl_deps() + [":cwise_op"],
)
# NOTE(lespeholt): This rule is deprecated, please use:

View File

@ -8,7 +8,7 @@ load("//tensorflow/core:platform/default/build_config_root.bzl", "if_static")
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda")
load(
"//third_party/mkl:build_defs.bzl",
"if_mkl",
"if_mkl_ml",
)
# Appends a suffix to a list of deps.
@ -700,8 +700,8 @@ def tf_additional_binary_deps():
# core).
"//tensorflow/core/kernels:lookup_util",
"//tensorflow/core/util/tensor_bundle",
] + if_mkl(
] + if_mkl_ml(
[
"//third_party/mkl:intel_binary_blob",
"//third_party/intel_mkl_ml",
],
)

View File

@ -23,7 +23,9 @@ load(
load(
"//third_party/mkl:build_defs.bzl",
"if_mkl",
"if_mkl_lnx_x64"
"if_mkl_lnx_x64",
"if_mkl_ml",
"mkl_deps",
)
load(
"//third_party/mkl_dnn:build_defs.bzl",
@ -377,9 +379,9 @@ def tf_cc_binary(name,
name=name,
copts=copts,
srcs=srcs + tf_binary_additional_srcs(),
deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl(
deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml(
[
"//third_party/mkl:intel_binary_blob",
"//third_party/intel_mkl_ml",
],
),
data=data + tf_binary_dynamic_kernel_dsos(kernels),
@ -695,9 +697,9 @@ def tf_cc_test(name,
"-lm"
],
}) + linkopts + _rpath_linkopts(name),
deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl(
deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml(
[
"//third_party/mkl:intel_binary_blob",
"//third_party/intel_mkl_ml",
],
),
data=data + tf_binary_dynamic_kernel_dsos(kernels),
@ -877,11 +879,7 @@ def tf_cc_test_mkl(srcs,
"-lm"
],
}) + _rpath_linkopts(src_to_test_name(src)),
deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl(
[
"//third_party/mkl:intel_binary_blob",
],
),
deps=deps + tf_binary_dynamic_kernel_deps(kernels) + mkl_deps(),
data=data + tf_binary_dynamic_kernel_dsos(kernels),
linkstatic=linkstatic,
tags=tags,
@ -1015,6 +1013,7 @@ def tf_cuda_library(deps=None, cuda_deps=None, copts=tf_copts(), **kwargs):
"@local_config_cuda//cuda:cuda_headers"
]),
copts=(copts + if_cuda(["-DGOOGLE_CUDA=1"]) + if_mkl(["-DINTEL_MKL=1"]) +
if_mkl_open_source_only(["-DINTEL_MKL_DNN_ONLY"]) +
if_tensorrt(["-DGOOGLE_TENSORRT=1"])),
**kwargs)

View File

@ -9,7 +9,7 @@ load(
"if_windows",
"transitive_hdrs",
)
load("//third_party/mkl:build_defs.bzl", "if_mkl")
load("//third_party/mkl:build_defs.bzl", "if_mkl", "if_mkl_ml")
load("//tensorflow:tensorflow.bzl", "if_cuda")
load("@local_config_syslibs//:build_defs.bzl", "if_not_system_lib")
load("//tensorflow/core:platform/default/build_config_root.bzl", "tf_additional_license_deps")
@ -214,7 +214,7 @@ sh_binary(
"//tensorflow/contrib/lite/python:tflite_convert",
"//tensorflow/contrib/lite/toco/python:toco_from_protos",
],
}) + if_mkl(["//third_party/mkl:intel_binary_blob"]),
}) + if_mkl_ml(["//third_party/intel_mkl_ml"]),
)
# A genrule for generating a marker file for the pip package on Windows

17
third_party/mkl/BUILD vendored
View File

@ -2,17 +2,28 @@ licenses(["notice"]) # 3-Clause BSD
config_setting(
name = "using_mkl",
values = {
"define": "using_mkl=true",
define_values = {
"using_mkl": "true",
},
visibility = ["//visibility:public"],
)
config_setting(
name = "using_mkl_ml_only",
define_values = {
"using_mkl": "true",
"using_mkl_ml_only": "true",
},
visibility = ["//visibility:public"],
)
config_setting(
name = "using_mkl_lnx_x64",
define_values = {
"using_mkl": "true",
},
values = {
"cpu": "k8",
"define": "using_mkl=true",
},
visibility = ["//visibility:public"],
)

View File

@ -1,6 +1,9 @@
# -*- Python -*-
"""Skylark macros for MKL.
if_mkl is a conditional to check if MKL is enabled or not.
if_mkl_ml is a conditional to check if MKL-ML is enabled.
if_mkl_ml_only is a conditional to check for MKL-ML-only (no MKL-DNN) mode.
if_mkl_lnx_x64 is a conditional to check for MKL
mkl_repository is a repository rule for creating MKL repository rule that can
be pointed to either a local folder, or download it from the internet.
@ -15,27 +18,89 @@ _TF_MKL_ROOT = "TF_MKL_ROOT"
def if_mkl(if_true, if_false = []):
"""Shorthand for select()'ing on whether we're building with MKL.
Returns a select statement which evaluates to if_true if we're building
with MKL enabled. Otherwise, the select statement evaluates to if_false.
Args:
if_true: expression to evaluate if building with MKL.
if_false: expression to evaluate if building without MKL.
Returns:
a select evaluating to either if_true or if_false as appropriate.
"""
return select({
str(Label("//third_party/mkl:using_mkl")): if_true,
"//conditions:default": if_false
"//third_party/mkl:using_mkl": if_true,
"//conditions:default": if_false,
})
def if_mkl_ml(if_true, if_false = []):
"""Shorthand for select()'ing on whether we're building with MKL-ML.
Args:
if_true: expression to evaluate if building with MKL-ML.
if_false: expression to evaluate if building without MKL-ML
(i.e. without MKL at all, or with MKL-DNN only).
Returns:
a select evaluating to either if_true or if_false as appropriate.
"""
return select({
"//third_party/mkl_dnn:using_mkl_dnn_only":
if_false,
"//third_party/mkl:using_mkl": if_true,
"//conditions:default": if_false,
})
def if_mkl_ml_only(if_true, if_false = []):
"""Shorthand for select()'ing on whether we're building with MKL-ML only.
Args:
if_true: expression to evaluate if building with MKL-ML only.
if_false: expression to evaluate if building without MKL, or with MKL-DNN.
Returns:
a select evaluating to either if_true or if_false as appropriate.
"""
return select({
"//third_party/mkl:using_mkl_ml_only": if_true,
"//conditions:default": if_false,
})
def if_mkl_lnx_x64(if_true, if_false = []):
"""Shorthand for select()'ing on whether we're building with MKL.
"""Shorthand to select() on if MKL is on and the target is Linux x86-64.
Returns a select statement which evaluates to if_true if we're building
with MKL enabled. Otherwise, the select statement evaluates to if_false.
Args:
if_true: expression to evaluate if building with MKL is enabled and the
target platform is Linux x86-64.
if_false: expression to evaluate if building without MKL or for a
different platform.
Returns:
a select evaluating to either if_true or if_false as appropriate.
"""
return select({
str(Label("//third_party/mkl:using_mkl_lnx_x64")): if_true,
"//conditions:default": if_false
"//third_party/mkl:using_mkl_lnx_x64": if_true,
"//conditions:default": if_false,
})
def mkl_deps():
"""Shorthand for select() to pull in the correct set of MKL library deps.
Can pull in MKL-ML, MKL-DNN, both, or neither depending on config settings.
Returns:
a select evaluating to a list of library dependencies, suitable for
inclusion in the deps attribute of rules.
"""
return select({
"//third_party/mkl_dnn:using_mkl_dnn_only":
["@mkl_dnn"],
"//third_party/mkl:using_mkl_ml_only":
["//third_party/mkl:intel_binary_blob"],
"//third_party/mkl:using_mkl":
[
"//third_party/mkl:intel_binary_blob",
"@mkl_dnn"
],
"//conditions:default": []
})
def _enable_local_mkl(repository_ctx):
return _TF_MKL_ROOT in repository_ctx.os.environ

View File

@ -4,8 +4,9 @@ exports_files(["LICENSE"])
config_setting(
name = "using_mkl_dnn_only",
values = {
"define": "using_mkl_dnn_only=true",
define_values = {
"using_mkl": "true",
"using_mkl_dnn_only": "true",
},
visibility = ["//visibility:public"],
)