whisper_android icon indicating copy to clipboard operation
whisper_android copied to clipboard

Idea: Temporary Workaround for Native C++ 16KB Memory Page Compatibility

Open yong1020 opened this issue 3 months ago • 6 comments

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:


🔧 Build Details

  • TensorFlow version: 2.12.0
    I couldn’t determine the exact TensorFlow version used in the original project, so I explored compatibility with TFLiteEngine and 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 0x4000 in 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 avatar Sep 05 '25 09:09 yong1020

@yong1020 Thanks for your efforts

vilassn avatar Sep 05 '25 10:09 vilassn

Thanks Yong, that looks like a great step forward.

However, when I compile it into whisper_native I get:

Image

Has something changed in TensorFlow than requires changes in whisper_native?

KiwiWilkinson avatar Sep 05 '25 13:09 KiwiWilkinson

@KiwiWilkinson

Did you replace both the attached in the 'libtensorflow.so' and the 'tensorflow/lite' source specified path?

It should work without any other changes.

yong1020 avatar Sep 05 '25 14:09 yong1020

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.

KiwiWilkinson avatar Sep 06 '25 11:09 KiwiWilkinson

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.

KiwiWilkinson avatar Sep 06 '25 18:09 KiwiWilkinson

@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:

libtensorflowlite.zip

and this is the file for x86_64:

libtensorflowlite.zip

@vilassn do you want to incorporate these in a new version of Whisper?

KiwiWilkinson avatar Sep 10 '25 16:09 KiwiWilkinson