tensorflow: Fail to build TFLite shared library with GPU delegates

Issue type

Build/Install

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

2.16.1

Custom code

No

OS platform and distribution

MacOS

Mobile device

Android

Python version

No response

Bazel version

No response

GCC/compiler version

Clang 17.0.2

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

Building TFLite with CMake following this guide, with the option to build shared lib and GPU delegates fails.

Standalone code to reproduce the issue

Follow Step 1-3 in the guide
`cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI=arm64-v8a -DTFLITE_ENABLE_GPU=ON -DBUILD_SHARED_LIBS=ON  ../tensorflow/lite`
`cmake --build . -j`

Relevant log output

1 warning generated.
[ 98%] Linking CXX shared library libabsl_flags_usage_internal.so
1 warning generated.
[ 98%] Built target absl_flags_usage_internal
[ 98%] Building CXX object _deps/abseil-cpp-build/absl/flags/CMakeFiles/absl_flags_usage.dir/usage.cc.o
1 warning generated.
1 warning generated.
1 warning generated.
[ 98%] Linking CXX shared library libabsl_flags_usage.so
1 warning generated.
[ 98%] Built target absl_flags_usage
[ 98%] Building CXX object _deps/abseil-cpp-build/absl/flags/CMakeFiles/absl_flags_parse.dir/parse.cc.o
1 warning generated.
1 warning generated.
1 warning generated.
1 warning generated.
[ 98%] Linking CXX shared library libabsl_flags_parse.so
[ 98%] Built target absl_flags_parse
1 warning generated.
[100%] Linking CXX shared library libtensorflow-lite.so
ld.lld: error: undefined symbol: tflite::gpu::OptionalAndroidHardwareBuffer::OptionalAndroidHardwareBuffer()
>>> referenced by android_hardware_buffer.h:69 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/android_hardware_buffer.h:69)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(TfLiteGpuDelegateV2CreateAsync)
>>> referenced by android_hardware_buffer.h:69 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/android_hardware_buffer.h:69)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::RegisterBuffer(TfLiteOpaqueContext*, TfLiteIoType, TfLiteBackendBuffer const*, TfLiteAttributeMap const*, int))
>>> referenced by android_hardware_buffer.h:69 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/android_hardware_buffer.h:69)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::SetBufferAttributes(TfLiteBackendBuffer const*, TfLiteAttributeMap const*))
>>> referenced 7 more times

ld.lld: error: undefined symbol: tflite::delegates::BackendAsyncKernelInterface::BackendAsyncKernelInterface()
>>> referenced by delegate.cc:772 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:772)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::CreateAsyncRegistration()::$_0::__invoke(TfLiteContext*, char const*, unsigned long))
>>> did you mean: tflite::delegates::BackendAsyncKernelInterface::~BackendAsyncKernelInterface()
>>> defined in: CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o

ld.lld: error: undefined symbol: tflite::delegates::utils::ReadBufferAttrs(TfLiteAttributeMap const*)
>>> referenced by delegate.cc:1034 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1034)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::ReconcileRestrictions(TfLiteOpaqueContext const*, TfLiteOpaqueNode const*, int, TfLiteAttributeMap const*, TfLiteAttributeMap*, TfLiteAttributeMap*) const)
>>> referenced by delegate.cc:892 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:892)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::CheckAttributes(TfLiteAttributeMap const*, tflite::delegates::utils::BufferAttributes&))

ld.lld: error: undefined symbol: tflite::delegates::utils::WriteBufferAttrs(tflite::delegates::utils::BufferAttributes const&, TfLiteAttributeMap*)
>>> referenced by delegate.cc:1036 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1036)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::ReconcileRestrictions(TfLiteOpaqueContext const*, TfLiteOpaqueNode const*, int, TfLiteAttributeMap const*, TfLiteAttributeMap*, TfLiteAttributeMap*) const)
>>> referenced by delegate.cc:1036 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1036)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::ReconcileRestrictions(TfLiteOpaqueContext const*, TfLiteOpaqueNode const*, int, TfLiteAttributeMap const*, TfLiteAttributeMap*, TfLiteAttributeMap*) const)
>>> referenced by delegate.cc:1036 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1036)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::ReconcileRestrictions(TfLiteOpaqueContext const*, TfLiteOpaqueNode const*, int, TfLiteAttributeMap const*, TfLiteAttributeMap*, TfLiteAttributeMap*) const)
>>> referenced 3 more times

ld.lld: error: undefined symbol: tflite::delegates::utils::ReadSyncAttrs(TfLiteAttributeMap const*)
>>> referenced by delegate.cc:1059 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1059)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::ReconcileRestrictions(TfLiteOpaqueContext const*, TfLiteOpaqueNode const*, int, TfLiteAttributeMap const*, TfLiteAttributeMap*, TfLiteAttributeMap*) const)
>>> referenced by delegate.cc:1092 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1092)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::SetAttributes(TfLiteOpaqueContext*, TfLiteOpaqueNode*, int, TfLiteAttributeMap const*))

ld.lld: error: undefined symbol: tflite::delegates::utils::WriteSyncAttrs(tflite::delegates::utils::SyncAttributes const&, TfLiteAttributeMap*)
>>> referenced by delegate.cc:1061 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1061)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::ReconcileRestrictions(TfLiteOpaqueContext const*, TfLiteOpaqueNode const*, int, TfLiteAttributeMap const*, TfLiteAttributeMap*, TfLiteAttributeMap*) const)
>>> referenced by delegate.cc:1061 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1061)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::ReconcileRestrictions(TfLiteOpaqueContext const*, TfLiteOpaqueNode const*, int, TfLiteAttributeMap const*, TfLiteAttributeMap*, TfLiteAttributeMap*) const)
>>> referenced by delegate.cc:1063 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1063)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::ReconcileRestrictions(TfLiteOpaqueContext const*, TfLiteOpaqueNode const*, int, TfLiteAttributeMap const*, TfLiteAttributeMap*, TfLiteAttributeMap*) const)

