Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xamarin.TensorFlow.Lite.GPU missing bindings #793

Open
taublast opened this issue Jul 12, 2023 · 3 comments
Open

Xamarin.TensorFlow.Lite.GPU missing bindings #793

taublast opened this issue Jul 12, 2023 · 3 comments

Comments

@taublast
Copy link

taublast commented Jul 12, 2023

The issue

Inside Xamarin.TensorFlow.Lite.Gpu" Version="2.12.0.1" we are missing

CompatibilityList.BestOptionsForThisDevice and
constructor GpuDelegate(GpuDelegate.Options options)

to be able to to implement gpu acceleration as described here:

https://www.tensorflow.org/lite/android/delegates/gpu?hl=en#enable_gpu_acceleration_2

and in .net maui like that:

var compatList = new CompatibilityList();
if (compatList.IsDelegateSupportedOnThisDevice)
{
	var bestOptions = compatList.BestOptionsForThisDevice; //<- no BestOptionsForThisDevice
	var gpuDelegate = new GpuDelegate(bestOptions); //<- constructor not accepting parameters
	options.AddDelegate(gpuDelegate);
}

The c# code above started working for me after i implemented the solution described below.

The cause of this is that is either:
a - tensorflow-lite-gpu-api was not included at all
b - both gpu-related aar's where processed is same project: both tensorflow-lite-gpu-api-2.13.0.aar and tensorflow-lite-gpu-2.13.0.aar define classes absolutely for same package tensorflow/lite/gpu, that creates a conflict for bindings generator and it just skips one of them (tensorflow-lite-gpu-api in our case).

This makes GpuDelegateFactory.Options not to be available and bindings are not generated for CompatibilityList.BestOptionsForThisDevice and the second constructor GpuDelegate(GpuDelegate.Options options)

The solution

To bind tensorflow-lite-gpu-api-2.13.0.aar and tensorflow-lite-gpu-2.13.0.aar in different projects, the latter would reference the first one with "-api"

https://github.com/taublast/AppoMobi.Maui.TensorFlow.Lite

Context

This was all about a .net maui 7.0 for android, trying to use
<PackageReference Include="Xamarin.TensorFlow.Lite.Gpu" Version="2.12.0.1" />

@wollac11
Copy link

This issue has been ongoing since 2.5.0 (xamarin/XamarinComponents#1319) and seems to affect every version I have tried since up to and including the very latest currently available (2.14.0). I have some older Xamarin projects that use monoandroid so I can't use the modified NuGet from @taublast sadly (but it could be useful after migrating to MAUI if this issue is still not fixed).

@taublast Could you perhaps open a PR to this repo with a fix?

@wollac11
Copy link

wollac11 commented Nov 22, 2023

The GPU bindings are also not the only missing bindings in the current Xamarin.Tensorflow.Lite packages as there is a similar issue with the processor builders (#754)

@taublast
Copy link
Author

@wollac11 unfortunately won't be able to work on a PR here, but could help you with older droid if you provide more details on what sdk level you need bindings to support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants