kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.35k stars 1.85k forks source link

Enhancement request: lapack recipe using OpenBLAS #2824

Open RobertFlatt opened 1 year ago

RobertFlatt commented 1 year ago

Description

The current lapack recipe implementation using LEGACY_NDK is clever but somewhat baroque. And not all users can navigate the steps.

Consider using lapack from OpenBLAS, it contains lapack (the same version 3.10.1) that has been run through f2c. So lapack can be be built with a C compiler, no extra NDK!

This is now the default behavior of OpenBLAS, so we might reasonably think it is stable.

From https://www.openblas.net/Changelog.txt

Version 0.3.21 07-Aug-2022

general:

  • Updated the included LAPACK to Reference-LAPACK release 3.10.1
  • when no Fortran compiler is available, OpenBLAS builds will now automatically build LAPACK from an f2c-converted copy of LAPACK 3.9.0 unless the NO_LAPACK option is specified

An alternative might be to use f2c directly, since OpenBLAS contains C not Fortran it is possible this translation has issues with automation. Impossible to know without trying it.

misl6 commented 1 year ago

Oh, that's nice!

+1 for getting rid of LEGACY_NDK, as it's legacy, and it will break sometimes in the future + is not available for Apple Silicon users (like me)

Are you considering trying yourself or we should schedule/advertise the proposal? 😁

RobertFlatt commented 1 year ago

Advertise, I have external things going on.

And I look at all the issues I just posted as possible training projects to allow other people to get inside the tools a little (one more enhancement request to come).

misl6 commented 1 year ago

Hi @mzakharo! (sorry for the ping)

I do not know if it happen that you're still active on python-for-android related projects (and maybe you also still make use of lapack).

I was wondering if you may be interested in working on this proposal, as you're the https://github.com/kivy/python-for-android/pull/2615 author, and you're likely (100% sure) most knowledgeable than me on lapack and scipy.

mzakharo commented 1 year ago

Lapack is not the end goal. Scipy needs Fortran last time I checked. Is this no longer the case?

misl6 commented 1 year ago

Lapack is not the end goal. Scipy needs Fortran last time I checked. Is this no longer the case?

You're right.

As I said, you're more knowledgeable than me on scipy and lapack 😀

RobertFlatt commented 1 year ago

Will Scipy run through f2c?

If not a built cache would address the complexity issue for most users. https://github.com/kivy/python-for-android/issues/2823

Samael-TLB commented 1 year ago

Currently, Scipy is relying on Meson for their cross-compilation and meson seems to be supporting ios and android. So may be we can try to venture into Meson and try out the cross-compilation for scipy. Next, we have the open-sourced methodology for cross -compilation for android by Chaquopy and for ios through Beeware. They have been successful in cross-compiling their own gfortran used for cross compiling scipy. https://github.com/chaquo/chaquopy/tree/master/server/pypi/packages https://github.com/freakboy3742/chaquopy/tree/iOS-support/server/pypi https://docs.scipy.org/doc/scipy/building/cross_compilation.html https://github.com/scipy/scipy/issues/14812

Old repo but possibly showing the methodology for cross-compilation for android irrespective of ndk version (??): https://github.com/buffer51/android-gfortran

mhsmith commented 1 month ago

Hi, I'm a member of the Chaquopy and BeeWare projects. We're actually not compiling our own gfortran for Android anymore; we're doing the same as Kivy and using the prebuilt gfortran from @mzakharo. But as I've just posted at https://github.com/kivy/python-for-android/pull/2615#issuecomment-2389073761, I'm not sure how long this will continue to be feasible.

On iOS we haven't found any adequate Fortran compiler yet – see https://github.com/beeware/mobile-forge/issues/10.