tensorflow / tflite-support

TFLite Support is a toolkit that helps users to develop ML and deploy TFLite models onto mobile / ioT devices.
Apache License 2.0
371 stars 125 forks source link

Cannot build gpu_delegate_plugin_android.aar #984

Open H4dr1en opened 1 month ago

H4dr1en commented 1 month ago

On v0.4.4, I cannot reproduce the build of gpu_delegate_plugin_android.aar. I want to rebuild the library locally with the support for arm64 page size 16kb, added in this TF commit (betwen 2.16.1 and 2.17)

I could not find instructions to build this library, are there any?

I tried to guess how to build it: I followed the instructions here to setup the docker container to compile, then I updated the tensorflow commit to point to 2.16.1, and finally I ran bazel build -c opt --config android_arm64 //tensorflow_lite_support/acceleration/configuration:gpu_delegate_plugin_android.aar in this dev env

I tried with both bazel 5.1.1 and bazel 6.5 without success, the logs are below.

I don't think that the errors matter too much because I think that my approach might be wrong - How can I build this app? What is the proper build environment? Tensorflow-lite as a dockerfile to create the build env, could we have one for tensorflow-lite-support?

TF 2.16.1, BAZEL 6.5

bazel build -c opt --config android_arm64 //tensorflow_lite_support/acceleration/configuration:gpu_delegate_plugin_android.aar
Starting local Bazel server and connecting to it...
WARNING: Option 'java_toolchain' is deprecated
WARNING: Option 'host_java_toolchain' is deprecated
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=168
INFO: Reading rc options for 'build' from /host_dir/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /etc/bazel.bazelrc:
  'build' options: --action_env=DOCKER_CACHEBUSTER=1723940018419409631 --host_action_env=DOCKER_HOST_CACHEBUSTER=1723940018483040100
INFO: Reading rc options for 'build' from /host_dir/.bazelrc:
  'build' options: --java_toolchain=//third_party/toolchains/java:tf_java_toolchain --host_java_toolchain=//third_party/toolchains/java:tf_java_toolchain --action_env ANDROID_NDK_HOME --action_env ANDROID_NDK_API_LEVEL --action_env ANDROID_BUILD_TOOLS_VERSION --action_env ANDROID_SDK_API_LEVEL --action_env ANDROID_SDK_HOME --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=local -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --enable_platform_specific_config --config=short_logs --config=v2
INFO: Found applicable config definition build:short_logs in file /host_dir/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /host_dir/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:android_arm64 in file /host_dir/.bazelrc: --config=android --cpu=arm64-v8a --fat_apk_cpu=arm64-v8a
INFO: Found applicable config definition build:android in file /host_dir/.bazelrc: --copt=-w --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --noenable_platform_specific_config
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/tensorflow/tools/toolchains/python/python_repo.bzl:32:14: 
TF_PYTHON_VERSION environment variable was not set correctly; using Python 3.11.

To set Python version, run:
export TF_PYTHON_VERSION=3.11
DEBUG: Rule 'robolectric' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "97f169d39f19412bdd07fd6c274dcda0a7c8f623f7f00aa5a3b94994fc6f0ec4"
DEBUG: Repository robolectric instantiated at:
  /host_dir/WORKSPACE:55:26: in <toplevel>
  /host_dir/workspace8.bzl:78:17: in tflite_support_workspace8
Repository rule http_archive defined at:
  /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/bazel_tools/tools/build_defs/repo/http.bzl:353:31: in <toplevel>
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_google_absl' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'flatbuffers' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'icu' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_googlesource_code_re2' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'six_archive' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'absl_py' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_google_protobuf' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_google_googletest' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_github_gflags_gflags' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'zlib' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'fft2d' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'snappy' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'build_bazel_rules_apple' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'build_bazel_rules_swift' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'build_bazel_apple_support' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'pybind11' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'pybind11_protobuf' because it already exists.
ERROR: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/private/common/py_executable.bzl:804:12: name 'RunEnvironmentInfo' is not defined
ERROR: /host_dir/tensorflow_lite_support/acceleration/configuration/BUILD:124:16: While resolving toolchains for target //tensorflow_lite_support/acceleration/configuration:gpu_delegate_plugin_android: invalid registered toolchain '@local_config_python//:py_toolchain': error loading package '@local_config_python//': at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/python/defs.bzl:9:5: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/entry_points/py_console_script_binary.bzl:77:6: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/private/py_console_script_binary.bzl:19:6: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/py_binary.bzl:19:6: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/private/common/py_binary_macro_bazel.bzl:17:6: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/private/common/py_binary_rule_bazel.bzl:19:5: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/private/common/py_executable_bazel.bzl:30:5: compilation of module 'python/private/common/py_executable.bzl' failed
ERROR: Analysis of target '//tensorflow_lite_support/acceleration/configuration:gpu_delegate_plugin_android.aar' failed; build aborted: 
INFO: Elapsed time: 28.770s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (40 packages loaded, 9 targets configured)
    currently loading: @local_execution_config_python// ... (2 packages)
    Fetching @local_jdk; fetching
    Fetching @go_sdk; fetching

