-
Notifications
You must be signed in to change notification settings - Fork 332
Add IoU3D as a custom c++ op (CPU) #890
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
Changes from all commits
6bcac82
87bcb8e
2c87da0
3112a03
3b92be3
b26f9d7
99b3b92
da958cf
734f74d
a25796d
2143176
3b10e4a
3b707b1
6085f7a
4d62a16
b91ba90
72a4f11
0157c4e
9d74837
2b1fa02
6468eb7
8ac5bfe
46f8200
081fa29
da49210
3b9aa15
146a959
870e795
982d3ba
eb585bc
c4a7fa6
f7f6b73
b0b4263
131872a
2b138d9
8a54df4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| sh_binary( | ||
| name = "build_pip_pkg", | ||
| srcs = ["build_deps/build_pip_pkg.sh"], | ||
| data = [ | ||
| "LICENSE", | ||
| "MANIFEST.in", | ||
| "README.md", | ||
| "setup.py", | ||
| "//keras_cv", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| recursive-include keras_cv/custom_ops *.so |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| load("//build_deps/tf_dependency:tf_configure.bzl", "tf_configure") | ||
|
|
||
| tf_configure(name = "local_config_tf") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright 2022 The KerasCV 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. | ||
| # ============================================================================== | ||
|
|
||
| # Builds a wheel of KerasCV for Pip. Requires Bazel. | ||
| # Adapted from https://github.com/tensorflow/addons/blob/master/build_deps/build_pip_pkg.sh | ||
|
|
||
| set -e | ||
| set -x | ||
|
|
||
| PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" | ||
| function is_windows() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some high level question on this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose that these things are ported from Addons: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pain is to support those if TF drops pre-built wheels for them |
||
| if [[ "${PLATFORM}" =~ (cygwin|mingw32|mingw64|msys)_nt* ]]; then | ||
| true | ||
| else | ||
| false | ||
| fi | ||
| } | ||
|
|
||
| if is_windows; then | ||
| PIP_FILE_PREFIX="bazel-bin/build_pip_pkg.exe.runfiles/__main__/" | ||
| else | ||
| PIP_FILE_PREFIX="bazel-bin/build_pip_pkg.runfiles/__main__/" | ||
| fi | ||
|
|
||
| function main() { | ||
| while [[ ! -z "${1}" ]]; do | ||
| if [[ ${1} == "make" ]]; then | ||
| echo "Using Makefile to build pip package." | ||
| PIP_FILE_PREFIX="" | ||
| else | ||
| DEST=${1} | ||
| fi | ||
| shift | ||
| done | ||
|
|
||
| if [[ -z ${DEST} ]]; then | ||
| echo "No destination dir provided" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Create the directory, then do dirname on a non-existent file inside it to | ||
| # give us an absolute paths with tilde characters resolved to the destination | ||
| # directory. | ||
| mkdir -p ${DEST} | ||
| if [[ ${PLATFORM} == "darwin" ]]; then | ||
| DEST=$(pwd -P)/${DEST} | ||
| else | ||
| DEST=$(readlink -f "${DEST}") | ||
| fi | ||
| echo "=== destination directory: ${DEST}" | ||
|
|
||
| TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXX) | ||
|
|
||
| echo $(date) : "=== Using tmpdir: ${TMPDIR}" | ||
|
|
||
| echo "=== Copy KerasCV Custom op files" | ||
|
|
||
| cp ${PIP_FILE_PREFIX}setup.py "${TMPDIR}" | ||
| cp ${PIP_FILE_PREFIX}MANIFEST.in "${TMPDIR}" | ||
| cp ${PIP_FILE_PREFIX}README.md "${TMPDIR}" | ||
| cp ${PIP_FILE_PREFIX}LICENSE "${TMPDIR}" | ||
| rsync -avm -L --exclude='*_test.py' ${PIP_FILE_PREFIX}keras_cv "${TMPDIR}" | ||
|
|
||
| pushd ${TMPDIR} | ||
| echo $(date) : "=== Building wheel" | ||
|
|
||
| python3 setup.py bdist_wheel > /dev/null | ||
|
|
||
| cp dist/*.whl "${DEST}" | ||
| popd | ||
| rm -rf ${TMPDIR} | ||
| echo $(date) : "=== Output wheel file is in: ${DEST}" | ||
| } | ||
|
|
||
| main "$@" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| # Copyright 2022 The KerasCV 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. | ||
| # ============================================================================== | ||
| # Usage: python configure.py | ||
| """Configures local environment to prepare for building KerasCV from source.""" | ||
|
|
||
|
|
||
| import logging | ||
| import os | ||
| import pathlib | ||
| import platform | ||
|
|
||
| import tensorflow as tf | ||
| from packaging.version import Version | ||
|
|
||
| _TFA_BAZELRC = ".bazelrc" | ||
|
|
||
|
|
||
| # Writes variables to bazelrc file | ||
| def write(line): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question with build_pip_pkg.sh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a little doc blurb at the top -- is there anything else specifically you're looking for here? |
||
| with open(_TFA_BAZELRC, "a") as f: | ||
| f.write(line + "\n") | ||
|
|
||
|
|
||
| def write_action_env(var_name, var): | ||
| write('build --action_env {}="{}"'.format(var_name, var)) | ||
|
|
||
|
|
||
| def is_macos(): | ||
| return platform.system() == "Darwin" | ||
|
|
||
|
|
||
| def is_windows(): | ||
| return platform.system() == "Windows" | ||
|
|
||
|
|
||
| def is_linux(): | ||
| return platform.system() == "Linux" | ||
|
|
||
|
|
||
| def is_raspi_arm(): | ||
| return os.uname()[4] == "armv7l" or os.uname()[4] == "aarch64" | ||
|
|
||
|
|
||
| def is_linux_ppc64le(): | ||
| return is_linux() and platform.machine() == "ppc64le" | ||
|
|
||
|
|
||
| def is_linux_x86_64(): | ||
| return is_linux() and platform.machine() == "x86_64" | ||
|
|
||
|
|
||
| def is_linux_arm(): | ||
| return is_linux() and platform.machine() == "arm" | ||
|
|
||
|
|
||
| def is_linux_aarch64(): | ||
| return is_linux() and platform.machine() == "aarch64" | ||
|
|
||
|
|
||
| def is_linux_s390x(): | ||
| return is_linux() and platform.machine() == "s390x" | ||
|
|
||
|
|
||
| def get_tf_header_dir(): | ||
| import tensorflow as tf | ||
|
|
||
| tf_header_dir = tf.sysconfig.get_compile_flags()[0][2:] | ||
| if is_windows(): | ||
| tf_header_dir = tf_header_dir.replace("\\", "/") | ||
| return tf_header_dir | ||
|
|
||
|
|
||
| def get_cpp_version(): | ||
| cpp_version = "c++14" | ||
| if Version(tf.__version__) >= Version("2.10"): | ||
| cpp_version = "c++17" | ||
| return cpp_version | ||
|
|
||
|
|
||
| def get_tf_shared_lib_dir(): | ||
| import tensorflow as tf | ||
|
|
||
| # OS Specific parsing | ||
| if is_windows(): | ||
| tf_shared_lib_dir = tf.sysconfig.get_compile_flags()[0][2:-7] + "python" | ||
| return tf_shared_lib_dir.replace("\\", "/") | ||
| elif is_raspi_arm(): | ||
| return tf.sysconfig.get_compile_flags()[0][2:-7] + "python" | ||
| else: | ||
| return tf.sysconfig.get_link_flags()[0][2:] | ||
|
|
||
|
|
||
| # Converts the linkflag namespec to the full shared library name | ||
| def get_shared_lib_name(): | ||
| import tensorflow as tf | ||
|
|
||
| namespec = tf.sysconfig.get_link_flags() | ||
| if is_macos(): | ||
| # MacOS | ||
| return "lib" + namespec[1][2:] + ".dylib" | ||
| elif is_windows(): | ||
| # Windows | ||
| return "_pywrap_tensorflow_internal.lib" | ||
| elif is_raspi_arm(): | ||
| # The below command for linux would return an empty list | ||
| return "_pywrap_tensorflow_internal.so" | ||
| else: | ||
| # Linux | ||
| return namespec[1][3:] | ||
|
|
||
|
|
||
| def create_build_configuration(): | ||
| print() | ||
| print("Configuring KerasCV to be built from source...") | ||
|
|
||
| if os.path.isfile(_TFA_BAZELRC): | ||
| os.remove(_TFA_BAZELRC) | ||
|
|
||
| logging.disable(logging.WARNING) | ||
|
|
||
| write_action_env("TF_HEADER_DIR", get_tf_header_dir()) | ||
| write_action_env("TF_SHARED_LIBRARY_DIR", get_tf_shared_lib_dir()) | ||
| write_action_env("TF_SHARED_LIBRARY_NAME", get_shared_lib_name()) | ||
| write_action_env("TF_CXX11_ABI_FLAG", tf.sysconfig.CXX11_ABI_FLAG) | ||
|
|
||
| # This should be replaced with a call to tf.sysconfig if it's added | ||
| write_action_env("TF_CPLUSPLUS_VER", get_cpp_version()) | ||
|
|
||
| write("build --spawn_strategy=standalone") | ||
| write("build --strategy=Genrule=standalone") | ||
| write("build --experimental_repo_remote_exec") | ||
| write("build -c opt") | ||
| write( | ||
| "build --cxxopt=" | ||
| + '"-D_GLIBCXX_USE_CXX11_ABI="' | ||
| + str(tf.sysconfig.CXX11_ABI_FLAG) | ||
| ) | ||
|
|
||
| if is_windows(): | ||
| write("build --config=windows") | ||
| write("build:windows --enable_runfiles") | ||
| write("build:windows --copt=/experimental:preprocessor") | ||
| write("build:windows --host_copt=/experimental:preprocessor") | ||
| write("build:windows --copt=/arch=AVX") | ||
| write("build:windows --cxxopt=/std:" + get_cpp_version()) | ||
| write("build:windows --host_cxxopt=/std:" + get_cpp_version()) | ||
|
|
||
| if is_macos() or is_linux(): | ||
| if not is_linux_ppc64le() and not is_linux_arm() and not is_linux_aarch64(): | ||
| write("build --copt=-mavx") | ||
| write("build --cxxopt=-std=" + get_cpp_version()) | ||
| write("build --host_cxxopt=-std=" + get_cpp_version()) | ||
|
|
||
| print("> Building only CPU ops") | ||
|
|
||
| print() | ||
| print("Build configurations successfully written to", _TFA_BAZELRC, ":\n") | ||
| print(pathlib.Path(_TFA_BAZELRC).read_text()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| create_build_configuration() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| cc_library( | ||
| name = "tf_header_lib", | ||
| hdrs = [":tf_header_include"], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the header file inclusion and libtensorflow_framework inclusion seems correct to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I follow -- do you mean comments specifying that this is enabling linking to the installed TF version, or something else? |
||
| includes = ["include"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
|
|
||
| cc_library( | ||
| name = "libtensorflow_framework", | ||
| srcs = ["%{TF_SHARED_LIBRARY_NAME}"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| %{TF_HEADER_GENRULE} | ||
| %{TF_SHARED_LIBRARY_GENRULE} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Addons Build Definitions inherited from TensorFlow Core | ||
|
|
||
| D_GLIBCXX_USE_CXX11_ABI = "%{tf_cx11_abi}" | ||
| CPLUSPLUS_VERSION = "%{tf_cplusplus_ver}" |
Uh oh!
There was an error while loading. Please reload this page.