Idea: Temporary Workaround for Native C++ 16KB Memory Page Compatibility
Hi everyone!
I’d like to share an idea that might help others who are running into issues with the recent 16KB memory page policy.
I experimented with rebuilding libtensorflowlite.so for arm64-v8a devices so that it aligns with a 16KB memory page size.
If you’d like to try it out, you can replace the following files in your project with the rebuilt versions:
cpp/tf-lite-api/generated-libs/arm64-v8a/libtensorflowlite.solibtensorflowlite.zipcpp/tf-lite-api/tensorflow_src/tensorflow/tensorflow.zip
🔧 Build Details
- TensorFlow version: 2.12.0
I couldn’t determine the exact TensorFlow version used in the original project, so I explored compatibility withTFLiteEngineand found that 2.12.0 worked. - OS: Ubuntu 20.04
- Build tool: Bazel 5.3.0 (compatible with TF 2.12.0)
- NDK version: 21.4.7075529
- Build command:
$ bazel build -c opt \ --config=android_arm64 \ --linkopt='-Wl,-z,max-page-size=0x4000' \ //tensorflow/lite:libtensorflowlite.so - Build Result:
If you see
0x4000in the alignment field, it means that the build successfully applied the 16KB memory page size:$ readelf -lW bazel-bin/tensorflow/lite/libtensorflowlite.so | grep LOAD LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x462ffc 0x462ffc R E 0x4000 LOAD 0x4632c8 0x00000000004672c8 0x00000000004672c8 0x00eb28 0x0160a8 RW 0x4000
@yong1020 Thanks for your efforts
Thanks Yong, that looks like a great step forward.
However, when I compile it into whisper_native I get:
Has something changed in TensorFlow than requires changes in whisper_native?
@KiwiWilkinson
Did you replace both the attached in the 'libtensorflow.so' and the 'tensorflow/lite' source specified path?
- cpp/tf-lite-api/generated-libs/arm64-v8a/libtensorflowlite.so -> libtensorflowlite.zip
- cpp/tf-lite-api/tensorflow_src/tensorflow/ -> tensorflow.zip
It should work without any other changes.
Thanks Yong. You were quite right. I'd copied the source code to the wrong place in the directory hierarchy!
It's now working properly. Thank you very much.
Do I also need a libtensorflowlite.so for other ABIs: armabi-v7a and x86_64? I'm getting a linking error when I try to build an apk.
@yong1020 , thanks to your bazel build instruction above, I've created the other two myself. I'm not familiar with Ubuntu or Bazel, but I created a new Virtual Machine and installed the necessary bits.
This is the file for armeabi-v7a:
and this is the file for x86_64:
@vilassn do you want to incorporate these in a new version of Whisper?