load("//third_party/mpi:mpi.bzl", "if_mpi")
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda")
load("@local_config_tensorrt//:build_defs.bzl", "if_tensorrt")
+load("//tensorflow:tensorflow.bzl", "if_not_windows")
py_library(
name = "contrib_py",
"//tensorflow/contrib/estimator:estimator_py",
"//tensorflow/contrib/factorization:factorization_py",
"//tensorflow/contrib/feature_column:feature_column_py",
- "//tensorflow/contrib/ffmpeg:ffmpeg_ops_py",
"//tensorflow/contrib/framework:framework_py",
"//tensorflow/contrib/fused_conv:fused_conv_py",
"//tensorflow/contrib/gan",
"//tensorflow/contrib/linalg:linalg_py",
"//tensorflow/contrib/linear_optimizer:sdca_estimator_py",
"//tensorflow/contrib/linear_optimizer:sdca_ops_py",
- "//tensorflow/contrib/lite/python:lite",
"//tensorflow/contrib/lookup:lookup_py",
"//tensorflow/contrib/losses:losses_py",
"//tensorflow/contrib/losses:metric_learning_py",
"//tensorflow/contrib/kafka",
],
"//conditions:default": [],
- }),
+ }) + if_not_windows([
+ "//tensorflow/contrib/ffmpeg:ffmpeg_ops_py",
+ "//tensorflow/contrib/lite/python:lite", # unix dependency, need to fix code
+ ]),
)
cc_library(
+# pylint: disable=g-import-not-at-top
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
from __future__ import division
from __future__ import print_function
+import os
+
# Add projects here, they will show up under tf.contrib.
from tensorflow.contrib import batching
from tensorflow.contrib import bayesflow
from tensorflow.contrib import training
from tensorflow.contrib import util
from tensorflow.contrib.eager.python import tfe as eager
-from tensorflow.contrib.lite.python import lite
+if os.name != "nt":
+ from tensorflow.contrib.lite.python import lite
from tensorflow.contrib.optimizer_v2 import optimizer_v2_symbols as optimizer_v2
from tensorflow.contrib.receptive_field import receptive_field_api as receptive_field
from tensorflow.contrib.remote_fused_graph import pylib as remote_fused_graph
from tensorflow.python.util.lazy_loader import LazyLoader
ffmpeg = LazyLoader("ffmpeg", globals(),
"tensorflow.contrib.ffmpeg")
+del os
del LazyLoader
del absolute_import
Status GetFeatureColumnSizes(int64* const num_dense_float_features,
int64* const num_sparse_float_features,
int64* const num_sparse_int_features) const {
- QCHECK_NE(num_dense_float_features, nullptr);
- QCHECK_NE(num_sparse_float_features, nullptr);
- QCHECK_NE(num_sparse_int_features, nullptr);
+ QCHECK_NE(num_dense_float_features, static_cast<int64*>(nullptr));
+ QCHECK_NE(num_sparse_float_features, static_cast<int64*>(nullptr));
+ QCHECK_NE(num_sparse_int_features, static_cast<int64*>(nullptr));
*num_dense_float_features = dense_float_feature_columns_.size();
*num_sparse_float_features = sparse_float_feature_columns_.size();
*num_sparse_int_features = sparse_int_feature_columns_.size();
"//tensorflow/python:framework_test_lib",
"//tensorflow/python:platform_test",
],
+ tags = ["no_windows"], # TODO: needs investigation on Windows
)
cuda_py_test(
"//tensorflow/python:math_ops",
"//tensorflow/python:platform_test",
],
+ tags = ["no_windows"], # TODO: needs investigation on Windows
)
cuda_py_test(
":linear_regression",
"//tensorflow:tensorflow_py",
],
+ tags = ["no_windows"], # TODO: needs investigation on Windows
)
cuda_py_test(
name = "classifier_metrics_test",
srcs = ["python/eval/python/classifier_metrics_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":classifier_metrics",
"//tensorflow/core:protos_all_py",
name = "utils_test",
srcs = ["utils_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
"//tensorflow/contrib/kfac/python/ops:utils",
"//tensorflow/contrib/tpu",
"python/ops/core_test.py",
],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":_typecheck",
":core",
size = "small",
srcs = ["python/layers/normalization_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":layers_py",
"//tensorflow/contrib/framework:framework_py",
size = "small",
srcs = ["python/ops/sparse_ops_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":layers_py",
"//tensorflow/python:array_ops",
size = "small",
srcs = ["python/learn/learn_io/data_feeder_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":learn",
"//tensorflow/python:client_testlib",
"//tensorflow/python:variables",
"//tensorflow/python/estimator",
],
+ tags = ["no_windows"], # TODO: needs investigation on Windows
)
py_test(
size = "small",
srcs = ["python/learn/graph_actions_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":learn",
"//tensorflow/contrib/framework:framework_py",
size = "small",
srcs = ["python/learn/learn_io/io_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":learn",
"//tensorflow/contrib/learn/python/learn/datasets",
size = "small",
srcs = ["python/learn/utils/saved_model_export_utils_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":learn",
"//tensorflow/contrib/layers:layers_py",
"//tensorflow/python:variables",
],
grpc_enabled = True,
+ tags = ["no_windows"], # TODO: needs investigation on Windows
)
size = "small",
srcs = ["python/ops/remote_fused_graph_ops_test.py"],
srcs_version = "PY2AND3",
- tags = ["no_windows"],
deps = [
":remote_fused_graph_ops_py",
"//tensorflow/core:protos_all_py",
size = "small",
srcs = ["python/saved_model/reader_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
visibility = ["//visibility:private"],
deps = [
":saved_model_py",
name = "gc_test",
srcs = ["gc_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
visibility = ["//visibility:private"],
deps = [
":gc",
name = "dataset_data_provider_test",
srcs = ["dataset_data_provider_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":dataset",
":dataset_data_provider",
srcs = ["client/random_forest_test.py"],
srcs_version = "PY2AND3",
tags = [
- "no_windows",
"nomac", # b/63258195
"notsan",
],
# For platform specific build config
load("//tensorflow/core:platform/default/build_config.bzl", "tf_proto_library")
+load("//tensorflow:tensorflow.bzl", "py_test")
tf_proto_library(
name = "protos_all",
srcs = ["predict_test.py"],
data = ["data/period_trend.csv"],
srcs_version = "PY2AND3",
- tags = ["notsan"], # b/67513579
+ tags = [
+ "no_windows", # TODO: needs investigation on Windows
+ "notsan", # b/67513579
+ ],
deps = [
":predict",
"//tensorflow/python:client_testlib",
"head_test.py",
],
srcs_version = "PY2AND3",
- tags = [
- "no_pip_gpu", # b/63391119
- ],
+ tags = ["no_pip_gpu"], # b/63391119
deps = [
":estimators",
":feature_keys",
srcs_version = "PY2AND3",
tags = [
"no_pip_gpu", # b/63391119
+ "no_windows", # TODO: needs investigation on Windows
],
deps = [
":feature_keys",
timeout = "long", # Moderate but for asan
srcs = ["state_space_model_test.py"],
srcs_version = "PY2AND3",
+ tags = ["no_windows"], # TODO: needs investigation on Windows
deps = [
":state_space_model",
"//tensorflow/contrib/layers:layers_py",
"//tensorflow/python:framework",
"//tensorflow/python:layers",
],
+ tags = ["no_windows"], # TODO: needs investigation on Windows
)
tf_py_test(
plugin.
"""
if os.name == 'nt':
- # To avoid makeing every user_ops aware of windows, re-write
- # the file extension from .so to .dll.
- path = re.sub(r'\.so$', '.dll', path)
+ # To avoid making every user_ops aware of windows, re-write
+ # the file extension from .so to .dll if .so file doesn't exist.
+ if not os.path.exists(path):
+ path = re.sub(r'\.so$', '.dll', path)
# Currently we have only some user_ops as dlls on windows - don't try
# to load them if the dll is not found.
}
// Key for storing the Dataset graph in the serialized format.
- static const char kDatasetGraphKey[];
+ TF_EXPORT static const char kDatasetGraphKey[];
// Key for storing the output node of the Dataset graph in the serialized
// format.
- static const char kDatasetGraphOutputNodeKey[];
+ TF_EXPORT static const char kDatasetGraphOutputNodeKey[];
private:
Status Serialize(OpKernelContext* ctx, string* serialized_graph_def,
return StringPiece(data_ + pos, n);
}
-const StringPiece::size_type StringPiece::npos = size_type(-1);
-
} // namespace tensorflow
iterator begin() const { return data_; }
iterator end() const { return data_ + size_; }
- static const size_t npos;
+ static const size_t npos = size_type(-1);
// Return the ith byte in the referenced data.
// REQUIRES: n < size()
#include "tensorflow/core/platform/abi.h"
-#if defined(PLATFORM_WINDOWS)
+#if defined(_MSC_VER)
#include <windows.h>
#include <cstring>
#else
#include <memory>
#include <string>
-#if defined(PLATFORM_WINDOWS)
+#if defined(_MSC_VER)
extern "C" char* __unDName(char* output_string, const char* name,
int max_string_length, void* (*p_alloc)(std::size_t),
void (*p_free)(void*), unsigned short disable_flags);
-#endif // defined(PLATFORM_WINDOWS)
+#endif // defined(_MSC_VER)
namespace tensorflow {
namespace port {
std::string MaybeAbiDemangle(const char* name) {
-#if defined(PLATFORM_WINDOWS)
+#if defined(_MSC_VER)
std::unique_ptr<char> demangled{__unDName(nullptr, name, 0, std::malloc,
std::free,
static_cast<unsigned short>(0))};
#include <string>
-#if defined(PLATFORM_WINDOWS)
+#if defined(_MSC_VER)
#include "tensorflow/core/platform/windows/cpu_info.h"
#endif
friend class ScopedAnnotation;
friend class TraceMe;
- static std::atomic<Tracing::Engine*> tracing_engine_;
+ // TODO: TF_EXPORT is for building //tensorflow/contrib/data:_dataset_ops.so
+ // on Windows. Figure out a way to remove TF_EXPORT here.
+ TF_EXPORT static std::atomic<Tracing::Engine*> tracing_engine_;
static Tracing::Engine* engine() {
return tracing_engine_.load(std::memory_order_acquire);
}
load("//tensorflow:tensorflow.bzl", "tf_py_build_info_genrule")
load("//tensorflow:tensorflow.bzl", "tf_py_wrap_cc")
load("//tensorflow:tensorflow.bzl", "tf_cc_shared_object")
+load("//tensorflow:tensorflow.bzl", "tf_native_cc_binary")
+load("//tensorflow:tensorflow.bzl", "tf_custom_op_library_additional_deps_impl")
load("//tensorflow:tensorflow.bzl", "cuda_py_test")
load("//tensorflow:tensorflow.bzl", "cuda_py_tests")
load("//tensorflow/core:platform/default/build_config.bzl", "pyx_library")
"//tensorflow/tools/api/generator:__pkg__",
"//tensorflow/tools/quantization:__pkg__", # TODO(b/34059704): remove when fixed
],
- deps = [":no_contrib"] + if_not_windows([
+ deps = [
+ ":no_contrib",
"//tensorflow/contrib:contrib_py",
- ]),
+ ],
)
py_library(
srcs = ["framework/contrib_test.py"],
main = "framework/contrib_test.py",
srcs_version = "PY2AND3",
- tags = ["no_windows"],
deps = [
"//tensorflow:tensorflow_py",
"//tensorflow/python:client_testlib",
srcs = ["framework/dtypes_test.py"],
main = "framework/dtypes_test.py",
srcs_version = "PY2AND3",
- tags = ["no_windows"],
deps = [
":framework_for_generated_wrappers",
":framework_test_lib",
size = "small",
srcs = ["ops/clip_ops_test.py"],
srcs_version = "PY2AND3",
- tags = ["no_windows"],
deps = [
":client_testlib",
":clip_ops",
],
data = ["//tensorflow/core:image_testdata"],
shard_count = 5,
- tags = ["no_windows"],
)
cuda_py_test(
tf_additional_gdr_deps()),
)
+# ** Targets for Windows build (start) **
+# We need the following targets to expose symbols from _pywrap_tensorflow.dll
+
+# Build a cc_binary from tf_custom_op_library_additional_deps_impl,
+# it contains all object code from its dependencies.
+tf_native_cc_binary(
+ name = "tf_custom_op_library_additional_deps.so",
+ linkshared = 1,
+ linkstatic = 1,
+ deps = tf_custom_op_library_additional_deps_impl(),
+)
+
+# Get a DEF file generated by parsing all object files
+# of tf_custom_op_library_additional_deps.so
+filegroup(
+ name = "pywrap_tensorflow_def_file",
+ srcs = [":tf_custom_op_library_additional_deps.so"],
+ output_group = "def_file",
+)
+
+# Filter the DEF file to reduce the number of symbols to 64K or less.
+# Note that we also write the name of the pyd file into DEF file so that
+# the dynamic libraries of custom ops can find it at runtime.
+genrule(
+ name = "pywrap_tensorflow_filtered_def_file",
+ srcs = [":pywrap_tensorflow_def_file"],
+ outs = ["pywrap_tensorflow_filtered_def_file.def"],
+ cmd = select({
+ "//tensorflow:windows": """
+ $(location @local_config_def_file_filter//:def_file_filter) \\
+ --input $(location :pywrap_tensorflow_def_file) \\
+ --output $@ \\
+ --target _pywrap_tensorflow_internal.pyd
+ """,
+ "//conditions:default": "touch $@", # Just a placeholder for Unix platforms
+ }),
+ tools = ["@local_config_def_file_filter//:def_file_filter"],
+)
+
+# Get the import library of _pywrap_tensorflow_internal.dll
+filegroup(
+ name = "pywrap_tensorflow_import_lib_file",
+ srcs = [":_pywrap_tensorflow_internal.so"],
+ output_group = "interface_library",
+)
+
+# Create a cc_import rule for the import library of _pywrap_tensorflow_internal.dll
+# so that custom ops' dynamic libraries can link against it.
+cc_import(
+ name = "pywrap_tensorflow_import_lib",
+ interface_library = select({
+ "//tensorflow:windows": ":pywrap_tensorflow_import_lib_file",
+ "//conditions:default": "not_exsiting_on_unix.lib", # Just a placeholder for Unix platforms
+ }),
+ system_provided = 1,
+)
+
+# ** Targets for Windows build (end) **
+
py_library(
name = "lib",
srcs = [
size = "small",
srcs = ["lib/core/bfloat16_test.py"],
srcs_version = "PY2AND3",
- tags = ["no_windows"],
deps = [
":client_testlib",
":lib",
size = "small",
srcs = ["training/checkpoint_ops_test.py"],
srcs_version = "PY2AND3",
- tags = ["no_windows"],
deps = [
":checkpoint_ops_gen",
":client",
size = "medium",
srcs = ["training/monitored_session_test.py"],
srcs_version = "PY2AND3",
- tags = [
- "no_windows",
- "notsan", # b/67945581
- ],
+ tags = ["notsan"], # b/67945581
deps = [
":array_ops",
":client_testlib",
"//tensorflow/python:util",
"//tensorflow/python:variables",
],
+ tags = ["no_windows"], # TODO: needs investigation on Windows
)
py_test(
size = "small",
srcs = ["_impl/keras/utils/io_utils_test.py"],
srcs_version = "PY2AND3",
- tags = ["notsan"],
+ tags = [
+ "no_windows", # TODO: needs investigation on Windows
+ "notsan",
+ ],
deps = [
":keras",
"//tensorflow/python:client_testlib",
"//tensorflow/python:nn_grad",
],
data = ["//tensorflow/core:image_testdata"],
- tags = ["no_windows"],
)
tf_py_test(
"//tensorflow/python:variables",
],
data = ["//tensorflow/core:lmdb_testdata"],
- tags = ["no_windows"],
)
cuda_py_test(
"//tensorflow/python:variables",
],
shard_count = 4,
- tags = ["no_windows"],
)
cuda_py_test(
"//tensorflow/python/eager:context",
],
shard_count = 10,
- tags = ["no_windows"],
)
cuda_py_test(
label_regex_for_dep = "{extension_name}.*",
)
+# 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)
+
+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="",
"@protobuf_archive//:protobuf_headers",
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 [
+ "@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"),
]
# Traverse the dependency graph along the "deps" attribute of the
deps=deps + if_cuda(cuda_deps),
data=[name + "_check_deps"],
copts=tf_copts(is_external=True),
+ features = ["windows_export_all_symbols"],
linkopts=linkopts + select({
"//conditions:default": [
"-lm",
]) + tf_extension_copts()),
linkopts=tf_extension_linkopts() + extra_linkopts,
linkstatic=1,
- deps=deps + extra_deps)
+ deps=deps + extra_deps,
+ **kwargs)
native.genrule(
name="gen_" + cc_library_pyd_name,
srcs=[":" + cc_library_name],
--define=no_tensorflow_py_deps=true --test_lang_filters=py \
--test_tag_filters=-no_pip,-no_windows,-no_oss \
--build_tag_filters=-no_pip,-no_windows,-no_oss --build_tests_only \
- //${PY_TEST_DIR}/tensorflow/python/...
+ //${PY_TEST_DIR}/tensorflow/python/... \
+ //${PY_TEST_DIR}/tensorflow/contrib/...
--- /dev/null
+# Description:
+# Tools for filtering DEF file for TensorFlow on Windows
+#
+# On Windows, we use a DEF file generated by Bazel to export
+# symbols from the tensorflow dynamic library(_pywrap_tensorflow.dll).
+# The maximum number of symbols that can be exported per DLL is 64K,
+# so we have to filter some useless symbols through this python script.
+
+package(default_visibility = ["//visibility:public"])
--- /dev/null
+# Description:
+# Tools for filtering DEF file for TensorFlow on Windows
+#
+# On Windows, we use a DEF file generated by Bazel to export
+# symbols from the tensorflow dynamic library(_pywrap_tensorflow.dll).
+# The maximum number of symbols that can be exported per DLL is 64K,
+# so we have to filter some useless symbols through this python script.
+
+package(default_visibility = ["//visibility:public"])
+
+py_binary(
+ name = "def_file_filter",
+ srcs = ["def_file_filter.py"],
+ srcs_version = "PY2AND3",
+)
--- /dev/null
+# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==============================================================================
+
+"""def_file_filter.py - tool to filter a windows def file.
+
+The def file can be used to export symbols from the tensorflow dll to enable
+tf.load_library().
+
+Because the linker allows only 64K symbols to be exported per dll
+we filter the symbols down to the essentials. The regular expressions
+we use for this are specific to tensorflow.
+
+TODO: this works fine but there is an issue with exporting
+'const char * const' and importing it from a user_ops. The problem is
+on the importing end and using __declspec(dllimport) works around it.
+"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+import argparse
+import io
+import os
+import re
+import subprocess
+import sys
+import tempfile
+
+# External tools we use that come with visual studio sdk
+UNDNAME = "%{undname_bin_path}"
+
+# Exclude if matched
+EXCLUDE_RE = re.compile(r"RTTI|deleting destructor|::internal::")
+
+# Include if matched before exclude
+INCLUDEPRE_RE = re.compile(r"google::protobuf::internal::ExplicitlyConstructed|"
+ r"google::protobuf::internal::ArenaImpl::AllocateAligned|" # for contrib/data/_prefetching_ops
+ r"google::protobuf::internal::ArenaImpl::AddCleanup|" # for contrib/data/_prefetching_ops
+ r"google::protobuf::Arena::OnArenaAllocation|" # for contrib/data/_prefetching_ops
+ r"tensorflow::internal::LogMessage|"
+ r"tensorflow::internal::LogString|"
+ r"tensorflow::internal::CheckOpMessageBuilder|"
+ r"tensorflow::internal::MakeCheckOpValueString|"
+ r"tensorflow::internal::PickUnusedPortOrDie|"
+ r"tensorflow::internal::ValidateDevice|"
+ r"tensorflow::ops::internal::Enter|"
+ r"tensorflow::strings::internal::AppendPieces|"
+ r"tensorflow::strings::internal::CatPieces|"
+ r"tensorflow::io::internal::JoinPathImpl")
+
+# Include if matched after exclude
+INCLUDE_RE = re.compile(r"^(TF_\w*)$|"
+ r"^(TFE_\w*)$|"
+ r"nsync::|"
+ r"tensorflow::|"
+ r"functor::|"
+ r"perftools::gputools")
+
+# We want to identify data members explicitly in the DEF file, so that no one
+# can implicitly link against the DLL if they use one of the variables exported
+# from the DLL and the header they use does not decorate the symbol with
+# __declspec(dllimport). It is easier to detect what a data symbol does
+# NOT look like, so doing it with the below regex.
+DATA_EXCLUDE_RE = re.compile(r"[)(]|"
+ r"vftable|"
+ r"vbtable|"
+ r"vcall|"
+ r"RTTI|"
+ r"protobuf::internal::ExplicitlyConstructed")
+
+def get_args():
+ """Parse command line."""
+ filename_list = lambda x: x.split(";")
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--input", type=filename_list,
+ help="paths to input def file",
+ required=True)
+ parser.add_argument("--output", help="output deffile", required=True)
+ parser.add_argument("--target", help="name of the target", required=True)
+ args = parser.parse_args()
+ return args
+
+
+def main():
+ """main."""
+ args = get_args()
+
+ # Pipe dumpbin to extract all linkable symbols from libs.
+ # Good symbols are collected in candidates and also written to
+ # a temp file.
+ candidates = []
+ tmpfile = tempfile.NamedTemporaryFile(mode="w", delete=False)
+ for def_file_path in args.input:
+ def_file = open(def_file_path, 'r')
+ for line in def_file:
+ cols = line.split()
+ sym = cols[0]
+ tmpfile.file.write(sym + "\n")
+ candidates.append(sym)
+ tmpfile.file.close()
+
+ # Run the symbols through undname to get their undecorated name
+ # so we can filter on something readable.
+ with open(args.output, "w") as def_fp:
+ # track dupes
+ taken = set()
+
+ # Header for the def file.
+ def_fp.write("LIBRARY " + args.target + "\n")
+ def_fp.write("EXPORTS\n")
+ def_fp.write("\t ??1OpDef@tensorflow@@UEAA@XZ\n")
+
+ # Each symbols returned by undname matches the same position in candidates.
+ # We compare on undname but use the decorated name from candidates.
+ dupes = 0
+ proc = subprocess.Popen([UNDNAME, tmpfile.name], stdout=subprocess.PIPE)
+ for idx, line in enumerate(io.TextIOWrapper(proc.stdout, encoding="utf-8")):
+ decorated = candidates[idx]
+ if decorated in taken:
+ # Symbol is already in output, done.
+ dupes += 1
+ continue
+
+ if not INCLUDEPRE_RE.search(line):
+ if EXCLUDE_RE.search(line):
+ continue
+ if not INCLUDE_RE.search(line):
+ continue
+
+ if "deleting destructor" in line:
+ # Some of the symbols convered by INCLUDEPRE_RE export deleting
+ # destructor symbols, which is a bad idea.
+ # So we filter out such symbols here.
+ continue
+
+ if DATA_EXCLUDE_RE.search(line):
+ def_fp.write("\t" + decorated + "\n")
+ else:
+ def_fp.write("\t" + decorated + " DATA\n")
+ taken.add(decorated)
+ def_fp.close()
+
+ exit_code = proc.wait()
+ if exit_code != 0:
+ print("{} failed, exit={}".format(UNDNAME, exit_code))
+ return exit_code
+
+ os.unlink(tmpfile.name)
+
+ print("symbols={}, taken={}, dupes={}"
+ .format(len(candidates), len(taken), dupes))
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
--- /dev/null
+"""Repository rule for def file filter autoconfiguration.
+
+This repository reuses Bazel's VC detect mechanism to find undname.exe,
+which is a tool used in def_file_filter.py.
+
+def_file_filter.py is for filtering the DEF file for TensorFlow on Windows.
+On Windows, we use a DEF file generated by Bazel to export symbols from the
+tensorflow dynamic library(_pywrap_tensorflow.dll). The maximum number of
+symbols that can be exported per DLL is 64K, so we have to filter some useless
+symbols through this python script.
+
+`def_file_filter_config` depends on the following environment variables:
+ * `BAZEL_VC`
+ * `BAZEL_VS`
+ * `VS90COMNTOOLS`
+ * `VS100COMNTOOLS`
+ * `VS110COMNTOOLS`
+ * `VS120COMNTOOLS`
+ * `VS140COMNTOOLS`
+"""
+
+load("@bazel_tools//tools/cpp:windows_cc_configure.bzl", "find_vc_path")
+load("@bazel_tools//tools/cpp:windows_cc_configure.bzl", "find_msvc_tool")
+load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "auto_configure_fail")
+
+def _def_file_filter_configure_impl(repository_ctx):
+ if repository_ctx.os.name.lower().find("windows") == -1:
+ repository_ctx.symlink(Label("//tensorflow/tools/def_file_filter:BUILD.tpl"), "BUILD")
+ repository_ctx.file("def_file_filter.py", "")
+ return
+ vc_path = find_vc_path(repository_ctx)
+ if vc_path == "visual-studio-not-found":
+ auto_configure_fail("Visual C++ build tools not found on your machine")
+ undname_bin_path = find_msvc_tool(repository_ctx, vc_path, "undname.exe").replace("\\", "\\\\")
+
+ repository_ctx.template(
+ "def_file_filter.py",
+ Label("//tensorflow/tools/def_file_filter:def_file_filter.py.tpl"),
+ {
+ "%{undname_bin_path}": undname_bin_path,
+ })
+ repository_ctx.symlink(Label("//tensorflow/tools/def_file_filter:BUILD.tpl"), "BUILD")
+
+
+def_file_filter_configure = repository_rule(
+ implementation = _def_file_filter_configure_impl,
+ environ = [
+ "BAZEL_VC",
+ "BAZEL_VS",
+ "VS90COMNTOOLS",
+ "VS100COMNTOOLS",
+ "VS110COMNTOOLS",
+ "VS120COMNTOOLS",
+ "VS140COMNTOOLS"
+ ],
+)
deps = ["//tensorflow:tensorflow_py"],
)
+COMMON_PIP_DEPS = [
+ ":licenses",
+ "MANIFEST.in",
+ "README",
+ "setup.py",
+ ":included_headers",
+ "//tensorflow:tensorflow_py",
+ "//tensorflow/contrib/autograph:autograph",
+ "//tensorflow/contrib/autograph/converters:converters",
+ "//tensorflow/contrib/autograph/converters:test_lib",
+ "//tensorflow/contrib/autograph/impl:impl",
+ "//tensorflow/contrib/autograph/pyct:pyct",
+ "//tensorflow/contrib/autograph/pyct/static_analysis:static_analysis",
+ "//tensorflow/contrib/boosted_trees:boosted_trees_pip",
+ "//tensorflow/contrib/cluster_resolver:cluster_resolver_pip",
+ "//tensorflow/contrib/data/python/kernel_tests:dataset_serialization_test",
+ "//tensorflow/contrib/data/python/ops:contrib_op_loader",
+ "//tensorflow/contrib/eager/python/examples:examples_pip",
+ "//tensorflow/contrib/eager/python:checkpointable_utils",
+ "//tensorflow/contrib/eager/python:evaluator",
+ "//tensorflow/contrib/gan:gan",
+ "//tensorflow/contrib/graph_editor:graph_editor_pip",
+ "//tensorflow/contrib/keras:keras",
+ "//tensorflow/contrib/labeled_tensor:labeled_tensor_pip",
+ "//tensorflow/contrib/nn:nn_py",
+ "//tensorflow/contrib/predictor:predictor_pip",
+ "//tensorflow/contrib/receptive_field:receptive_field_pip",
+ "//tensorflow/contrib/session_bundle:session_bundle_pip",
+ "//tensorflow/contrib/signal:signal_py",
+ "//tensorflow/contrib/signal:test_util",
+ "//tensorflow/contrib/slim:slim",
+ "//tensorflow/contrib/slim/python/slim/data:data_pip",
+ "//tensorflow/contrib/slim/python/slim/nets:nets_pip",
+ "//tensorflow/contrib/specs:specs",
+ "//tensorflow/contrib/summary:summary_test_util",
+ "//tensorflow/contrib/tensor_forest:init_py",
+ "//tensorflow/contrib/tensor_forest/hybrid:hybrid_pip",
+ "//tensorflow/contrib/timeseries:timeseries_pip",
+ "//tensorflow/contrib/tpu",
+ "//tensorflow/examples/tutorials/mnist:package",
+ "//tensorflow/python:distributed_framework_test_lib",
+ "//tensorflow/python:meta_graph_testdata",
+ "//tensorflow/python:spectral_ops_test_util",
+ "//tensorflow/python:util_example_parser_configuration",
+ "//tensorflow/python/debug:debug_pip",
+ "//tensorflow/python/eager:eager_pip",
+ "//tensorflow/python/kernel_tests/testdata:self_adjoint_eig_op_test_files",
+ "//tensorflow/python/saved_model:saved_model",
+ "//tensorflow/python/tools:tools_pip",
+ "//tensorflow/python:test_ops",
+ "//tensorflow/tools/dist_test/server:grpc_tensorflow_server",
+]
+
# On Windows, python binary is a zip file of runfiles tree.
# Add everything to its data dependency for generating a runfiles tree
# for building the pip package on Windows.
py_binary(
name = "simple_console_for_windows",
srcs = ["simple_console_for_windows.py"],
- data = [
- "MANIFEST.in",
- "README",
- "setup.py",
- ":included_headers",
- "//tensorflow/contrib/nn:nn_py",
- "//tensorflow/contrib/session_bundle:session_bundle_pip",
- "//tensorflow/contrib/signal:signal_py",
- "//tensorflow/contrib/slim/python/slim/data:data_pip",
- "//tensorflow/python:util_example_parser_configuration",
- "//tensorflow/python/debug:debug_pip",
- "//tensorflow/python/saved_model",
- "//tensorflow/python:spectral_ops_test_util",
- "//tensorflow/python/tools:tools_pip",
- "//tensorflow/python/eager:eager_pip",
- "//tensorflow/contrib/summary:summary_test_util",
- # These targets don't build on Windows yet. Exclude them for now.
- # "//tensorflow/contrib/slim",
- # "//tensorflow/contrib/slim/python/slim/nets:nets_pip",
- # "//tensorflow/contrib/specs",
- # "//tensorflow/contrib/tensor_forest:init_py",
- # "//tensorflow/contrib/tensor_forest/hybrid:hybrid_pip",
- # "//tensorflow/examples/tutorials/mnist:package",
- ],
+ data = COMMON_PIP_DEPS,
srcs_version = "PY2AND3",
deps = ["//tensorflow:tensorflow_py"],
)
data = select({
"//tensorflow:windows": [":simple_console_for_windows"],
"//tensorflow:windows_msvc": [":simple_console_for_windows"],
- "//conditions:default": [
- ":licenses",
- "MANIFEST.in",
- "README",
- "setup.py",
- ":included_headers",
+ "//conditions:default": COMMON_PIP_DEPS + [
":simple_console",
- "//tensorflow:tensorflow_py",
- "//tensorflow/contrib/boosted_trees:boosted_trees_pip",
- "//tensorflow/contrib/cluster_resolver:cluster_resolver_pip",
- "//tensorflow/contrib/data/python/kernel_tests:dataset_serialization_test",
- "//tensorflow/contrib/data/python/ops:contrib_op_loader",
- "//tensorflow/contrib/eager/python/examples:examples_pip",
- "//tensorflow/contrib/eager/python:checkpointable_utils",
- "//tensorflow/contrib/eager/python:evaluator",
- "//tensorflow/contrib/gan:gan",
- "//tensorflow/contrib/graph_editor:graph_editor_pip",
- "//tensorflow/contrib/keras:keras",
- "//tensorflow/contrib/labeled_tensor:labeled_tensor_pip",
"//tensorflow/contrib/lite/python:interpreter_test_data",
"//tensorflow/contrib/lite/python:tf_lite_py_pip",
"//tensorflow/contrib/lite/toco:toco",
"//tensorflow/contrib/lite/toco/python:toco_wrapper",
"//tensorflow/contrib/lite/toco/python:toco_from_protos",
- "//tensorflow/contrib/nn:nn_py",
- "//tensorflow/contrib/predictor:predictor_pip",
- "//tensorflow/contrib/autograph:autograph",
- "//tensorflow/contrib/autograph/converters:converters",
- "//tensorflow/contrib/autograph/converters:test_lib",
- "//tensorflow/contrib/autograph/impl:impl",
- "//tensorflow/contrib/autograph/pyct:pyct",
- "//tensorflow/contrib/autograph/pyct/static_analysis:static_analysis",
- "//tensorflow/contrib/receptive_field:receptive_field_pip",
- "//tensorflow/contrib/session_bundle:session_bundle_pip",
- "//tensorflow/contrib/signal:signal_py",
- "//tensorflow/contrib/signal:test_util",
- "//tensorflow/contrib/slim:slim",
- "//tensorflow/contrib/slim/python/slim/data:data_pip",
- "//tensorflow/contrib/slim/python/slim/nets:nets_pip",
- "//tensorflow/contrib/specs:specs",
- "//tensorflow/contrib/summary:summary_test_util",
- "//tensorflow/contrib/tensor_forest:init_py",
- "//tensorflow/contrib/tensor_forest/hybrid:hybrid_pip",
- "//tensorflow/contrib/timeseries:timeseries_pip",
- "//tensorflow/contrib/tpu",
- "//tensorflow/examples/tutorials/mnist:package",
- "//tensorflow/python:distributed_framework_test_lib",
- "//tensorflow/python:meta_graph_testdata",
- "//tensorflow/python:spectral_ops_test_util",
- "//tensorflow/python:util_example_parser_configuration",
- "//tensorflow/python/debug:debug_pip",
- "//tensorflow/python/eager:eager_pip",
- "//tensorflow/python/kernel_tests/testdata:self_adjoint_eig_op_test_files",
- "//tensorflow/python/saved_model:saved_model",
- "//tensorflow/python/tools:tools_pip",
- "//tensorflow/python:test_ops",
- "//tensorflow/tools/dist_test/server:grpc_tensorflow_server",
],
}) + if_mkl(["//third_party/mkl:intel_binary_blob"]) + if_tensorrt([
"//tensorflow/contrib/tensorrt:init_py",
load("//third_party/clang_toolchain:cc_configure_clang.bzl", "cc_download_clang_toolchain")
load("@io_bazel_rules_closure//closure/private:java_import_external.bzl", "java_import_external")
load("@io_bazel_rules_closure//closure:defs.bzl", "filegroup_external")
+load("//tensorflow/tools/def_file_filter:def_file_filter_configure.bzl",
+ "def_file_filter_configure")
# Sanitize a dependency so that it works correctly from code that includes
sycl_configure(name="local_config_sycl")
python_configure(name="local_config_python")
+ # For windows bazel build
+ # TODO: Remove def file filter when TensorFlow can export symbols properly on Windows.
+ def_file_filter_configure(name = "local_config_def_file_filter")
+
# Point //external/local_config_arm_compiler to //external/arm_compiler
arm_compiler_configure(
name="local_config_arm_compiler",