-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Scipy #10
Comments
Via @ydesgagn - he reports that it's possible to get flang working for iOS by running it through a Docker container. Use this docker file to prepare a flang image:
Then, use this script (
The replacement
The
|
@meow464: You used to have a good summary of this at https://meow464.neocities.org/Fortran/state-of-fortran-on-ios. Is there some reason why you've taken it down? |
The url changed https://meow464.neocities.org/blog/state-of-fortran-on-ios/ I added support for iOS cross compilation on LFortran but it still can't compile scipy and lapack. Both are being actively worked on. |
I will add instructions for cross compiling for iOS, there was a pull request for that but I forgot about it. It's not complicated, just cross compile the runtime with a iOS cmake toolchain file then use --target=apple-iphone-ios |
@freakboy3742 is that the old or new flang? |
That's the old flang also known as flang classic, it's based on the open sourced PGI compiler and it has a problem generating the apple-arm ABI. I spent some 6 months working on it in 2021 but couldn't fix it. The problem is with variadic arguments. On arm they should be put on registers until none are available and then on the stack. On apple they should all be put on the stack. The flang intrinsic functions are written in C and compiled with the apple abi (as they should) but the fortran code is compiled with the arm abi. |
Ah - good to know. Thanks for those details. "Run flang through Docker" seemed like a neat trick, but it also seemed like just enough of a neat trick that there was very likely a land mine in waiting. |
It's worth noting that Quansight recently blogged about getting flang working with SciPy. |
@meow464 We are executing unit tests on an iPad M2 and they all pass for Scipy. Can you be more specific on @freakboy3742 one of my guy is about to PR in https://github.com/beeware/mobile-forge to add scikit-learn. Will do more after that and we can try Scipy if you think the Docker way is not too hacky. |
@ydesgagn "Working with a weird hack" is better than "not working"... but I guess it depends how much engineering overhead we'll need to add to support the hack. If it's something that we can add now, then remove easily later if/when a "direct" flang approach works, then I don't mind living with a hack. Suffice to say, I'd much rather see a "direct" flang approach - but I'd also like a pony, and a gold Lamborghini :-) |
There are some more details and links here, but they may not be up to date. |
For 3.11 Getting error Before built numpy 1.26.0 Will appreciate any advice? |
It seems to me that the error message is telling you exactly what is going on:
You need to have numpy 1.23.2 available for installation. On 3.11, 1.23.2 is a special version of numpy - it's the oldest supported version. A lot of numpy-related tooling will deliberately build against the "oldest-supported-numpy" target to ensure maximum ABI compatibility. You'll need to build this version first ( |
You can patch out the dependence on |
Sure, you can patch it out, but that's not how official Scipy builds are made. The goal of this project is to provide a stepping stone towards Scipy providing its own official iOS packages (although, to be clear - that's a way off). If we're going to patch SciPy, the patches are going to be specific to getting a successful build on iOS, not hacks to get around inconveniences that have no chance of being upstreamed. Plus - it's not like it's hard to build numpy 1.23.2. The recipe is already there. |
It's super cool that you're working on it, thanks. I was just struggling making Meanwhile I'll take a look on the mobile forge mechanism. |
I tried to
seems to be related to the Fortran compilation you mentionned earlier. Do you have an ongoing PR @freakboy3742 or something we can help you on ? @ydesgagn Hello ! Could you describe the all process to compile Thanks ! |
@hyazel will create a PR this weekend so you can try with the proper tools available. |
Everything I have in progress for mobile forge is open on PRs on this repo at present. I haven't tackled BLAS/LAPACK at all. |
Hello, I'm interested in the topic too. |
@pasdeloup We'd definitely appreciate any assistance you can provide. SciPy is a big obvious gap in BeeWare's iOS offering, which we'd like to address. All the details that I have are in this ticket; I don't know if that gives you anything to work with, but I'm happy to provide guidance where I can. |
Here the PR #28 Really sorry for not responding sooner. I'm no longer familiar with the code the repo but if somebody can add the recipe with the instructions in the PR, this was working for me in the past with: From Python-Apple-support:
Then I build the following with this hack:
I will try to help if you run out in any trouble. |
@ydesgagn Thanks for that PR. I'm not sure when I'll get a chance to take a deep look at it myself, but if anyone else wants to dig into the problem, they've now got all the pieces. |
Thanks @ydesgagn So you don't need to build first BLAS/LAPACK? |
No I did not built it. I just pointed scipy at the homebrew ARM64 version and linked with that. But I know @freakboy3742 is not a big fan of homebrew dependencies. |
I'm not a fan because homebrew libraries have a history of breaking iOS builds because they're linked against macOS system libraries, not iOS system libraries (gettext is a particularly recurring culprit here) If the homebrew build of BLAS/LAPACK does work on iOS, then it should be possible to port the recipe directly to mobile-forge, except explicitly using iOS compilers and libraries, rather than relying on a lack of problematic symbols. We already do builds for libraries like libpng and libjpeg; if we've got a working recipe, I can't see why BLAS/LAPACK would be any different. |
It looks like there are already official BLAS and LAPACK builds from Apple (see OS support indicators at the top). Maybe we could use these, although SciPy might need a bit of help to find them. |
@pasdeloup Hi, do you have any progress on building SciPy wheel for iOS?. @ydesgagn Could you please share the working SciPy wheel that you have built, while we figure out how to make build on out own? Thank you. |
SciPy works well with Apple's BLAS/LAPACK library, Accelerate. It can be built from the SciPy repo with It appears that the Pyto iOS app supports SciPy, and that app's author has found a way to compile Fortran code with Docker, similar to the approach discussed above. Their repo: https://github.com/ColdGrub1384/fortran-ios . Presumably, this is the tool they're using for SciPy for Pyto. @ColdGrub1384 are you able to share a more fleshed-out list of steps for compiling these Fortran files for SciPy? For example, how did you deal with things like, the linking in of Another strategy would be to take the .so files for macOS and just change their binary metadata so that they look like iOS binaries, and then use them like that. This is a little weird, but I'm told that it's pretty safe. |
Scipy used to support Accelerate but no longer does, the reasons are listed here: https://github.com/scipy/archive/blob/main/wiki/dropping-accelerate-support.md |
@meow464 Are you sure that information is current? I know it was definitely true in the SciPy v1.2 timeframe (which is where that document comes from), but conversations I've had recently suggest that that the SciPy team either have moved, or are planning to move back to Accelerate because the bugs in the Accelerate implementation of BLAS/LAPACK have become less of a problem than the general problem of trying to get a Fortran compiler that works. |
I do not know if it's current and good to hear they are considering Accelerate again. |
Since apple introduced an updated LAPACK in MacOS 13.3, we have readded explicit support, see scipy/scipy#19816 |
What is the PyPI name of the package you would like to see added?
scipy
Additional details
Major blocker is availability of a Fortran compiler that can target iOS
The text was updated successfully, but these errors were encountered: