termux-packages icon indicating copy to clipboard operation
termux-packages copied to clipboard

[Package]: `libtensorflow`. TensorFlow can use the TPUs on smartphones (such as Google Tensor, which has 5.2 teraFLOPS at 6 watts)

Open SwuduSusuwu opened this issue 7 months ago • 4 comments

Why is it worth to add this package?

Home page URL

https://www.tensorflow.org/install/lang_c

Source code URL

https://github.com/tensorflow/tensorflow

Packaging policy acknowledgement

  • [x] The project is actively developed.

  • [x] The project has existing packages and is "well known".

  • [x] Licensed under an open source license.

  • [x] Not available through a language package manager: pip, npm, cpan, cargo, etc.

  • [x] Not taking up too much disk space (< 100MiB per architecture, exceptions can be made)

  • [x] Not duplicating the functionality of existing packages.

  • [x] Not serving hacking, malware, phishing, spamming, spying, ddos functionality.

  • [x] I certify that I have read Termux Packaging Policy and understand that my request will be denied if it is found lacking.

Additional information

Build steps: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/lib_package/README.md

  • Use --depth 1 to just clone TensorFlow's working directory, since the repo is huge:
~ $ git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git --depth 1
Cloning into 'tensorflow'...
remote: Enumerating objects: 34943, done.
remote: Counting objects: 100% (34943/34943), done.
remote: Compressing objects: 100% (23717/23717), done.
remote: Total 34943 (delta 11587), reused 29863 (delta 10638), pack-reused 0 (from 0)
Receiving objects: 100% (34943/34943), 88.71 MiB | 3.49 MiB/s, done.
Resolving deltas: 100% (11587/11587), done.
Updating files: 100% (34418/34418), done.
~ $ ls tensorflow/
AUTHORS             ISSUES.md    arm_compiler.BUILD  requirements_lock_3_10.txt  third_party
BUILD               LICENSE      ci                  requirements_lock_3_11.txt  tools
CITATION.cff        README.md    configure           requirements_lock_3_12.txt
CODEOWNERS          RELEASE.md   configure.cmd       requirements_lock_3_13.txt
CODE_OF_CONDUCT.md  SECURITY.md  configure.py        requirements_lock_3_9.txt
CONTRIBUTING.md     WORKSPACE    models.BUILD        tensorflow

https://stackoverflow.com/questions/33620794/how-to-build-and-use-google-tensorflow-c-api/43920376#43920376 has:

./configure
bazel build //tensorflow:libtensorflow_cc.so

Then Copy the following include headers and dynamic shared library to /usr/local/lib and /usr/local/include:

mkdir /usr/local/include/tf
cp -r bazel-genfiles/ /usr/local/include/tf/
cp -r tensorflow /usr/local/include/tf/
cp -r third_party /usr/local/include/tf/
cp -r bazel-bin/libtensorflow_cc.so /usr/local/lib/

SwuduSusuwu avatar May 09 '25 01:05 SwuduSusuwu

This was search for the C / C++ libs for TensorFlow:

~ $ pkg install *tensorflow*
Error: Unable to locate package *tensorflow*
Error: Couldn't find any package by glob '*tensorflow*'
~ $ pkg install *tensorFlow*
Error: Unable to locate package *tensorFlow*
Error: Couldn't find any package by glob '*tensorFlow*'
~ $ pkg install *TensorFlow*
Error: Unable to locate package *TensorFlow*
Error: Couldn't find any package by glob '*TensorFlow*'

. Should post new issue for the Python libs (which have different build steps and do not use apt or pkg, but pip install tensorflow)?

SwuduSusuwu avatar May 09 '25 15:05 SwuduSusuwu

If bazel is a problem, https://github.com/FloopCZ/tensorflow_cc#tensorflow_cc has cmake build steps for libtensorflow.

SwuduSusuwu avatar May 10 '25 06:05 SwuduSusuwu

Termux can almost build static libs with just the #include headers from TensorFlow, but requires workarounds: https://github.com/tensorflow/tensorflow/issues/93130

SwuduSusuwu avatar May 11 '25 09:05 SwuduSusuwu

Now know that TensorFlow's TPU backend has use on lots more phones. What follows is just the list of Google phones with TPU's.

Even-numbered releases share the previous odd-numbered release's edgeTPU. Of course, smartphones without TPU's can have some use for TensorFlow, too, since TensorFlow's backend support include CPU's and GPU's, but you can port such programs (whereas to use the smartphone's TPU requires TensorFlow, since most smartphones edgeTPU's protocols are not known.)

SwuduSusuwu avatar May 24 '25 14:05 SwuduSusuwu