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

[Mobile] Will provide supported 16KB-page-size prebuilt Android .so in the future? #21837

Open
w11m opened this issue Aug 23, 2024 · 11 comments
Open
Labels
contributions welcome lower priority issues for the core ORT teams feature request request for unsupported feature or enhancement platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@w11m
Copy link

w11m commented Aug 23, 2024

Describe the issue

With Android A15 introducing a beta requirement for shared libraries to support a 16KB page size on ARM64 devices
W

source: (https://source.android.com/docs/core/architecture/16kb-page-size/16kb)

We’re keen to ensure our project remains compatible with this and future Android versions, including A16.
Our current prebuilt .so files follow the older page size specifications
which might cause compatibility or performance concerns.

To reproduce

Use the existing prebuilt .so file on an Android A15 device or emulator.
Check for failures in the VTS elf_alignment_test related to the 16KB page size.

Urgency

Maybe Urgent

As the Android A15 adoption grows, addressing this could become more pressing. We would appreciate guidance on whether there are plans to provide a prebuilt .so file that meets the 16KB page size requirement or any recommended steps we can take to ensure continued compatibility.

Platform

Android

OS Version

15

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

prebuild

Package Name (if 'Released Package')

onnxruntime-android

ONNX Runtime Version or Commit ID

version 1.16.1

ONNX Runtime API

C++/C

Architecture

ARM64

Execution Provider

Default CPU, NNAPI

Execution Provider Library Version

No response

@w11m w11m added the platform:mobile issues related to ONNX Runtime mobile; typically submitted using template label Aug 23, 2024
@skottmckay skottmckay added the contributions welcome lower priority issues for the core ORT teams label Aug 26, 2024
@skottmckay
Copy link
Contributor

We'll look at adding the build flags in the next release. Based on this there are no actual devices with a 16KB page size yet.

https://android-developers.googleblog.com/2024/08/adding-16-kb-page-size-to-android.html

There are no production Android devices available today or expected for the Android 15 release that support a 16 KB page size.

@w11m
Copy link
Author

w11m commented Aug 26, 2024

Thank you for the update!
We appreciate that you're considering adding the build flags in the next release.

We'll look at adding the build flags in the next release. Based on this there are no actual devices with a 16KB page size yet.

https://android-developers.googleblog.com/2024/08/adding-16-kb-page-size-to-android.html

There are no production Android devices available today or expected for the Android 15 release that support a 16 KB page size.

@w11m
Copy link
Author

w11m commented Aug 27, 2024

Hi, @skottmckay, could you please suggest which file would be best to add the flag '16KB page size'
so I can quickly try build and check with the elf_alignment_test.

@skottmckay
Copy link
Contributor

If it needs to be set globally you could try adding an if (ANDROID) ... endif() section at the end of https://github.com/microsoft/onnxruntime/blob/main/cmake/adjust_global_compile_flags.cmake.

If it just needs to be set for libonnxruntime.so you could add something to https://github.com/microsoft/onnxruntime/blob/main/cmake/onnxruntime.cmake

Note that if (CMAKE_SYSTEM_NAME STREQUAL "Android") isn't necessary anymore as the minimum cmake version required supports if (ANDROID)

@w11m
Copy link
Author

w11m commented Aug 27, 2024

Work great with the build comment and with modified https://github.com/microsoft/onnxruntime/blob/main/cmake/onnxruntime.cmake

build.bat --android --android_sdk_path <android_sdk_path> --android_ndk_path <android_ndk_path> --android_abi arm64-v8a --android_api 33 --cmake_generator Ninja --use_nnapi --build_shared_lib --skip_tests --config Release --cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF

Also passed with my local VTS elf_alignment_test "16KB-page-size" check

Thanks for the help.

If it needs to be set globally you could try adding an if (ANDROID) ... endif() section at the end of https://github.com/microsoft/onnxruntime/blob/main/cmake/adjust_global_compile_flags.cmake.

If it just needs to be set for libonnxruntime.so you could add something to https://github.com/microsoft/onnxruntime/blob/main/cmake/onnxruntime.cmake

Note that if (CMAKE_SYSTEM_NAME STREQUAL "Android") isn't necessary anymore as the minimum cmake version required supports if (ANDROID)

@skottmckay
Copy link
Contributor

Excellent. Would you be able to submit a PR with the change?

@w11m
Copy link
Author

w11m commented Aug 27, 2024

Submit a PR #21876 based on v1.16.1 changed

@skottmckay
Copy link
Contributor

Thanks for submitting the PR. You may need to merge your fork with the latest version of main though as it seems to be out of date leading to a massive number of changed files.

@skottmckay
Copy link
Contributor

If it's easier I can create a PR with your change.

Would be interested to know if this works instead so we limit where the linker flag is applied to just the onnxruntime shared library.

set_target_link_options(onnxruntime PRIVATE -Wl,-z,max-page-size=16384)

@skottmckay
Copy link
Contributor

On second thought we probably need to do this globally so the unit test projects have the same setting applied. adjust_global_compile_flags.cmake may be the best place to do this.

@w11m
Copy link
Author

w11m commented Aug 30, 2024

@skottmckay You can create a PR with the changes. I'm currently without the necessary device to conduct the tests.
However, based on what I know, the 16KB alignment check should cover all shared libraries on the device.
It seems adjusting the .adjust_global_compile_flags.cmake might be appropriate.

@sophies927 sophies927 added the feature request request for unsupported feature or enhancement label Sep 5, 2024
skottmckay added a commit that referenced this issue Sep 19, 2024
### Description
<!-- Describe your changes. -->
Add linker flags to support 16KB page size support on Android. 

See
https://source.android.com/docs/core/architecture/16kb-page-size/16kb#build-lib-16kb-alignment

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
#21837
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions welcome lower priority issues for the core ORT teams feature request request for unsupported feature or enhancement platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

No branches or pull requests

3 participants