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

Use FlexiBLAS to pick a BLAS and LAPACK at runtime. #27

Closed
staticfloat opened this issue Sep 17, 2013 · 14 comments
Closed

Use FlexiBLAS to pick a BLAS and LAPACK at runtime. #27

staticfloat opened this issue Sep 17, 2013 · 14 comments
Labels
help wanted Extra attention is needed

Comments

@staticfloat
Copy link
Member

It would be neat to attempt switching BLAS backends by creating a libblas.{so,dylib,dll} symlink in JULIA_HOME/lib/julia and linking to that instead of directly to a system library or OpenBLAS. Using this method, we could then select a BLAS library to dynamically link against at startup time. (Unfortunately, I don't think this would allow us to switch BLAS implementations after we've already started up, but correct me if there's some strange dynamic "unlinking" magic I don't know about!)

A good way to test this is to install ATLAS, OpenBLAS and Reference BLAS on a Linux computer and symlink to one of them in the Julia build directory, while overriding the Makefile variables for which BLAS library to use to point to that symlink. If you can change the symlink to point to different BLAS implementations, we have a winner.

There's some added complexity involved with LAPACK, to start with I think we can just always compile our own and have it link to our symlinked BLAS implementation. If whoever wants to tackle this happens to have access to an MKL installation, that would be great to test as well.

@ViralBShah
Copy link
Member

It would be great if this works. I have always wanted this.

@lindahua
Copy link

+1 for this. Very useful.

@StefanKarpinski
Copy link
Member

Doing it with symlinks seems like asking for trouble to me – what happens when you start two different julia instances with different BLAS flags at the same time?

@staticfloat
Copy link
Member Author

I'm not sure of a better way to do it, other than writing (yet another) wrapper around the BLAS libraries that is able to intelligently forward requests for a function to another library.

The worst thing I can imagine with the symlink idea is that someone could change the BLAS provider, and then start up worker processes which would then have separate BLAS providers. That's not really the worst thing in the world, but could give rise to subtle bugs just by virtue of having different workers using different implementations. Changing BLAS implementations underneath a running Julia shouldn't be any problem at all, as once Julia is loaded up, the shared libraries are loaded into memory. You can delete the julia executable and all its (opened) libraries and it doesn't care.

@StefanKarpinski
Copy link
Member

Hmm. It just seems like it's ripe for a race condition, but if there's only one object file to load, then I suppose that can't happen – the symlink points to one version or the other at load time.

@staticfloat
Copy link
Member Author

I'm closing this as, between the dimensions of specialty BLAS calls, ILP64, and different LAPACK implementations, it's best to not pull the rug out from under Julia by changing the linked BLAS library willy-nilly. We have good support for building against different BLAS implementations, let's leave it at that until we have a compelling use case for something else.

@tkelman
Copy link

tkelman commented May 6, 2016

At a minimum it requires rebuilding the system image because the threading API's vary quite a bit between different implementations. Now if rebuilding the system image incrementally didn't take quite so long, that would be satisfactory I think. I've written a few helper routines somewhere for doing this.

@gramian
Copy link

gramian commented Oct 20, 2020

Maybe the FlexiBLAS project ( https://github.com/mpimd-csc/flexiblas ) helps with this as well as issue #595 .

@ViralBShah
Copy link
Member

ViralBShah commented Oct 31, 2020

@gramian Does FlexiBLAS work with Windows too? I have been reading a bit more about it - and I always wished something like this existed. Thanks for putting it together. We probably want to get it working in BinaryBuilder and then bring it into the Julia source build.

Also, the README for FlexiBLAS suggests that it needs to use the reference LAPACK - unless I misread it. So, does it not use the LAPACK from MKL or patched LAPACK from OpenBLAS?

@ViralBShah ViralBShah reopened this Oct 31, 2020
@ViralBShah ViralBShah changed the title Experiment with switching BLAS backends via symlinks Use FlexiBLAS to switch between BLAS and LAPACK at runtime. Oct 31, 2020
@ViralBShah ViralBShah changed the title Use FlexiBLAS to switch between BLAS and LAPACK at runtime. Use FlexiBLAS to pick a BLAS and LAPACK at runtime. Oct 31, 2020
@gramian
Copy link

gramian commented Oct 31, 2020

Hi,
first of all, I am a mere contributor, and I guess we should add the lead developer @grisuthedragon to this discussion.
As far as I know, FlexiBLAS is not compatible to Windows, only to Linux and likely BSD. I am not sure if the WSL is changing the game in this regard.
In response to the LAPACK question:
FlexiBLAS provides the reference LAPACK functions as a fall-back in case the selected LAPACK implementation does not provide the called function. So, if for example MKL is set as FlexiBLAS backend, all MKL LAPACK functions are used.
If this can be misunderstood, we will update the README in this regard.
@grisuthedragon please correct me or expand if necessary.

@StefanKarpinski
Copy link
Member

We can't rely on WSL on Windows — anything we use has to work on Windows natively. However, BinaryBuilder allows us to cross-compile from Linux to any other platform, which can often be easier than getting something to compile on Windows using MSVC. So it might not be that hard to BinaryBuild FlexiBLAS for all platforms.

@ViralBShah
Copy link
Member

Things are going to also get a bit complicated on Macs with the new processors and the current state of Fortran.

@ViralBShah
Copy link
Member

Various flexiblas issues opened as part of my experimentation to see if we can adopt it: mpimd-csc/flexiblas#9, mpimd-csc/flexiblas#10, mpimd-csc/flexiblas#11

@ViralBShah
Copy link
Member

With LBT, we now have a solution in place for 1.7 onwards.

@KristofferC KristofferC transferred this issue from JuliaLang/julia Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants