google-ai-edge / LiteRT

LiteRT is the new name for TensorFlow Lite (TFLite). While the name is new, it's still the same trusted, high-performance runtime for on-device AI, now with an expanded vision.
https://ai.google.dev/edge/litert
Apache License 2.0
169 stars 13 forks source link

Building TFLite fails on nnapi_delegate requiring C++20 extensions #70

Open gaikwadrahul8 opened 4 days ago

gaikwadrahul8 commented 4 days ago

Issue type

Build/Install

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

2.16.1

Custom code

No

OS platform and distribution

Docker

Mobile device

No response

Python version

3.11

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

Hi,

I'm following the steps to build TF Lite using docker (https://www.tensorflow.org/lite/android/lite_build#set_up_build_environment_using_docker) with TF release 2.16.1 (also tried 2.15). No modifications to the sources, Dockerfile or commands, only change is limiting the target architectures to arm64_v8a

The step of building aar for a given model fails by throwing C++20 extensions needed by the nnapi delegate. It seems that the rest of tooling is using gnu++17?

Standalone code to reproduce the issue

docker build . -t tflite-builder -f tflite-android.Dockerfile
docker run -it -v $PWD:/host_dir tflite-builder bash

sdkmanager \
  "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
  "platform-tools" \
  "platforms;android-${ANDROID_API_LEVEL}"

./configure

bazel build -c opt --cxxopt=--std=c++17 --config=android_arm64 \
  --fat_apk_cpu=arm64-v8a \
  --define=android_dexmerger_tool=d8_dexmerger \
  --define=android_incremental_dexing_tool=d8_dexbuilder \
  //tensorflow/lite/java:tensorflow-lite

bash tensorflow/lite/tools/build_aar.sh \
  --input_models=model.tflite \
  --target_archs=arm64-v8a

Relevant log output

ERROR: /host_dir/tensorflow-2.16.1/tensorflow/lite/delegates/nnapi/BUILD:14:11: Compiling tensorflow/lite/delegates/nnapi/nnapi_delegate.cc failed: (Exit 1): clang failed: error executing command (from target //tensorflow/lite/delegates/nnapi:nnapi_delegate_no_nnapi_implementation) external/androidndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -no-canonical-prefixes '--target=aarch64-linux-android30' -fdiagnostics-color -Wa,--noexecstack -fno-exceptions '-std=gnu++17' ... (remaining 158 arguments skipped)
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:522:7: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
      .type = nn_type,
      ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1529:45: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
    ANeuralNetworksOperandType operand_type{.type = nn_type};
                                            ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1682:45: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
    ANeuralNetworksOperandType operand_type{.type = nn_type};
                                            ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1701:45: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
    ANeuralNetworksOperandType operand_type{.type = nn_type,
                                            ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1743:9: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
        .type = nn_type,
        ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:1844:17: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
                .channelDim = static_cast<uint32_t>(
                ^
tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:6915:7: error: designated initializers are a C++20 extension [-Werror,-Wc++20-designator]
      .init = [](TfLiteContext* context, const char* buffer,
      ^
7 errors generated.
Target //tmp:tensorflow-lite failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 11.395s, Critical Path: 8.54s
INFO: 62 processes: 21 internal, 41 local.
FAILED: Build did NOT complete successfully
gaikwadrahul8 commented 2 days ago

This issue originally reported by @kubaraczkowski has been moved to this dedicated repository for LiteRT to enhance issue tracking and prioritization. To ensure continuity, we have created this new issue on your behalf.

We appreciate your understanding and look forward to your continued involvement.