From 763386db0cadb773021cfb8cc69658bfe20599ea Mon Sep 17 00:00:00 2001 From: Feiteng Date: Sat, 21 Nov 2020 13:45:38 +0800 Subject: [PATCH 01/10] [1/4] Support for macOS - update reverb/cc --- .bazelrc | 2 +- configure.py | 8 ++ docker/dev.dockerfile | 102 +++++++++++++++++++++ docker/release.dockerfile | 1 + reverb/BUILD | 9 ++ reverb/cc/platform/default/build_rules.bzl | 11 ++- reverb/cc/platform/default/repo.bzl | 18 +++- 7 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 docker/dev.dockerfile diff --git a/.bazelrc b/.bazelrc index b066fd0..8e74164 100644 --- a/.bazelrc +++ b/.bazelrc @@ -17,7 +17,7 @@ build --cxxopt="-std=c++17" build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" build --auto_output_filter=subpackages build --copt="-Wall" --copt="-Wno-sign-compare" -build --linkopt="-lrt -lm" + # We build with AVX and eigen byte alignment to match tensorflow's (and Eigen) # pip package byte alignment. See b/186669968 for more details. build --copt=-mavx --copt=-DEIGEN_MAX_ALIGN_BYTES=64 diff --git a/configure.py b/configure.py index 15ddcc9..b114523 100644 --- a/configure.py +++ b/configure.py @@ -37,6 +37,7 @@ """ import argparse import os +import platform import subprocess import sys @@ -74,6 +75,13 @@ def main(): reset_configure_bazelrc() setup_python(environ_cp, args.force_defaults) + write_to_bazelrc('\n') + if platform.system() == 'Darwin': + write_to_bazelrc('# https://github.com/googleapis/google-cloud-cpp-spanner/issues/1003') + write_to_bazelrc('build --copt=-DGRPC_BAZEL_BUILD') + else: + write_to_bazelrc('build --linkopt="-lrt -lm"') + def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var, var_default): diff --git a/docker/dev.dockerfile b/docker/dev.dockerfile new file mode 100644 index 0000000..ce62406 --- /dev/null +++ b/docker/dev.dockerfile @@ -0,0 +1,102 @@ +# Run the following commands in order: +# +# REVERB_DIR="/tmp/reverb" # (change to the cloned reverb directory, e.g. "$HOME/reverb") +# docker build --tag tensorflow:reverb - < "$REVERB_DIR/docker/dev.dockerfile" +# docker run --rm -it -v ${REVERB_DIR}:/tmp/reverb \ +# -v ${HOME}/.gitconfig:/home/${USER}/.gitconfig:ro \ +# --name reverb tensorflow:reverb bash +# +# Test that everything worked: +# +# bazel test -c opt --test_output=streamed //reverb:tf_client_test + +ARG cpu_base_image="ubuntu:18.04" +ARG base_image=$cpu_base_image +FROM $base_image + +LABEL maintainer="Reverb Team " + +# Re-declare args because the args declared before FROM can't be used in any +# instruction after a FROM. +ARG cpu_base_image="ubuntu:18.04" +ARG base_image=$cpu_base_image +ARG tensorflow_pip="tf-nightly" +ARG python_version="python3.6" + +# Pick up some TF dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + software-properties-common \ + aria2 \ + build-essential \ + curl \ + git \ + less \ + libfreetype6-dev \ + libhdf5-serial-dev \ + libpng-dev \ + libzmq3-dev \ + lsof \ + pkg-config \ + python3-distutils \ + python3.6-dev \ + python3.7-dev \ + python3.8-dev \ + python3.8-distutils \ + rename \ + rsync \ + sox \ + unzip \ + vim \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +RUN curl -O https://bootstrap.pypa.io/get-pip.py + +ARG bazel_version=2.2.0 +# This is to install bazel, for development purposes. +ENV BAZEL_VERSION ${bazel_version} +RUN mkdir /bazel && \ + cd /bazel && \ + curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -O https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ + curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -o /bazel/LICENSE.txt https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE && \ + chmod +x bazel-*.sh && \ + ./bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ + cd / && \ + rm -f /bazel/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh + +# Add support for Bazel autocomplete, see +# https://docs.bazel.build/versions/master/completion.html for instructions. +RUN cp /usr/local/lib/bazel/bin/bazel-complete.bash /etc/bash_completion.d +# TODO(b/154932078): This line should go into bashrc. +# NOTE(ebrevdo): RUN source doesn't work. Disabling the command below for now. +# RUN source /etc/bash_autcompletion.d/bazel-complete.bash + +ARG pip_dependencies=' \ + contextlib2 \ + dm-tree>=0.1.5 \ + google-api-python-client \ + h5py \ + numpy \ + oauth2client \ + pandas \ + platform \ + portpicker' + + +# So dependencies are installed for the supported Python versions +RUN for python in ${python_version}; do \ + $python get-pip.py && \ + $python -mpip uninstall -y tensorflow tensorflow-gpu tf-nightly tf-nightly-gpu && \ + $python -mpip --no-cache-dir install ${tensorflow_pip} --upgrade && \ + $python -mpip --no-cache-dir install $pip_dependencies; \ + done + +RUN rm get-pip.py + +# bazel assumes the python executable is "python". +RUN ln -s /usr/bin/python3 /usr/bin/python + +WORKDIR "/tmp/reverb" + +CMD ["/bin/bash"] diff --git a/docker/release.dockerfile b/docker/release.dockerfile index f26e193..4bf59d7 100644 --- a/docker/release.dockerfile +++ b/docker/release.dockerfile @@ -70,6 +70,7 @@ ARG pip_dependencies=' \ numpy \ oauth2client \ pandas \ + platform \ portpicker' RUN for python in ${python_version}; do \ diff --git a/reverb/BUILD b/reverb/BUILD index c373075..2d1b798 100644 --- a/reverb/BUILD +++ b/reverb/BUILD @@ -16,6 +16,15 @@ licenses(["notice"]) exports_files(["LICENSE"]) +config_setting( + name = "macos", + values = { + "apple_platform_type": "macos", + "cpu": "darwin", + }, + visibility = ["//visibility:public"], +) + reverb_pytype_strict_library( name = "reverb", srcs = ["__init__.py"], diff --git a/reverb/cc/platform/default/build_rules.bzl b/reverb/cc/platform/default/build_rules.bzl index c154ff3..8394bff 100644 --- a/reverb/cc/platform/default/build_rules.bzl +++ b/reverb/cc/platform/default/build_rules.bzl @@ -314,7 +314,6 @@ def reverb_gen_op_wrapper_py(name, out, kernel_lib, linkopts = [], **kwargs): ], linkshared = 1, linkopts = linkopts + _rpath_linkopts(module_name) + [ - "-Wl,--version-script", "$(location %s)" % version_script_file, ], **kwargs @@ -371,7 +370,14 @@ def _rpath_linkopts(name): # 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 ["-Wl,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),)] + return select({ + "//reverb:macos": [ + "-Wl,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),), + ], + "//conditions:default": [ + "-Wl,--version-script,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),), + ], + }) def reverb_pybind_extension( name, @@ -456,7 +462,6 @@ def reverb_pybind_extension( "-fvisibility=hidden", # avoid pybind symbol clashes between DSOs. ], linkopts = linkopts + _rpath_linkopts(module_name) + [ - "-Wl,--version-script", "$(location %s)" % version_script_file, ], deps = depset(deps + [ diff --git a/reverb/cc/platform/default/repo.bzl b/reverb/cc/platform/default/repo.bzl index 19ea78e..03ff399 100644 --- a/reverb/cc/platform/default/repo.bzl +++ b/reverb/cc/platform/default/repo.bzl @@ -90,6 +90,9 @@ def _find_python_solib_path(repo_ctx): .format(exec_result.stderr)) version = exec_result.stdout.splitlines()[-1] basename = "lib{}.so".format(version) + if repo_ctx.os.name.lower().find("mac") != -1: + basename = "lib{}m.a".format(version) + exec_result = repo_ctx.execute( ["{}-config".format(version), "--configdir"], quiet = True, @@ -220,17 +223,20 @@ filegroup( def _tensorflow_solib_repo_impl(repo_ctx): tf_lib_path = _find_tf_lib_path(repo_ctx) repo_ctx.symlink(tf_lib_path, "tensorflow_solib") + suffix = "2.so" + if repo_ctx.os.name.lower().find("mac") != -1: + suffix = "2.dylib" + repo_ctx.file( "BUILD", content = """ cc_library( name = "framework_lib", - srcs = ["tensorflow_solib/libtensorflow_framework.so.2"], + srcs = ["tensorflow_solib/libtensorflow_framework.{}"], deps = ["@python_includes", "@python_includes//:numpy_includes"], visibility = ["//visibility:public"], ) -""", - ) +""".format(suffix)) def _python_includes_repo_impl(repo_ctx): python_include_path = _find_python_include_path(repo_ctx) @@ -362,6 +368,12 @@ def _protoc_archive(ctx): urls = [ "https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-linux-x86_64.zip" % (version, version), ] + if ctx.os.name.lower().find("mac") != -1: + urls = [ + "https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-osx-x86_64.zip" % (version, version), + ] + sha256 = "" # TODO(Feiteng) set this in WORKSPACE + ctx.download_and_extract( url = urls, sha256 = sha256, From f42509b75f8e5d58be4bc9a2ae676b89e3f6a2bb Mon Sep 17 00:00:00 2001 From: Feiteng Date: Sat, 21 Nov 2020 19:50:45 +0800 Subject: [PATCH 02/10] [2/4] Support for macOS - Fix python code build --- configure.py | 2 +- oss_build.sh | 21 ++++++++----- reverb/cc/platform/default/build_rules.bzl | 34 +++++++++++++--------- reverb/cc/platform/default/repo.bzl | 9 +++--- reverb/pip_package/build_pip_package.sh | 8 ++++- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/configure.py b/configure.py index b114523..6d46745 100644 --- a/configure.py +++ b/configure.py @@ -75,7 +75,7 @@ def main(): reset_configure_bazelrc() setup_python(environ_cp, args.force_defaults) - write_to_bazelrc('\n') + write_to_bazelrc('') if platform.system() == 'Darwin': write_to_bazelrc('# https://github.com/googleapis/google-cloud-cpp-spanner/issues/1003') write_to_bazelrc('build --copt=-DGRPC_BAZEL_BUILD') diff --git a/oss_build.sh b/oss_build.sh index ff74872..1080e0a 100644 --- a/oss_build.sh +++ b/oss_build.sh @@ -95,20 +95,24 @@ for python_version in $PYTHON_VERSIONS; do fi if [ "$python_version" = "3.7" ]; then - export PYTHON_BIN_PATH=/usr/bin/python3.7 && export PYTHON_LIB_PATH=/usr/local/lib/python3.7/dist-packages ABI=cp37 elif [ "$python_version" = "3.8" ]; then - export PYTHON_BIN_PATH=/usr/bin/python3.8 && export PYTHON_LIB_PATH=/usr/local/lib/python3.8/dist-packages ABI=cp38 elif [ "$python_version" = "3.9" ]; then - export PYTHON_BIN_PATH=/usr/bin/python3.9 && export PYTHON_LIB_PATH=/usr/local/lib/python3.9/dist-packages ABI=cp39 elif [ "$python_version" = "3.10" ]; then - export PYTHON_BIN_PATH=/usr/bin/python3.10 && export PYTHON_LIB_PATH=/usr/local/lib/python3.10/dist-packages ABI=cp310 else echo "Error unknown --python. Only [3.7|3.8|3.9|3.10]" exit 1 + + if [ "$(uname)" = "Darwin" ]; then + bazel_config="" + version=`sw_vers | grep ProductVersion | awk '{print $2}' | sed 's/\./_/g' | cut -d"_" -f1,2` + PLATFORM="macosx_${version}_x86_64" + else + bazel_config="--config=manylinux2010" + PLATFORM="manylinux2010_x86_64" fi # Configures Bazel environment for selected Python version. @@ -121,15 +125,16 @@ for python_version in $PYTHON_VERSIONS; do # someone's system unexpectedly. We are executing the python tests after # installing the final package making this approach satisfactory. # TODO(b/157223742): Execute Python tests as well. - bazel test -c opt --copt=-mavx --config=manylinux2014 --test_output=errors //reverb/cc/... + bazel test -c opt --copt=-mavx $bazel_config --test_output=errors //reverb/cc/... EXTRA_OPT="" if [ "$DEBUG_BUILD" = "true" ]; then EXTRA_OPT="--copt=-g2" fi + # Builds Reverb and creates the wheel package. - bazel build -c opt --copt=-mavx $EXTRA_OPT --config=manylinux2014 reverb/pip_package:build_pip_package - ./bazel-bin/reverb/pip_package/build_pip_package --dst $OUTPUT_DIR $PIP_PKG_EXTRA_ARGS + bazel build -c opt --copt=-mavx $EXTRA_OPT $bazel_config reverb/pip_package:build_pip_package + ./bazel-bin/reverb/pip_package/build_pip_package --dst $OUTPUT_DIR $PIP_PKG_EXTRA_ARGS --plat "$PLATFORM" # Installs pip package. $PYTHON_BIN_PATH -mpip install ${OUTPUT_DIR}*${ABI}*.whl @@ -138,7 +143,7 @@ for python_version in $PYTHON_VERSIONS; do echo "Run Python tests..." set +e - bash run_python_tests.sh |& tee ./unittest_log.txt + bash run_python_tests.sh 2>&1| tee ./unittest_log.txt UNIT_TEST_ERROR_CODE=$? set -e if [[ $UNIT_TEST_ERROR_CODE != 0 ]]; then diff --git a/reverb/cc/platform/default/build_rules.bzl b/reverb/cc/platform/default/build_rules.bzl index 8394bff..3bbb9bb 100644 --- a/reverb/cc/platform/default/build_rules.bzl +++ b/reverb/cc/platform/default/build_rules.bzl @@ -313,9 +313,16 @@ def reverb_gen_op_wrapper_py(name, out, kernel_lib, linkopts = [], **kwargs): "-fvisibility=hidden", # avoid symbol clashes between DSOs. ], linkshared = 1, - linkopts = linkopts + _rpath_linkopts(module_name) + [ - "$(location %s)" % version_script_file, - ], + linkopts = linkopts + _rpath_linkopts(module_name) + select({ + "//reverb:macos": [ + "-Wl", + "$(location %s)" % version_script_file, + ], + "//conditions:default": [ + "-Wl,--version-script", + "$(location %s)" % version_script_file, + ], + }), **kwargs ) native.genrule( @@ -370,14 +377,7 @@ def _rpath_linkopts(name): # 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({ - "//reverb:macos": [ - "-Wl,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),), - ], - "//conditions:default": [ - "-Wl,--version-script,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),), - ], - }) + return ["-Wl,%s" % (_make_search_paths("$$ORIGIN", levels_to_root),)] def reverb_pybind_extension( name, @@ -461,9 +461,15 @@ def reverb_pybind_extension( "-fexceptions", # pybind relies on exceptions, required to compile. "-fvisibility=hidden", # avoid pybind symbol clashes between DSOs. ], - linkopts = linkopts + _rpath_linkopts(module_name) + [ - "$(location %s)" % version_script_file, - ], + linkopts = linkopts + _rpath_linkopts(module_name) + + select({"//reverb:macos": [ + "-Wl,-exported_symbols_list,$(location %s)" % exported_symbols_file, + ], + "//conditions:default": [ + "-Wl,--version-script", + "$(location %s)" % version_script_file, + ], + }), deps = depset(deps + [ exported_symbols_file, version_script_file, diff --git a/reverb/cc/platform/default/repo.bzl b/reverb/cc/platform/default/repo.bzl index 03ff399..67174d2 100644 --- a/reverb/cc/platform/default/repo.bzl +++ b/reverb/cc/platform/default/repo.bzl @@ -90,9 +90,6 @@ def _find_python_solib_path(repo_ctx): .format(exec_result.stderr)) version = exec_result.stdout.splitlines()[-1] basename = "lib{}.so".format(version) - if repo_ctx.os.name.lower().find("mac") != -1: - basename = "lib{}m.a".format(version) - exec_result = repo_ctx.execute( ["{}-config".format(version), "--configdir"], quiet = True, @@ -101,6 +98,10 @@ def _find_python_solib_path(repo_ctx): fail("Could not locate python shared library path:\n{}" .format(exec_result.stderr)) solib_dir = exec_result.stdout.splitlines()[-1] + if repo_ctx.os.name.lower().find("mac") != -1: + basename = "lib{}m.dylib".format(version) + solib_dir = "/".join(solib_dir.split("/")[:-2]) + full_path = repo_ctx.path("{}/{}".format(solib_dir, basename)) if not full_path.exists: fail("Unable to find python shared library file:\n{}/{}" @@ -223,7 +224,7 @@ filegroup( def _tensorflow_solib_repo_impl(repo_ctx): tf_lib_path = _find_tf_lib_path(repo_ctx) repo_ctx.symlink(tf_lib_path, "tensorflow_solib") - suffix = "2.so" + suffix = "so.2" if repo_ctx.os.name.lower().find("mac") != -1: suffix = "2.dylib" diff --git a/reverb/pip_package/build_pip_package.sh b/reverb/pip_package/build_pip_package.sh index f6a1fd9..200c62e 100755 --- a/reverb/pip_package/build_pip_package.sh +++ b/reverb/pip_package/build_pip_package.sh @@ -32,7 +32,7 @@ function build_wheel() { pushd ${TMPDIR} > /dev/null echo $(date) : "=== Building wheel" - "${PYTHON_BIN_PATH}" setup.py bdist_wheel ${PKG_NAME_FLAG} ${RELEASE_FLAG} ${TF_VERSION_FLAG} --plat manylinux2014_x86_64 > /dev/null + "${PYTHON_BIN_PATH}" setup.py bdist_wheel ${PKG_NAME_FLAG} ${RELEASE_FLAG} ${TF_VERSION_FLAG} --plat $PLATFORM > /dev/null DEST=${TMPDIR}/dist/ if [[ ! "$TMPDIR" -ef "$DESTDIR" ]]; then mkdir -p ${DESTDIR} @@ -80,6 +80,7 @@ function usage() { echo " --release build a release version" echo " --dst path to copy the .whl into." echo " --tf-version tensorflow version dependency passed to setup.py." + echo " --plat platform." echo "" exit 1 } @@ -91,6 +92,8 @@ function main() { # This is where the source code is copied and where the whl will be built. DST_DIR="" + PLATFORM="manylinux2010_x86_64" + while true; do if [[ "$1" == "--help" ]]; then usage @@ -103,6 +106,9 @@ function main() { elif [[ "$1" == "--tf-version" ]]; then shift TF_VERSION_FLAG="--tf-version $1" + elif [[ "$1" == "--plat" ]]; then + shift + PLATFORM=$1 fi if [[ -z "$1" ]]; then From 243cc06538fb1fbb96edc8624bfd01c52fb3ad0c Mon Sep 17 00:00:00 2001 From: Feiteng Date: Thu, 3 Dec 2020 20:33:02 +0800 Subject: [PATCH 03/10] [3/4] Support for macOS - Fix Library not loaded ImportError --- reverb/cc/platform/default/build_rules.bzl | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/reverb/cc/platform/default/build_rules.bzl b/reverb/cc/platform/default/build_rules.bzl index 3bbb9bb..1a0a3c0 100644 --- a/reverb/cc/platform/default/build_rules.bzl +++ b/reverb/cc/platform/default/build_rules.bzl @@ -297,6 +297,14 @@ def reverb_gen_op_wrapper_py(name, out, kernel_lib, linkopts = [], **kwargs): fail("Argument out must end with '.py', but saw: {}".format(out)) module_name = "lib{}_gen_op".format(name) + exported_symbols_file = "%s-exported-symbols.lds" % module_name + native.genrule( + name = module_name + "_exported_symbols", + outs = [exported_symbols_file], + cmd = "echo '*ReverbDataset*\n*ReverbClient*' >$@", + output_licenses = ["unencumbered"], + visibility = ["//visibility:private"], + ) version_script_file = "%s-version-script.lds" % module_name native.genrule( name = module_name + "_version_script", @@ -307,20 +315,25 @@ def reverb_gen_op_wrapper_py(name, out, kernel_lib, linkopts = [], **kwargs): ) native.cc_binary( name = "{}.so".format(module_name), - deps = [kernel_lib] + reverb_tf_deps() + [version_script_file], + deps = [kernel_lib] + reverb_tf_deps() + [ + exported_symbols_file, + version_script_file + ], copts = tf_copts() + [ "-fno-strict-aliasing", # allow a wider range of code [aliasing] to compile. - "-fvisibility=hidden", # avoid symbol clashes between DSOs. - ], + ]+ select({ + "//reverb:macos": [], + "//conditions:default": [ + "-fvisibility=hidden", # avoid symbol clashes between DSOs. + ], + }), linkshared = 1, linkopts = linkopts + _rpath_linkopts(module_name) + select({ "//reverb:macos": [ - "-Wl", - "$(location %s)" % version_script_file, + "-Wl,-exported_symbols_list,$(location %s)" % exported_symbols_file, ], "//conditions:default": [ - "-Wl,--version-script", - "$(location %s)" % version_script_file, + "-Wl,--version-script,$(location %s)" % version_script_file, ], }), **kwargs From d51ee1b9058a76f7f9c1591fa2b89dcc523ffbe7 Mon Sep 17 00:00:00 2001 From: Feiteng Date: Thu, 3 Dec 2020 20:43:31 +0800 Subject: [PATCH 04/10] [3/4] Support for macOS - Format build scripts --- oss_build.sh | 8 ++++---- reverb/cc/platform/default/build_rules.bzl | 12 +++++------- reverb/cc/platform/default/repo.bzl | 11 ++++++++--- reverb/pip_package/build_pip_package.sh | 4 ++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/oss_build.sh b/oss_build.sh index 1080e0a..1b3a653 100644 --- a/oss_build.sh +++ b/oss_build.sh @@ -108,7 +108,7 @@ for python_version in $PYTHON_VERSIONS; do if [ "$(uname)" = "Darwin" ]; then bazel_config="" - version=`sw_vers | grep ProductVersion | awk '{print $2}' | sed 's/\./_/g' | cut -d"_" -f1,2` + version=`sw_vers -productVersion | sed 's/\./_/g' | cut -d"_" -f1,2` PLATFORM="macosx_${version}_x86_64" else bazel_config="--config=manylinux2010" @@ -125,7 +125,7 @@ for python_version in $PYTHON_VERSIONS; do # someone's system unexpectedly. We are executing the python tests after # installing the final package making this approach satisfactory. # TODO(b/157223742): Execute Python tests as well. - bazel test -c opt --copt=-mavx $bazel_config --test_output=errors //reverb/cc/... + bazel test -c opt --copt=-mavx ${bazel_config} --test_output=errors //reverb/cc/... EXTRA_OPT="" if [ "$DEBUG_BUILD" = "true" ]; then @@ -134,7 +134,7 @@ for python_version in $PYTHON_VERSIONS; do # Builds Reverb and creates the wheel package. bazel build -c opt --copt=-mavx $EXTRA_OPT $bazel_config reverb/pip_package:build_pip_package - ./bazel-bin/reverb/pip_package/build_pip_package --dst $OUTPUT_DIR $PIP_PKG_EXTRA_ARGS --plat "$PLATFORM" + ./bazel-bin/reverb/pip_package/build_pip_package --dst $OUTPUT_DIR $PIP_PKG_EXTRA_ARGS --platform "$PLATFORM" # Installs pip package. $PYTHON_BIN_PATH -mpip install ${OUTPUT_DIR}*${ABI}*.whl @@ -143,7 +143,7 @@ for python_version in $PYTHON_VERSIONS; do echo "Run Python tests..." set +e - bash run_python_tests.sh 2>&1| tee ./unittest_log.txt + bash run_python_tests.sh 2>&1 | tee ./unittest_log.txt UNIT_TEST_ERROR_CODE=$? set -e if [[ $UNIT_TEST_ERROR_CODE != 0 ]]; then diff --git a/reverb/cc/platform/default/build_rules.bzl b/reverb/cc/platform/default/build_rules.bzl index 1a0a3c0..af2b49a 100644 --- a/reverb/cc/platform/default/build_rules.bzl +++ b/reverb/cc/platform/default/build_rules.bzl @@ -298,10 +298,12 @@ def reverb_gen_op_wrapper_py(name, out, kernel_lib, linkopts = [], **kwargs): module_name = "lib{}_gen_op".format(name) exported_symbols_file = "%s-exported-symbols.lds" % module_name + # gen_client_ops -> ReverbClient + symbol = "Reverb{}".format(name.split('_')[1].capitalize()) native.genrule( name = module_name + "_exported_symbols", outs = [exported_symbols_file], - cmd = "echo '*ReverbDataset*\n*ReverbClient*' >$@", + cmd = "echo '*%s*' >$@" % symbol, output_licenses = ["unencumbered"], visibility = ["//visibility:private"], ) @@ -321,12 +323,8 @@ def reverb_gen_op_wrapper_py(name, out, kernel_lib, linkopts = [], **kwargs): ], copts = tf_copts() + [ "-fno-strict-aliasing", # allow a wider range of code [aliasing] to compile. - ]+ select({ - "//reverb:macos": [], - "//conditions:default": [ - "-fvisibility=hidden", # avoid symbol clashes between DSOs. - ], - }), + "-fvisibility=hidden", # avoid symbol clashes between DSOs. + ], linkshared = 1, linkopts = linkopts + _rpath_linkopts(module_name) + select({ "//reverb:macos": [ diff --git a/reverb/cc/platform/default/repo.bzl b/reverb/cc/platform/default/repo.bzl index 67174d2..74f1506 100644 --- a/reverb/cc/platform/default/repo.bzl +++ b/reverb/cc/platform/default/repo.bzl @@ -2,6 +2,11 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +def is_darwin(ctx): + if ctx.os.name.lower().find("mac") != -1: + return True + return False + # Sanitize a dependency so that it works correctly from code that includes # codebase as a submodule. def clean_dep(dep): @@ -98,7 +103,7 @@ def _find_python_solib_path(repo_ctx): fail("Could not locate python shared library path:\n{}" .format(exec_result.stderr)) solib_dir = exec_result.stdout.splitlines()[-1] - if repo_ctx.os.name.lower().find("mac") != -1: + if is_darwin(repo_ctx): basename = "lib{}m.dylib".format(version) solib_dir = "/".join(solib_dir.split("/")[:-2]) @@ -225,7 +230,7 @@ def _tensorflow_solib_repo_impl(repo_ctx): tf_lib_path = _find_tf_lib_path(repo_ctx) repo_ctx.symlink(tf_lib_path, "tensorflow_solib") suffix = "so.2" - if repo_ctx.os.name.lower().find("mac") != -1: + if is_darwin(repo_ctx): suffix = "2.dylib" repo_ctx.file( @@ -369,7 +374,7 @@ def _protoc_archive(ctx): urls = [ "https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-linux-x86_64.zip" % (version, version), ] - if ctx.os.name.lower().find("mac") != -1: + if is_darwin(ctx): urls = [ "https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-osx-x86_64.zip" % (version, version), ] diff --git a/reverb/pip_package/build_pip_package.sh b/reverb/pip_package/build_pip_package.sh index 200c62e..8bf75c7 100755 --- a/reverb/pip_package/build_pip_package.sh +++ b/reverb/pip_package/build_pip_package.sh @@ -32,7 +32,7 @@ function build_wheel() { pushd ${TMPDIR} > /dev/null echo $(date) : "=== Building wheel" - "${PYTHON_BIN_PATH}" setup.py bdist_wheel ${PKG_NAME_FLAG} ${RELEASE_FLAG} ${TF_VERSION_FLAG} --plat $PLATFORM > /dev/null + "${PYTHON_BIN_PATH}" setup.py bdist_wheel ${PKG_NAME_FLAG} ${RELEASE_FLAG} ${TF_VERSION_FLAG} --plat ${PLATFORM} > /dev/null DEST=${TMPDIR}/dist/ if [[ ! "$TMPDIR" -ef "$DESTDIR" ]]; then mkdir -p ${DESTDIR} @@ -106,7 +106,7 @@ function main() { elif [[ "$1" == "--tf-version" ]]; then shift TF_VERSION_FLAG="--tf-version $1" - elif [[ "$1" == "--plat" ]]; then + elif [[ "$1" == "--platform" ]]; then shift PLATFORM=$1 fi From 4eb92a86c0a7c2ca39818bddcb10a87a1361b5cd Mon Sep 17 00:00:00 2001 From: Feiteng Date: Sat, 2 Jan 2021 18:38:05 +0800 Subject: [PATCH 05/10] [3/4] Support for macOS - Fix @loader_path/../_solib_darwin image not found --- oss_build.sh | 5 ++++- reverb/pip_package/build_pip_package.sh | 13 +++++++++++++ reverb/pip_package/setup.py | 13 +++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/oss_build.sh b/oss_build.sh index 1b3a653..da1870a 100644 --- a/oss_build.sh +++ b/oss_build.sh @@ -106,6 +106,9 @@ for python_version in $PYTHON_VERSIONS; do echo "Error unknown --python. Only [3.7|3.8|3.9|3.10]" exit 1 + export PYTHON_BIN_PATH=`which python${python_version}` + export PYTHON_LIB_PATH=`$PYTHON_BIN_PATH -c 'import site; print("\\n".join(site.getsitepackages()))'` + if [ "$(uname)" = "Darwin" ]; then bazel_config="" version=`sw_vers -productVersion | sed 's/\./_/g' | cut -d"_" -f1,2` @@ -137,7 +140,7 @@ for python_version in $PYTHON_VERSIONS; do ./bazel-bin/reverb/pip_package/build_pip_package --dst $OUTPUT_DIR $PIP_PKG_EXTRA_ARGS --platform "$PLATFORM" # Installs pip package. - $PYTHON_BIN_PATH -mpip install ${OUTPUT_DIR}*${ABI}*.whl + $PYTHON_BIN_PATH -mpip install --force-reinstall ${OUTPUT_DIR}*${ABI}*.whl if [ "$PYTHON_TESTS" = "true" ]; then echo "Run Python tests..." diff --git a/reverb/pip_package/build_pip_package.sh b/reverb/pip_package/build_pip_package.sh index 8bf75c7..c474e25 100755 --- a/reverb/pip_package/build_pip_package.sh +++ b/reverb/pip_package/build_pip_package.sh @@ -71,6 +71,19 @@ function prepare_src() { # must remain where they are for TF to find them. find "${TMPDIR}/reverb/cc" -type d -name ops -prune -o -name '*.so' \ -exec mv {} "${TMPDIR}/reverb" \; + + # Copy darwin libs over so they can be loaded at runtime + so_lib_dir=$(ls $RUNFILES | grep solib) || true + if [ -n "${so_lib_dir}" ]; then + mkdir -p "${TMPDIR}/${so_lib_dir}" + proto_so_dir=$(ls ${RUNFILES}/${so_lib_dir} | grep proto) || true + for dir in ${proto_so_dir}; do + echo "===== DIR = $dir" + cp -R ${RUNFILES}/${so_lib_dir}/${dir} "${TMPDIR}/${so_lib_dir}" + done + + cp -r $TMPDIR/${so_lib_dir} `dirname $PYTHON_LIB_PATH` + fi } function usage() { diff --git a/reverb/pip_package/setup.py b/reverb/pip_package/setup.py index b7c878d..c4d2ba0 100644 --- a/reverb/pip_package/setup.py +++ b/reverb/pip_package/setup.py @@ -111,6 +111,16 @@ def run_setup(self): long_description = f.read() version, project_name = self._get_version() + + so_lib_paths = [ + i for i in os.listdir('.') + if os.path.isdir(i) and fnmatch.fnmatch(i, '_solib_*') + ] + + matches = [] + for path in so_lib_paths: + matches.extend(['../' + x for x in find_files('*', path) if '.py' not in x]) + setup( name=project_name, version=version, @@ -125,6 +135,9 @@ def run_setup(self): packages=find_packages(), headers=list(find_files('*.proto', 'reverb')), include_package_data=True, + package_data={ + 'reverb': matches, + }, install_requires=self._get_required_packages(), extras_require={ 'tensorflow': self._get_tensorflow_packages(), From c3dff42240efd2745064cd85b49bcf38f3f3a3f0 Mon Sep 17 00:00:00 2001 From: Feiteng Date: Sat, 9 Jan 2021 13:35:59 +0800 Subject: [PATCH 06/10] [4/4] Support for macOS - Fix bazel test //reverb:*_test --- reverb/cc/platform/default/repo.bzl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/reverb/cc/platform/default/repo.bzl b/reverb/cc/platform/default/repo.bzl index 74f1506..4653038 100644 --- a/reverb/cc/platform/default/repo.bzl +++ b/reverb/cc/platform/default/repo.bzl @@ -255,12 +255,21 @@ def _python_includes_repo_impl(repo_ctx): python_solib.basename, ) + python_includes_srcs = 'srcs = ["%s"],' % python_solib.basename + if is_darwin(repo_ctx): + # Fix Fatal Python error: PyThreadState_Get: no current thread + python_includes_srcs = "" + + # Note, "@python_includes" is a misnomer since we include the + # libpythonX.Y.so in the srcs, so we can get access to python's various + # symbols at link time. repo_ctx.file( "BUILD", content = """ cc_library( name = "python_includes", hdrs = glob(["python_includes/**/*.h"]), + {} includes = ["python_includes"], visibility = ["//visibility:public"], ) @@ -270,7 +279,7 @@ cc_library( includes = ["numpy_includes"], visibility = ["//visibility:public"], ) -""".format(python_solib.basename), +""".format(python_includes_srcs), executable = False, ) From aa805cd9e694d14e1ff1828e4b3c91cd8f357d74 Mon Sep 17 00:00:00 2001 From: Feiteng Date: Sun, 10 Jan 2021 12:40:56 +0800 Subject: [PATCH 07/10] [4/4] Support for macOS - Fix python tests --- reverb/cc/platform/default/build_rules.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/reverb/cc/platform/default/build_rules.bzl b/reverb/cc/platform/default/build_rules.bzl index af2b49a..c8826b8 100644 --- a/reverb/cc/platform/default/build_rules.bzl +++ b/reverb/cc/platform/default/build_rules.bzl @@ -110,7 +110,7 @@ def reverb_cc_proto_library(name, srcs = [], deps = [], **kwargs): name = "{}_static".format(name), srcs = gen_srcs, hdrs = gen_hdrs, - deps = depset(deps + reverb_tf_deps()), + deps = depset([dep.replace(":", ":lib") + ".so" for dep in deps] + reverb_tf_deps()), alwayslink = 1, **kwargs ) @@ -298,8 +298,8 @@ def reverb_gen_op_wrapper_py(name, out, kernel_lib, linkopts = [], **kwargs): module_name = "lib{}_gen_op".format(name) exported_symbols_file = "%s-exported-symbols.lds" % module_name - # gen_client_ops -> ReverbClient - symbol = "Reverb{}".format(name.split('_')[1].capitalize()) + # gen_client_ops -> reverb_client + symbol = "reverb_{}".format(name.split('_')[1]) native.genrule( name = module_name + "_exported_symbols", outs = [exported_symbols_file], From 8991de7faa716cc5dea4ed42466ed17287c168da Mon Sep 17 00:00:00 2001 From: Feiteng Date: Sun, 28 Feb 2021 17:11:53 +0800 Subject: [PATCH 08/10] [4/4] Support for macOS - Address review comments --- configure.py | 3 +-- oss_build.sh | 5 ++-- reverb/cc/platform/default/repo.bzl | 41 ++++++++++++++++++----------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/configure.py b/configure.py index 6d46745..675e303 100644 --- a/configure.py +++ b/configure.py @@ -37,7 +37,6 @@ """ import argparse import os -import platform import subprocess import sys @@ -76,7 +75,7 @@ def main(): setup_python(environ_cp, args.force_defaults) write_to_bazelrc('') - if platform.system() == 'Darwin': + if sys.platform == 'darwin': write_to_bazelrc('# https://github.com/googleapis/google-cloud-cpp-spanner/issues/1003') write_to_bazelrc('build --copt=-DGRPC_BAZEL_BUILD') else: diff --git a/oss_build.sh b/oss_build.sh index da1870a..01f21ea 100644 --- a/oss_build.sh +++ b/oss_build.sh @@ -107,14 +107,15 @@ for python_version in $PYTHON_VERSIONS; do exit 1 export PYTHON_BIN_PATH=`which python${python_version}` - export PYTHON_LIB_PATH=`$PYTHON_BIN_PATH -c 'import site; print("\\n".join(site.getsitepackages()))'` + export PYTHON_LIB_PATH=`${PYTHON_BIN_PATH} -c 'import site; print(site.getsitepackages()[0])'` if [ "$(uname)" = "Darwin" ]; then bazel_config="" version=`sw_vers -productVersion | sed 's/\./_/g' | cut -d"_" -f1,2` - PLATFORM="macosx_${version}_x86_64" + PLATFORM="macosx_${version}_"`uname -m` else bazel_config="--config=manylinux2010" + bazel_config="" PLATFORM="manylinux2010_x86_64" fi diff --git a/reverb/cc/platform/default/repo.bzl b/reverb/cc/platform/default/repo.bzl index 4653038..e4796f0 100644 --- a/reverb/cc/platform/default/repo.bzl +++ b/reverb/cc/platform/default/repo.bzl @@ -94,7 +94,6 @@ def _find_python_solib_path(repo_ctx): fail("Could not locate python shared library path:\n{}" .format(exec_result.stderr)) version = exec_result.stdout.splitlines()[-1] - basename = "lib{}.so".format(version) exec_result = repo_ctx.execute( ["{}-config".format(version), "--configdir"], quiet = True, @@ -102,10 +101,13 @@ def _find_python_solib_path(repo_ctx): if exec_result.return_code != 0: fail("Could not locate python shared library path:\n{}" .format(exec_result.stderr)) - solib_dir = exec_result.stdout.splitlines()[-1] + if is_darwin(repo_ctx): basename = "lib{}m.dylib".format(version) - solib_dir = "/".join(solib_dir.split("/")[:-2]) + solib_dir = "/".join(exec_result.stdout.splitlines()[-1].split("/")[:-2]) + else: + basename = "lib{}.so".format(version) + solib_dir = exec_result.stdout.splitlines()[-1] full_path = repo_ctx.path("{}/{}".format(solib_dir, basename)) if not full_path.exists: @@ -229,20 +231,21 @@ filegroup( def _tensorflow_solib_repo_impl(repo_ctx): tf_lib_path = _find_tf_lib_path(repo_ctx) repo_ctx.symlink(tf_lib_path, "tensorflow_solib") - suffix = "so.2" if is_darwin(repo_ctx): suffix = "2.dylib" + else: + suffix = "so.2" repo_ctx.file( "BUILD", content = """ cc_library( name = "framework_lib", - srcs = ["tensorflow_solib/libtensorflow_framework.{}"], + srcs = ["tensorflow_solib/libtensorflow_framework.{suffix}"], deps = ["@python_includes", "@python_includes//:numpy_includes"], visibility = ["//visibility:public"], ) -""".format(suffix)) +""".format(suffix=suffix)) def _python_includes_repo_impl(repo_ctx): python_include_path = _find_python_include_path(repo_ctx) @@ -255,10 +258,11 @@ def _python_includes_repo_impl(repo_ctx): python_solib.basename, ) - python_includes_srcs = 'srcs = ["%s"],' % python_solib.basename if is_darwin(repo_ctx): # Fix Fatal Python error: PyThreadState_Get: no current thread python_includes_srcs = "" + else: + python_includes_srcs = 'srcs = ["%s"],' % python_solib.basename # Note, "@python_includes" is a misnomer since we include the # libpythonX.Y.so in the srcs, so we can get access to python's various @@ -269,7 +273,7 @@ def _python_includes_repo_impl(repo_ctx): cc_library( name = "python_includes", hdrs = glob(["python_includes/**/*.h"]), - {} + {srcs} includes = ["python_includes"], visibility = ["//visibility:public"], ) @@ -279,7 +283,7 @@ cc_library( includes = ["numpy_includes"], visibility = ["//visibility:public"], ) -""".format(python_includes_srcs), +""".format(srcs=python_includes_srcs), executable = False, ) @@ -380,15 +384,20 @@ def _protoc_archive(ctx): version = ctx.attr.version sha256 = ctx.attr.sha256 - urls = [ - "https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-linux-x86_64.zip" % (version, version), - ] + override_version = ctx.os.environ.get("REVERB_PROTOC_VERSION") + if override_version: + sha256 = "" + version = override_version + if is_darwin(ctx): - urls = [ - "https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-osx-x86_64.zip" % (version, version), - ] - sha256 = "" # TODO(Feiteng) set this in WORKSPACE + platform = "osx" + sha256 = "" + else: + platform = "linux" + urls = [ + "https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-%s-x86_64.zip" % (version, version, platform), + ] ctx.download_and_extract( url = urls, sha256 = sha256, From 6e1d4b4cd2ec6ac2100315f770f9921a966545bd Mon Sep 17 00:00:00 2001 From: Feiteng Date: Thu, 6 May 2021 22:34:39 +0800 Subject: [PATCH 09/10] [4/4] Support for macOS - Fix python solib path --- reverb/cc/platform/default/repo.bzl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/reverb/cc/platform/default/repo.bzl b/reverb/cc/platform/default/repo.bzl index e4796f0..a05eb15 100644 --- a/reverb/cc/platform/default/repo.bzl +++ b/reverb/cc/platform/default/repo.bzl @@ -111,8 +111,11 @@ def _find_python_solib_path(repo_ctx): full_path = repo_ctx.path("{}/{}".format(solib_dir, basename)) if not full_path.exists: - fail("Unable to find python shared library file:\n{}/{}" - .format(solib_dir, basename)) + basename = basename.replace('m.dylib', '.dylib') + full_path = repo_ctx.path("{}/{}".format(solib_dir, basename)) + if not full_path.exists: + fail("Unable to find python shared library file:\n{}/{}" + .format(solib_dir, basename)) return struct(dir = solib_dir, basename = basename) def _eigen_archive_repo_impl(repo_ctx): From 34be612db7c58c2e8b75462b974688f329943d37 Mon Sep 17 00:00:00 2001 From: Feiteng Date: Fri, 13 Jan 2023 01:29:38 +0800 Subject: [PATCH 10/10] [4/4] Support for macOS - update --- docker/dev.dockerfile | 102 ------------------------ docker/release.dockerfile | 1 - oss_build.sh | 11 ++- reverb/cc/platform/default/repo.bzl | 16 ++-- reverb/cc/table.cc | 6 +- reverb/pip_package/build_pip_package.sh | 7 +- run_python_tests.sh | 3 +- 7 files changed, 23 insertions(+), 123 deletions(-) delete mode 100644 docker/dev.dockerfile diff --git a/docker/dev.dockerfile b/docker/dev.dockerfile deleted file mode 100644 index ce62406..0000000 --- a/docker/dev.dockerfile +++ /dev/null @@ -1,102 +0,0 @@ -# Run the following commands in order: -# -# REVERB_DIR="/tmp/reverb" # (change to the cloned reverb directory, e.g. "$HOME/reverb") -# docker build --tag tensorflow:reverb - < "$REVERB_DIR/docker/dev.dockerfile" -# docker run --rm -it -v ${REVERB_DIR}:/tmp/reverb \ -# -v ${HOME}/.gitconfig:/home/${USER}/.gitconfig:ro \ -# --name reverb tensorflow:reverb bash -# -# Test that everything worked: -# -# bazel test -c opt --test_output=streamed //reverb:tf_client_test - -ARG cpu_base_image="ubuntu:18.04" -ARG base_image=$cpu_base_image -FROM $base_image - -LABEL maintainer="Reverb Team " - -# Re-declare args because the args declared before FROM can't be used in any -# instruction after a FROM. -ARG cpu_base_image="ubuntu:18.04" -ARG base_image=$cpu_base_image -ARG tensorflow_pip="tf-nightly" -ARG python_version="python3.6" - -# Pick up some TF dependencies -RUN apt-get update && apt-get install -y --no-install-recommends \ - software-properties-common \ - aria2 \ - build-essential \ - curl \ - git \ - less \ - libfreetype6-dev \ - libhdf5-serial-dev \ - libpng-dev \ - libzmq3-dev \ - lsof \ - pkg-config \ - python3-distutils \ - python3.6-dev \ - python3.7-dev \ - python3.8-dev \ - python3.8-distutils \ - rename \ - rsync \ - sox \ - unzip \ - vim \ - && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -RUN curl -O https://bootstrap.pypa.io/get-pip.py - -ARG bazel_version=2.2.0 -# This is to install bazel, for development purposes. -ENV BAZEL_VERSION ${bazel_version} -RUN mkdir /bazel && \ - cd /bazel && \ - curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -O https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ - curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -o /bazel/LICENSE.txt https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE && \ - chmod +x bazel-*.sh && \ - ./bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ - cd / && \ - rm -f /bazel/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh - -# Add support for Bazel autocomplete, see -# https://docs.bazel.build/versions/master/completion.html for instructions. -RUN cp /usr/local/lib/bazel/bin/bazel-complete.bash /etc/bash_completion.d -# TODO(b/154932078): This line should go into bashrc. -# NOTE(ebrevdo): RUN source doesn't work. Disabling the command below for now. -# RUN source /etc/bash_autcompletion.d/bazel-complete.bash - -ARG pip_dependencies=' \ - contextlib2 \ - dm-tree>=0.1.5 \ - google-api-python-client \ - h5py \ - numpy \ - oauth2client \ - pandas \ - platform \ - portpicker' - - -# So dependencies are installed for the supported Python versions -RUN for python in ${python_version}; do \ - $python get-pip.py && \ - $python -mpip uninstall -y tensorflow tensorflow-gpu tf-nightly tf-nightly-gpu && \ - $python -mpip --no-cache-dir install ${tensorflow_pip} --upgrade && \ - $python -mpip --no-cache-dir install $pip_dependencies; \ - done - -RUN rm get-pip.py - -# bazel assumes the python executable is "python". -RUN ln -s /usr/bin/python3 /usr/bin/python - -WORKDIR "/tmp/reverb" - -CMD ["/bin/bash"] diff --git a/docker/release.dockerfile b/docker/release.dockerfile index 4bf59d7..f26e193 100644 --- a/docker/release.dockerfile +++ b/docker/release.dockerfile @@ -70,7 +70,6 @@ ARG pip_dependencies=' \ numpy \ oauth2client \ pandas \ - platform \ portpicker' RUN for python in ${python_version}; do \ diff --git a/oss_build.sh b/oss_build.sh index 01f21ea..1554c56 100644 --- a/oss_build.sh +++ b/oss_build.sh @@ -105,18 +105,17 @@ for python_version in $PYTHON_VERSIONS; do else echo "Error unknown --python. Only [3.7|3.8|3.9|3.10]" exit 1 + fi export PYTHON_BIN_PATH=`which python${python_version}` export PYTHON_LIB_PATH=`${PYTHON_BIN_PATH} -c 'import site; print(site.getsitepackages()[0])'` if [ "$(uname)" = "Darwin" ]; then bazel_config="" - version=`sw_vers -productVersion | sed 's/\./_/g' | cut -d"_" -f1,2` - PLATFORM="macosx_${version}_"`uname -m` + PLATFORM=`${PYTHON_BIN_PATH} -c "from distutils import util; print(util.get_platform())"` else - bazel_config="--config=manylinux2010" - bazel_config="" - PLATFORM="manylinux2010_x86_64" + bazel_config="--config=manylinux2014" + PLATFORM="manylinux2014_x86_64" fi # Configures Bazel environment for selected Python version. @@ -141,7 +140,7 @@ for python_version in $PYTHON_VERSIONS; do ./bazel-bin/reverb/pip_package/build_pip_package --dst $OUTPUT_DIR $PIP_PKG_EXTRA_ARGS --platform "$PLATFORM" # Installs pip package. - $PYTHON_BIN_PATH -mpip install --force-reinstall ${OUTPUT_DIR}*${ABI}*.whl + $PYTHON_BIN_PATH -m pip install --force-reinstall ${OUTPUT_DIR}*${ABI}*.whl if [ "$PYTHON_TESTS" = "true" ]; then echo "Run Python tests..." diff --git a/reverb/cc/platform/default/repo.bzl b/reverb/cc/platform/default/repo.bzl index a05eb15..c53697d 100644 --- a/reverb/cc/platform/default/repo.bzl +++ b/reverb/cc/platform/default/repo.bzl @@ -235,20 +235,23 @@ def _tensorflow_solib_repo_impl(repo_ctx): tf_lib_path = _find_tf_lib_path(repo_ctx) repo_ctx.symlink(tf_lib_path, "tensorflow_solib") if is_darwin(repo_ctx): - suffix = "2.dylib" + tensorflow_solib = "libtensorflow_cc.2.dylib" + full_path = repo_ctx.path("tensorflow_solib/{}".format(tensorflow_solib)) + if not full_path.exists: + tensorflow_solib = "libtensorflow_framework.2.dylib" else: - suffix = "so.2" + tensorflow_solib = "libtensorflow_framework.so.2" repo_ctx.file( "BUILD", content = """ cc_library( name = "framework_lib", - srcs = ["tensorflow_solib/libtensorflow_framework.{suffix}"], + srcs = ["tensorflow_solib/{tensorflow_solib}"], deps = ["@python_includes", "@python_includes//:numpy_includes"], visibility = ["//visibility:public"], ) -""".format(suffix=suffix)) +""".format(tensorflow_solib=tensorflow_solib)) def _python_includes_repo_impl(repo_ctx): python_include_path = _find_python_include_path(repo_ctx) @@ -267,9 +270,6 @@ def _python_includes_repo_impl(repo_ctx): else: python_includes_srcs = 'srcs = ["%s"],' % python_solib.basename - # Note, "@python_includes" is a misnomer since we include the - # libpythonX.Y.so in the srcs, so we can get access to python's various - # symbols at link time. repo_ctx.file( "BUILD", content = """ @@ -394,7 +394,7 @@ def _protoc_archive(ctx): if is_darwin(ctx): platform = "osx" - sha256 = "" + sha256 = "99729771ccb2f70621ac20f241f6ab1c70271f2c6bd2ea1ddbd9c2f7ae08d316" else: platform = "linux" diff --git a/reverb/cc/table.cc b/reverb/cc/table.cc index 07b53b5..cd7460d 100644 --- a/reverb/cc/table.cc +++ b/reverb/cc/table.cc @@ -154,10 +154,12 @@ Table::Table(std::string name, std::shared_ptr sampler, num_unique_samples_(0), max_size_(max_size), max_enqueued_inserts_( - std::max(1L, std::min(max_size * kMaxEnqueuedInsertsPerc, + std::max(static_cast(1), + std::min(max_size * kMaxEnqueuedInsertsPerc, kMaxEnqueuedInserts))), max_enqueued_extension_ops_( - std::max(1L, std::min(max_size * kMaxPendingExtensionOpsPerc, + std::max(static_cast(1), + std::min(max_size * kMaxPendingExtensionOpsPerc, kMaxPendingExtensionOps))), max_times_sampled_(max_times_sampled), name_(std::move(name)), diff --git a/reverb/pip_package/build_pip_package.sh b/reverb/pip_package/build_pip_package.sh index c474e25..45bb576 100755 --- a/reverb/pip_package/build_pip_package.sh +++ b/reverb/pip_package/build_pip_package.sh @@ -20,6 +20,7 @@ function build_wheel() { DESTDIR="$2" RELEASE_FLAG="$3" TF_VERSION_FLAG="$4" + PLATFORM="$5" # Before we leave the top-level directory, make sure we know how to # call python. @@ -93,7 +94,7 @@ function usage() { echo " --release build a release version" echo " --dst path to copy the .whl into." echo " --tf-version tensorflow version dependency passed to setup.py." - echo " --plat platform." + echo " --platform platform." echo "" exit 1 } @@ -105,7 +106,7 @@ function main() { # This is where the source code is copied and where the whl will be built. DST_DIR="" - PLATFORM="manylinux2010_x86_64" + PLATFORM="manylinux2014_x86_64" while true; do if [[ "$1" == "--help" ]]; then @@ -136,7 +137,7 @@ function main() { fi prepare_src "$TMPDIR" - build_wheel "$TMPDIR" "$DST_DIR" "$RELEASE_FLAG" "$TF_VERSION_FLAG" + build_wheel "$TMPDIR" "$DST_DIR" "$RELEASE_FLAG" "$TF_VERSION_FLAG" "$PLATFORM" } main "$@" diff --git a/run_python_tests.sh b/run_python_tests.sh index 088ce6c..1ba369f 100644 --- a/run_python_tests.sh +++ b/run_python_tests.sh @@ -29,7 +29,8 @@ py_test() { echo "===========Running Python tests============" - for test_file in `find reverb/ -name '*_test.py' -print` + cd reverb/ # Fix OSX circular import error + for test_file in `find ./ -name '*_test.py' -print` do echo "####=======Testing ${test_file}=======####" ${PYTHON_BIN_PATH} "${test_file}"