Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the Windows Bazel build #15125

Merged
merged 11 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,15 @@ def create_android_bazelrc_configs():
def set_grpc_build_flags():
write_to_bazelrc('build --define grpc_no_ares=true')

def set_windows_build_flags():
if is_windows():
# The non-monolithic build is not supported yet
write_to_bazelrc('build --config monolithic')
# Suppress warning messages
write_to_bazelrc('build --copt=-w --host_copt=-w')
# Output more verbose information when something goes wrong
write_to_bazelrc('build --verbose_failures')


def main():
# Make a copy of os.environ to be clear when functions and getting and setting
Expand Down Expand Up @@ -1101,6 +1110,7 @@ def main():
set_cc_opt_flags(environ_cp)
set_mkl()
set_monolithic()
set_windows_build_flags()
create_android_bazelrc_configs()

if __name__ == '__main__':
Expand Down
43 changes: 34 additions & 9 deletions tensorflow/tensorflow.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ def if_not_windows(a):
"//conditions:default": a,
})

def if_windows(a):
return select({
clean_dep("//tensorflow:windows"): a,
clean_dep("//tensorflow:windows_msvc"): a,
"//conditions:default": [],
})

def if_linux_x86_64(a):
return select({
clean_dep("//tensorflow:linux_x86_64"): a,
Expand Down Expand Up @@ -1298,11 +1305,32 @@ def tf_py_wrap_cc(name,
"//conditions:default": [":" + cc_library_name],
}))

