-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Make USE_BLAS64 a runtime option? #891
Comments
One way of doing it would be via dispatch on an optional argument, so the type signature of a hypothetical BLAS function
This would make it possible to choose the interface on each call, but also to change the global default (by re-defining the |
I believe that Accelerate is already usable through LBT. We just need to have an MKL.jl like package for Accelerate. The real issue is always LAPACK, and we may need to ensure that Perhaps https://github.com/JuliaMath/AppleAccelerate.jl should be updated to work similar to MKL.jl. |
OpenBLAS does have multi-threaded |
Note that to do this we'd need to make OpenBLAS32_jll a stdlib, and probably start also that one at LinearAlgebra loading time. I can see Linux distributions will be hating us more than they do already 😛 |
Accelerate only provides LP64 symbols (https://developer.apple.com/forums/thread/653440): you can add it to LBT, but from what I understand Julia will still use the ILP64 symbols provided by OpenBLAS:
|
I'm pretty sure we map them in the internal LBT table. @staticfloat or @giordano can say more. |
As it is now, yes. With your proposal of having a way to switch ILP64 <-> LP64 at runtime LBT will forward the calls to the right library, because the calls would be different. However, regarding packaging Julia, @haampie confirmed that having two variants of OpenBLAS in Spack would be, let's say, not easy. |
MKL does not have ILP64 symbols either, but they do have an ILP64 API. I suppose Accelerate does not have an ILP64 API, which is why we need |
I think @perrutquist's solution is roughly the right thing to do. LBT allows you to forward to different libraries no matter what they name their things, but it maintains its own mapping that preserves the property that Right now Julia's method of choosing which BLAS symbols to call is hardcoded; @perrutquist suggests one way of making it more dynamic, which I kind of like, although the fact that there is a semantic difference in some cases (e.g. when |
Is it even worth asking Apple for an ILP64 API? |
Yes: I've opened a ticket, but they've said previously that they base their development priorities on the demand, so others should ask as well (and ask for a newer LAPACK while you're at it). |
Keno and I have asked our internal Apple developer contact as well, so they're aware that this is something we'd like. |
I have been asking for this for months. |
@RoyiAvital You keep mentioning this in slack, discourse, and any time anyone discusses anything related to BLAS. We have heard you. But repeating it so many times does not really help. |
Regarding the need to provide two variants of OpenBLAS: If Julia would allow LP64 calls, then the documentation could warn the user to first install and load a library (and/or call some LBT does not crash if an LP64 call is attempted without first loading a compatible library. It simply prints an error message and returns. |
Another question would be what to do with structs like Should these structs have another type parameter, or should the LAPACK wrappers perform a conversion whenever the integer type used by Julia does not match the one used by LAPACK? |
Yes those should receive another type parameter. |
Idea: wouldn‘t it be possible to dynamically route between ILP64 and LP64 within libblastrampoline? With dynamically I mean that LBT could decide by inspecting the integer arguments of the call whether it is necessary to invoke the presumingly loaded int32 or int64 BLAS variant: if any integer argument exceeds 2^31-1 LBT could fall back to the ILP64 variant (only if a LP64 variant is first choice). Usually only a few scalar integer values should need to be inspected (and maybe converted) for that which should be possible in no time. Explicit calls to routines with integer arrays as input arguments (not working arrays) may be problematic but they are probably an exception… |
The idea is cool and probably not too hard to implement, but concatenating two strings at runtime to decide whether to call
And I guess you'd also need to add the runtime check of whether there is a backing ILP64 or LP64 BLAS library. At the moment all these decisions are no-cost (well, they are hardcoded, aren't really decisions), your proposals adds this runtime cost for each call. |
It's not possible to tell the difference between 1 valid 64-bit value, and 2 valid 32-bit values. When passing in indices for an array, how can you tell which way of looking at the set of indices is correct:
They both look completely valid, but will give wildly different answers. |
Perhaps with ILP64 BLAS and LAPACK available everywhere now (Apple being the final holdout) and our LBT tooling, I think we may no longer need to put effort into this. I'm suggesting we close this but happy to reopen if we feel like it would be still nice to have. |
Now that we have libblastrampoline, we can switch BLAS libraries at runtime, but can't switch between using the ILP64 and LP64 interfaces: this can only be done by modifying the
USE_BLAS64
build flag. Some BLAS libraries (notably, Apple's Accelerate) are only provided as LP64, see https://discourse.julialang.org/t/apple-m1-gpu-from-julia/69563@perrutquist created a library SetBlasInt.jl, that attempts to do this by redefining methods, but would it be feasible to do something like this in Julia itself?
The text was updated successfully, but these errors were encountered: