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

GPU delegate linker errors when building TFLite 2.16.1 for Android with CMake #69

Open gaikwadrahul8 opened 4 days ago

gaikwadrahul8 commented 4 days ago

Issue type

Build/Install

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

2.16.1

Custom code

Yes

OS platform and distribution

No response

Mobile device

No response

Python version

No response

Bazel version

No response

GCC/compiler version

Clang 14.0.6 (Android NDK r25b)

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

I'm trying to build TFLite 2.16.1 for Android using CMake and Android NDK r25b and got the following linker errors related to GPU delegate. It looks like some source files was not added to CMake configuration files.

ld: error: undefined symbol: tflite::gpu::OptionalAndroidHardwareBuffer::OptionalAndroidHardwareBuffer()
>>> referenced by android_hardware_buffer.h:69 (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 (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 (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 5 more times

ld: error: undefined symbol: tflite::delegates::BackendAsyncKernelInterface::BackendAsyncKernelInterface()
>>> referenced by delegate.cc:687 (tensorflow/lite/delegates/gpu/delegate.cc:687)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::CreateAsyncRegistration()::$_2::__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: error: undefined symbol: tflite::delegates::utils::ReadBufferAttrs(TfLiteAttributeMap const*)
>>> referenced by delegate.cc:1048 (tensorflow/lite/delegates/gpu/delegate.cc:1048)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::RegisterBuffer(TfLiteOpaqueContext*, TfLiteIoType, TfLiteBackendBuffer const*, TfLiteAttributeMap const*, int))
>>> referenced by delegate.cc:911 (tensorflow/lite/delegates/gpu/delegate.cc:911)
>>>               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: error: undefined symbol: tflite::delegates::utils::WriteBufferAttrs(tflite::delegates::utils::BufferAttributes const&, TfLiteAttributeMap*)
>>> referenced by delegate.cc:913 (tensorflow/lite/delegates/gpu/delegate.cc:913)
>>>               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:913 (tensorflow/lite/delegates/gpu/delegate.cc:913)
>>>               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:913 (tensorflow/lite/delegates/gpu/delegate.cc:913)
>>>               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 2 more times

ld: error: undefined symbol: tflite::delegates::utils::ReadSyncAttrs(TfLiteAttributeMap const*)
>>> referenced by delegate.cc:936 (tensorflow/lite/delegates/gpu/delegate.cc:936)
>>>               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:969 (tensorflow/lite/delegates/gpu/delegate.cc:969)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::SetAttributes(TfLiteOpaqueContext*, TfLiteOpaqueNode*, int, TfLiteAttributeMap const*))

ld: error: undefined symbol: tflite::delegates::utils::WriteSyncAttrs(tflite::delegates::utils::SyncAttributes const&, TfLiteAttributeMap*)
>>> referenced by delegate.cc:938 (tensorflow/lite/delegates/gpu/delegate.cc:938)
>>>               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:940 (tensorflow/lite/delegates/gpu/delegate.cc:940)
>>>               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: error: undefined symbol: tflite::gpu::gl::WaitFdGpu(int)
>>> referenced by delegate.cc:1167 (tensorflow/lite/delegates/gpu/delegate.cc:1167)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))

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

ld: 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:1175 (tensorflow/lite/delegates/gpu/delegate.cc:1175)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))

ld: error: undefined symbol: tflite::delegates::utils::ConvertToTfLiteStatus(absl::lts_20230802::Status)
>>> referenced by delegate.cc:1175 (tensorflow/lite/delegates/gpu/delegate.cc:1175)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
>>> referenced by delegate.cc:1186 (tensorflow/lite/delegates/gpu/delegate.cc:1186)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
>>> referenced by delegate.cc:1187 (tensorflow/lite/delegates/gpu/delegate.cc:1187)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
>>> referenced 3 more times

ld: error: undefined symbol: tflite::gpu::gl::EglEnvironment::~EglEnvironment()
>>> referenced by memory:2427 (android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/memory:2427)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))
>>> referenced by memory:2427 (android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/memory:2427)
>>>               CMakeFiles/tensorflow-lite.dir/delegates/gpu/delegate.cc.o:(tflite::gpu::(anonymous namespace)::DelegateAsyncKernel::Eval(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*))

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

ld: error: undefined symbol: tflite::gpu::gl::CreateFdGpu()
>>> referenced by delegate.cc:1211 (tensorflow/lite/delegates/gpu/delegate.cc:1211)
>>>               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]: *** [CMakeFiles/tensorflow-lite.dir/build.make:6296: libtensorflow-lite.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:1336: CMakeFiles/tensorflow-lite.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Standalone code to reproduce the issue

CMake options:

cmake -S tensorflow/lite -B build -D CMAKE_BUILD_TYPE=Release -D CMAKE_SYSTEM_PROCESSOR=aarch64 -D BUILD_SHARED_LIBS=ON -D TFLITE_ENABLE_GPU=ON -D CMAKE_SYSTEM_NAME=Linux -D CMAKE_SYSTEM_VERSION=29 -D ANDROID_PLATFORM=29 -D CMAKE_ANDROID_ARCH_ABI=arm64-v8a -D ANDROID_ABI=arm64-v8a -D CMAKE_TOOLCHAIN_FILE=android-ndk-r25b/build/cmake/android.toolchain.cmake

Relevant log output

No response

gaikwadrahul8 commented 2 days ago

This issue originally reported by @eltimen 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.