From bdd8bf316e4ab7d699127d192d30eb614a158462 Mon Sep 17 00:00:00 2001 From: Loo Rong Jie Date: Wed, 11 Jul 2018 20:24:10 +0800 Subject: Remove all references of windows_msvc config_setting --- tensorflow/tensorflow.bzl | 9 --------- 1 file changed, 9 deletions(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index e4241667ad..8e3323ded5 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -137,14 +137,12 @@ def if_not_mobile(a): def if_not_windows(a): return select({ clean_dep("//tensorflow:windows"): [], - clean_dep("//tensorflow:windows_msvc"): [], "//conditions:default": a, }) def if_windows(a): return select({ clean_dep("//tensorflow:windows"): a, - clean_dep("//tensorflow:windows_msvc"): a, "//conditions:default": [], }) @@ -226,7 +224,6 @@ def tf_copts(android_optimization_level_override="-O2", is_external=False): clean_dep("//tensorflow:android"): android_copts, clean_dep("//tensorflow:darwin"): [], clean_dep("//tensorflow:windows"): get_win_copts(is_external), - clean_dep("//tensorflow:windows_msvc"): get_win_copts(is_external), clean_dep("//tensorflow:ios"): ["-std=c++11"], "//conditions:default": ["-pthread"] })) @@ -286,7 +283,6 @@ def _rpath_linkopts(name): "-Wl,%s" % (_make_search_paths("@loader_path", levels_to_root),), ], clean_dep("//tensorflow:windows"): [], - clean_dep("//tensorflow:windows_msvc"): [], "//conditions:default": [ "-Wl,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),), ], @@ -656,7 +652,6 @@ def tf_cc_test(name, "-pie", ], clean_dep("//tensorflow:windows"): [], - clean_dep("//tensorflow:windows_msvc"): [], clean_dep("//tensorflow:darwin"): [ "-lm", ], @@ -838,7 +833,6 @@ def tf_cc_test_mkl(srcs, "-pie", ], clean_dep("//tensorflow:windows"): [], - clean_dep("//tensorflow:windows_msvc"): [], "//conditions:default": [ "-lpthread", "-lm" @@ -1351,7 +1345,6 @@ def tf_custom_op_library(name, srcs=[], gpu_srcs=[], deps=[], linkopts=[]): "-lm", ], clean_dep("//tensorflow:windows"): [], - clean_dep("//tensorflow:windows_msvc"): [], clean_dep("//tensorflow:darwin"): [], }),) @@ -1461,7 +1454,6 @@ def tf_py_wrap_cc(name, "$(location %s.lds)"%vscriptname, ], clean_dep("//tensorflow:windows"): [], - clean_dep("//tensorflow:windows_msvc"): [], "//conditions:default": [ "-Wl,--version-script", "$(location %s.lds)"%vscriptname, @@ -1472,7 +1464,6 @@ def tf_py_wrap_cc(name, "%s.lds"%vscriptname, ], clean_dep("//tensorflow:windows"): [], - clean_dep("//tensorflow:windows_msvc"): [], "//conditions:default": [ "%s.lds"%vscriptname, ] -- cgit v1.2.3 From ecd8decac3d9f3c7cd772e1561b9c2d3f23aa830 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Thu, 26 Jul 2018 11:05:28 -0700 Subject: Replace //tools/defaults:crosstool to @bazel_tools//tools/cpp:current_cc_toolchain //tools/defaults will be removed soon PiperOrigin-RevId: 206187625 --- tensorflow/tensorflow.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index 340d3f393c..4da6493723 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -1456,7 +1456,7 @@ def tf_py_wrap_cc(name, srcs=srcs, swig_includes=swig_includes, deps=deps + extra_deps, - toolchain_deps=["//tools/defaults:crosstool"], + toolchain_deps=["@bazel_tools//tools/cpp:current_cc_toolchain"], module_name=module_name, py_module_name=name) vscriptname=name+"_versionscript" -- cgit v1.2.3 From b4cc9c34195e0fd557f56ceda29bd4830833ffbb Mon Sep 17 00:00:00 2001 From: Guangda Lai Date: Thu, 26 Jul 2018 11:57:51 -0700 Subject: Remove the gen_locally tag which is no more needed. PiperOrigin-RevId: 206197083 --- tensorflow/contrib/tensorrt/BUILD | 1 - tensorflow/tensorflow.bzl | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/contrib/tensorrt/BUILD b/tensorflow/contrib/tensorrt/BUILD index 5889fd5aaf..033d5207f6 100644 --- a/tensorflow/contrib/tensorrt/BUILD +++ b/tensorflow/contrib/tensorrt/BUILD @@ -122,7 +122,6 @@ tf_cuda_library( tf_gen_op_wrapper_py( name = "trt_engine_op", - gen_locally = True, deps = [ ":trt_engine_op_op_lib", ":trt_logging", diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index 4da6493723..f8e55abe79 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -549,9 +549,6 @@ def tf_gen_op_wrappers_cc(name, # is invalid to specify both "hidden" and "op_whitelist". # cc_linkopts: Optional linkopts to be added to tf_cc_binary that contains the # specified ops. -# gen_locally: if True, the genrule to generate the Python library will be run -# without sandboxing. This would help when the genrule depends on symlinks -# which may not be supported in the sandbox. def tf_gen_op_wrapper_py(name, out=None, hidden=None, @@ -562,8 +559,7 @@ def tf_gen_op_wrapper_py(name, generated_target_name=None, op_whitelist=[], cc_linkopts=[], - api_def_srcs=[], - gen_locally=False): + api_def_srcs=[]): if (hidden or hidden_file) and op_whitelist: fail('Cannot pass specify both hidden and op_whitelist.') @@ -618,7 +614,6 @@ def tf_gen_op_wrapper_py(name, outs=[out], srcs=api_def_srcs + [hidden_file], tools=[tool_name] + tf_binary_additional_srcs(), - local = (1 if gen_locally else 0), cmd=("$(location " + tool_name + ") " + api_def_args_str + " @$(location " + hidden_file + ") " + ("1" if require_shape_functions else "0") + " > $@")) @@ -628,7 +623,6 @@ def tf_gen_op_wrapper_py(name, outs=[out], srcs=api_def_srcs, tools=[tool_name] + tf_binary_additional_srcs(), - local = (1 if gen_locally else 0), cmd=("$(location " + tool_name + ") " + api_def_args_str + " " + op_list_arg + " " + ("1" if require_shape_functions else "0") + " " + -- cgit v1.2.3 From cde1c8e835f7fdfbb3ab8a4c8a01edb3a7e569aa Mon Sep 17 00:00:00 2001 From: Gunhan Gulsoy Date: Sun, 29 Jul 2018 00:11:42 -0700 Subject: Add a new kernels option to bazel rules to enable adding dynamic kernel dependencies. PiperOrigin-RevId: 206473913 --- tensorflow/BUILD | 8 ++++ .../core/platform/default/build_config_root.bzl | 6 +++ tensorflow/tensorflow.bzl | 53 +++++++++++++++++++--- 3 files changed, 60 insertions(+), 7 deletions(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/BUILD b/tensorflow/BUILD index c9d67021e1..60db234c9c 100644 --- a/tensorflow/BUILD +++ b/tensorflow/BUILD @@ -381,6 +381,14 @@ config_setting( }, ) +# Setting to use when loading kernels dynamically +config_setting( + name = "dynamic_loaded_kernels", + define_values = { + "dynamic_loaded_kernels": "true", + }, +) + config_setting( name = "using_cuda_nvcc", define_values = { diff --git a/tensorflow/core/platform/default/build_config_root.bzl b/tensorflow/core/platform/default/build_config_root.bzl index 09029a4b25..3a012c23fd 100644 --- a/tensorflow/core/platform/default/build_config_root.bzl +++ b/tensorflow/core/platform/default/build_config_root.bzl @@ -58,3 +58,9 @@ def if_static(extra_deps, otherwise=[]): str(Label("//tensorflow:framework_shared_object")): otherwise, "//conditions:default": extra_deps, }) + +def if_dynamic_kernels(extra_deps, otherwise=[]): + return select({ + str(Label("//tensorflow:dynamic_loaded_kernels")): extra_deps, + "//conditions:default": otherwise, + }) diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index f8e55abe79..58282ec1c7 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -9,6 +9,7 @@ load( "tf_additional_grpc_deps_py", "tf_additional_xla_deps_py", "if_static", + "if_dynamic_kernels", ) load( "@local_config_tensorrt//:build_defs.bzl", @@ -318,18 +319,36 @@ def tf_binary_additional_srcs(): clean_dep("//tensorflow:libtensorflow_framework.so"), ]) + +# Helper functions to add kernel dependencies to tf binaries when using dynamic +# kernel linking. +def tf_binary_dynamic_kernel_dsos(kernels): + return if_dynamic_kernels( + extra_deps=["libtfkernel_%s.so" % clean_dep(k) for k in kernels], + otherwise=[]) + +# Helper functions to add kernel dependencies to tf binaries when using static +# kernel linking. +def tf_binary_dynamic_kernel_deps(kernels): + return if_dynamic_kernels( + extra_deps=[], + otherwise=kernels) + def tf_cc_shared_object( name, srcs=[], deps=[], + data=[], linkopts=[], framework_so=tf_binary_additional_srcs(), + kernels=[], **kwargs): native.cc_binary( name=name, srcs=srcs + framework_so, - deps=deps, + deps=deps + tf_binary_dynamic_kernel_deps(kernels), linkshared = 1, + data = data + tf_binary_dynamic_kernel_dsos(kernels), linkopts=linkopts + _rpath_linkopts(name) + select({ clean_dep("//tensorflow:darwin"): [ "-Wl,-install_name,@rpath/" + name.split("/")[-1], @@ -353,18 +372,21 @@ register_extension_info( def tf_cc_binary(name, srcs=[], deps=[], + data=[], linkopts=[], copts=tf_copts(), + kernels=[], **kwargs): native.cc_binary( name=name, copts=copts, srcs=srcs + tf_binary_additional_srcs(), - deps=deps + if_mkl( + deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl( [ "//third_party/mkl:intel_binary_blob", ], ), + data=data + tf_binary_dynamic_kernel_dsos(kernels), linkopts=linkopts + _rpath_linkopts(name), **kwargs) @@ -652,11 +674,13 @@ def tf_gen_op_wrapper_py(name, def tf_cc_test(name, srcs, deps, + data=[], linkstatic=0, extra_copts=[], suffix="", linkopts=[], nocopts=None, + kernels=[], **kwargs): native.cc_test( name="%s%s" % (name, suffix), @@ -676,11 +700,12 @@ def tf_cc_test(name, "-lm" ], }) + linkopts + _rpath_linkopts(name), - deps=deps + if_mkl( + deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl( [ "//third_party/mkl:intel_binary_blob", ], ), + data=data + tf_binary_dynamic_kernel_dsos(kernels), # Nested select() statements seem not to be supported when passed to # linkstatic, and we already have a cuda select() passed in to this # function. @@ -781,6 +806,7 @@ def tf_cuda_only_cc_test(name, size="medium", linkstatic=0, args=[], + kernels=[], linkopts=[]): native.cc_test( name="%s%s" % (name, "_gpu"), @@ -788,8 +814,8 @@ def tf_cuda_only_cc_test(name, size=size, args=args, copts= _cuda_copts() + tf_copts(), - data=data, - deps=deps + if_cuda([ + data=data + tf_binary_dynamic_kernel_dsos(kernels), + deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_cuda([ clean_dep("//tensorflow/core:cuda"), clean_dep("//tensorflow/core:gpu_lib")]), linkopts=if_not_windows(["-lpthread", "-lm"]) + linkopts + _rpath_linkopts(name), @@ -832,9 +858,11 @@ def tf_cc_tests(srcs, def tf_cc_test_mkl(srcs, deps, name="", + data=[], linkstatic=0, tags=[], size="medium", + kernels=[], args=None): # -fno-exceptions in nocopts breaks compilation if header modules are enabled. disable_header_modules = ["-use_header_modules"] @@ -855,11 +883,12 @@ def tf_cc_test_mkl(srcs, "-lm" ], }) + _rpath_linkopts(src_to_test_name(src)), - deps=deps + if_mkl( + deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl( [ "//third_party/mkl:intel_binary_blob", ], ), + data=data + tf_binary_dynamic_kernel_dsos(kernels), linkstatic=linkstatic, tags=tags, size=size, @@ -899,12 +928,13 @@ def tf_cuda_cc_tests(srcs, def tf_java_test(name, srcs=[], deps=[], + kernels=[], *args, **kwargs): native.java_test( name=name, srcs=srcs, - deps=deps + tf_binary_additional_srcs(), + deps=deps + tf_binary_additional_srcs() + tf_binary_dynamic_kernel_dsos(kernels) + tf_binary_dynamic_kernel_deps(kernels), *args, **kwargs) @@ -1078,6 +1108,15 @@ def tf_kernel_library( deps=deps, **kwargs) + # TODO(gunan): CUDA dependency not clear here. Fix it. + tf_cc_shared_object( + name="libtfkernel_%s.so" % name, + srcs=srcs + hdrs, + copts=copts, + deps=deps, + tags=["manual", "notap"]) + + register_extension_info( extension_name = "tf_kernel_library", label_regex_for_dep = "{extension_name}(_gpu)?", -- cgit v1.2.3 From be0396813b25e3180f670d7196ddfac88da80b5e Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Tue, 31 Jul 2018 14:02:30 -0700 Subject: Remove the deprecated, now no-op, "data" transition. RELNOTES: n/a PiperOrigin-RevId: 206822820 --- tensorflow/tensorflow.bzl | 1 - 1 file changed, 1 deletion(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index 58282ec1c7..7d6a27b102 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -1201,7 +1201,6 @@ _py_wrap_cc = rule( allow_files = True, ), "swig_includes": attr.label_list( - cfg = "data", allow_files = True, ), "deps": attr.label_list( -- cgit v1.2.3 From f8afea0e1dc7226d2d4e6bc9fb75ba7094fa727e Mon Sep 17 00:00:00 2001 From: Jonathan Shen Date: Thu, 2 Aug 2018 15:26:37 -0700 Subject: Internal change. PiperOrigin-RevId: 207176147 --- tensorflow/tensorflow.bzl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index 7d6a27b102..39db840884 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -1096,6 +1096,10 @@ def tf_kernel_library( tf_gpu_kernel_library( name=name + "_gpu", srcs=gpu_srcs, deps=deps, **kwargs) cuda_deps.extend([":" + name + "_gpu"]) + kwargs["tags"] = kwargs.get("tags", []) + [ + "req_dep=%s" % clean_dep("//tensorflow/core:gpu_lib"), + "req_dep=@local_config_cuda//cuda:cuda_headers", + ] tf_cuda_library( name=name, srcs=srcs, -- cgit v1.2.3 From be3f9abf85cb8f0a80aa034ec8bfb6b5844fd3e6 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Fri, 10 Aug 2018 16:03:14 -0700 Subject: Internal change. PiperOrigin-RevId: 208283367 --- tensorflow/tensorflow.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index 39db840884..ca9c0d0aae 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -27,7 +27,7 @@ load( ) load( "//third_party/mkl_dnn:build_defs.bzl", - "if_mkl_open_source_only", + "if_mkl_open_source_only" ) def register_extension_info(**kwargs): pass -- cgit v1.2.3 From a8e78e2e617b6ca10f4878fe99fdf43ddedfa7c6 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Fri, 10 Aug 2018 22:34:17 -0700 Subject: Rename MKL-related feature macros. The existing feature macros are named INTEL_MKL to indicate that any flavor of MKL is available, INTEL_MKL_ML to indicate that *only* MKL-ML is available (i.e. MKL-DNN is not), and DO_NOT_USE_ML to indicate that *only* MKL-DNN is available (i.e. MKL-ML is not). This change renames INTEL_MKL_ML to INTEL_MKL_ML_ONLY and DO_NOT_USE_ML to INTEL_MKL_DNN_ONLY. The meanings of the macros have not changed. This change also adds a few sanity checks to mkl_util.h that ensures that the combination of INTEL_MKL, INTEL_MKL_ML_ONLY, and INTEL_MKL_DNN_ONLY is logically consistent: the *_ONLY macros may not both be defined, and if either of them is defined, bare INTEL_MKL must also be defined. PiperOrigin-RevId: 208313735 --- .../compiler/xla/service/cpu/runtime_matmul_mkl.cc | 2 +- tensorflow/core/common_runtime/mkl_cpu_allocator.h | 4 +- tensorflow/core/graph/mkl_layout_pass.cc | 6 +-- tensorflow/core/graph/mkl_layout_pass_test.cc | 6 +-- tensorflow/core/kernels/batch_matmul_op_complex.cc | 2 +- tensorflow/core/kernels/batch_matmul_op_real.cc | 2 +- tensorflow/core/kernels/matmul_op.cc | 4 +- tensorflow/core/kernels/mkl_aggregate_ops.cc | 7 ++-- tensorflow/core/kernels/mkl_avgpooling_op.cc | 6 +-- tensorflow/core/kernels/mkl_batch_matmul_op.cc | 2 +- tensorflow/core/kernels/mkl_concat_op.cc | 7 ++-- tensorflow/core/kernels/mkl_conv_grad_bias_ops.cc | 6 +-- .../core/kernels/mkl_conv_grad_filter_ops.cc | 9 ++-- tensorflow/core/kernels/mkl_conv_grad_input_ops.cc | 10 ++--- tensorflow/core/kernels/mkl_conv_ops.cc | 6 +-- tensorflow/core/kernels/mkl_conv_ops.h | 7 ++-- tensorflow/core/kernels/mkl_fused_batch_norm_op.cc | 7 ++-- tensorflow/core/kernels/mkl_identity_op.cc | 6 +-- tensorflow/core/kernels/mkl_input_conversion_op.cc | 4 +- tensorflow/core/kernels/mkl_lrn_op.cc | 6 +-- tensorflow/core/kernels/mkl_matmul_op.cc | 8 ++-- tensorflow/core/kernels/mkl_maxpooling_op.cc | 6 +-- tensorflow/core/kernels/mkl_pooling_ops_common.cc | 6 +-- tensorflow/core/kernels/mkl_pooling_ops_common.h | 8 ++-- tensorflow/core/kernels/mkl_relu_op.cc | 12 ++---- tensorflow/core/kernels/mkl_reshape_op.cc | 7 ++-- tensorflow/core/kernels/mkl_softmax_op.cc | 4 +- tensorflow/core/kernels/mkl_tfconv_op.h | 6 +-- tensorflow/core/kernels/mkl_transpose_op.cc | 20 ++++----- tensorflow/core/ops/nn_ops.cc | 10 ++--- tensorflow/core/util/mkl_util.h | 48 +++++++++++++--------- tensorflow/core/util/mkl_util_test.cc | 4 +- tensorflow/tensorflow.bzl | 2 +- 33 files changed, 125 insertions(+), 125 deletions(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/compiler/xla/service/cpu/runtime_matmul_mkl.cc b/tensorflow/compiler/xla/service/cpu/runtime_matmul_mkl.cc index 997fdd2ab3..8dc5f3c93b 100644 --- a/tensorflow/compiler/xla/service/cpu/runtime_matmul_mkl.cc +++ b/tensorflow/compiler/xla/service/cpu/runtime_matmul_mkl.cc @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#if defined(INTEL_MKL) && !defined(DO_NOT_USE_ML) +#if defined(INTEL_MKL) && !defined(INTEL_MKL_DNN_ONLY) #include "tensorflow/compiler/xla/service/cpu/runtime_matmul_mkl.h" #include "third_party/intel_mkl_ml/include/mkl_cblas.h" #include "third_party/intel_mkl_ml/include/mkl_service.h" diff --git a/tensorflow/core/common_runtime/mkl_cpu_allocator.h b/tensorflow/core/common_runtime/mkl_cpu_allocator.h index 94e10dbfa2..99bd43e090 100644 --- a/tensorflow/core/common_runtime/mkl_cpu_allocator.h +++ b/tensorflow/core/common_runtime/mkl_cpu_allocator.h @@ -28,7 +28,7 @@ limitations under the License. #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/mem.h" -#ifndef DO_NOT_USE_ML +#ifndef INTEL_MKL_DNN_ONLY #include "i_malloc.h" #endif @@ -98,7 +98,7 @@ class MklCPUAllocator : public VisitableAllocator { VLOG(1) << "MklCPUAllocator: Setting max_mem_bytes: " << max_mem_bytes; allocator_ = new BFCAllocator(new MklSubAllocator, max_mem_bytes, kAllowGrowth, kName); -#ifndef DO_NOT_USE_ML +#ifndef INTEL_MKL_DNN_ONLY // For redirecting all allocations from MKL to this allocator // From: http://software.intel.com/en-us/node/528565 i_malloc = MallocHook; diff --git a/tensorflow/core/graph/mkl_layout_pass.cc b/tensorflow/core/graph/mkl_layout_pass.cc index c22e0a3872..5683944e46 100644 --- a/tensorflow/core/graph/mkl_layout_pass.cc +++ b/tensorflow/core/graph/mkl_layout_pass.cc @@ -43,7 +43,7 @@ limitations under the License. namespace tensorflow { -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY // This pass implements rewriting of graph to support following scenarios: // (A) Merging nodes in the graph @@ -2211,7 +2211,7 @@ Status MklLayoutRewritePass::Run(const GraphOptimizationPassOptions& options) { return Status::OK(); } -#else // INTEL_MKL_ML +#else // INTEL_MKL_ML_ONLY // This pass implements rewriting of graph to support following scenarios: // (A) Merging nodes in the graph @@ -4474,7 +4474,7 @@ Status MklLayoutRewritePass::Run(const GraphOptimizationPassOptions& options) { return Status::OK(); } -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY } // namespace tensorflow #endif diff --git a/tensorflow/core/graph/mkl_layout_pass_test.cc b/tensorflow/core/graph/mkl_layout_pass_test.cc index a41f5861af..e8bac847e5 100644 --- a/tensorflow/core/graph/mkl_layout_pass_test.cc +++ b/tensorflow/core/graph/mkl_layout_pass_test.cc @@ -37,7 +37,7 @@ limitations under the License. namespace tensorflow { -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY namespace { @@ -1898,7 +1898,7 @@ BENCHMARK(BM_MklLayoutRewritePass)->Arg(1000)->Arg(10000); } // namespace -#else // INTEL_MKL_ML +#else // INTEL_MKL_ML_ONLY // NOTE: Unit tests in this file rely on a topological sorted graph for // printing. But since sibling nodes of a node in the topologically sorted graph @@ -3582,7 +3582,7 @@ BENCHMARK(BM_MklLayoutRewritePass)->Arg(1000)->Arg(10000); } // namespace -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY } // namespace tensorflow diff --git a/tensorflow/core/kernels/batch_matmul_op_complex.cc b/tensorflow/core/kernels/batch_matmul_op_complex.cc index b77c80c01f..54c45bfe63 100644 --- a/tensorflow/core/kernels/batch_matmul_op_complex.cc +++ b/tensorflow/core/kernels/batch_matmul_op_complex.cc @@ -17,7 +17,7 @@ limitations under the License. namespace tensorflow { -#if !defined(INTEL_MKL) || defined(DO_NOT_USE_ML) +#if !defined(INTEL_MKL) || defined(INTEL_MKL_DNN_ONLY) TF_CALL_complex64(REGISTER_BATCH_MATMUL_CPU); TF_CALL_complex128(REGISTER_BATCH_MATMUL_CPU); #endif diff --git a/tensorflow/core/kernels/batch_matmul_op_real.cc b/tensorflow/core/kernels/batch_matmul_op_real.cc index aa7a2752e8..584b507c70 100644 --- a/tensorflow/core/kernels/batch_matmul_op_real.cc +++ b/tensorflow/core/kernels/batch_matmul_op_real.cc @@ -21,7 +21,7 @@ limitations under the License. namespace tensorflow { -#if !defined(INTEL_MKL) || defined(DO_NOT_USE_ML) +#if !defined(INTEL_MKL) || defined(INTEL_MKL_DNN_ONLY) TF_CALL_float(REGISTER_BATCH_MATMUL_CPU); TF_CALL_double(REGISTER_BATCH_MATMUL_CPU); #endif diff --git a/tensorflow/core/kernels/matmul_op.cc b/tensorflow/core/kernels/matmul_op.cc index 5d4737549b..79967aab38 100644 --- a/tensorflow/core/kernels/matmul_op.cc +++ b/tensorflow/core/kernels/matmul_op.cc @@ -598,11 +598,11 @@ TF_CALL_float(REGISTER_CPU_EIGEN); // to use only opensource MKL DNN then use default implementation for these // types otherwise use GEMM from MKL ML binary -#if defined(DO_NOT_USE_ML) +#if defined(INTEL_MKL_DNN_ONLY) TF_CALL_complex64(REGISTER_CPU); TF_CALL_complex128(REGISTER_CPU); TF_CALL_double(REGISTER_CPU); -#else // DO_NOT_USE_ML +#else // INTEL_MKL_DNN_ONLY TF_CALL_complex64(REGISTER_CPU_EIGEN); TF_CALL_complex128(REGISTER_CPU_EIGEN); TF_CALL_double(REGISTER_CPU_EIGEN); diff --git a/tensorflow/core/kernels/mkl_aggregate_ops.cc b/tensorflow/core/kernels/mkl_aggregate_ops.cc index 3d04aeeb3e..28edf51546 100644 --- a/tensorflow/core/kernels/mkl_aggregate_ops.cc +++ b/tensorflow/core/kernels/mkl_aggregate_ops.cc @@ -24,8 +24,7 @@ limitations under the License. #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/platform/logging.h" - -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::stream; using mkldnn::sum; @@ -38,7 +37,7 @@ using mkldnn::sum; namespace tensorflow { typedef Eigen::ThreadPoolDevice CPUDevice; -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklAddNOp : public OpKernel { @@ -286,7 +285,7 @@ class MklAddNOp : public OpKernel { } MklAddNOpContext; }; -#else // INTEL_MKL_ML +#else // INTEL_MKL_ML_ONLY template class MklAddNOp : public OpKernel { public: diff --git a/tensorflow/core/kernels/mkl_avgpooling_op.cc b/tensorflow/core/kernels/mkl_avgpooling_op.cc index d3566c2e37..969baecc51 100644 --- a/tensorflow/core/kernels/mkl_avgpooling_op.cc +++ b/tensorflow/core/kernels/mkl_avgpooling_op.cc @@ -24,7 +24,7 @@ #include "tensorflow/core/kernels/mkl_pooling_ops_common.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::algorithm; using mkldnn::engine; @@ -40,7 +40,7 @@ namespace tensorflow { typedef Eigen::ThreadPoolDevice CPUDevice; -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklAvgPoolingOp : public OpKernel { @@ -664,7 +664,7 @@ class MklAvgPoolingGradOp : public MklPoolingBackwardOpBase { } }; // MklAvgPoolingGradOp -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY REGISTER_KERNEL_BUILDER(Name("_MklAvgPool") .Device(DEVICE_CPU) diff --git a/tensorflow/core/kernels/mkl_batch_matmul_op.cc b/tensorflow/core/kernels/mkl_batch_matmul_op.cc index 45328b03d6..0841395dc3 100644 --- a/tensorflow/core/kernels/mkl_batch_matmul_op.cc +++ b/tensorflow/core/kernels/mkl_batch_matmul_op.cc @@ -25,7 +25,7 @@ limitations under the License. #define EIGEN_USE_THREADS -#if defined(INTEL_MKL) && !defined(DO_NOT_USE_ML) +#if defined(INTEL_MKL) && !defined(INTEL_MKL_DNN_ONLY) #include #include "mkl_cblas.h" #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" diff --git a/tensorflow/core/kernels/mkl_concat_op.cc b/tensorflow/core/kernels/mkl_concat_op.cc index d8efb1be3e..8ad7ebb51f 100644 --- a/tensorflow/core/kernels/mkl_concat_op.cc +++ b/tensorflow/core/kernels/mkl_concat_op.cc @@ -27,8 +27,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/platform/types.h" - -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::concat; @@ -64,7 +63,7 @@ class EigenConcatBaseOp : public OpKernel { // we need to have empty Compute because Compute is pure virtual function. void Compute(OpKernelContext* c) {} -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY void Compute(OpKernelContext* c, const std::vector& values) { const Tensor* concat_dim_tensor; @@ -232,7 +231,7 @@ class EigenConcatBaseOp : public OpKernel { #endif }; -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY // -------------------------------------------------------------------------- // Mkl Concat Op diff --git a/tensorflow/core/kernels/mkl_conv_grad_bias_ops.cc b/tensorflow/core/kernels/mkl_conv_grad_bias_ops.cc index f857be6c32..7c687f6581 100644 --- a/tensorflow/core/kernels/mkl_conv_grad_bias_ops.cc +++ b/tensorflow/core/kernels/mkl_conv_grad_bias_ops.cc @@ -18,7 +18,7 @@ limitations under the License. // bias. #ifdef INTEL_MKL -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY #define USE_EIGEN_TENSOR #define EIGEN_USE_THREADS @@ -39,7 +39,7 @@ limitations under the License. #include "tensorflow/core/util/use_cudnn.h" #include "tensorflow/core/util/work_sharder.h" -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY #include "mkl_dnn.h" #include "mkl_dnn_types.h" #endif @@ -265,5 +265,5 @@ class MklConv2DCustomBackpropBiasOp : public OpKernel { TF_CALL_float(REGISTER_CPU_KERNELS); #undef REGISTER_CPU_KERNELS } /* namespace tensorflow */ -#endif /* INTEL_MKL_ML */ +#endif /* INTEL_MKL_ML_ONLY */ #endif /* INTEL_MKL */ diff --git a/tensorflow/core/kernels/mkl_conv_grad_filter_ops.cc b/tensorflow/core/kernels/mkl_conv_grad_filter_ops.cc index b73a119a88..50c25e1da7 100644 --- a/tensorflow/core/kernels/mkl_conv_grad_filter_ops.cc +++ b/tensorflow/core/kernels/mkl_conv_grad_filter_ops.cc @@ -38,8 +38,7 @@ limitations under the License. #include "tensorflow/core/util/use_cudnn.h" #include "tensorflow/core/util/work_sharder.h" - -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::convolution_backward_weights; @@ -56,7 +55,7 @@ using mkldnn::stream; namespace tensorflow { typedef Eigen::ThreadPoolDevice CPUDevice; -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY struct MklConvBwdFilterParams { memory::dims src_dims; @@ -358,7 +357,7 @@ class MklConv2DBwdFilterPrimitiveFactory : public MklPrimitiveFactory { #endif -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklConv2DCustomBackpropFilterOp : public OpKernel { @@ -1050,7 +1049,7 @@ class MklConv2DCustomBackpropFilterOp TF_CALL_float(REGISTER_MKL_FILTER_KERNELS); #undef REGISTER_MKL_FILTER_KERNELS -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY } // namespace tensorflow diff --git a/tensorflow/core/kernels/mkl_conv_grad_input_ops.cc b/tensorflow/core/kernels/mkl_conv_grad_input_ops.cc index 39498f1a80..38e014d68e 100644 --- a/tensorflow/core/kernels/mkl_conv_grad_input_ops.cc +++ b/tensorflow/core/kernels/mkl_conv_grad_input_ops.cc @@ -23,7 +23,7 @@ limitations under the License. #define EIGEN_USE_THREADS #include #include -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY #include "mkl_dnn.h" #include "mkl_dnn_types.h" #endif @@ -46,7 +46,7 @@ limitations under the License. #include "tensorflow/core/util/use_cudnn.h" #include "tensorflow/core/util/work_sharder.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::convolution_backward_data; @@ -57,7 +57,7 @@ using mkldnn::stream; namespace tensorflow { typedef Eigen::ThreadPoolDevice CPUDevice; -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY /// utility classes enabling primitive reuse for backward conv2d ops. struct MklConvBwdInputParams { @@ -294,7 +294,7 @@ class MklConv2DBwdInputPrimitiveFactory : public MklPrimitiveFactory { #endif -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklConv2DCustomBackpropInputOp : public OpKernel { @@ -839,7 +839,7 @@ class MklConv2DCustomBackpropInputOp } }; -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY #define REGISTER_MKL_CPU_KERNELS(T) \ REGISTER_KERNEL_BUILDER(Name("_MklConv2DBackpropInput") \ diff --git a/tensorflow/core/kernels/mkl_conv_ops.cc b/tensorflow/core/kernels/mkl_conv_ops.cc index 62396eeb8b..bca1aa21a8 100644 --- a/tensorflow/core/kernels/mkl_conv_ops.cc +++ b/tensorflow/core/kernels/mkl_conv_ops.cc @@ -42,7 +42,7 @@ limitations under the License. #include "tensorflow/core/util/mkl_util.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::prop_kind; @@ -57,7 +57,7 @@ using mkldnn::convolution_direct; namespace tensorflow { -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY // This structure aggregates multiple inputs to Conv2DFwd* methods. struct MklConvFwdParams { @@ -329,7 +329,7 @@ class MklConv2DFwdPrimitiveFactory : public MklPrimitiveFactory { typedef Eigen::ThreadPoolDevice CPUDevice; // For now, MKL-ML is default. So making MKL-DNN not a default choice. -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklConv2DOp : public OpKernel { public: diff --git a/tensorflow/core/kernels/mkl_conv_ops.h b/tensorflow/core/kernels/mkl_conv_ops.h index 3f154ff33b..838c06f49d 100644 --- a/tensorflow/core/kernels/mkl_conv_ops.h +++ b/tensorflow/core/kernels/mkl_conv_ops.h @@ -40,7 +40,7 @@ limitations under the License. #include "tensorflow/core/util/mkl_util.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::prop_kind; @@ -52,7 +52,7 @@ using mkldnn::convolution_forward; namespace tensorflow { -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY class MklDnnConvUtil { protected: @@ -397,8 +397,7 @@ class MklConv2DBackpropCommonOp : public OpKernel { TensorFormat data_format_; // NCHW or NHWC }; -#endif // INTEL_MKL_ML - +#endif // INTEL_MKL_ML_ONLY ///////////////////////////////////////////////////////////////////// /// Dummy Mkl op that is just used for operators that are intermediate diff --git a/tensorflow/core/kernels/mkl_fused_batch_norm_op.cc b/tensorflow/core/kernels/mkl_fused_batch_norm_op.cc index aa572fb0a3..2ec6c8fa89 100644 --- a/tensorflow/core/kernels/mkl_fused_batch_norm_op.cc +++ b/tensorflow/core/kernels/mkl_fused_batch_norm_op.cc @@ -21,8 +21,7 @@ limitations under the License. #include "tensorflow/core/framework/tensor_types.h" #include "tensorflow/core/util/tensor_format.h" - -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::batch_normalization_backward; using mkldnn::batch_normalization_forward; @@ -41,7 +40,7 @@ using mkldnn::use_scale_shift; namespace tensorflow { using CPUDevice = Eigen::ThreadPoolDevice; -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklFusedBatchNormOp : public OpKernel { @@ -684,7 +683,7 @@ class MklFusedBatchNormGradOp : public OpKernel { }; #endif -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY struct MklBatchNormFwdParams { memory::dims src_dims; diff --git a/tensorflow/core/kernels/mkl_identity_op.cc b/tensorflow/core/kernels/mkl_identity_op.cc index b02cc5384c..b57e816028 100644 --- a/tensorflow/core/kernels/mkl_identity_op.cc +++ b/tensorflow/core/kernels/mkl_identity_op.cc @@ -24,20 +24,20 @@ limitations under the License. #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/platform/logging.h" -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY #include "mkl_dnn.h" #include "mkl_dnn_types.h" #endif #include "tensorflow/core/util/mkl_util.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" #endif namespace tensorflow { typedef Eigen::ThreadPoolDevice CPUDevice; -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklIdentityOp : public OpKernel { diff --git a/tensorflow/core/kernels/mkl_input_conversion_op.cc b/tensorflow/core/kernels/mkl_input_conversion_op.cc index dc4da33a06..06ce820ae9 100644 --- a/tensorflow/core/kernels/mkl_input_conversion_op.cc +++ b/tensorflow/core/kernels/mkl_input_conversion_op.cc @@ -32,7 +32,7 @@ limitations under the License. #include "tensorflow/core/kernels/mkl_tfconv_op.h" #include "tensorflow/core/util/mkl_util.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::stream; @@ -60,7 +60,7 @@ typedef Eigen::ThreadPoolDevice CPUDevice; // convert the TF format input to MKL format /////////////////////////////////////////////////////////// -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklInputConversionOp : public OpKernel { public: diff --git a/tensorflow/core/kernels/mkl_lrn_op.cc b/tensorflow/core/kernels/mkl_lrn_op.cc index 7966c271d5..22ff4cd80f 100644 --- a/tensorflow/core/kernels/mkl_lrn_op.cc +++ b/tensorflow/core/kernels/mkl_lrn_op.cc @@ -35,7 +35,7 @@ limitations under the License. #include "tensorflow/core/util/work_sharder.h" #endif -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::lrn_across_channels; using mkldnn::lrn_backward; @@ -69,7 +69,7 @@ void GetBandMatrix(int depth, int depth_radius, } // namespace -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklLRNOp : public OpKernel { @@ -1345,7 +1345,7 @@ class MklLRNGradOp : public OpKernel { float beta_; }; -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY #define REGISTER_MKL_LRN_CPU(T) \ REGISTER_KERNEL_BUILDER(Name("_MklLRN") \ diff --git a/tensorflow/core/kernels/mkl_matmul_op.cc b/tensorflow/core/kernels/mkl_matmul_op.cc index fd261433a0..077d62ce32 100644 --- a/tensorflow/core/kernels/mkl_matmul_op.cc +++ b/tensorflow/core/kernels/mkl_matmul_op.cc @@ -31,7 +31,7 @@ limitations under the License. #include "tensorflow/core/kernels/fill_functor.h" // This header file is part of MKL ML, need equivalent file in MKL DNN -#ifndef DO_NOT_USE_ML +#ifndef INTEL_MKL_DNN_ONLY #include "mkl_cblas.h" #else #include "mkldnn.h" @@ -155,7 +155,7 @@ class MklMatMulOp : public OpKernel { // 1.0 and 0.0 respectively. const float alpha = 1.0f; const float beta = 0.0f; -#if defined(DO_NOT_USE_ML) +#if defined(INTEL_MKL_DNN_ONLY) const char* const ftrans[] = {"N", "T", "C"}; int index_transa = transa ? 1 : 0; int index_transb = transb ? 1 : 0; @@ -173,7 +173,7 @@ class MklMatMulOp : public OpKernel { } // MKLDNN only supports SGEMM -#ifndef DO_NOT_USE_ML +#ifndef INTEL_MKL_DNN_ONLY // Matrix-Matrix Multiplication with FP64 tensors. For detailed info about // parameters, look at FP32 function description. @@ -229,7 +229,7 @@ class MklMatMulOp : public OpKernel { // additional types TF_CALL_float(REGISTER_CPU); -#ifndef DO_NOT_USE_ML +#ifndef INTEL_MKL_DNN_ONLY TF_CALL_double(REGISTER_CPU); TF_CALL_complex64(REGISTER_CPU); TF_CALL_complex128(REGISTER_CPU); diff --git a/tensorflow/core/kernels/mkl_maxpooling_op.cc b/tensorflow/core/kernels/mkl_maxpooling_op.cc index 0a2151566e..e149f003e5 100644 --- a/tensorflow/core/kernels/mkl_maxpooling_op.cc +++ b/tensorflow/core/kernels/mkl_maxpooling_op.cc @@ -22,7 +22,7 @@ limitations under the License. #include "tensorflow/core/util/mkl_util.h" #include "tensorflow/core/util/padding.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include #include "mkldnn.hpp" using mkldnn::algorithm; @@ -40,7 +40,7 @@ namespace tensorflow { typedef Eigen::ThreadPoolDevice CPUDevice; // MKL-DNN is now default. MKL-ML must be specified explicitly. -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY // An implementation of MaxPooling (forward). template @@ -817,7 +817,7 @@ class MklMaxPoolingGradOp : public MklPoolingBackwardOpBase { } }; // MklMaxPoolingGradOp -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY REGISTER_KERNEL_BUILDER(Name("_MklMaxPool") .Device(DEVICE_CPU) diff --git a/tensorflow/core/kernels/mkl_pooling_ops_common.cc b/tensorflow/core/kernels/mkl_pooling_ops_common.cc index 915878d9ea..d7ad3f9dcd 100644 --- a/tensorflow/core/kernels/mkl_pooling_ops_common.cc +++ b/tensorflow/core/kernels/mkl_pooling_ops_common.cc @@ -223,7 +223,7 @@ void MklPoolParameters::Init(OpKernelContext* context, Init(context, ksize, stride, padding, data_format); } -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY // Initialization for MKL format void MklPoolParameters::Init(OpKernelContext* context, const std::vector& ksize, @@ -253,7 +253,7 @@ void MklPoolParameters::Init(OpKernelContext* context, Init(context, ksize, stride, padding, data_format); } -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY // Common Initialization for TensorFlow and MKL formats void MklPoolParameters::Init(OpKernelContext* context, const std::vector& ksize, @@ -288,7 +288,7 @@ void MklPoolParameters::Init(OpKernelContext* context, OP_REQUIRES_OK(context, GetWindowedOutputSizeVerbose( tensor_in_cols, window_cols, col_stride, padding, &out_width, &pad_left, &pad_right)); -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY // TF can work with int64, but mkldnn only supports int32 // Fail if the height or width are greater than MAX_INT diff --git a/tensorflow/core/kernels/mkl_pooling_ops_common.h b/tensorflow/core/kernels/mkl_pooling_ops_common.h index 3a3de1c58b..ec7af5092d 100644 --- a/tensorflow/core/kernels/mkl_pooling_ops_common.h +++ b/tensorflow/core/kernels/mkl_pooling_ops_common.h @@ -22,7 +22,7 @@ limitations under the License. #include "tensorflow/core/util/mkl_util.h" #include "tensorflow/core/util/padding.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::memory; using mkldnn::pooling_backward; @@ -405,7 +405,7 @@ struct MklPoolParameters { void Init(OpKernelContext* context, const std::vector& ksize, const std::vector& stride, Padding padding, TensorFormat data_format, const TensorShape& tensor_in_shape); -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY void Init(OpKernelContext* context, const std::vector& ksize, const std::vector& stride, Padding padding, TensorFormat data_format, const MklShape* mkl_in_shape); @@ -422,7 +422,7 @@ struct MklPoolParameters { TensorFormat data_format); }; -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY template class MklPoolingOpBase : public OpKernel { @@ -674,7 +674,7 @@ class MklPoolingBackwardOpBase : public MklPoolingOpBase { return grad_reorder_needed ? target_diff_dst_md : original_input_grad_md; } }; -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY //------------------------------------------------------------------- // Utility functions diff --git a/tensorflow/core/kernels/mkl_relu_op.cc b/tensorflow/core/kernels/mkl_relu_op.cc index 78abbdb730..05034894e5 100644 --- a/tensorflow/core/kernels/mkl_relu_op.cc +++ b/tensorflow/core/kernels/mkl_relu_op.cc @@ -23,8 +23,7 @@ limitations under the License. #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/lib/core/errors.h" - -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::algorithm; @@ -58,7 +57,7 @@ struct MklReluHelpers { } }; -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY template class MklReluOp : public OpKernel { @@ -368,10 +367,7 @@ void MklReluGradOp::Compute(OpKernelContext* context) { mkl_context.MklCleanup(); } - - -#else // INTEL_MKL_ML - +#else // INTEL_MKL_ML_ONLY template class MklReluOpBase : public OpKernel { @@ -874,7 +870,7 @@ class MklTanhGradOp : public MklReluGradOpBase { MklReluGradOp); TF_CALL_float(REGISTER_RELU_MKL_SUPPORTED_KERNELS_TYPES); -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY // register dnn kernels for supported operations and supported types #define REGISTER_ELU_MKL_SUPPORTED_KERNELS_TYPES(type) \ diff --git a/tensorflow/core/kernels/mkl_reshape_op.cc b/tensorflow/core/kernels/mkl_reshape_op.cc index 9c536df215..d9a7893a53 100644 --- a/tensorflow/core/kernels/mkl_reshape_op.cc +++ b/tensorflow/core/kernels/mkl_reshape_op.cc @@ -24,8 +24,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/platform/logging.h" - -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" using mkldnn::stream; #else @@ -42,7 +41,7 @@ class MklReshapeOp : public OpKernel { public: explicit MklReshapeOp(OpKernelConstruction* context) : OpKernel(context) {} -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY void Compute(OpKernelContext* context) override { const Tensor& input = MklGetInput(context, 0); const Tensor& sizes = MklGetInput(context, 1); @@ -317,7 +316,7 @@ class MklReshapeOp : public OpKernel { } } -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY private: const int kInputSlotIdx = 0; diff --git a/tensorflow/core/kernels/mkl_softmax_op.cc b/tensorflow/core/kernels/mkl_softmax_op.cc index 638392954e..8bde966be9 100644 --- a/tensorflow/core/kernels/mkl_softmax_op.cc +++ b/tensorflow/core/kernels/mkl_softmax_op.cc @@ -15,7 +15,7 @@ limitations under the License. // See docs in ../ops/nn_ops.cc. #ifdef INTEL_MKL -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" #include "tensorflow/core/framework/numeric_op.h" @@ -153,5 +153,5 @@ TF_CALL_float(REGISTER_SOFTMAX_MKL_SUPPORTED_KERNELS_TYPES); } // namespace tensorflow -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY #endif // INTEL_MKL diff --git a/tensorflow/core/kernels/mkl_tfconv_op.h b/tensorflow/core/kernels/mkl_tfconv_op.h index a9e92f6638..894c2e34e8 100644 --- a/tensorflow/core/kernels/mkl_tfconv_op.h +++ b/tensorflow/core/kernels/mkl_tfconv_op.h @@ -32,13 +32,13 @@ limitations under the License. #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/util/tensor_format.h" -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY #include "mkl_dnn.h" #include "mkl_dnn_types.h" #endif #include "tensorflow/core/util/mkl_util.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY using mkldnn::stream; #endif @@ -64,7 +64,7 @@ class MklToTfOp : public OpKernel { VLOG(1) << "MKLToTFConversion complete successfully."; } -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY static void ConvertMklToTf(OpKernel* op_kernel, OpKernelContext* context, string data_format_str, DataType op_data_type, bool has_avx512f, uint input_number) { diff --git a/tensorflow/core/kernels/mkl_transpose_op.cc b/tensorflow/core/kernels/mkl_transpose_op.cc index 109e634feb..6bbe271c54 100644 --- a/tensorflow/core/kernels/mkl_transpose_op.cc +++ b/tensorflow/core/kernels/mkl_transpose_op.cc @@ -18,14 +18,14 @@ limitations under the License. #if defined(INTEL_MKL) #define EIGEN_USE_THREADS -#if !defined(DO_NOT_USE_ML) +#if !defined(INTEL_MKL_DNN_ONLY) #include "mkl_trans.h" #endif #include "tensorflow/core/kernels/transpose_functor.h" #include "tensorflow/core/kernels/transpose_op.h" -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" #include "tensorflow/core/util/mkl_util.h" @@ -50,7 +50,7 @@ namespace tensorflow { // REQUIRES: perm is a permutation. namespace { -#if !defined(DO_NOT_USE_ML) +#if !defined(INTEL_MKL_DNN_ONLY) template Status MKLTranspose2D(const char trans, const Tensor& in, Tensor* out); @@ -104,9 +104,9 @@ Status MKLTranspose2D(const char trans, const Tensor& in, static const char kMKLTranspose = 'T'; static const char kMKLConjugateTranspose = 'C'; -#endif // if !defined(DO_NOT_USE_ML) +#endif // if !defined(INTEL_MKL_DNN_ONLY) -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY // MKL-DNN based Transpose implementation template Status MKLTransposeND(OpKernelContext* ctx, const Tensor& in, Tensor* out, @@ -154,14 +154,14 @@ Status MKLTransposeND(OpKernelContext* context, const Tensor& in_tensor, return errors::Aborted("Operation received an exception:", error_msg); } } -#endif // #ifndef INTEL_MKL_ML +#endif // #ifndef INTEL_MKL_ML_ONLY } // namespace Status MklTransposeCpuOp::DoTranspose(OpKernelContext* ctx, const Tensor& in, gtl::ArraySlice perm, Tensor* out) { -#if !defined(DO_NOT_USE_ML) +#if !defined(INTEL_MKL_DNN_ONLY) if (in.dims() == 2) { if (perm[0] == 0 && perm[1] == 1) { return Status::OK(); @@ -181,7 +181,7 @@ Status MklTransposeCpuOp::DoTranspose(OpKernelContext* ctx, const Tensor& in, } #endif -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY // MKL-DNN has limit on the maximum number of dimensions in a tensor. // Fallback to Eigen for not supported cases. if (in.dims() <= TENSOR_MAX_DIMS) { @@ -206,7 +206,7 @@ Status MklConjugateTransposeCpuOp::DoTranspose(OpKernelContext* ctx, const Tensor& in, gtl::ArraySlice perm, Tensor* out) { -#if !defined(DO_NOT_USE_ML) +#if !defined(INTEL_MKL_DNN_ONLY) if (in.dims() == 2 && perm[0] == 1 && perm[1] == 0) { // TODO(rmlarsen): By setting lda and ldb, we could use the MKL kernels // for any transpose that can be reduced to swapping the last two @@ -227,7 +227,7 @@ Status MklConjugateTransposeCpuOp::DoTranspose(OpKernelContext* ctx, } #endif -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY // MKL-DNN has limit on the maximum number of dimensions in a tensor. // Fallback to Eigen for not supported cases. if (in.dims() <= TENSOR_MAX_DIMS) { diff --git a/tensorflow/core/ops/nn_ops.cc b/tensorflow/core/ops/nn_ops.cc index f947d4c30d..e0f25fb4ef 100644 --- a/tensorflow/core/ops/nn_ops.cc +++ b/tensorflow/core/ops/nn_ops.cc @@ -1687,7 +1687,7 @@ NOTE Do not invoke this operator directly in Python. Graph rewrite pass is expected to invoke these operators. )doc"); -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY REGISTER_OP("_MklConv2DWithBiasBackpropBias") .Input("out_backprop: T") .Input("mkl_out_backprop: uint8") @@ -1849,7 +1849,7 @@ REGISTER_OP("_MklMaxPool") .Input("input: T") .Input("mkl_input: uint8") .Output("output: T") -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY .Output("workspace: T") #else .Output("workspace: uint8") @@ -1875,7 +1875,7 @@ REGISTER_OP("_MklMaxPoolGrad") .Input("orig_input: T") .Input("orig_output: T") .Input("grad: T") -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY .Input("workspace: T") #else .Input("workspace: uint8") @@ -1947,7 +1947,7 @@ REGISTER_OP("_MklLRN") .Input("input: T") .Input("mkl_input: uint8") .Output("output: T") -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY .Output("workspace: T") #else .Output("workspace: uint8") @@ -1975,7 +1975,7 @@ REGISTER_OP("_MklLRNGrad") .Input("input_grads: T") .Input("input_image: T") .Input("output_image: T") -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY .Input("workspace: T") #else .Input("workspace: uint8") diff --git a/tensorflow/core/util/mkl_util.h b/tensorflow/core/util/mkl_util.h index a66b1215bd..159a787d05 100644 --- a/tensorflow/core/util/mkl_util.h +++ b/tensorflow/core/util/mkl_util.h @@ -22,7 +22,17 @@ limitations under the License. #include #include -#ifdef INTEL_MKL_ML +#if defined(INTEL_MKL_ML_ONLY) || defined(INTEL_MKL_DNN_ONLY) +#ifndef INTEL_MKL +#error "INTEL_MKL_{ML,DNN}_ONLY require INTEL_MKL" +#endif +#endif + +#if defined(INTEL_MKL_ML_ONLY) && defined(INTEL_MKL_DNN_ONLY) +#error "at most one of INTEL_MKL_ML_ONLY and INTEL_MKL_DNN_ONLY may be defined" +#endif + +#ifdef INTEL_MKL_ML_ONLY #include "mkl_dnn.h" #include "mkl_dnn_types.h" #include "mkl_service.h" @@ -40,7 +50,8 @@ limitations under the License. #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/util/padding.h" #include "tensorflow/core/util/tensor_format.h" -#ifndef INTEL_MKL_ML + +#ifndef INTEL_MKL_ML_ONLY #include "mkldnn.hpp" #include "tensorflow/core/lib/core/stringpiece.h" @@ -76,7 +87,7 @@ typedef enum { Dim_I = 1 } MklDnnDims; -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY class MklShape { public: MklShape() {} @@ -670,14 +681,13 @@ class MklDnnShape { // List of MklShape objects. Used in Concat/Split layers. - -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY typedef std::vector MklDnnShapeList; #else typedef std::vector MklShapeList; #endif -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY // Check if all tensors specified by MklShapes are MKL tensors. inline bool AreAllMklTensors(const MklShapeList& shapes) { for (auto& s : shapes) { @@ -760,7 +770,7 @@ inline Tensor ConvertMklToTF(OpKernelContext* context, const Tensor& mkl_tensor, #endif // Get the MKL shape from the second string tensor -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY inline void GetMklShape(OpKernelContext* ctext, int n, MklShape* mklshape) { mklshape->DeSerializeMklShape( ctext->input(GetTensorMetaDataIndex(n, ctext->num_inputs())) @@ -795,7 +805,7 @@ inline void GetMklInputList(OpKernelContext* ctext, StringPiece name, ctext->input_list(name, input_tensors); } -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY inline void GetMklShapeList(OpKernelContext* ctext, StringPiece name, MklShapeList* mkl_shapes) { @@ -825,7 +835,7 @@ inline void GetMklShapeList(OpKernelContext* ctext, StringPiece name, #endif -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY /// Get shape of input tensor pointed by 'input_idx' in TensorShape format. /// If the input tensor is in MKL layout, then obtains TensorShape from /// MklShape. @@ -845,7 +855,7 @@ inline TensorShape GetTfShape(OpKernelContext* context, size_t input_idx) { } #endif -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY // Allocate the second output tensor that will contain // the MKL shape serialized inline void AllocateOutputSetMklShape(OpKernelContext* ctext, int n, @@ -878,7 +888,7 @@ inline void AllocateOutputSetMklShape(OpKernelContext* ctext, int n, } #endif -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY // Allocate the output tensor, create a second output tensor that will contain // the MKL shape serialized inline void AllocateOutputSetMklShape(OpKernelContext* ctext, int n, @@ -923,7 +933,7 @@ inline void AllocateOutputSetMklShape(OpKernelContext* ctext, int n, // Allocates a temp tensor and returns the data buffer for temporary storage. // Currently -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY template inline void AllocTmpBuffer(OpKernelContext* context, Tensor* tensor_out, const memory::primitive_desc& pd, void** buf_out) { @@ -972,7 +982,7 @@ inline void GetStridesFromSizes(TensorFormat data_format, size_t* strides, } } -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY inline void MklSizesToTFSizes(OpKernelContext* context, TensorFormat data_format_, const MklShape& mkl_shape, @@ -1016,7 +1026,7 @@ inline int32 GetMklTensorDimIndex(char dimension) { } } -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY inline int64 GetMklTensorDim(const MklShape& mkl_shape, char dimension) { int index = GetMklTensorDimIndex(dimension); CHECK(index >= 0 && index < mkl_shape.GetDimension()) @@ -1046,7 +1056,7 @@ inline void CopyMklTensorInToOut(OpKernelContext* context, int idx_in, context->set_output(idx_meta_out, meta_output); } -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY inline void CopyTfTensorInToOutWithShape(OpKernelContext* context, int idx_in, int idx_out, const TensorShape& shape) { @@ -1084,7 +1094,7 @@ inline void CopyTfTensorInToOutWithShape(OpKernelContext* context, int idx_in, } #endif -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY inline void ForwardTfTensorInToOut(OpKernelContext* context, int idx_in, int idx_out) { @@ -1142,7 +1152,7 @@ inline void ForwardMklTensorInToOut(OpKernelContext* context, int idx_in, } } -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY // Set a dummy MKLDNN shape (called when the output is in TF format) inline void SetDummyMklDnnShapeOutput(OpKernelContext* context, uint32 idx_data_out) { @@ -1186,7 +1196,7 @@ inline void ForwardMklMetaDataInToOut(OpKernelContext* context, } } -#ifdef INTEL_MKL_ML +#ifdef INTEL_MKL_ML_ONLY // Set a dummy MKL shape (called when the output is in TF format) inline void SetDummyMklShapeOutput(OpKernelContext* context, uint32 idx_data_out) { @@ -1303,7 +1313,7 @@ inline void MklNCHWToNHWC(const Tensor& input, Tensor** output) { #endif // ------------------------------------------------------------------- -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY /// Return MKL-DNN data type (memory::data_type) for input type T /// diff --git a/tensorflow/core/util/mkl_util_test.cc b/tensorflow/core/util/mkl_util_test.cc index cd1d0713ad..4f837f105d 100644 --- a/tensorflow/core/util/mkl_util_test.cc +++ b/tensorflow/core/util/mkl_util_test.cc @@ -22,7 +22,7 @@ limitations under the License. namespace tensorflow { namespace { -#ifndef INTEL_MKL_ML +#ifndef INTEL_MKL_ML_ONLY TEST(MklUtilTest, MklDnnTfShape) { auto cpu_engine = engine(engine::cpu, 0); @@ -84,7 +84,7 @@ TEST(MklUtilTest, MklDnnBlockedFormatTest) { EXPECT_EQ(b_md2.data.format, mkldnn_blocked); } -#endif // INTEL_MKL_ML +#endif // INTEL_MKL_ML_ONLY } // namespace } // namespace tensorflow diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index ca9c0d0aae..30dc4313d0 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -230,7 +230,7 @@ def tf_copts(android_optimization_level_override="-O2", is_external=False): + if_cuda(["-DGOOGLE_CUDA=1"]) + if_tensorrt(["-DGOOGLE_TENSORRT=1"]) + if_mkl(["-DINTEL_MKL=1", "-DEIGEN_USE_VML"]) - + if_mkl_open_source_only(["-DDO_NOT_USE_ML"]) + + if_mkl_open_source_only(["-DINTEL_MKL_DNN_ONLY"]) + if_mkl_lnx_x64(["-fopenmp"]) + if_android_arm(["-mfpu=neon"]) + if_linux_x86_64(["-msse3"]) -- cgit v1.2.3 From 7253bd04a4bdeaa22aeafc61af0f1f611dfda77c Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Tue, 14 Aug 2018 14:10:20 -0700 Subject: 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 --- tensorflow/BUILD | 6 +- tensorflow/compiler/xla/service/cpu/BUILD | 12 +--- tensorflow/core/BUILD | 28 ++------ tensorflow/core/kernels/BUILD | 65 ++++++------------ tensorflow/core/platform/default/build_config.bzl | 6 +- tensorflow/tensorflow.bzl | 19 +++--- tensorflow/tools/pip_package/BUILD | 4 +- third_party/mkl/BUILD | 17 ++++- third_party/mkl/build_defs.bzl | 83 ++++++++++++++++++++--- third_party/mkl_dnn/BUILD | 5 +- 10 files changed, 136 insertions(+), 109 deletions(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/BUILD b/tensorflow/BUILD index b807c8c2c6..f1000c1bff 100644 --- a/tensorflow/BUILD +++ b/tensorflow/BUILD @@ -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", ], ), ) diff --git a/tensorflow/compiler/xla/service/cpu/BUILD b/tensorflow/compiler/xla/service/cpu/BUILD index 07a22d6906..84779c60b0 100644 --- a/tensorflow/compiler/xla/service/cpu/BUILD +++ b/tensorflow/compiler/xla/service/cpu/BUILD @@ -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( diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index 0af8627290..aef652e185 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -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( diff --git a/tensorflow/core/kernels/BUILD b/tensorflow/core/kernels/BUILD index 86ed56a93a..46c234d057 100644 --- a/tensorflow/core/kernels/BUILD +++ b/tensorflow/core/kernels/BUILD @@ -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", ]), # *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: diff --git a/tensorflow/core/platform/default/build_config.bzl b/tensorflow/core/platform/default/build_config.bzl index fb4ee1c33c..6383180e94 100644 --- a/tensorflow/core/platform/default/build_config.bzl +++ b/tensorflow/core/platform/default/build_config.bzl @@ -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", ], ) diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index fc1f9e956f..0b26c0d445 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -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) diff --git a/tensorflow/tools/pip_package/BUILD b/tensorflow/tools/pip_package/BUILD index a8c7afc040..6bba139b4d 100644 --- a/tensorflow/tools/pip_package/BUILD +++ b/tensorflow/tools/pip_package/BUILD @@ -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 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"], ) -- cgit v1.2.3 From 252b822a474da9f5afd31bbb1c32c21744d40260 Mon Sep 17 00:00:00 2001 From: Gunhan Gulsoy Date: Wed, 15 Aug 2018 10:13:37 -0700 Subject: Run buildifier on tensorflow.bzl PiperOrigin-RevId: 208838993 --- tensorflow/tensorflow.bzl | 2725 +++++++++++++++++++++++---------------------- 1 file changed, 1415 insertions(+), 1310 deletions(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index 0b26c0d445..1e028e3350 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -4,12 +4,12 @@ # Uses the ":optmode" config_setting to pick the options. load( "//tensorflow/core:platform/default/build_config_root.bzl", - "tf_cuda_tests_tags", - "tf_sycl_tests_tags", + "if_dynamic_kernels", + "if_static", "tf_additional_grpc_deps_py", "tf_additional_xla_deps_py", - "if_static", - "if_dynamic_kernels", + "tf_cuda_tests_tags", + "tf_sycl_tests_tags", ) load( "@local_config_tensorrt//:build_defs.bzl", @@ -17,8 +17,8 @@ load( ) load( "@local_config_cuda//cuda:build_defs.bzl", - "if_cuda", "cuda_default_copts", + "if_cuda", ) load( "//third_party/mkl:build_defs.bzl", @@ -29,7 +29,7 @@ load( ) load( "//third_party/mkl_dnn:build_defs.bzl", - "if_mkl_open_source_only" + "if_mkl_open_source_only", ) def register_extension_info(**kwargs): pass @@ -38,153 +38,154 @@ def register_extension_info(**kwargs): # i.e. "common_runtime/direct_session_test.cc" becomes # "common_runtime_direct_session_test" def src_to_test_name(src): - return src.replace("/", "_").split(".")[0] + return src.replace("/", "_").split(".")[0] def full_path(relative_paths): - return [native.package_name() + "/" + relative for relative in relative_paths] + return [native.package_name() + "/" + relative for relative in relative_paths] def _add_tfcore_prefix(src): - if src.startswith("//"): - return src - return "//tensorflow/core:" + src + if src.startswith("//"): + return src + return "//tensorflow/core:" + src # List of proto files for android builds def tf_android_core_proto_sources(core_proto_sources_relative): - return [ - _add_tfcore_prefix(p) for p in core_proto_sources_relative - ] + return [ + _add_tfcore_prefix(p) + for p in core_proto_sources_relative + ] # Returns the list of pb.h and proto.h headers that are generated for # tf_android_core_proto_sources(). def tf_android_core_proto_headers(core_proto_sources_relative): - return ([ - _add_tfcore_prefix(p).replace(":", "/").replace(".proto", ".pb.h") - for p in core_proto_sources_relative - ] + [ - _add_tfcore_prefix(p).replace(":", "/").replace(".proto", ".proto.h") - for p in core_proto_sources_relative - ]) + return ([ + _add_tfcore_prefix(p).replace(":", "/").replace(".proto", ".pb.h") + for p in core_proto_sources_relative + ] + [ + _add_tfcore_prefix(p).replace(":", "/").replace(".proto", ".proto.h") + for p in core_proto_sources_relative + ]) # Sanitize a dependency so that it works correctly from code that includes # TensorFlow as a submodule. def clean_dep(dep): - return str(Label(dep)) + return str(Label(dep)) def if_android_x86(a): - return select({ - clean_dep("//tensorflow:android_x86"): a, - clean_dep("//tensorflow:android_x86_64"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:android_x86"): a, + clean_dep("//tensorflow:android_x86_64"): a, + "//conditions:default": [], + }) def if_android_arm(a): - return select({ - clean_dep("//tensorflow:android_arm"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:android_arm"): a, + "//conditions:default": [], + }) def if_android_arm64(a): - return select({ - clean_dep("//tensorflow:android_arm64"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:android_arm64"): a, + "//conditions:default": [], + }) def if_android_mips(a): - return select({ - clean_dep("//tensorflow:android_mips"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:android_mips"): a, + "//conditions:default": [], + }) def if_not_android(a): - return select({ - clean_dep("//tensorflow:android"): [], - "//conditions:default": a, - }) + return select({ + clean_dep("//tensorflow:android"): [], + "//conditions:default": a, + }) def if_not_android_mips_and_mips64(a): - return select({ - clean_dep("//tensorflow:android_mips"): [], - clean_dep("//tensorflow:android_mips64"): [], - "//conditions:default": a, - }) + return select({ + clean_dep("//tensorflow:android_mips"): [], + clean_dep("//tensorflow:android_mips64"): [], + "//conditions:default": a, + }) def if_android(a): - return select({ - clean_dep("//tensorflow:android"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:android"): a, + "//conditions:default": [], + }) def if_ios(a): - return select({ - clean_dep("//tensorflow:ios"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:ios"): a, + "//conditions:default": [], + }) def if_ios_x86_64(a): - return select({ - clean_dep("//tensorflow:ios_x86_64"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:ios_x86_64"): a, + "//conditions:default": [], + }) def if_mobile(a): - return select({ - clean_dep("//tensorflow:android"): a, - clean_dep("//tensorflow:ios"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:android"): a, + clean_dep("//tensorflow:ios"): a, + "//conditions:default": [], + }) def if_not_mobile(a): - return select({ - clean_dep("//tensorflow:android"): [], - clean_dep("//tensorflow:ios"): [], - "//conditions:default": a, - }) + return select({ + clean_dep("//tensorflow:android"): [], + clean_dep("//tensorflow:ios"): [], + "//conditions:default": a, + }) # Config setting selector used when building for products # which requires restricted licenses to be avoided. def if_not_lgpl_restricted(a): - _ = (a,) - return select({ - "//conditions:default": [], - }) + _ = (a,) + return select({ + "//conditions:default": [], + }) def if_not_windows(a): - return select({ - clean_dep("//tensorflow:windows"): [], - "//conditions:default": a, - }) + return select({ + clean_dep("//tensorflow:windows"): [], + "//conditions:default": a, + }) def if_windows(a): - return select({ - clean_dep("//tensorflow:windows"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:windows"): a, + "//conditions:default": [], + }) def if_not_windows_cuda(a): - return select({ - clean_dep("//tensorflow:with_cuda_support_windows_override"): [], - "//conditions:default": a, - }) + return select({ + clean_dep("//tensorflow:with_cuda_support_windows_override"): [], + "//conditions:default": a, + }) def if_linux_x86_64(a): - return select({ - clean_dep("//tensorflow:linux_x86_64"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:linux_x86_64"): a, + "//conditions:default": [], + }) def if_darwin(a): - return select({ - clean_dep("//tensorflow:darwin"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:darwin"): a, + "//conditions:default": [], + }) def if_override_eigen_strong_inline(a): - return select({ - clean_dep("//tensorflow:override_eigen_strong_inline"): a, - "//conditions:default": [], - }) + return select({ + clean_dep("//tensorflow:override_eigen_strong_inline"): a, + "//conditions:default": [], + }) -def get_win_copts(is_external=False): +def get_win_copts(is_external = False): WINDOWS_COPTS = [ "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", @@ -202,161 +203,169 @@ def get_win_copts(is_external=False): "/DNOGDI", ] if is_external: - return WINDOWS_COPTS + ["/UTF_COMPILE_LIBRARY"] + return WINDOWS_COPTS + ["/UTF_COMPILE_LIBRARY"] else: - return WINDOWS_COPTS + ["/DTF_COMPILE_LIBRARY"] + return WINDOWS_COPTS + ["/DTF_COMPILE_LIBRARY"] # LINT.IfChange -def tf_copts(android_optimization_level_override="-O2", is_external=False): - # For compatibility reasons, android_optimization_level_override - # is currently only being set for Android. - # To clear this value, and allow the CROSSTOOL default - # to be used, pass android_optimization_level_override=None - android_copts = [ - "-std=c++11", - "-DTF_LEAN_BINARY", - "-Wno-narrowing", - "-fomit-frame-pointer", - ] - if android_optimization_level_override: - android_copts.append(android_optimization_level_override) - return ( - if_not_windows([ - "-DEIGEN_AVOID_STL_ARRAY", - "-Iexternal/gemmlowp", - "-Wno-sign-compare", - "-fno-exceptions", - "-ftemplate-depth=900"]) - + if_cuda(["-DGOOGLE_CUDA=1"]) - + if_tensorrt(["-DGOOGLE_TENSORRT=1"]) - + if_mkl(["-DINTEL_MKL=1", "-DEIGEN_USE_VML"]) - + if_mkl_open_source_only(["-DINTEL_MKL_DNN_ONLY"]) - + if_mkl_lnx_x64(["-fopenmp"]) - + if_android_arm(["-mfpu=neon"]) - + if_linux_x86_64(["-msse3"]) - + if_ios_x86_64(["-msse4.1"]) - + select({ +def tf_copts(android_optimization_level_override = "-O2", is_external = False): + # For compatibility reasons, android_optimization_level_override + # is currently only being set for Android. + # To clear this value, and allow the CROSSTOOL default + # to be used, pass android_optimization_level_override=None + android_copts = [ + "-std=c++11", + "-DTF_LEAN_BINARY", + "-Wno-narrowing", + "-fomit-frame-pointer", + ] + if android_optimization_level_override: + android_copts.append(android_optimization_level_override) + return ( + if_not_windows([ + "-DEIGEN_AVOID_STL_ARRAY", + "-Iexternal/gemmlowp", + "-Wno-sign-compare", + "-fno-exceptions", + "-ftemplate-depth=900", + ]) + + if_cuda(["-DGOOGLE_CUDA=1"]) + + if_tensorrt(["-DGOOGLE_TENSORRT=1"]) + + if_mkl(["-DINTEL_MKL=1", "-DEIGEN_USE_VML"]) + + if_mkl_open_source_only(["-DINTEL_MKL_DNN_ONLY"]) + + if_mkl_lnx_x64(["-fopenmp"]) + + if_android_arm(["-mfpu=neon"]) + + if_linux_x86_64(["-msse3"]) + + if_ios_x86_64(["-msse4.1"]) + + select({ clean_dep("//tensorflow:framework_shared_object"): [], "//conditions:default": ["-DTENSORFLOW_MONOLITHIC_BUILD"], - }) - + select({ + }) + + select({ clean_dep("//tensorflow:android"): android_copts, clean_dep("//tensorflow:darwin"): [], clean_dep("//tensorflow:windows"): get_win_copts(is_external), clean_dep("//tensorflow:ios"): ["-std=c++11"], clean_dep("//tensorflow:no_lgpl_deps"): ["-D__TENSORFLOW_NO_LGPL_DEPS__", "-pthread"], - "//conditions:default": ["-pthread"] - })) - + "//conditions:default": ["-pthread"], + }) + ) def tfe_xla_copts(): - return select({ - "//tensorflow:with_xla_support": ["-DTENSORFLOW_EAGER_USE_XLA"], - "//conditions:default": [], - }) + return select({ + "//tensorflow:with_xla_support": ["-DTENSORFLOW_EAGER_USE_XLA"], + "//conditions:default": [], + }) def tf_opts_nortti_if_android(): - return if_android([ - "-fno-rtti", - "-DGOOGLE_PROTOBUF_NO_RTTI", - "-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER", - ]) + return if_android([ + "-fno-rtti", + "-DGOOGLE_PROTOBUF_NO_RTTI", + "-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER", + ]) # LINT.ThenChange(//tensorflow/contrib/android/cmake/CMakeLists.txt) def tf_features_nomodules_if_android(): - return if_android(["-use_header_modules"]) + return if_android(["-use_header_modules"]) # Given a list of "op_lib_names" (a list of files in the ops directory # without their .cc extensions), generate a library for that file. -def tf_gen_op_libs(op_lib_names, deps=None, is_external=True): - # Make library out of each op so it can also be used to generate wrappers - # for various languages. - if not deps: - deps = [] - for n in op_lib_names: - native.cc_library( - name=n + "_op_lib", - copts=tf_copts(is_external=is_external), - srcs=["ops/" + n + ".cc"], - deps=deps + [clean_dep("//tensorflow/core:framework")], - visibility=["//visibility:public"], - alwayslink=1, - linkstatic=1,) +def tf_gen_op_libs(op_lib_names, deps = None, is_external = True): + # Make library out of each op so it can also be used to generate wrappers + # for various languages. + if not deps: + deps = [] + for n in op_lib_names: + native.cc_library( + name = n + "_op_lib", + copts = tf_copts(is_external = is_external), + srcs = ["ops/" + n + ".cc"], + deps = deps + [clean_dep("//tensorflow/core:framework")], + visibility = ["//visibility:public"], + alwayslink = 1, + linkstatic = 1, + ) def _make_search_paths(prefix, levels_to_root): - return ",".join( - ["-rpath,%s/%s" % (prefix, "/".join([".."] * search_level)) - for search_level in range(levels_to_root + 1)]) + return ",".join( + [ + "-rpath,%s/%s" % (prefix, "/".join([".."] * search_level)) + for search_level in range(levels_to_root + 1) + ], + ) def _rpath_linkopts(name): - # Search parent directories up to the TensorFlow root directory for shared - # object dependencies, even if this op shared object is deeply nested - # (e.g. tensorflow/contrib/package:python/ops/_op_lib.so). tensorflow/ is then - # the root and tensorflow/libtensorflow_framework.so should exist when - # deployed. Other shared object dependencies (e.g. shared between contrib/ - # ops) are picked up as long as they are in either the same or a parent - # directory in the tensorflow/ tree. - levels_to_root = native.package_name().count("/") + name.count("/") - return select({ - clean_dep("//tensorflow:darwin"): [ - "-Wl,%s" % (_make_search_paths("@loader_path", levels_to_root),), - ], - clean_dep("//tensorflow:windows"): [], - "//conditions:default": [ - "-Wl,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),), - ], - }) + # Search parent directories up to the TensorFlow root directory for shared + # object dependencies, even if this op shared object is deeply nested + # (e.g. tensorflow/contrib/package:python/ops/_op_lib.so). tensorflow/ is then + # the root and tensorflow/libtensorflow_framework.so should exist when + # deployed. Other shared object dependencies (e.g. shared between contrib/ + # ops) are picked up as long as they are in either the same or a parent + # directory in the tensorflow/ tree. + levels_to_root = native.package_name().count("/") + name.count("/") + return select({ + clean_dep("//tensorflow:darwin"): [ + "-Wl,%s" % (_make_search_paths("@loader_path", levels_to_root),), + ], + clean_dep("//tensorflow:windows"): [], + "//conditions:default": [ + "-Wl,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),), + ], + }) # Bazel-generated shared objects which must be linked into TensorFlow binaries # to define symbols from //tensorflow/core:framework and //tensorflow/core:lib. def tf_binary_additional_srcs(): - return if_static( - extra_deps=[], - otherwise=[ - clean_dep("//tensorflow:libtensorflow_framework.so"), - ]) - + return if_static( + extra_deps = [], + otherwise = [ + clean_dep("//tensorflow:libtensorflow_framework.so"), + ], + ) # Helper functions to add kernel dependencies to tf binaries when using dynamic # kernel linking. def tf_binary_dynamic_kernel_dsos(kernels): - return if_dynamic_kernels( - extra_deps=["libtfkernel_%s.so" % clean_dep(k) for k in kernels], - otherwise=[]) + return if_dynamic_kernels( + extra_deps = ["libtfkernel_%s.so" % clean_dep(k) for k in kernels], + otherwise = [], + ) # Helper functions to add kernel dependencies to tf binaries when using static # kernel linking. def tf_binary_dynamic_kernel_deps(kernels): - return if_dynamic_kernels( - extra_deps=[], - otherwise=kernels) + return if_dynamic_kernels( + extra_deps = [], + otherwise = kernels, + ) def tf_cc_shared_object( - name, - srcs=[], - deps=[], - data=[], - linkopts=[], - framework_so=tf_binary_additional_srcs(), - kernels=[], - **kwargs): - native.cc_binary( - name=name, - srcs=srcs + framework_so, - deps=deps + tf_binary_dynamic_kernel_deps(kernels), - linkshared = 1, - data = data + tf_binary_dynamic_kernel_dsos(kernels), - linkopts=linkopts + _rpath_linkopts(name) + select({ - clean_dep("//tensorflow:darwin"): [ - "-Wl,-install_name,@rpath/" + name.split("/")[-1], - ], - clean_dep("//tensorflow:windows"): [], - "//conditions:default": [ - "-Wl,-soname," + name.split("/")[-1], - ], - }), - **kwargs) + name, + srcs = [], + deps = [], + data = [], + linkopts = [], + framework_so = tf_binary_additional_srcs(), + kernels = [], + **kwargs): + native.cc_binary( + name = name, + srcs = srcs + framework_so, + deps = deps + tf_binary_dynamic_kernel_deps(kernels), + linkshared = 1, + data = data + tf_binary_dynamic_kernel_dsos(kernels), + linkopts = linkopts + _rpath_linkopts(name) + select({ + clean_dep("//tensorflow:darwin"): [ + "-Wl,-install_name,@rpath/" + name.split("/")[-1], + ], + clean_dep("//tensorflow:windows"): [], + "//conditions:default": [ + "-Wl,-soname," + name.split("/")[-1], + ], + }), + **kwargs + ) register_extension_info( extension_name = "tf_cc_shared_object", @@ -367,26 +376,28 @@ register_extension_info( # (//third_party/tensorflow:libtensorflow_framework.so) when not building # statically. Also adds linker options (rpaths) so that the framework shared # object can be found. -def tf_cc_binary(name, - srcs=[], - deps=[], - data=[], - linkopts=[], - copts=tf_copts(), - kernels=[], - **kwargs): - native.cc_binary( - name=name, - copts=copts, - srcs=srcs + tf_binary_additional_srcs(), - deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml( - [ - "//third_party/intel_mkl_ml", - ], - ), - data=data + tf_binary_dynamic_kernel_dsos(kernels), - linkopts=linkopts + _rpath_linkopts(name), - **kwargs) +def tf_cc_binary( + name, + srcs = [], + deps = [], + data = [], + linkopts = [], + copts = tf_copts(), + kernels = [], + **kwargs): + native.cc_binary( + name = name, + copts = copts, + srcs = srcs + tf_binary_additional_srcs(), + deps = deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml( + [ + "//third_party/intel_mkl_ml", + ], + ), + data = data + tf_binary_dynamic_kernel_dsos(kernels), + linkopts = linkopts + _rpath_linkopts(name), + **kwargs + ) register_extension_info( extension_name = "tf_cc_binary", @@ -396,64 +407,72 @@ register_extension_info( # A simple wrap around native.cc_binary rule. # When using this rule, you should realize it doesn't link to any tensorflow # dependencies by default. -def tf_native_cc_binary(name, - copts=tf_copts(), - **kwargs): - native.cc_binary( - name=name, - copts=copts, - **kwargs) +def tf_native_cc_binary( + name, + copts = tf_copts(), + **kwargs): + native.cc_binary( + name = name, + copts = copts, + **kwargs + ) register_extension_info( extension_name = "tf_native_cc_binary", label_regex_for_dep = "{extension_name}.*", ) -def tf_gen_op_wrapper_cc(name, - out_ops_file, - pkg="", - op_gen=clean_dep("//tensorflow/cc:cc_op_gen_main"), - deps=None, - include_internal_ops=0, - # ApiDefs will be loaded in the order specified in this list. - api_def_srcs=[]): - # Construct an op generator binary for these ops. - tool = out_ops_file + "_gen_cc" - if deps == None: - deps = [pkg + ":" + name + "_op_lib"] - tf_cc_binary( - name=tool, - copts=tf_copts(), - linkopts=if_not_windows(["-lm"]), - linkstatic=1, # Faster to link this one-time-use binary dynamically - deps=[op_gen] + deps) - - srcs = api_def_srcs[:] - - if not api_def_srcs: - api_def_args_str = "," - else: - api_def_args = [] - for api_def_src in api_def_srcs: - # Add directory of the first ApiDef source to args. - # We are assuming all ApiDefs in a single api_def_src are in the - # same directory. - api_def_args.append( - " $$(dirname $$(echo $(locations " + api_def_src + - ") | cut -d\" \" -f1))") - api_def_args_str = ",".join(api_def_args) - - native.genrule( - name=name + "_genrule", - outs=[ - out_ops_file + ".h", out_ops_file + ".cc", - out_ops_file + "_internal.h", out_ops_file + "_internal.cc" - ], - srcs=srcs, - tools=[":" + tool] + tf_binary_additional_srcs(), - cmd=("$(location :" + tool + ") $(location :" + out_ops_file + ".h) " + - "$(location :" + out_ops_file + ".cc) " + - str(include_internal_ops) + " " + api_def_args_str)) +def tf_gen_op_wrapper_cc( + name, + out_ops_file, + pkg = "", + op_gen = clean_dep("//tensorflow/cc:cc_op_gen_main"), + deps = None, + include_internal_ops = 0, + # ApiDefs will be loaded in the order specified in this list. + api_def_srcs = []): + # Construct an op generator binary for these ops. + tool = out_ops_file + "_gen_cc" + if deps == None: + deps = [pkg + ":" + name + "_op_lib"] + tf_cc_binary( + name = tool, + copts = tf_copts(), + linkopts = if_not_windows(["-lm"]), + linkstatic = 1, # Faster to link this one-time-use binary dynamically + deps = [op_gen] + deps, + ) + + srcs = api_def_srcs[:] + + if not api_def_srcs: + api_def_args_str = "," + else: + api_def_args = [] + for api_def_src in api_def_srcs: + # Add directory of the first ApiDef source to args. + # We are assuming all ApiDefs in a single api_def_src are in the + # same directory. + api_def_args.append( + " $$(dirname $$(echo $(locations " + api_def_src + + ") | cut -d\" \" -f1))", + ) + api_def_args_str = ",".join(api_def_args) + + native.genrule( + name = name + "_genrule", + outs = [ + out_ops_file + ".h", + out_ops_file + ".cc", + out_ops_file + "_internal.h", + out_ops_file + "_internal.cc", + ], + srcs = srcs, + tools = [":" + tool] + tf_binary_additional_srcs(), + cmd = ("$(location :" + tool + ") $(location :" + out_ops_file + ".h) " + + "$(location :" + out_ops_file + ".cc) " + + str(include_internal_ops) + " " + api_def_args_str), + ) # Given a list of "op_lib_names" (a list of files in the ops directory # without their .cc extensions), generate individual C++ .cc and .h @@ -482,68 +501,72 @@ def tf_gen_op_wrapper_cc(name, # "ops/math_ops_internal.h" ], # deps = [ ... ]) # TODO(joshl): Cleaner approach for hidden ops. -def tf_gen_op_wrappers_cc(name, - op_lib_names=[], - other_srcs=[], - other_hdrs=[], - pkg="", - deps=[ - clean_dep("//tensorflow/cc:ops"), - clean_dep("//tensorflow/cc:scope"), - clean_dep("//tensorflow/cc:const_op"), - ], - op_gen=clean_dep("//tensorflow/cc:cc_op_gen_main"), - include_internal_ops=0, - visibility=None, - # ApiDefs will be loaded in the order apecified in this list. - api_def_srcs=[]): - subsrcs = other_srcs[:] - subhdrs = other_hdrs[:] - internalsrcs = [] - internalhdrs = [] - for n in op_lib_names: - tf_gen_op_wrapper_cc( - n, - "ops/" + n, - pkg=pkg, - op_gen=op_gen, - include_internal_ops=include_internal_ops, - api_def_srcs=api_def_srcs) - subsrcs += ["ops/" + n + ".cc"] - subhdrs += ["ops/" + n + ".h"] - internalsrcs += ["ops/" + n + "_internal.cc"] - internalhdrs += ["ops/" + n + "_internal.h"] - - native.cc_library( - name=name, - srcs=subsrcs, - hdrs=subhdrs, - deps=deps + if_not_android([ - clean_dep("//tensorflow/core:core_cpu"), - clean_dep("//tensorflow/core:framework"), - clean_dep("//tensorflow/core:lib"), - clean_dep("//tensorflow/core:protos_all_cc"), - ]) + if_android([ - clean_dep("//tensorflow/core:android_tensorflow_lib"), - ]), - copts=tf_copts(), - alwayslink=1, - visibility=visibility) - native.cc_library( - name=name + "_internal", - srcs=internalsrcs, - hdrs=internalhdrs, - deps=deps + if_not_android([ - clean_dep("//tensorflow/core:core_cpu"), - clean_dep("//tensorflow/core:framework"), - clean_dep("//tensorflow/core:lib"), - clean_dep("//tensorflow/core:protos_all_cc"), - ]) + if_android([ - clean_dep("//tensorflow/core:android_tensorflow_lib"), - ]), - copts=tf_copts(), - alwayslink=1, - visibility=[clean_dep("//tensorflow:internal")]) +def tf_gen_op_wrappers_cc( + name, + op_lib_names = [], + other_srcs = [], + other_hdrs = [], + pkg = "", + deps = [ + clean_dep("//tensorflow/cc:ops"), + clean_dep("//tensorflow/cc:scope"), + clean_dep("//tensorflow/cc:const_op"), + ], + op_gen = clean_dep("//tensorflow/cc:cc_op_gen_main"), + include_internal_ops = 0, + visibility = None, + # ApiDefs will be loaded in the order apecified in this list. + api_def_srcs = []): + subsrcs = other_srcs[:] + subhdrs = other_hdrs[:] + internalsrcs = [] + internalhdrs = [] + for n in op_lib_names: + tf_gen_op_wrapper_cc( + n, + "ops/" + n, + pkg = pkg, + op_gen = op_gen, + include_internal_ops = include_internal_ops, + api_def_srcs = api_def_srcs, + ) + subsrcs += ["ops/" + n + ".cc"] + subhdrs += ["ops/" + n + ".h"] + internalsrcs += ["ops/" + n + "_internal.cc"] + internalhdrs += ["ops/" + n + "_internal.h"] + + native.cc_library( + name = name, + srcs = subsrcs, + hdrs = subhdrs, + deps = deps + if_not_android([ + clean_dep("//tensorflow/core:core_cpu"), + clean_dep("//tensorflow/core:framework"), + clean_dep("//tensorflow/core:lib"), + clean_dep("//tensorflow/core:protos_all_cc"), + ]) + if_android([ + clean_dep("//tensorflow/core:android_tensorflow_lib"), + ]), + copts = tf_copts(), + alwayslink = 1, + visibility = visibility, + ) + native.cc_library( + name = name + "_internal", + srcs = internalsrcs, + hdrs = internalhdrs, + deps = deps + if_not_android([ + clean_dep("//tensorflow/core:core_cpu"), + clean_dep("//tensorflow/core:framework"), + clean_dep("//tensorflow/core:lib"), + clean_dep("//tensorflow/core:protos_all_cc"), + ]) + if_android([ + clean_dep("//tensorflow/core:android_tensorflow_lib"), + ]), + copts = tf_copts(), + alwayslink = 1, + visibility = [clean_dep("//tensorflow:internal")], + ) # Generates a Python library target wrapping the ops registered in "deps". # @@ -569,96 +592,102 @@ def tf_gen_op_wrappers_cc(name, # is invalid to specify both "hidden" and "op_whitelist". # cc_linkopts: Optional linkopts to be added to tf_cc_binary that contains the # specified ops. -def tf_gen_op_wrapper_py(name, - out=None, - hidden=None, - visibility=None, - deps=[], - require_shape_functions=False, - hidden_file=None, - generated_target_name=None, - op_whitelist=[], - cc_linkopts=[], - api_def_srcs=[]): - if (hidden or hidden_file) and op_whitelist: - fail('Cannot pass specify both hidden and op_whitelist.') - - # Construct a cc_binary containing the specified ops. - tool_name = "gen_" + name + "_py_wrappers_cc" - if not deps: - deps = [str(Label("//tensorflow/core:" + name + "_op_lib"))] - tf_cc_binary( - name=tool_name, - linkopts=if_not_windows(["-lm"]) + cc_linkopts, - copts=tf_copts(), - linkstatic=1, # Faster to link this one-time-use binary dynamically - deps=([ - clean_dep("//tensorflow/core:framework"), - clean_dep("//tensorflow/python:python_op_gen_main") - ] + deps), - visibility=[clean_dep("//tensorflow:internal")],) - - # Invoke the previous cc_binary to generate a python file. - if not out: - out = "ops/gen_" + name + ".py" - - if hidden: - op_list_arg = ",".join(hidden) - op_list_is_whitelist = False - elif op_whitelist: - op_list_arg = ",".join(op_whitelist) - op_list_is_whitelist = True - else: - op_list_arg = "''" - op_list_is_whitelist = False - - # Prepare ApiDef directories to pass to the genrule. - if not api_def_srcs: - api_def_args_str = "," - else: - api_def_args = [] - for api_def_src in api_def_srcs: - # Add directory of the first ApiDef source to args. - # We are assuming all ApiDefs in a single api_def_src are in the - # same directory. - api_def_args.append( - "$$(dirname $$(echo $(locations " + api_def_src + - ") | cut -d\" \" -f1))") - api_def_args_str = ",".join(api_def_args) - - if hidden_file: - # `hidden_file` is file containing a list of op names to be hidden in the - # generated module. - native.genrule( - name=name + "_pygenrule", - outs=[out], - srcs=api_def_srcs + [hidden_file], - tools=[tool_name] + tf_binary_additional_srcs(), - cmd=("$(location " + tool_name + ") " + api_def_args_str + - " @$(location " + hidden_file + ") " + - ("1" if require_shape_functions else "0") + " > $@")) - else: - native.genrule( - name=name + "_pygenrule", - outs=[out], - srcs=api_def_srcs, - tools=[tool_name] + tf_binary_additional_srcs(), - cmd=("$(location " + tool_name + ") " + api_def_args_str + " " + - op_list_arg + " " + - ("1" if require_shape_functions else "0") + " " + - ("1" if op_list_is_whitelist else "0") + " > $@")) - - # Make a py_library out of the generated python file. - if not generated_target_name: - generated_target_name = name - native.py_library( - name=generated_target_name, - srcs=[out], - srcs_version="PY2AND3", - visibility=visibility, - deps=[ - clean_dep("//tensorflow/python:framework_for_generated_wrappers_v2"), - ],) +def tf_gen_op_wrapper_py( + name, + out = None, + hidden = None, + visibility = None, + deps = [], + require_shape_functions = False, + hidden_file = None, + generated_target_name = None, + op_whitelist = [], + cc_linkopts = [], + api_def_srcs = []): + if (hidden or hidden_file) and op_whitelist: + fail("Cannot pass specify both hidden and op_whitelist.") + + # Construct a cc_binary containing the specified ops. + tool_name = "gen_" + name + "_py_wrappers_cc" + if not deps: + deps = [str(Label("//tensorflow/core:" + name + "_op_lib"))] + tf_cc_binary( + name = tool_name, + linkopts = if_not_windows(["-lm"]) + cc_linkopts, + copts = tf_copts(), + linkstatic = 1, # Faster to link this one-time-use binary dynamically + deps = ([ + clean_dep("//tensorflow/core:framework"), + clean_dep("//tensorflow/python:python_op_gen_main"), + ] + deps), + visibility = [clean_dep("//tensorflow:internal")], + ) + + # Invoke the previous cc_binary to generate a python file. + if not out: + out = "ops/gen_" + name + ".py" + + if hidden: + op_list_arg = ",".join(hidden) + op_list_is_whitelist = False + elif op_whitelist: + op_list_arg = ",".join(op_whitelist) + op_list_is_whitelist = True + else: + op_list_arg = "''" + op_list_is_whitelist = False + + # Prepare ApiDef directories to pass to the genrule. + if not api_def_srcs: + api_def_args_str = "," + else: + api_def_args = [] + for api_def_src in api_def_srcs: + # Add directory of the first ApiDef source to args. + # We are assuming all ApiDefs in a single api_def_src are in the + # same directory. + api_def_args.append( + "$$(dirname $$(echo $(locations " + api_def_src + + ") | cut -d\" \" -f1))", + ) + api_def_args_str = ",".join(api_def_args) + + if hidden_file: + # `hidden_file` is file containing a list of op names to be hidden in the + # generated module. + native.genrule( + name = name + "_pygenrule", + outs = [out], + srcs = api_def_srcs + [hidden_file], + tools = [tool_name] + tf_binary_additional_srcs(), + cmd = ("$(location " + tool_name + ") " + api_def_args_str + + " @$(location " + hidden_file + ") " + + ("1" if require_shape_functions else "0") + " > $@"), + ) + else: + native.genrule( + name = name + "_pygenrule", + outs = [out], + srcs = api_def_srcs, + tools = [tool_name] + tf_binary_additional_srcs(), + cmd = ("$(location " + tool_name + ") " + api_def_args_str + " " + + op_list_arg + " " + + ("1" if require_shape_functions else "0") + " " + + ("1" if op_list_is_whitelist else "0") + " > $@"), + ) + + # Make a py_library out of the generated python file. + if not generated_target_name: + generated_target_name = name + native.py_library( + name = generated_target_name, + srcs = [out], + srcs_version = "PY2AND3", + visibility = visibility, + deps = [ + clean_dep("//tensorflow/python:framework_for_generated_wrappers_v2"), + ], + ) # Define a bazel macro that creates cc_test for tensorflow. # @@ -669,52 +698,54 @@ def tf_gen_op_wrapper_py(name, # # TODO(opensource): we need to enable this to work around the hidden symbol # __cudaRegisterFatBinary error. Need more investigations. -def tf_cc_test(name, - srcs, - deps, - data=[], - linkstatic=0, - extra_copts=[], - suffix="", - linkopts=[], - nocopts=None, - kernels=[], - **kwargs): - native.cc_test( - name="%s%s" % (name, suffix), - srcs=srcs + tf_binary_additional_srcs(), - copts=tf_copts() + extra_copts, - linkopts=select({ - clean_dep("//tensorflow:android"): [ - "-pie", - ], - clean_dep("//tensorflow:windows"): [], - clean_dep("//tensorflow:darwin"): [ - "-lm", - ], - "//conditions:default": [ - "-lpthread", - "-lm" - ], - }) + linkopts + _rpath_linkopts(name), - deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml( - [ - "//third_party/intel_mkl_ml", - ], - ), - data=data + tf_binary_dynamic_kernel_dsos(kernels), - # Nested select() statements seem not to be supported when passed to - # linkstatic, and we already have a cuda select() passed in to this - # function. - linkstatic=linkstatic or select({ - # cc_tests with ".so"s in srcs incorrectly link on Darwin unless - # linkstatic=1 (https://github.com/bazelbuild/bazel/issues/3450). - # TODO(allenl): Remove Mac static linking when Bazel 0.6 is out. - clean_dep("//tensorflow:darwin"): 1, - "//conditions:default": 0, - }), - nocopts=nocopts, - **kwargs) +def tf_cc_test( + name, + srcs, + deps, + data = [], + linkstatic = 0, + extra_copts = [], + suffix = "", + linkopts = [], + nocopts = None, + kernels = [], + **kwargs): + native.cc_test( + name = "%s%s" % (name, suffix), + srcs = srcs + tf_binary_additional_srcs(), + copts = tf_copts() + extra_copts, + linkopts = select({ + clean_dep("//tensorflow:android"): [ + "-pie", + ], + clean_dep("//tensorflow:windows"): [], + clean_dep("//tensorflow:darwin"): [ + "-lm", + ], + "//conditions:default": [ + "-lpthread", + "-lm", + ], + }) + linkopts + _rpath_linkopts(name), + deps = deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml( + [ + "//third_party/intel_mkl_ml", + ], + ), + data = data + tf_binary_dynamic_kernel_dsos(kernels), + # Nested select() statements seem not to be supported when passed to + # linkstatic, and we already have a cuda select() passed in to this + # function. + linkstatic = linkstatic or select({ + # cc_tests with ".so"s in srcs incorrectly link on Darwin unless + # linkstatic=1 (https://github.com/bazelbuild/bazel/issues/3450). + # TODO(allenl): Remove Mac static linking when Bazel 0.6 is out. + clean_dep("//tensorflow:darwin"): 1, + "//conditions:default": 0, + }), + nocopts = nocopts, + **kwargs + ) register_extension_info( extension_name = "tf_cc_test", @@ -723,107 +754,115 @@ register_extension_info( # Part of the testing workflow requires a distinguishable name for the build # rules that involve a GPU, even if otherwise identical to the base rule. -def tf_cc_test_gpu(name, - srcs, - deps, - linkstatic=0, - tags=[], - data=[], - size="medium", - suffix="", - args=None): - tf_cc_test( - name, - srcs, - deps, - linkstatic=linkstatic, - tags=tags, - data=data, - size=size, - suffix=suffix, - args=args) +def tf_cc_test_gpu( + name, + srcs, + deps, + linkstatic = 0, + tags = [], + data = [], + size = "medium", + suffix = "", + args = None): + tf_cc_test( + name, + srcs, + deps, + linkstatic = linkstatic, + tags = tags, + data = data, + size = size, + suffix = suffix, + args = args, + ) register_extension_info( extension_name = "tf_cc_test_gpu", label_regex_for_dep = "{extension_name}", ) -def tf_cuda_cc_test(name, - srcs=[], - deps=[], - tags=[], - data=[], - size="medium", - extra_copts=[], - linkstatic=0, - args=[], - linkopts=[]): - tf_cc_test( - name=name, - srcs=srcs, - deps=deps, - tags=tags + ["manual"], - data=data, - size=size, - extra_copts=extra_copts, - linkstatic=linkstatic, - linkopts=linkopts, - args=args) - tf_cc_test( - name=name, - srcs=srcs, - suffix="_gpu", - deps=deps + if_cuda([ - clean_dep("//tensorflow/core:gpu_runtime"), - ]), - linkstatic=select({ - # TODO(allenl): Remove Mac static linking when Bazel 0.6 is out. - clean_dep("//tensorflow:darwin"): 1, - "@local_config_cuda//cuda:using_nvcc": 1, - "@local_config_cuda//cuda:using_clang": 1, - "//conditions:default": 0, - }), - tags=tags + tf_cuda_tests_tags(), - data=data, - size=size, - extra_copts=extra_copts, - linkopts=linkopts, - args=args) +def tf_cuda_cc_test( + name, + srcs = [], + deps = [], + tags = [], + data = [], + size = "medium", + extra_copts = [], + linkstatic = 0, + args = [], + linkopts = []): + tf_cc_test( + name = name, + srcs = srcs, + deps = deps, + tags = tags + ["manual"], + data = data, + size = size, + extra_copts = extra_copts, + linkstatic = linkstatic, + linkopts = linkopts, + args = args, + ) + tf_cc_test( + name = name, + srcs = srcs, + suffix = "_gpu", + deps = deps + if_cuda([ + clean_dep("//tensorflow/core:gpu_runtime"), + ]), + linkstatic = select({ + # TODO(allenl): Remove Mac static linking when Bazel 0.6 is out. + clean_dep("//tensorflow:darwin"): 1, + "@local_config_cuda//cuda:using_nvcc": 1, + "@local_config_cuda//cuda:using_clang": 1, + "//conditions:default": 0, + }), + tags = tags + tf_cuda_tests_tags(), + data = data, + size = size, + extra_copts = extra_copts, + linkopts = linkopts, + args = args, + ) register_extension_info( extension_name = "tf_cuda_cc_test", label_regex_for_dep = "{extension_name}", ) -def tf_cuda_only_cc_test(name, - srcs=[], - deps=[], - tags=[], - data=[], - size="medium", - linkstatic=0, - args=[], - kernels=[], - linkopts=[]): - native.cc_test( - name="%s%s" % (name, "_gpu"), - srcs=srcs + tf_binary_additional_srcs(), - size=size, - args=args, - copts= _cuda_copts() + tf_copts(), - data=data + tf_binary_dynamic_kernel_dsos(kernels), - deps=deps + tf_binary_dynamic_kernel_deps(kernels) + if_cuda([ - clean_dep("//tensorflow/core:cuda"), - clean_dep("//tensorflow/core:gpu_lib")]), - linkopts=if_not_windows(["-lpthread", "-lm"]) + linkopts + _rpath_linkopts(name), - linkstatic=linkstatic or select({ - # cc_tests with ".so"s in srcs incorrectly link on Darwin - # unless linkstatic=1. - # TODO(allenl): Remove Mac static linking when Bazel 0.6 is out. - clean_dep("//tensorflow:darwin"): 1, - "//conditions:default": 0, - }), - tags=tags + tf_cuda_tests_tags()) +def tf_cuda_only_cc_test( + name, + srcs = [], + deps = [], + tags = [], + data = [], + size = "medium", + linkstatic = 0, + args = [], + kernels = [], + linkopts = []): + native.cc_test( + name = "%s%s" % (name, "_gpu"), + srcs = srcs + tf_binary_additional_srcs(), + size = size, + args = args, + copts = _cuda_copts() + tf_copts(), + data = data + tf_binary_dynamic_kernel_dsos(kernels), + deps = deps + tf_binary_dynamic_kernel_deps(kernels) + if_cuda([ + clean_dep("//tensorflow/core:cuda"), + clean_dep("//tensorflow/core:gpu_lib"), + ]), + linkopts = if_not_windows(["-lpthread", "-lm"]) + linkopts + _rpath_linkopts(name), + linkstatic = linkstatic or select({ + # cc_tests with ".so"s in srcs incorrectly link on Darwin + # unless linkstatic=1. + # TODO(allenl): Remove Mac static linking when Bazel 0.6 is out. + clean_dep("//tensorflow:darwin"): 1, + "//conditions:default": 0, + }), + tags = tags + tf_cuda_tests_tags(), + ) register_extension_info( extension_name = "tf_cuda_only_cc_test", @@ -831,104 +870,112 @@ register_extension_info( ) # Create a cc_test for each of the tensorflow tests listed in "tests" -def tf_cc_tests(srcs, - deps, - name="", - linkstatic=0, - tags=[], - size="medium", - args=None, - linkopts=[], - nocopts=None): - for src in srcs: - tf_cc_test( - name=src_to_test_name(src), - srcs=[src], - deps=deps, - linkstatic=linkstatic, - tags=tags, - size=size, - args=args, - linkopts=linkopts, - nocopts=nocopts) - -def tf_cc_test_mkl(srcs, - deps, - name="", - data=[], - linkstatic=0, - tags=[], - size="medium", - kernels=[], - args=None): - # -fno-exceptions in nocopts breaks compilation if header modules are enabled. - disable_header_modules = ["-use_header_modules"] - - for src in srcs: - native.cc_test( - name=src_to_test_name(src), - srcs=if_mkl([src]) + tf_binary_additional_srcs(), - copts=tf_copts(), - linkopts=select({ - clean_dep("//tensorflow:android"): [ - "-pie", - ], - clean_dep("//tensorflow:windows"): [], - "//conditions:default": [ - "-lpthread", - "-lm" - ], - }) + _rpath_linkopts(src_to_test_name(src)), - deps=deps + tf_binary_dynamic_kernel_deps(kernels) + mkl_deps(), - data=data + tf_binary_dynamic_kernel_dsos(kernels), - linkstatic=linkstatic, - tags=tags, - size=size, - args=args, - features=disable_header_modules, - nocopts="-fno-exceptions") - - -def tf_cc_tests_gpu(srcs, - deps, - name="", - linkstatic=0, - tags=[], - size="medium", - args=None): - tf_cc_tests(srcs, deps, linkstatic, tags=tags, size=size, args=args) - -def tf_cuda_cc_tests(srcs, - deps, - name="", - tags=[], - size="medium", - linkstatic=0, - args=None, - linkopts=[]): - for src in srcs: - tf_cuda_cc_test( - name=src_to_test_name(src), - srcs=[src], - deps=deps, - tags=tags, - size=size, - linkstatic=linkstatic, - args=args, - linkopts=linkopts) - -def tf_java_test(name, - srcs=[], - deps=[], - kernels=[], - *args, - **kwargs): - native.java_test( - name=name, - srcs=srcs, - deps=deps + tf_binary_additional_srcs() + tf_binary_dynamic_kernel_dsos(kernels) + tf_binary_dynamic_kernel_deps(kernels), - *args, - **kwargs) +def tf_cc_tests( + srcs, + deps, + name = "", + linkstatic = 0, + tags = [], + size = "medium", + args = None, + linkopts = [], + nocopts = None): + for src in srcs: + tf_cc_test( + name = src_to_test_name(src), + srcs = [src], + deps = deps, + linkstatic = linkstatic, + tags = tags, + size = size, + args = args, + linkopts = linkopts, + nocopts = nocopts, + ) + +def tf_cc_test_mkl( + srcs, + deps, + name = "", + data = [], + linkstatic = 0, + tags = [], + size = "medium", + kernels = [], + args = None): + # -fno-exceptions in nocopts breaks compilation if header modules are enabled. + disable_header_modules = ["-use_header_modules"] + + for src in srcs: + native.cc_test( + name = src_to_test_name(src), + srcs = if_mkl([src]) + tf_binary_additional_srcs(), + copts = tf_copts(), + linkopts = select({ + clean_dep("//tensorflow:android"): [ + "-pie", + ], + clean_dep("//tensorflow:windows"): [], + "//conditions:default": [ + "-lpthread", + "-lm", + ], + }) + _rpath_linkopts(src_to_test_name(src)), + deps = deps + tf_binary_dynamic_kernel_deps(kernels) + mkl_deps(), + data = data + tf_binary_dynamic_kernel_dsos(kernels), + linkstatic = linkstatic, + tags = tags, + size = size, + args = args, + features = disable_header_modules, + nocopts = "-fno-exceptions", + ) + +def tf_cc_tests_gpu( + srcs, + deps, + name = "", + linkstatic = 0, + tags = [], + size = "medium", + args = None): + tf_cc_tests(srcs, deps, linkstatic, tags = tags, size = size, args = args) + +def tf_cuda_cc_tests( + srcs, + deps, + name = "", + tags = [], + size = "medium", + linkstatic = 0, + args = None, + linkopts = []): + for src in srcs: + tf_cuda_cc_test( + name = src_to_test_name(src), + srcs = [src], + deps = deps, + tags = tags, + size = size, + linkstatic = linkstatic, + args = args, + linkopts = linkopts, + ) + +def tf_java_test( + name, + srcs = [], + deps = [], + kernels = [], + *args, + **kwargs): + native.java_test( + name = name, + srcs = srcs, + deps = deps + tf_binary_additional_srcs() + tf_binary_dynamic_kernel_dsos(kernels) + tf_binary_dynamic_kernel_deps(kernels), + *args, + **kwargs + ) register_extension_info( extension_name = "tf_java_test", @@ -936,86 +983,89 @@ register_extension_info( ) def _cuda_copts(): - """Gets the appropriate set of copts for (maybe) CUDA compilation. - - If we're doing CUDA compilation, returns copts for our particular CUDA - compiler. If we're not doing CUDA compilation, returns an empty list. - - """ - return cuda_default_copts() + select({ - "//conditions:default": [], - "@local_config_cuda//cuda:using_nvcc": ([ - "-nvcc_options=relaxed-constexpr", - "-nvcc_options=ftz=true", - ]), - "@local_config_cuda//cuda:using_clang": ([ - "-fcuda-flush-denormals-to-zero", - ]), - }) + """Gets the appropriate set of copts for (maybe) CUDA compilation. + + If we're doing CUDA compilation, returns copts for our particular CUDA + compiler. If we're not doing CUDA compilation, returns an empty list. + + """ + return cuda_default_copts() + select({ + "//conditions:default": [], + "@local_config_cuda//cuda:using_nvcc": ([ + "-nvcc_options=relaxed-constexpr", + "-nvcc_options=ftz=true", + ]), + "@local_config_cuda//cuda:using_clang": ([ + "-fcuda-flush-denormals-to-zero", + ]), + }) # Build defs for TensorFlow kernels # When this target is built using --config=cuda, a cc_library is built # that passes -DGOOGLE_CUDA=1 and '-x cuda', linking in additional # libraries needed by GPU kernels. -def tf_gpu_kernel_library(srcs, - copts=[], - cuda_copts=[], - deps=[], - hdrs=[], - **kwargs): - copts = copts + _cuda_copts() + if_cuda(cuda_copts) + tf_copts() - kwargs["features"] = kwargs.get("features", []) + ["-use_header_modules"] - - native.cc_library( - srcs=srcs, - hdrs=hdrs, - copts=copts, - deps=deps + if_cuda([ - clean_dep("//tensorflow/core:cuda"), - clean_dep("//tensorflow/core:gpu_lib"), - ]), - alwayslink=1, - **kwargs) +def tf_gpu_kernel_library( + srcs, + copts = [], + cuda_copts = [], + deps = [], + hdrs = [], + **kwargs): + copts = copts + _cuda_copts() + if_cuda(cuda_copts) + tf_copts() + kwargs["features"] = kwargs.get("features", []) + ["-use_header_modules"] + + native.cc_library( + srcs = srcs, + hdrs = hdrs, + copts = copts, + deps = deps + if_cuda([ + clean_dep("//tensorflow/core:cuda"), + clean_dep("//tensorflow/core:gpu_lib"), + ]), + alwayslink = 1, + **kwargs + ) register_extension_info( extension_name = "tf_gpu_kernel_library", label_regex_for_dep = "{extension_name}", ) -def tf_cuda_library(deps=None, cuda_deps=None, copts=tf_copts(), **kwargs): - """Generate a cc_library with a conditional set of CUDA dependencies. - - When the library is built with --config=cuda: - - - Both deps and cuda_deps are used as dependencies. - - The cuda runtime is added as a dependency (if necessary). - - The library additionally passes -DGOOGLE_CUDA=1 to the list of copts. - - In addition, when the library is also built with TensorRT enabled, it - additionally passes -DGOOGLE_TENSORRT=1 to the list of copts. - - Args: - - cuda_deps: BUILD dependencies which will be linked if and only if: - '--config=cuda' is passed to the bazel command line. - - deps: dependencies which will always be linked. - - copts: copts always passed to the cc_library. - - kwargs: Any other argument to cc_library. - """ - if not deps: - deps = [] - if not cuda_deps: - cuda_deps = [] - - kwargs["features"] = kwargs.get("features", []) + ["-use_header_modules"] - native.cc_library( - deps=deps + if_cuda(cuda_deps + [ - clean_dep("//tensorflow/core:cuda"), - "@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) +def tf_cuda_library(deps = None, cuda_deps = None, copts = tf_copts(), **kwargs): + """Generate a cc_library with a conditional set of CUDA dependencies. + + When the library is built with --config=cuda: + + - Both deps and cuda_deps are used as dependencies. + - The cuda runtime is added as a dependency (if necessary). + - The library additionally passes -DGOOGLE_CUDA=1 to the list of copts. + - In addition, when the library is also built with TensorRT enabled, it + additionally passes -DGOOGLE_TENSORRT=1 to the list of copts. + + Args: + - cuda_deps: BUILD dependencies which will be linked if and only if: + '--config=cuda' is passed to the bazel command line. + - deps: dependencies which will always be linked. + - copts: copts always passed to the cc_library. + - kwargs: Any other argument to cc_library. + """ + if not deps: + deps = [] + if not cuda_deps: + cuda_deps = [] + + kwargs["features"] = kwargs.get("features", []) + ["-use_header_modules"] + native.cc_library( + deps = deps + if_cuda(cuda_deps + [ + clean_dep("//tensorflow/core:cuda"), + "@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 + ) register_extension_info( extension_name = "tf_cuda_library", @@ -1033,126 +1083,138 @@ def tf_kernel_library( copts = None, is_external = False, **kwargs): - """A rule to build a TensorFlow OpKernel. - - May either specify srcs/hdrs or prefix. Similar to tf_cuda_library, - but with alwayslink=1 by default. If prefix is specified: - * prefix*.cc (except *.cu.cc) is added to srcs - * prefix*.h (except *.cu.h) is added to hdrs - * prefix*.cu.cc and prefix*.h (including *.cu.h) are added to gpu_srcs. - With the exception that test files are excluded. - For example, with prefix = "cast_op", - * srcs = ["cast_op.cc"] - * hdrs = ["cast_op.h"] - * gpu_srcs = ["cast_op_gpu.cu.cc", "cast_op.h"] - * "cast_op_test.cc" is excluded - With prefix = "cwise_op" - * srcs = ["cwise_op_abs.cc", ..., "cwise_op_tanh.cc"], - * hdrs = ["cwise_ops.h", "cwise_ops_common.h"], - * gpu_srcs = ["cwise_op_gpu_abs.cu.cc", ..., "cwise_op_gpu_tanh.cu.cc", - "cwise_ops.h", "cwise_ops_common.h", - "cwise_ops_gpu_common.cu.h"] - * "cwise_ops_test.cc" is excluded - """ - if not srcs: - srcs = [] - if not hdrs: - hdrs = [] - if not deps: - deps = [] - if not copts: - copts = [] - textual_hdrs = [] - copts = copts + tf_copts(is_external=is_external) - if prefix: - if native.glob([prefix + "*.cu.cc"], exclude=["*test*"]): - if not gpu_srcs: - gpu_srcs = [] - gpu_srcs = gpu_srcs + native.glob( - [prefix + "*.cu.cc", prefix + "*.h"], exclude=[prefix + "*test*"]) - srcs = srcs + native.glob( - [prefix + "*.cc"], exclude=[prefix + "*test*", prefix + "*.cu.cc"]) - hdrs = hdrs + native.glob( + """A rule to build a TensorFlow OpKernel. + + May either specify srcs/hdrs or prefix. Similar to tf_cuda_library, + but with alwayslink=1 by default. If prefix is specified: + * prefix*.cc (except *.cu.cc) is added to srcs + * prefix*.h (except *.cu.h) is added to hdrs + * prefix*.cu.cc and prefix*.h (including *.cu.h) are added to gpu_srcs. + With the exception that test files are excluded. + For example, with prefix = "cast_op", + * srcs = ["cast_op.cc"] + * hdrs = ["cast_op.h"] + * gpu_srcs = ["cast_op_gpu.cu.cc", "cast_op.h"] + * "cast_op_test.cc" is excluded + With prefix = "cwise_op" + * srcs = ["cwise_op_abs.cc", ..., "cwise_op_tanh.cc"], + * hdrs = ["cwise_ops.h", "cwise_ops_common.h"], + * gpu_srcs = ["cwise_op_gpu_abs.cu.cc", ..., "cwise_op_gpu_tanh.cu.cc", + "cwise_ops.h", "cwise_ops_common.h", + "cwise_ops_gpu_common.cu.h"] + * "cwise_ops_test.cc" is excluded + """ + if not srcs: + srcs = [] + if not hdrs: + hdrs = [] + if not deps: + deps = [] + if not copts: + copts = [] + textual_hdrs = [] + copts = copts + tf_copts(is_external = is_external) + if prefix: + if native.glob([prefix + "*.cu.cc"], exclude = ["*test*"]): + if not gpu_srcs: + gpu_srcs = [] + gpu_srcs = gpu_srcs + native.glob( + [prefix + "*.cu.cc", prefix + "*.h"], + exclude = [prefix + "*test*"], + ) + srcs = srcs + native.glob( + [prefix + "*.cc"], + exclude = [prefix + "*test*", prefix + "*.cu.cc"], + ) + hdrs = hdrs + native.glob( [prefix + "*.h"], exclude = [prefix + "*test*", prefix + "*.cu.h", prefix + "*impl.h"], ) - textual_hdrs = native.glob( + textual_hdrs = native.glob( [prefix + "*impl.h"], exclude = [prefix + "*test*", prefix + "*.cu.h"], ) - cuda_deps = [clean_dep("//tensorflow/core:gpu_lib")] - if gpu_srcs: - for gpu_src in gpu_srcs: - if gpu_src.endswith(".cc") and not gpu_src.endswith(".cu.cc"): - fail("{} not allowed in gpu_srcs. .cc sources must end with .cu.cc". - format(gpu_src)) - tf_gpu_kernel_library( - name=name + "_gpu", srcs=gpu_srcs, deps=deps, **kwargs) - cuda_deps.extend([":" + name + "_gpu"]) - kwargs["tags"] = kwargs.get("tags", []) + [ - "req_dep=%s" % clean_dep("//tensorflow/core:gpu_lib"), - "req_dep=@local_config_cuda//cuda:cuda_headers", - ] - tf_cuda_library( - name=name, - srcs=srcs, - hdrs=hdrs, - textual_hdrs = textual_hdrs, - copts=copts, - cuda_deps=cuda_deps, - linkstatic=1, # Needed since alwayslink is broken in bazel b/27630669 - alwayslink=alwayslink, - deps=deps, - **kwargs) - - # TODO(gunan): CUDA dependency not clear here. Fix it. - tf_cc_shared_object( - name="libtfkernel_%s.so" % name, - srcs=srcs + hdrs, - copts=copts, - deps=deps, - tags=["manual", "notap"]) + cuda_deps = [clean_dep("//tensorflow/core:gpu_lib")] + if gpu_srcs: + for gpu_src in gpu_srcs: + if gpu_src.endswith(".cc") and not gpu_src.endswith(".cu.cc"): + fail("{} not allowed in gpu_srcs. .cc sources must end with .cu.cc" + .format(gpu_src)) + tf_gpu_kernel_library( + name = name + "_gpu", + srcs = gpu_srcs, + deps = deps, + **kwargs + ) + cuda_deps.extend([":" + name + "_gpu"]) + kwargs["tags"] = kwargs.get("tags", []) + [ + "req_dep=%s" % clean_dep("//tensorflow/core:gpu_lib"), + "req_dep=@local_config_cuda//cuda:cuda_headers", + ] + tf_cuda_library( + name = name, + srcs = srcs, + hdrs = hdrs, + textual_hdrs = textual_hdrs, + copts = copts, + cuda_deps = cuda_deps, + linkstatic = 1, # Needed since alwayslink is broken in bazel b/27630669 + alwayslink = alwayslink, + deps = deps, + **kwargs + ) + # TODO(gunan): CUDA dependency not clear here. Fix it. + tf_cc_shared_object( + name = "libtfkernel_%s.so" % name, + srcs = srcs + hdrs, + copts = copts, + deps = deps, + tags = ["manual", "notap"], + ) register_extension_info( extension_name = "tf_kernel_library", label_regex_for_dep = "{extension_name}(_gpu)?", ) -def tf_mkl_kernel_library(name, - prefix=None, - srcs=None, - hdrs=None, - deps=None, - alwayslink=1, - copts=tf_copts(), - nocopts="-fno-exceptions"): - """A rule to build MKL-based TensorFlow kernel libraries.""" - - if not bool(srcs): - srcs = [] - if not bool(hdrs): - hdrs = [] - - if prefix: - srcs = srcs + native.glob( - [prefix + "*.cc"]) - hdrs = hdrs + native.glob( - [prefix + "*.h"]) - - # -fno-exceptions in nocopts breaks compilation if header modules are enabled. - disable_header_modules = ["-use_header_modules"] - - native.cc_library( - name=name, - srcs=if_mkl(srcs), - hdrs=hdrs, - deps=deps, - alwayslink=alwayslink, - copts=copts, - nocopts=nocopts, - features = disable_header_modules - ) +def tf_mkl_kernel_library( + name, + prefix = None, + srcs = None, + hdrs = None, + deps = None, + alwayslink = 1, + copts = tf_copts(), + nocopts = "-fno-exceptions"): + """A rule to build MKL-based TensorFlow kernel libraries.""" + + if not bool(srcs): + srcs = [] + if not bool(hdrs): + hdrs = [] + + if prefix: + srcs = srcs + native.glob( + [prefix + "*.cc"], + ) + hdrs = hdrs + native.glob( + [prefix + "*.h"], + ) + + # -fno-exceptions in nocopts breaks compilation if header modules are enabled. + disable_header_modules = ["-use_header_modules"] + + native.cc_library( + name = name, + srcs = if_mkl(srcs), + hdrs = hdrs, + deps = deps, + alwayslink = alwayslink, + copts = copts, + nocopts = nocopts, + features = disable_header_modules, + ) register_extension_info( extension_name = "tf_mkl_kernel_library", @@ -1161,35 +1223,42 @@ register_extension_info( # Bazel rules for building swig files. def _py_wrap_cc_impl(ctx): - srcs = ctx.files.srcs - if len(srcs) != 1: - fail("Exactly one SWIG source file label must be specified.", "srcs") - module_name = ctx.attr.module_name - src = ctx.files.srcs[0] - inputs = depset([src]) - inputs += ctx.files.swig_includes - for dep in ctx.attr.deps: - inputs += dep.cc.transitive_headers - inputs += ctx.files._swiglib - inputs += ctx.files.toolchain_deps - swig_include_dirs = depset(_get_repository_roots(ctx, inputs)) - swig_include_dirs += sorted([f.dirname for f in ctx.files._swiglib]) - args = [ - "-c++", "-python", "-module", module_name, "-o", ctx.outputs.cc_out.path, - "-outdir", ctx.outputs.py_out.dirname - ] - args += ["-l" + f.path for f in ctx.files.swig_includes] - args += ["-I" + i for i in swig_include_dirs] - args += [src.path] - outputs = [ctx.outputs.cc_out, ctx.outputs.py_out] - ctx.action( - executable=ctx.executable._swig, - arguments=args, - inputs=list(inputs), - outputs=outputs, - mnemonic="PythonSwig", - progress_message="SWIGing " + src.path) - return struct(files=depset(outputs)) + srcs = ctx.files.srcs + if len(srcs) != 1: + fail("Exactly one SWIG source file label must be specified.", "srcs") + module_name = ctx.attr.module_name + src = ctx.files.srcs[0] + inputs = depset([src]) + inputs += ctx.files.swig_includes + for dep in ctx.attr.deps: + inputs += dep.cc.transitive_headers + inputs += ctx.files._swiglib + inputs += ctx.files.toolchain_deps + swig_include_dirs = depset(_get_repository_roots(ctx, inputs)) + swig_include_dirs += sorted([f.dirname for f in ctx.files._swiglib]) + args = [ + "-c++", + "-python", + "-module", + module_name, + "-o", + ctx.outputs.cc_out.path, + "-outdir", + ctx.outputs.py_out.dirname, + ] + args += ["-l" + f.path for f in ctx.files.swig_includes] + args += ["-I" + i for i in swig_include_dirs] + args += [src.path] + outputs = [ctx.outputs.cc_out, ctx.outputs.py_out] + ctx.action( + executable = ctx.executable._swig, + arguments = args, + inputs = list(inputs), + outputs = outputs, + mnemonic = "PythonSwig", + progress_message = "SWIGing " + src.path, + ) + return struct(files = depset(outputs)) _py_wrap_cc = rule( attrs = { @@ -1227,40 +1296,40 @@ _py_wrap_cc = rule( ) def _get_repository_roots(ctx, files): - """Returns abnormal root directories under which files reside. - - When running a ctx.action, source files within the main repository are all - relative to the current directory; however, files that are generated or exist - in remote repositories will have their root directory be a subdirectory, - e.g. bazel-out/local-fastbuild/genfiles/external/jpeg_archive. This function - returns the set of these devious directories, ranked and sorted by popularity - in order to hopefully minimize the number of I/O system calls within the - compiler, because includes have quadratic complexity. - """ - result = {} - for f in files: - root = f.root.path - if root: - if root not in result: - result[root] = 0 - result[root] -= 1 - work = f.owner.workspace_root - if work: - if root: - root += "/" - root += work - if root: - if root not in result: - result[root] = 0 - result[root] -= 1 - return [k for v, k in sorted([(v, k) for k, v in result.items()])] + """Returns abnormal root directories under which files reside. + + When running a ctx.action, source files within the main repository are all + relative to the current directory; however, files that are generated or exist + in remote repositories will have their root directory be a subdirectory, + e.g. bazel-out/local-fastbuild/genfiles/external/jpeg_archive. This function + returns the set of these devious directories, ranked and sorted by popularity + in order to hopefully minimize the number of I/O system calls within the + compiler, because includes have quadratic complexity. + """ + result = {} + for f in files: + root = f.root.path + if root: + if root not in result: + result[root] = 0 + result[root] -= 1 + work = f.owner.workspace_root + if work: + if root: + root += "/" + root += work + if root: + if root not in result: + result[root] = 0 + result[root] -= 1 + return [k for v, k in sorted([(v, k) for k, v in result.items()])] # Bazel rule for collecting the header files that a target depends on. def _transitive_hdrs_impl(ctx): - outputs = depset() - for dep in ctx.attr.deps: - outputs += dep.cc.transitive_headers - return struct(files=outputs) + outputs = depset() + for dep in ctx.attr.deps: + outputs += dep.cc.transitive_headers + return struct(files = outputs) _transitive_hdrs = rule( attrs = { @@ -1272,52 +1341,54 @@ _transitive_hdrs = rule( implementation = _transitive_hdrs_impl, ) -def transitive_hdrs(name, deps=[], **kwargs): - _transitive_hdrs(name=name + "_gather", deps=deps) - native.filegroup(name=name, srcs=[":" + name + "_gather"]) +def transitive_hdrs(name, deps = [], **kwargs): + _transitive_hdrs(name = name + "_gather", deps = deps) + native.filegroup(name = name, srcs = [":" + name + "_gather"]) # Create a header only library that includes all the headers exported by # the libraries in deps. -def cc_header_only_library(name, deps=[], includes=[], **kwargs): - _transitive_hdrs(name=name + "_gather", deps=deps) - native.cc_library(name=name, - hdrs=[":" + name + "_gather"], - includes=includes, - **kwargs) +def cc_header_only_library(name, deps = [], includes = [], **kwargs): + _transitive_hdrs(name = name + "_gather", deps = deps) + native.cc_library( + name = name, + hdrs = [":" + name + "_gather"], + includes = includes, + **kwargs + ) def tf_custom_op_library_additional_deps(): - return [ + return [ "@protobuf_archive//:protobuf_headers", - clean_dep("//third_party/eigen3"), - clean_dep("//tensorflow/core:framework_headers_lib"), - ] + if_windows(["//tensorflow/python:pywrap_tensorflow_import_lib"]) + clean_dep("//third_party/eigen3"), + clean_dep("//tensorflow/core:framework_headers_lib"), + ] + if_windows(["//tensorflow/python:pywrap_tensorflow_import_lib"]) # A list of targets that contains the implemenation of # tf_custom_op_library_additional_deps. It's used to generate a DEF file for # exporting symbols from _pywrap_tensorflow.dll on Windows. def tf_custom_op_library_additional_deps_impl(): - return [ + return [ "@protobuf_archive//:protobuf", "@nsync//:nsync_cpp", - # for //third_party/eigen3 - clean_dep("//third_party/eigen3"), - # for //tensorflow/core:framework_headers_lib - clean_dep("//tensorflow/core:framework"), - clean_dep("//tensorflow/core:reader_base"), - ] + # for //third_party/eigen3 + clean_dep("//third_party/eigen3"), + # for //tensorflow/core:framework_headers_lib + clean_dep("//tensorflow/core:framework"), + clean_dep("//tensorflow/core:reader_base"), + ] # Traverse the dependency graph along the "deps" attribute of the # target and return a struct with one field called 'tf_collected_deps'. # tf_collected_deps will be the union of the deps of the current target # and the tf_collected_deps of the dependencies of this target. def _collect_deps_aspect_impl(target, ctx): - alldeps = depset() - if hasattr(ctx.rule.attr, "deps"): - for dep in ctx.rule.attr.deps: - alldeps = alldeps | depset([dep.label]) - if hasattr(dep, "tf_collected_deps"): - alldeps = alldeps | dep.tf_collected_deps - return struct(tf_collected_deps=alldeps) + alldeps = depset() + if hasattr(ctx.rule.attr, "deps"): + for dep in ctx.rule.attr.deps: + alldeps = alldeps | depset([dep.label]) + if hasattr(dep, "tf_collected_deps"): + alldeps = alldeps | dep.tf_collected_deps + return struct(tf_collected_deps = alldeps) collect_deps_aspect = aspect( attr_aspects = ["deps"], @@ -1325,24 +1396,26 @@ collect_deps_aspect = aspect( ) def _dep_label(dep): - label = dep.label - return label.package + ":" + label.name + label = dep.label + return label.package + ":" + label.name # This rule checks that the transitive dependencies of targets listed # in the 'deps' attribute don't depend on the targets listed in # the 'disallowed_deps' attribute. def _check_deps_impl(ctx): - disallowed_deps = ctx.attr.disallowed_deps - for input_dep in ctx.attr.deps: - if not hasattr(input_dep, "tf_collected_deps"): - continue - for dep in input_dep.tf_collected_deps: - for disallowed_dep in disallowed_deps: - if dep == disallowed_dep.label: - fail( - _dep_label(input_dep) + " cannot depend on " + _dep_label( - disallowed_dep)) - return struct() + disallowed_deps = ctx.attr.disallowed_deps + for input_dep in ctx.attr.deps: + if not hasattr(input_dep, "tf_collected_deps"): + continue + for dep in input_dep.tf_collected_deps: + for disallowed_dep in disallowed_deps: + if dep == disallowed_dep.label: + fail( + _dep_label(input_dep) + " cannot depend on " + _dep_label( + disallowed_dep, + ), + ) + return struct() check_deps = rule( _check_deps_impl, @@ -1361,65 +1434,70 @@ check_deps = rule( # Helper to build a dynamic library (.so) from the sources containing # implementations of custom ops and kernels. -def tf_custom_op_library(name, srcs=[], gpu_srcs=[], deps=[], linkopts=[]): - cuda_deps = [ - clean_dep("//tensorflow/core:stream_executor_headers_lib"), - "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuda//cuda:cudart_static", - ] - deps = deps + tf_custom_op_library_additional_deps() - if gpu_srcs: - basename = name.split(".")[0] - native.cc_library( - name=basename + "_gpu", - srcs=gpu_srcs, - copts=_cuda_copts() + if_tensorrt(["-DGOOGLE_TENSORRT=1"]), - features = if_cuda(["-use_header_modules"]), - deps=deps + if_cuda(cuda_deps)) - cuda_deps.extend([":" + basename + "_gpu"]) - - check_deps( - name=name + "_check_deps", - deps=deps + if_cuda(cuda_deps), - disallowed_deps=[ - clean_dep("//tensorflow/core:framework"), - clean_dep("//tensorflow/core:lib") - ]) - tf_cc_shared_object( - name=name, - srcs=srcs, - deps=deps + if_cuda(cuda_deps), - data=if_static([name + "_check_deps"]), - copts=tf_copts(is_external=True), - features = ["windows_export_all_symbols"], - linkopts=linkopts + select({ - "//conditions:default": [ - "-lm", - ], - clean_dep("//tensorflow:windows"): [], - clean_dep("//tensorflow:darwin"): [], - }),) +def tf_custom_op_library(name, srcs = [], gpu_srcs = [], deps = [], linkopts = []): + cuda_deps = [ + clean_dep("//tensorflow/core:stream_executor_headers_lib"), + "@local_config_cuda//cuda:cuda_headers", + "@local_config_cuda//cuda:cudart_static", + ] + deps = deps + tf_custom_op_library_additional_deps() + if gpu_srcs: + basename = name.split(".")[0] + native.cc_library( + name = basename + "_gpu", + srcs = gpu_srcs, + copts = _cuda_copts() + if_tensorrt(["-DGOOGLE_TENSORRT=1"]), + features = if_cuda(["-use_header_modules"]), + deps = deps + if_cuda(cuda_deps), + ) + cuda_deps.extend([":" + basename + "_gpu"]) + + check_deps( + name = name + "_check_deps", + deps = deps + if_cuda(cuda_deps), + disallowed_deps = [ + clean_dep("//tensorflow/core:framework"), + clean_dep("//tensorflow/core:lib"), + ], + ) + tf_cc_shared_object( + name = name, + srcs = srcs, + deps = deps + if_cuda(cuda_deps), + data = if_static([name + "_check_deps"]), + copts = tf_copts(is_external = True), + features = ["windows_export_all_symbols"], + linkopts = linkopts + select({ + "//conditions:default": [ + "-lm", + ], + clean_dep("//tensorflow:windows"): [], + clean_dep("//tensorflow:darwin"): [], + }), + ) register_extension_info( extension_name = "tf_custom_op_library", label_regex_for_dep = "{extension_name}", ) -def tf_custom_op_py_library(name, - srcs=[], - dso=[], - kernels=[], - srcs_version="PY2AND3", - visibility=None, - deps=[]): - kernels = kernels # unused argument - native.py_library( - name=name, - data=dso, - srcs=srcs, - srcs_version=srcs_version, - visibility=visibility, - deps=deps,) +def tf_custom_op_py_library( + name, + srcs = [], + dso = [], + kernels = [], + srcs_version = "PY2AND3", + visibility = None, + deps = []): + kernels = kernels # unused argument + native.py_library( + name = name, + data = dso, + srcs = srcs, + srcs_version = srcs_version, + visibility = visibility, + deps = deps, + ) register_extension_info( extension_name = "tf_custom_op_py_library", @@ -1433,117 +1511,127 @@ register_extension_info( # This function attempts to append init_module_name to list of # exported functions in version script def _append_init_to_versionscript_impl(ctx): - mod_name = ctx.attr.module_name - if ctx.attr.is_version_script: - ctx.actions.expand_template( - template=ctx.file.template_file, - output=ctx.outputs.versionscript, - substitutions={ - "global:":"global:\n init_%s;\n PyInit_*;"%(mod_name), - }, - is_executable=False, - ) - else: - ctx.actions.expand_template( - template=ctx.file.template_file, - output=ctx.outputs.versionscript, - substitutions={ - "*tensorflow*":"*tensorflow*\ninit_%s\nPyInit_*\n"%(mod_name), - }, - is_executable=False, - ) - + mod_name = ctx.attr.module_name + if ctx.attr.is_version_script: + ctx.actions.expand_template( + template = ctx.file.template_file, + output = ctx.outputs.versionscript, + substitutions = { + "global:": "global:\n init_%s;\n PyInit_*;" % (mod_name), + }, + is_executable = False, + ) + else: + ctx.actions.expand_template( + template = ctx.file.template_file, + output = ctx.outputs.versionscript, + substitutions = { + "*tensorflow*": "*tensorflow*\ninit_%s\nPyInit_*\n" % (mod_name), + }, + is_executable = False, + ) -_append_init_to_versionscript= rule( - implementation=_append_init_to_versionscript_impl, - attrs={ - "module_name":attr.string(mandatory=True), - "template_file":attr.label(allow_files=True,single_file=True,mandatory=True), - "is_version_script":attr.bool(default=True, - doc='whether target is a ld version script or exported symbol list', - mandatory=False), - }, - outputs={"versionscript":"%{name}.lds"}, +_append_init_to_versionscript = rule( + implementation = _append_init_to_versionscript_impl, + attrs = { + "module_name": attr.string(mandatory = True), + "template_file": attr.label(allow_files = True, single_file = True, mandatory = True), + "is_version_script": attr.bool( + default = True, + doc = "whether target is a ld version script or exported symbol list", + mandatory = False, + ), + }, + outputs = {"versionscript": "%{name}.lds"}, ) -def tf_py_wrap_cc(name, - srcs, - swig_includes=[], - deps=[], - copts=[], - **kwargs): - module_name = name.split("/")[-1] - # Convert a rule name such as foo/bar/baz to foo/bar/_baz.so - # and use that as the name for the rule producing the .so file. - cc_library_name = "/".join(name.split("/")[:-1] + ["_" + module_name + ".so"]) - cc_library_pyd_name = "/".join( - name.split("/")[:-1] + ["_" + module_name + ".pyd"]) - extra_deps = [] - _py_wrap_cc( - name=name + "_py_wrap", - srcs=srcs, - swig_includes=swig_includes, - deps=deps + extra_deps, - toolchain_deps=["@bazel_tools//tools/cpp:current_cc_toolchain"], - module_name=module_name, - py_module_name=name) - vscriptname=name+"_versionscript" - _append_init_to_versionscript( - name=vscriptname, - module_name=module_name, - is_version_script=select({ - "@local_config_cuda//cuda:darwin":False, - "//conditions:default":True, - }), - template_file=select({ - "@local_config_cuda//cuda:darwin":clean_dep("//tensorflow:tf_exported_symbols.lds"), - "//conditions:default":clean_dep("//tensorflow:tf_version_script.lds") - }) - ) - extra_linkopts = select({ - "@local_config_cuda//cuda:darwin": [ - "-Wl,-exported_symbols_list", - "$(location %s.lds)"%vscriptname, - ], - clean_dep("//tensorflow:windows"): [], - "//conditions:default": [ - "-Wl,--version-script", - "$(location %s.lds)"%vscriptname, - ] - }) - extra_deps += select({ - "@local_config_cuda//cuda:darwin": [ - "%s.lds"%vscriptname, - ], - clean_dep("//tensorflow:windows"): [], - "//conditions:default": [ - "%s.lds"%vscriptname, - ] - }) - - tf_cc_shared_object( - name=cc_library_name, - srcs=[module_name + ".cc"], - copts=copts + if_not_windows([ - "-Wno-self-assign", "-Wno-sign-compare", "-Wno-write-strings" - ]), - linkopts=extra_linkopts, - linkstatic=1, - deps=deps + extra_deps, - **kwargs) - native.genrule( - name="gen_" + cc_library_pyd_name, - srcs=[":" + cc_library_name], - outs=[cc_library_pyd_name], - cmd="cp $< $@",) - native.py_library( - name=name, - srcs=[":" + name + ".py"], - srcs_version="PY2AND3", - data=select({ - clean_dep("//tensorflow:windows"): [":" + cc_library_pyd_name], - "//conditions:default": [":" + cc_library_name], - })) +def tf_py_wrap_cc( + name, + srcs, + swig_includes = [], + deps = [], + copts = [], + **kwargs): + module_name = name.split("/")[-1] + + # Convert a rule name such as foo/bar/baz to foo/bar/_baz.so + # and use that as the name for the rule producing the .so file. + cc_library_name = "/".join(name.split("/")[:-1] + ["_" + module_name + ".so"]) + cc_library_pyd_name = "/".join( + name.split("/")[:-1] + ["_" + module_name + ".pyd"], + ) + extra_deps = [] + _py_wrap_cc( + name = name + "_py_wrap", + srcs = srcs, + swig_includes = swig_includes, + deps = deps + extra_deps, + toolchain_deps = ["@bazel_tools//tools/cpp:current_cc_toolchain"], + module_name = module_name, + py_module_name = name, + ) + vscriptname = name + "_versionscript" + _append_init_to_versionscript( + name = vscriptname, + module_name = module_name, + is_version_script = select({ + "@local_config_cuda//cuda:darwin": False, + "//conditions:default": True, + }), + template_file = select({ + "@local_config_cuda//cuda:darwin": clean_dep("//tensorflow:tf_exported_symbols.lds"), + "//conditions:default": clean_dep("//tensorflow:tf_version_script.lds"), + }), + ) + extra_linkopts = select({ + "@local_config_cuda//cuda:darwin": [ + "-Wl,-exported_symbols_list", + "$(location %s.lds)" % vscriptname, + ], + clean_dep("//tensorflow:windows"): [], + "//conditions:default": [ + "-Wl,--version-script", + "$(location %s.lds)" % vscriptname, + ], + }) + extra_deps += select({ + "@local_config_cuda//cuda:darwin": [ + "%s.lds" % vscriptname, + ], + clean_dep("//tensorflow:windows"): [], + "//conditions:default": [ + "%s.lds" % vscriptname, + ], + }) + + tf_cc_shared_object( + name = cc_library_name, + srcs = [module_name + ".cc"], + copts = copts + if_not_windows([ + "-Wno-self-assign", + "-Wno-sign-compare", + "-Wno-write-strings", + ]), + linkopts = extra_linkopts, + linkstatic = 1, + deps = deps + extra_deps, + **kwargs + ) + native.genrule( + name = "gen_" + cc_library_pyd_name, + srcs = [":" + cc_library_name], + outs = [cc_library_pyd_name], + cmd = "cp $< $@", + ) + native.py_library( + name = name, + srcs = [":" + name + ".py"], + srcs_version = "PY2AND3", + data = select({ + clean_dep("//tensorflow:windows"): [":" + cc_library_pyd_name], + "//conditions:default": [":" + cc_library_name], + }), + ) # This macro is for running python tests against system installed pip package # on Windows. @@ -1561,246 +1649,263 @@ def tf_py_wrap_cc(name, # Note that this only works on Windows. See the definition of # //third_party/tensorflow/tools/pip_package:win_pip_package_marker for specific reasons. # 2. When --define=no_tensorflow_py_deps=false (by default), it's a normal py_test. -def py_test(deps=[], data=[], **kwargs): - native.py_test( - # TODO(jlebar): Ideally we'd use tcmalloc here., - deps=select({ - "//conditions:default": deps, - clean_dep("//tensorflow:no_tensorflow_py_deps"): [], - }), - data = data + select({ - "//conditions:default": [], - clean_dep("//tensorflow:no_tensorflow_py_deps"): - ["//tensorflow/tools/pip_package:win_pip_package_marker"], - }), - **kwargs) +def py_test(deps = [], data = [], **kwargs): + native.py_test( + # TODO(jlebar): Ideally we'd use tcmalloc here., + deps = select({ + "//conditions:default": deps, + clean_dep("//tensorflow:no_tensorflow_py_deps"): [], + }), + data = data + select({ + "//conditions:default": [], + clean_dep("//tensorflow:no_tensorflow_py_deps"): ["//tensorflow/tools/pip_package:win_pip_package_marker"], + }), + **kwargs + ) register_extension_info( extension_name = "py_test", label_regex_for_dep = "{extension_name}", ) -def tf_py_test(name, - srcs, - size="medium", - data=[], - main=None, - args=[], - tags=[], - shard_count=1, - additional_deps=[], - flaky=0, - xla_enabled=False, - grpc_enabled=False): - if xla_enabled: - additional_deps = additional_deps + tf_additional_xla_deps_py() - if grpc_enabled: - additional_deps = additional_deps + tf_additional_grpc_deps_py() - py_test( - name=name, - size=size, - srcs=srcs, - main=main, - args=args, - tags=tags, - visibility=[clean_dep("//tensorflow:internal")], - shard_count=shard_count, - data=data, - deps=[ +def tf_py_test( + name, + srcs, + size = "medium", + data = [], + main = None, + args = [], + tags = [], + shard_count = 1, + additional_deps = [], + flaky = 0, + xla_enabled = False, + grpc_enabled = False): + if xla_enabled: + additional_deps = additional_deps + tf_additional_xla_deps_py() + if grpc_enabled: + additional_deps = additional_deps + tf_additional_grpc_deps_py() + py_test( + name = name, + size = size, + srcs = srcs, + main = main, + args = args, + tags = tags, + visibility = [clean_dep("//tensorflow:internal")], + shard_count = shard_count, + data = data, + deps = [ clean_dep("//tensorflow/python:extra_py_tests_deps"), clean_dep("//tensorflow/python:gradient_checker"), - ] + additional_deps, - flaky=flaky, - srcs_version="PY2AND3") + ] + additional_deps, + flaky = flaky, + srcs_version = "PY2AND3", + ) register_extension_info( extension_name = "tf_py_test", label_regex_map = {"additional_deps": "deps:{extension_name}"}, ) -def cuda_py_test(name, - srcs, - size="medium", - data=[], - main=None, - args=[], - shard_count=1, - additional_deps=[], - tags=[], - flaky=0, - xla_enabled=False, - grpc_enabled=False): - test_tags = tags + tf_cuda_tests_tags() - tf_py_test( - name=name, - size=size, - srcs=srcs, - data=data, - main=main, - args=args, - tags=test_tags, - shard_count=shard_count, - additional_deps=additional_deps, - flaky=flaky, - xla_enabled=xla_enabled, - grpc_enabled=grpc_enabled) +def cuda_py_test( + name, + srcs, + size = "medium", + data = [], + main = None, + args = [], + shard_count = 1, + additional_deps = [], + tags = [], + flaky = 0, + xla_enabled = False, + grpc_enabled = False): + test_tags = tags + tf_cuda_tests_tags() + tf_py_test( + name = name, + size = size, + srcs = srcs, + data = data, + main = main, + args = args, + tags = test_tags, + shard_count = shard_count, + additional_deps = additional_deps, + flaky = flaky, + xla_enabled = xla_enabled, + grpc_enabled = grpc_enabled, + ) register_extension_info( extension_name = "cuda_py_test", label_regex_map = {"additional_deps": "additional_deps:{extension_name}"}, ) -def sycl_py_test(name, - srcs, - size="medium", - data=[], - main=None, - args=[], - shard_count=1, - additional_deps=[], - tags=[], - flaky=0, - xla_enabled=False, - grpc_enabled=False): - test_tags = tags + tf_sycl_tests_tags() - tf_py_test( - name=name, - size=size, - srcs=srcs, - data=data, - main=main, - args=args, - tags=test_tags, - shard_count=shard_count, - additional_deps=additional_deps, - flaky=flaky, - xla_enabled=xla_enabled, - grpc_enabled=grpc_enabled) +def sycl_py_test( + name, + srcs, + size = "medium", + data = [], + main = None, + args = [], + shard_count = 1, + additional_deps = [], + tags = [], + flaky = 0, + xla_enabled = False, + grpc_enabled = False): + test_tags = tags + tf_sycl_tests_tags() + tf_py_test( + name = name, + size = size, + srcs = srcs, + data = data, + main = main, + args = args, + tags = test_tags, + shard_count = shard_count, + additional_deps = additional_deps, + flaky = flaky, + xla_enabled = xla_enabled, + grpc_enabled = grpc_enabled, + ) register_extension_info( extension_name = "sycl_py_test", label_regex_map = {"additional_deps": "additional_deps:{extension_name}"}, ) -def py_tests(name, - srcs, - size="medium", - additional_deps=[], - data=[], - tags=[], - shard_count=1, - prefix="", - xla_enabled=False, - grpc_enabled=False): - for src in srcs: - test_name = src.split("/")[-1].split(".")[0] - if prefix: - test_name = "%s_%s" % (prefix, test_name) - tf_py_test( - name=test_name, - size=size, - srcs=[src], - main=src, - tags=tags, - shard_count=shard_count, - data=data, - additional_deps=additional_deps, - xla_enabled=xla_enabled, - grpc_enabled=grpc_enabled) - -def cuda_py_tests(name, - srcs, - size="medium", - additional_deps=[], - data=[], - shard_count=1, - tags=[], - prefix="", - xla_enabled=False, - grpc_enabled=False): - test_tags = tags + tf_cuda_tests_tags() - py_tests( - name=name, - size=size, - srcs=srcs, - additional_deps=additional_deps, - data=data, - tags=test_tags, - shard_count=shard_count, - prefix=prefix, - xla_enabled=xla_enabled, - grpc_enabled=grpc_enabled) +def py_tests( + name, + srcs, + size = "medium", + additional_deps = [], + data = [], + tags = [], + shard_count = 1, + prefix = "", + xla_enabled = False, + grpc_enabled = False): + for src in srcs: + test_name = src.split("/")[-1].split(".")[0] + if prefix: + test_name = "%s_%s" % (prefix, test_name) + tf_py_test( + name = test_name, + size = size, + srcs = [src], + main = src, + tags = tags, + shard_count = shard_count, + data = data, + additional_deps = additional_deps, + xla_enabled = xla_enabled, + grpc_enabled = grpc_enabled, + ) + +def cuda_py_tests( + name, + srcs, + size = "medium", + additional_deps = [], + data = [], + shard_count = 1, + tags = [], + prefix = "", + xla_enabled = False, + grpc_enabled = False): + test_tags = tags + tf_cuda_tests_tags() + py_tests( + name = name, + size = size, + srcs = srcs, + additional_deps = additional_deps, + data = data, + tags = test_tags, + shard_count = shard_count, + prefix = prefix, + xla_enabled = xla_enabled, + grpc_enabled = grpc_enabled, + ) # Creates a genrule named for running tools/proto_text's generator to # make the proto_text functions, for the protos passed in . # # Return a struct with fields (hdrs, srcs) containing the names of the # generated files. -def tf_generate_proto_text_sources(name, srcs_relative_dir, srcs, protodeps=[], deps=[], visibility=None): - out_hdrs = ( - [p.replace(".proto", ".pb_text.h") - for p in srcs] + [p.replace(".proto", ".pb_text-impl.h") for p in srcs]) - out_srcs = [p.replace(".proto", ".pb_text.cc") for p in srcs] - native.genrule( - name=name + "_srcs", - srcs=srcs + protodeps + [clean_dep("//tensorflow/tools/proto_text:placeholder.txt")], - outs=out_hdrs + out_srcs, - visibility=visibility, - cmd= - "$(location //tensorflow/tools/proto_text:gen_proto_text_functions) " - + "$(@D) " + srcs_relative_dir + " $(SRCS)", - tools=[ - clean_dep("//tensorflow/tools/proto_text:gen_proto_text_functions") - ],) - - native.filegroup( - name=name + "_hdrs", - srcs=out_hdrs, - visibility=visibility, - ) - - native.cc_library( - name=name, - srcs=out_srcs, - hdrs=out_hdrs, - visibility=visibility, - deps = deps, - ) +def tf_generate_proto_text_sources(name, srcs_relative_dir, srcs, protodeps = [], deps = [], visibility = None): + out_hdrs = ( + [ + p.replace(".proto", ".pb_text.h") + for p in srcs + ] + [p.replace(".proto", ".pb_text-impl.h") for p in srcs] + ) + out_srcs = [p.replace(".proto", ".pb_text.cc") for p in srcs] + native.genrule( + name = name + "_srcs", + srcs = srcs + protodeps + [clean_dep("//tensorflow/tools/proto_text:placeholder.txt")], + outs = out_hdrs + out_srcs, + visibility = visibility, + cmd = + "$(location //tensorflow/tools/proto_text:gen_proto_text_functions) " + + "$(@D) " + srcs_relative_dir + " $(SRCS)", + tools = [ + clean_dep("//tensorflow/tools/proto_text:gen_proto_text_functions"), + ], + ) + + native.filegroup( + name = name + "_hdrs", + srcs = out_hdrs, + visibility = visibility, + ) + + native.cc_library( + name = name, + srcs = out_srcs, + hdrs = out_hdrs, + visibility = visibility, + deps = deps, + ) def tf_genrule_cmd_append_to_srcs(to_append): - return ("cat $(SRCS) > $(@) && " + "echo >> $(@) && " + "echo " + to_append + - " >> $(@)") + return ("cat $(SRCS) > $(@) && " + "echo >> $(@) && " + "echo " + to_append + + " >> $(@)") def tf_version_info_genrule(): - native.genrule( - name="version_info_gen", - srcs=[ - clean_dep("@local_config_git//:gen/spec.json"), - clean_dep("@local_config_git//:gen/head"), - clean_dep("@local_config_git//:gen/branch_ref"), - ], - outs=["util/version_info.cc"], - cmd= - "$(location //tensorflow/tools/git:gen_git_source.py) --generate $(SRCS) \"$@\" --git_tag_override=$${GIT_TAG_OVERRIDE:-}", - local=1, - tools=[clean_dep("//tensorflow/tools/git:gen_git_source.py")],) + native.genrule( + name = "version_info_gen", + srcs = [ + clean_dep("@local_config_git//:gen/spec.json"), + clean_dep("@local_config_git//:gen/head"), + clean_dep("@local_config_git//:gen/branch_ref"), + ], + outs = ["util/version_info.cc"], + cmd = + "$(location //tensorflow/tools/git:gen_git_source.py) --generate $(SRCS) \"$@\" --git_tag_override=$${GIT_TAG_OVERRIDE:-}", + local = 1, + tools = [clean_dep("//tensorflow/tools/git:gen_git_source.py")], + ) def tf_py_build_info_genrule(): - native.genrule( - name="py_build_info_gen", - outs=["platform/build_info.py"], - cmd= - "$(location //tensorflow/tools/build_info:gen_build_info.py) --raw_generate \"$@\" --build_config " + if_cuda("cuda", "cpu"), - local=1, - tools=[clean_dep("//tensorflow/tools/build_info:gen_build_info.py")],) - -def cc_library_with_android_deps(deps, - android_deps=[], - common_deps=[], - copts=tf_copts(), - **kwargs): - deps = if_not_android(deps) + if_android(android_deps) + common_deps - native.cc_library(deps=deps, copts=copts, **kwargs) + native.genrule( + name = "py_build_info_gen", + outs = ["platform/build_info.py"], + cmd = + "$(location //tensorflow/tools/build_info:gen_build_info.py) --raw_generate \"$@\" --build_config " + if_cuda("cuda", "cpu"), + local = 1, + tools = [clean_dep("//tensorflow/tools/build_info:gen_build_info.py")], + ) + +def cc_library_with_android_deps( + deps, + android_deps = [], + common_deps = [], + copts = tf_copts(), + **kwargs): + deps = if_not_android(deps) + if_android(android_deps) + common_deps + native.cc_library(deps = deps, copts = copts, **kwargs) register_extension_info( extension_name = "cc_library_with_android_deps", -- cgit v1.2.3 From 00590b6973cb071744cdd1335a161b17866dea87 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 15 Aug 2018 15:29:52 -0700 Subject: Fix the MKL build by correcting misspelled references to MKL's build package. PiperOrigin-RevId: 208894550 --- tensorflow/BUILD | 2 +- tensorflow/core/kernels/BUILD | 2 +- tensorflow/tensorflow.bzl | 4 ++-- tensorflow/tools/pip_package/BUILD | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/BUILD b/tensorflow/BUILD index f1000c1bff..94e059b914 100644 --- a/tensorflow/BUILD +++ b/tensorflow/BUILD @@ -431,7 +431,7 @@ filegroup( name = "intel_binary_blob", data = if_mkl_ml( [ - "//third_party/intel_mkl_ml", + "//third_party/mkl:intel_binary_blob", ], ), ) diff --git a/tensorflow/core/kernels/BUILD b/tensorflow/core/kernels/BUILD index 46c234d057..ae617a6998 100644 --- a/tensorflow/core/kernels/BUILD +++ b/tensorflow/core/kernels/BUILD @@ -2884,7 +2884,7 @@ tf_kernel_library( copts = if_override_eigen_strong_inline(["/DEIGEN_STRONG_INLINE=inline"]), prefix = "batch_matmul_op", deps = MATH_DEPS + if_mkl_ml([ - "//third_party/intel_mkl_ml", + "//third_party/mkl:intel_binary_blob", ]), ) diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index 1e028e3350..14e678d1ca 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -391,7 +391,7 @@ def tf_cc_binary( srcs = srcs + tf_binary_additional_srcs(), deps = deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml( [ - "//third_party/intel_mkl_ml", + "//third_party/mkl:intel_binary_blob", ], ), data = data + tf_binary_dynamic_kernel_dsos(kernels), @@ -729,7 +729,7 @@ def tf_cc_test( }) + linkopts + _rpath_linkopts(name), deps = deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml( [ - "//third_party/intel_mkl_ml", + "//third_party/mkl:intel_binary_blob", ], ), data = data + tf_binary_dynamic_kernel_dsos(kernels), diff --git a/tensorflow/tools/pip_package/BUILD b/tensorflow/tools/pip_package/BUILD index 6bba139b4d..00c1337b19 100644 --- a/tensorflow/tools/pip_package/BUILD +++ b/tensorflow/tools/pip_package/BUILD @@ -214,7 +214,7 @@ sh_binary( "//tensorflow/contrib/lite/python:tflite_convert", "//tensorflow/contrib/lite/toco/python:toco_from_protos", ], - }) + if_mkl_ml(["//third_party/intel_mkl_ml"]), + }) + if_mkl_ml(["//third_party/mkl:intel_binary_blob"]), ) # A genrule for generating a marker file for the pip package on Windows -- cgit v1.2.3 From fe48d9189c74e05be21e928a445a006bcd4a13f8 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Fri, 17 Aug 2018 10:29:33 -0700 Subject: Reformat tensorflow bazel files; NFC Avoids whitespace changes in a later CL. PiperOrigin-RevId: 209168698 --- tensorflow/tensorflow.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tensorflow/tensorflow.bzl') diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index 14e678d1ca..c7766f384e 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -391,7 +391,7 @@ def tf_cc_binary( srcs = srcs + tf_binary_additional_srcs(), deps = deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml( [ - "//third_party/mkl:intel_binary_blob", + "//third_party/mkl:intel_binary_blob", ], ), data = data + tf_binary_dynamic_kernel_dsos(kernels), @@ -729,7 +729,7 @@ def tf_cc_test( }) + linkopts + _rpath_linkopts(name), deps = deps + tf_binary_dynamic_kernel_deps(kernels) + if_mkl_ml( [ - "//third_party/mkl:intel_binary_blob", + "//third_party/mkl:intel_binary_blob", ], ), data = data + tf_binary_dynamic_kernel_dsos(kernels), -- cgit v1.2.3