aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-08-14 14:10:20 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-08-14 14:15:42 -0700
commit7253bd04a4bdeaa22aeafc61af0f1f611dfda77c (patch)
treefd4a52af3ee3dfaa35294fece401bd9ab6c26978 /third_party
parentab53f852b70250286cefb3192445775d7a5491e0 (diff)
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
Diffstat (limited to 'third_party')
-rw-r--r--third_party/mkl/BUILD17
-rw-r--r--third_party/mkl/build_defs.bzl83
-rw-r--r--third_party/mkl_dnn/BUILD5
3 files changed, 91 insertions, 14 deletions
diff --git a/third_party/mkl/BUILD b/third_party/mkl/BUILD
index a058c46cc4..efff7fd51b 100644
--- a/third_party/mkl/BUILD
+++ b/third_party/mkl/BUILD
@@ -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"],
)
diff --git a/third_party/mkl/build_defs.bzl b/third_party/mkl/build_defs.bzl
index 53e02769da..06a8c3518c 100644
--- a/third_party/mkl/build_defs.bzl
+++ b/third_party/mkl/build_defs.bzl
@@ -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
diff --git a/third_party/mkl_dnn/BUILD b/third_party/mkl_dnn/BUILD
index d075809ee9..3e567fa9fc 100644
--- a/third_party/mkl_dnn/BUILD
+++ b/third_party/mkl_dnn/BUILD
@@ -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"],
)