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

Use TensorFlowLiteC from source (tensorflow/) on Android as well #34

Open
mrousavy opened this issue Jan 31, 2024 · 0 comments
Open

Use TensorFlowLiteC from source (tensorflow/) on Android as well #34

mrousavy opened this issue Jan 31, 2024 · 0 comments

Comments

@mrousavy
Copy link
Owner

mrousavy commented Jan 31, 2024

Today, we build TensorFlowLiteC from source to use it in iOS:

# Assumes the user ran ./configure in tensorflow/ already
cd tensorflow
bazel build --config=ios_fat -c opt --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteC_framework
bazel build --config=ios_fat -c opt --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteCCoreML_framework
cd ..
cp -f -r tensorflow/bazel-bin/tensorflow/lite/ios/ ios/
unzip -o ios/TensorFlowLiteC_framework.zip -d ios
rm ios/TensorFlowLiteC_framework.zip
unzip -o ios/TensorFlowLiteCCoreML_framework.zip -d ios
rm ios/TensorFlowLiteCCoreML_framework.zip

The source code is added to this repo as a git submodule (tensorflow/), and when shipping the library to npm I prebuild a TensorFlowLiteC binary (including the TensorFlowLiteCCoreML delegate), add the headers, then ship it.

On Android however, we use the org.tensorflow:tensorflow-lite library from Gradle:

// Tensorflow Lite .aar (includes C API via prefabs)
implementation "org.tensorflow:tensorflow-lite:2.12.0"
extractHeaders("org.tensorflow:tensorflow-lite:2.12.0")
extractSO("org.tensorflow:tensorflow-lite:2.12.0")

This ships the Java files as well as introducing some other unnecessary files for the bundle. Also, it is outdated and not in sync with the iOS version, some fixes, features or improvements may only be available on iOS, but not on Android due to us using the published package from Maven. (Currently we use v2.2.0, which is outdated by more than two versions)

Instead, we should aim to also use TensorFlowLiteC (any potentially also an Android GPU delegate?) from source by also building it in the tensorflow/ submodule, just like how we do it on iOS, then add the headers and link the library in the android/CMakeLists.txt config.

This would align the versions perfectly and we don't need to fetch a prebuild version from Maven.

This PR was an attempt at doing so: #33 ...but I couldn't manage to get Bazel to build the Android version.

We need to make sure this ships the correct binaries (x86, x86_64, arm, and arm64 - or just x86_fat and arm_fat).


Added Bonus: Maybe we can even do the whole building in the CI with dependabot, so everytime the submodule changes (a commit lands on main in tensorflow/) it opens a PR, prebuilds the libraries, moves them into ios and android, and I only need to merge that to get the changes. No need to build it on my mac. Makes it even more safe

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

1 participant