ld.lld: error: undefined symbol: tflite::gpu::gl::WaitFdGpu(int)
>>> referenced by delegate.cc:1350 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1350)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))

ld.lld: error: undefined symbol: tflite::delegates::utils::WaitForAllFds(absl::lts_20230802::Span<int const>)
>>> referenced by delegate.cc:1353 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1353)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))

ld.lld: error: undefined symbol: tflite::gpu::gl::EglEnvironment::NewEglEnvironment(std::__ndk1::unique_ptr<tflite::gpu::gl::EglEnvironment, std::__ndk1::default_delete<tflite::gpu::gl::EglEnvironment>>*)
>>> referenced by delegate.cc:1358 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1358)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))

ld.lld: error: undefined symbol: tflite::delegates::utils::ConvertToTfLiteStatus(absl::lts_20230802::Status)
>>> referenced by delegate.cc:1358 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1358)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
>>> referenced by delegate.cc:1369 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1369)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
>>> referenced by delegate.cc:1370 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1370)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
>>> referenced 3 more times

ld.lld: error: undefined symbol: tflite::gpu::gl::EglEnvironment::~EglEnvironment()
>>> referenced by unique_ptr.h:65 (/Users/dhe/Library/Android/sdk/ndk/26.2.11394342/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__memory/unique_ptr.h:65)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
>>> referenced by unique_ptr.h:65 (/Users/dhe/Library/Android/sdk/ndk/26.2.11394342/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__memory/unique_ptr.h:65)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))

ld.lld: error: undefined symbol: tflite::gpu::AsyncBuffer::GetOpenGlBuffer(unsigned int&)
>>> referenced by delegate.cc:1369 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1369)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
>>> referenced by delegate.cc:1382 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1382)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))

ld.lld: error: undefined symbol: tflite::gpu::gl::CreateFdGpu()
>>> referenced by delegate.cc:1394 (/Users/dhe/Snapchat/Dev/tensorflow/tensorflow/lite/delegates/gpu/delegate.cc:1394)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libtensorflow-lite.so] Error 1
make[1]: *** [CMakeFiles/tensorflow-lite.dir/all] Error 2
make: *** [all] Error 2

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15

Most upvoted comments

Looks like some sources got lost in CMake build. Below is a minimal patch file with which I’ve managed to get this to work:


diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
index a61f537365a..7817c545d1f 100644
--- a/tensorflow/lite/CMakeLists.txt
+++ b/tensorflow/lite/CMakeLists.txt
@@ -286,6 +286,8 @@ populate_tflite_source_vars("core/kernels" TFLITE_CORE_KERNELS_SRCS)
 populate_tflite_source_vars("core/tools" TFLITE_CORE_TOOLS_SRCS)
 populate_tflite_source_vars("c" TFLITE_C_SRCS)
 populate_tflite_source_vars("delegates" TFLITE_DELEGATES_SRCS)
+populate_tflite_source_vars("delegates/utils" TFLITE_DELEGATES_UTILS_SRCS)
+populate_tflite_source_vars("async" TFLITE_ASYNC_SRCS)
 if(TFLITE_ENABLE_GPU)
   find_package(opencl_headers REQUIRED)
   find_package(vulkan_headers REQUIRED)
@@ -368,6 +370,14 @@ if(TFLITE_ENABLE_GPU)
     ${TFLITE_DELEGATES_GPU_COMMON_TRANSFORMATIONS_SRCS}
     ${TFLITE_SOURCE_DIR}/tools/versioning/gpu_compatibility.cc
     ${TFLITE_SOURCE_DIR}/tools/versioning/op_signature.cc
+    ${TFLITE_SOURCE_DIR}/delegates/gpu/async_buffers.cc
+    ${TFLITE_SOURCE_DIR}/delegates/gpu/android_hardware_buffer.cc
+    ${TFLITE_SOURCE_DIR}/delegates/gpu/gl/android_sync.cc
+    ${TFLITE_SOURCE_DIR}/delegates/gpu/gl/gl_errors.cc
+    ${TFLITE_SOURCE_DIR}/delegates/gpu/gl/egl_environment.cc
+    ${TFLITE_SOURCE_DIR}/delegates/gpu/gl/egl_context.cc
+    ${TFLITE_SOURCE_DIR}/delegates/gpu/gl/egl_surface.cc
+    ${TFLITE_SOURCE_DIR}/delegates/gpu/gl/request_gpu_info.cc
   )
   include_directories(
     AFTER
@@ -622,6 +632,8 @@ set(_ALL_TFLITE_SRCS
   ${TFLITE_SOURCE_DIR}/schema/conversion_metadata_generated.h
   ${TFLITE_SOURCE_DIR}/schema/schema_utils.cc
   ${TFLITE_SOURCE_DIR}/schema/schema_generated.h
+  ${TFLITE_DELEGATES_UTILS_SRCS}
+  ${TFLITE_ASYNC_SRCS}
 )
 add_library(tensorflow-lite
   ${_ALL_TFLITE_SRCS}

@dorishyc3 You can download above patch file and apply it to v2.16.1 patch apply <filename>