TF 2.16.1, BAZEL 5.1.1

bazel build //tensorflow_lite_support/acceleration/configuration:gpu_delegate_plugin_android.aar
WARNING: Option 'java_toolchain' is deprecated
WARNING: Option 'host_java_toolchain' is deprecated
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=168
INFO: Reading rc options for 'build' from /host_dir/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /etc/bazel.bazelrc:
  'build' options: --action_env=DOCKER_CACHEBUSTER=1723940018419409631 --host_action_env=DOCKER_HOST_CACHEBUSTER=1723940018483040100
INFO: Reading rc options for 'build' from /host_dir/.bazelrc:
  'build' options: --java_toolchain=//third_party/toolchains/java:tf_java_toolchain --host_java_toolchain=//third_party/toolchains/java:tf_java_toolchain --action_env ANDROID_NDK_HOME --action_env ANDROID_NDK_API_LEVEL --action_env ANDROID_BUILD_TOOLS_VERSION --action_env ANDROID_SDK_API_LEVEL --action_env ANDROID_SDK_HOME --define framework_shared_object=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=local -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --enable_platform_specific_config --config=short_logs --config=v2
INFO: Found applicable config definition build:short_logs in file /host_dir/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /host_dir/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:linux in file /host_dir/.bazelrc: --copt=-w --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/tensorflow/tools/toolchains/python/python_repo.bzl:32:14: 
TF_PYTHON_VERSION environment variable was not set correctly; using Python 3.11.

To set Python version, run:
export TF_PYTHON_VERSION=3.11
DEBUG: Rule 'robolectric' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "97f169d39f19412bdd07fd6c274dcda0a7c8f623f7f00aa5a3b94994fc6f0ec4"
DEBUG: Repository robolectric instantiated at:
  /host_dir/WORKSPACE:55:26: in <toplevel>
  /host_dir/workspace8.bzl:78:17: in tflite_support_workspace8
Repository rule http_archive defined at:
  /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/bazel_tools/tools/build_defs/repo/http.bzl:353:31: in <toplevel>
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_google_absl' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'flatbuffers' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'icu' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_googlesource_code_re2' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'six_archive' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'absl_py' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_google_protobuf' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_google_googletest' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'com_github_gflags_gflags' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'zlib' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'fft2d' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'snappy' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'build_bazel_rules_apple' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'build_bazel_rules_swift' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'build_bazel_apple_support' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'pybind11' because it already exists.
DEBUG: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/org_tensorflow/third_party/repo.bzl:132:14: 
Warning: skipping import of repository 'pybind11_protobuf' because it already exists.
INFO: Build options --cpu, --crosstool_top, and --fat_apk_cpu have changed, discarding analysis cache.
ERROR: /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/private/common/py_executable.bzl:804:12: name 'RunEnvironmentInfo' is not defined
ERROR: /host_dir/tensorflow_lite_support/acceleration/configuration/BUILD:124:16: While resolving toolchains for target //tensorflow_lite_support/acceleration/configuration:gpu_delegate_plugin_android: invalid registered toolchain '@local_execution_config_python//:py_toolchain': error loading package '@local_execution_config_python//': at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/python/defs.bzl:4:5: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/config_settings/transition.bzl:21:6: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/py_test.bzl:19:6: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/private/common/py_test_macro_bazel.bzl:17:6: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/private/common/py_test_rule_bazel.bzl:20:5: at /root/.cache/bazel/_bazel_root/faa585346465e7978a465c0d1bdb5e9e/external/rules_python/python/private/common/py_executable_bazel.bzl:30:5: compilation of module 'python/private/common/py_executable.bzl' failed
ERROR: Analysis of target '//tensorflow_lite_support/acceleration/configuration:gpu_delegate_plugin_android.aar' failed; build aborted: 
INFO: Elapsed time: 0.233s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 9 targets configured)
    currently loading: @local_config_python// ... (3 packages)
    Fetching @go_sdk; fetching
    Fetching @local_jdk; fetching