def py_test(deps=[], **kwargs):
# This macro is for running python tests against system installed pip package
# on Windows.
#
# py_test is built as an exectuable python zip file on Windows, which contains all
# dependencies of the target. Because of the C++ extensions, it would be very
# inefficient if the py_test zips all runfiles, plus we don't need them when running
# tests against system installed pip package. So we'd like to get rid of the deps
# of py_test in this case.
#
# In order to trigger the tests without bazel clean after getting rid of deps,
# we introduce the following :
# 1. When --define=no_tensorflow_py_deps=true, the py_test depends on a marker
# file of the pip package, the test gets to rerun when the pip package change.
# Note that this only works on Windows. See the definition of
# //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(
deps=select({
"//conditions:default": deps,
clean_dep("//tensorflow:no_tensorflow_py_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)

Expand All @@ -1324,7 +1352,7 @@ def tf_py_test(name,
xla_enabled=False):
if xla_enabled:
additional_deps = additional_deps + tf_additional_xla_deps_py()
native.py_test(
py_test(
name=name,
size=size,
srcs=srcs,
Expand All @@ -1334,13 +1362,10 @@ def tf_py_test(name,
visibility=[clean_dep("//tensorflow:internal")],
shard_count=shard_count,
data=data,
deps=select({
"//conditions:default": [
clean_dep("//tensorflow/python:extra_py_tests_deps"),
clean_dep("//tensorflow/python:gradient_checker"),
deps=[
clean_dep("//tensorflow/python:extra_py_tests_deps"),
clean_dep("//tensorflow/python:gradient_checker"),
] + additional_deps,
clean_dep("//tensorflow:no_tensorflow_py_deps"): []
}),
flaky=flaky,
srcs_version="PY2AND3")

Expand Down
4 changes: 0 additions & 4 deletions tensorflow/tools/ci_build/windows/bazel/bazel_test_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ exclude_cpu_cc_tests="${failing_cpu_cc_tests} + ${broken_cpu_cc_tests}"

exclude_gpu_cc_tests="${extra_failing_gpu_cc_tests} + ${exclude_cpu_cc_tests}"

function clean_output_base() {
bazel clean --expunge
}

function run_configure_for_cpu_build {
# Due to a bug in Bazel: https://github.com/bazelbuild/bazel/issues/2182
# yes "" | ./configure doesn't work on Windows, so we set all the
Expand Down
16 changes: 0 additions & 16 deletions tensorflow/tools/ci_build/windows/bazel/common_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ export BAZEL_SH=${BAZEL_SH:-"C:/tools/msys64/usr/bin/bash"}
export PYTHON_BIN_PATH="C:/Program Files/Anaconda3/python.exe"
export PYTHON_LIB_PATH="C:/Program Files/Anaconda3/lib/site-packages"

# Set Python path for cc_configure.bzl
export BAZEL_PYTHON="C:/Program Files/Anaconda3/python.exe"

# Set Visual Studio path
export BAZEL_VS="C:/Program Files (x86)/Microsoft Visual Studio 14.0"

# Add python into PATH, it's needed because gen_git_source.py uses
# '/usr/bin/env python' as a shebang
export PATH="/c/Program Files/Anaconda3:$PATH"
Expand All @@ -53,13 +47,3 @@ export PATH="/c/Program Files/Anaconda3/Scripts:$PATH"
export PATH="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/bin:$PATH"
export PATH="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/extras/CUPTI/libx64:$PATH"
export PATH="/c/tools/cuda/bin:$PATH"

# Set the common build options on Windows
export BUILD_OPTS='--config=monolithic --copt=-w --host_copt=-w --verbose_failures --experimental_ui'

# Build TF with wrapper-less CROSSTOOL
# TODO(pcloudy): Remove this after wrapper-less CROSSTOOL becomes default
export NO_MSVC_WRAPPER=1

export USE_DYNAMIC_CRT=1

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ source "tensorflow/tools/ci_build/windows/bazel/common_env.sh" \
source "tensorflow/tools/ci_build/windows/bazel/bazel_test_lib.sh" \
|| { echo "Failed to source bazel_test_lib.sh" >&2; exit 1; }

clean_output_base

run_configure_for_cpu_build

# Compliling the following test is extremely slow with -c opt
Expand All @@ -54,5 +52,5 @@ passing_tests=$(bazel query "kind(cc_test, //tensorflow/cc/... + //tensorflow/co
# We need to strip \r so that the result could be store into a variable under MSYS
tr '\r' ' ')

bazel test $BUILD_OPTS -k $slow_compiling_test --test_output=errors
bazel test -c opt $BUILD_OPTS -k $passing_tests --test_output=errors
bazel test -k $slow_compiling_test --test_output=errors
bazel test -c opt -k $passing_tests --test_output=errors
9 changes: 2 additions & 7 deletions tensorflow/tools/ci_build/windows/cpu/pip/build_tf_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ source "tensorflow/tools/ci_build/windows/bazel/bazel_test_lib.sh" \

run_configure_for_cpu_build

clean_output_base

bazel build -c opt $BUILD_OPTS tensorflow/tools/pip_package:build_pip_package || exit $?
bazel build -c opt tensorflow/tools/pip_package:build_pip_package || exit $?

# Create a python test directory to avoid package name conflict
PY_TEST_DIR="py_test_dir"
Expand All @@ -60,11 +58,8 @@ reinstall_tensorflow_pip ${PIP_NAME}

# Define no_tensorflow_py_deps=true so that every py_test has no deps anymore,
# which will result testing system installed tensorflow
# TODO(pcloudy): Remove TF_SAVER_LENIENT_NAMES after
# https://github.com/tensorflow/tensorflow/issues/12844 is fixed.
bazel test -c opt $BUILD_OPTS -k --test_output=errors \
bazel test -c opt -k --test_output=errors \
--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 \
--test_env=TF_SAVER_LENIENT_NAMES=True \
//${PY_TEST_DIR}/tensorflow/python/...
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ passing_tests=$(bazel query "kind(cc_test, //tensorflow/cc/... + //tensorflow/co

# TODO(pcloudy): There is a bug in Bazel preventing build with GPU support without -c opt
# Re-enable this test after it is fixed.
# bazel test --config=win-cuda $BUILD_OPTS -k $slow_compiling_test --test_output=errors
bazel test -c opt --config=win-cuda $BUILD_OPTS -k $passing_tests --test_output=errors
# bazel test --config=win-cuda -k $slow_compiling_test --test_output=errors
bazel test -c opt --config=win-cuda -k $passing_tests --test_output=errors
9 changes: 2 additions & 7 deletions tensorflow/tools/ci_build/windows/gpu/pip/build_tf_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ source "tensorflow/tools/ci_build/windows/bazel/bazel_test_lib.sh" \

run_configure_for_gpu_build

clean_output_base

bazel build -c opt $BUILD_OPTS tensorflow/tools/pip_package:build_pip_package || exit $?
bazel build -c opt tensorflow/tools/pip_package:build_pip_package || exit $?

# Create a python test directory to avoid package name conflict
PY_TEST_DIR="py_test_dir"
Expand All @@ -61,11 +59,8 @@ reinstall_tensorflow_pip ${PIP_NAME}
# Define no_tensorflow_py_deps=true so that every py_test has no deps anymore,
# which will result testing system installed tensorflow
# GPU tests are very flaky when running concurrently, so set local_test_jobs=1
# TODO(pcloudy): Remove TF_SAVER_LENIENT_NAMES after
# https://github.com/tensorflow/tensorflow/issues/12844 is fixed.
bazel test -c opt $BUILD_OPTS -k --test_output=errors \
bazel test -c opt -k --test_output=errors \
--define=no_tensorflow_py_deps=true --test_lang_filters=py \
--test_tag_filters=-no_pip,-no_windows,-no_windows_gpu,-no_gpu,-no_pip_gpu,no_oss \
--build_tag_filters=-no_pip,-no_windows,-no_windows_gpu,-no_gpu,-no_pip_gpu,no_oss \
--test_env=TF_SAVER_LENIENT_NAMES=True \
--local_test_jobs=1 --build_tests_only //${PY_TEST_DIR}/tensorflow/python/...
3 changes: 1 addition & 2 deletions tensorflow/tools/ci_build/windows/libtensorflow_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ export TF_BAZEL_TARGETS="${TF_BAZEL_TARGETS} //tensorflow/tools/lib_package:clic
export TF_BAZEL_TARGETS="${TF_BAZEL_TARGETS} //tensorflow/java:libtensorflow_jni.so"
export TF_BAZEL_TARGETS="${TF_BAZEL_TARGETS} //tensorflow/tools/lib_package:jnilicenses_generate"

clean_output_base
run_configure_for_cpu_build

# build_libtensorflow_tarball in ../builds/libtensorflow.sh
# cannot be used on Windows since it relies on pkg_tar rules.
# So we do something special here
bazel build -c opt ${BUILD_OPTS} \
bazel build -c opt \
tensorflow:libtensorflow.so \
tensorflow/tools/lib_package:clicenses_generate \
tensorflow/java:libtensorflow_jni.so \
Expand Down
21 changes: 21 additions & 0 deletions tensorflow/tools/pip_package/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package(default_visibility = ["//visibility:private"])
load(
"//tensorflow:tensorflow.bzl",
"if_not_windows",
"if_windows",
"transitive_hdrs",
)
load("//third_party/mkl:build_defs.bzl", "if_mkl")
Expand Down Expand Up @@ -193,3 +194,23 @@ sh_binary(
],
}) + if_mkl(["//third_party/mkl:intel_binary_blob"]),
)

# A genrule for generating a marker file for the pip package on Windows
#
# This only works on Windows, because :simple_console_for_windows is a
# python zip file containing everything we need for building the pip package.
# However, on other platforms, due to https://github.com/bazelbuild/bazel/issues/4223,
# when C++ extensions change, this generule doesn't rebuild.
genrule(
name = "win_pip_package_marker",
srcs = if_windows([
":build_pip_package",
":simple_console_for_windows",
]),
outs = ["win_pip_package_marker_file"],
cmd = select({
"//conditions:default": "touch $@",
"//tensorflow:windows": "md5sum $(locations :build_pip_package) $(locations :simple_console_for_windows) > $@",
}),
visibility = ["//visibility:public"],
)
4 changes: 1 addition & 3 deletions tensorflow/tools/pip_package/build_pip_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function real_path() {
function cp_external() {
local src_dir=$1
local dest_dir=$2
for f in `find "$src_dir" -maxdepth 1 -mindepth 1 ! -name '*local_config_cuda*'`; do
for f in `find "$src_dir" -maxdepth 1 -mindepth 1 ! -name '*local_config_cuda*' ! -name '*org_tensorflow*'`; do
cp -R "$f" "$dest_dir"
done
}
Expand Down Expand Up @@ -92,7 +92,6 @@ function main() {
bazel-bin/tensorflow/tools/pip_package/simple_console_for_window_unzip/runfiles/org_tensorflow/tensorflow \
"${TMPDIR}"
mkdir "${TMPDIR}/external"
# Note: this makes an extra copy of org_tensorflow.
cp_external \
bazel-bin/tensorflow/tools/pip_package/simple_console_for_window_unzip/runfiles \
"${TMPDIR}/external"
Expand Down Expand Up @@ -123,7 +122,6 @@ function main() {
bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/tensorflow \
"${TMPDIR}"
mkdir "${TMPDIR}/external"
# Note: this makes an extra copy of org_tensorflow.
cp_external \
bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles \
"${TMPDIR}/external"
Expand Down
1 change: 1 addition & 0 deletions tensorflow/tools/pip_package/pip_smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"//tensorflow/python:extra_py_tests_deps",
"//tensorflow/cc/saved_model:saved_model_half_plus_two",
"//tensorflow:no_tensorflow_py_deps",
"//tensorflow/tools/pip_package:win_pip_package_marker",
"//tensorflow/python:test_ops_2",
"//tensorflow/python:tf_optimizer",
"//tensorflow/python:compare_test_proto_py",
Expand Down