NobuoTsukamoto / meta-tensorflow-lite

Yocto layer for TensorFlow Lite interpreter with Python / C++.
MIT License
33 stars 18 forks source link

Support for TFLITE_ENABLE_GPU=ON for using a GPU Delegate #85

Open chadrockey opened 2 weeks ago

chadrockey commented 2 weeks ago

Hi, it seems like adding TFLITE_ENABLE_GPU via bbappend via -DTFLITE_ENABLE_GPU=ON seems to build correctly for me.

However, I don't think the delegate or other required libraries are installed. Do you have any insight on what's required to correctly support this flag similar to the direct cmake instructions: https://www.tensorflow.org/lite/guide/build_cmake#step_4_run_cmake_tool_with_configurations

NobuoTsukamoto commented 2 weeks ago

Thank you for the issue.

However, I don't think the delegate or other required libraries are installed.

Is this when running on Raspberry Pi? I was considering supporting GPU Delegate in the Yocto recipe but had not yet started. First, I will check what is missing.

chadrockey commented 2 weeks ago

Thanks! This is for a BSP that is not raspberry pi. My OEM has demos that support GPU Delegate in Python, but my application is in C++ and your recipes are much closer to my use case.

NobuoTsukamoto commented 6 days ago

Sorry for the late reply.

First, I checked the operation based on https://github.com/NobuoTsukamoto/meta-tensorflow-lite/tree/gpu_delegate. The Benchmark Tool worked correctly on VisionFive 2 (meta-riscv).

It seems that the library is missing on Raspberry Pi 4 (meta-raspberrypi). However, a similar error occurs on Raspberry Pi OS.

I plan to continue checking whether it works with libtensorflowlite.

chadrockey commented 1 day ago

@NobuoTsukamoto I actually had success with my BSP using commit e74b569e1b5606c6a8357bc80ecdff46fb95102b

This was my libtensorflow-lite_%.bbappend since I'm not on raspberry pi:

RDEPENDS:${PN} += " opencl "

TENSORFLOW_TARGET_ARCH = "aarch64"
EXTRA_OECMAKE:append = " -DTFLITE_ENABLE_XNNPACK=ON"
EXTRA_OECMAKE:append = " -DTFLITE_ENABLE_GPU=ON"
EXTRA_OECMAKE:append = " -DTFLITE_ENABLE_MMAP=ON"

I am on kirkstone but I pulled in abseil-cpp and flat buffers from main of open embedded.

My GPU Delegate worked fine from the tf lite cmake installation instructions. So all that was needed was this bbappend and the following c++ code to actually use the GPU Delegate:

auto* delegate = TfLiteGpuDelegateV2Create((/*default options=*/nullptr);
builder.AddDelegate(delegate);