Skip to content

BLD: Allow users to specify BLAS and LAPACK library link order#13132

Merged
rgommers merged 7 commits intonumpy:masterfrom
zerothi:linalg-order
May 1, 2019
Merged

BLD: Allow users to specify BLAS and LAPACK library link order#13132
rgommers merged 7 commits intonumpy:masterfrom
zerothi:linalg-order

Conversation

@zerothi
Copy link
Copy Markdown
Contributor

@zerothi zerothi commented Mar 15, 2019

Prior to this enhancement compiling numpy would forcefully check BLAS/LAPACK
libraries in the following order:

BLAS:

  • mkl
  • blis
  • openblas
  • atlas
  • accelerate
  • NetLIB BLAS

LAPACK:

  • mkl
  • openblas
  • atlas
  • accelerate
  • NetLIB LAPACK

This is problematic if a user want to build using, say, OpenBLAS but MKL is installed.
Even populating the site.cfg correspondingly one would get a successful build, but
using MKL, if present.

The same applies to OpenBLAS vs. ATLAS etc.

Especially for developers this may be desirable to check performance with various
BLAS/LAPACK libraries.

This fixes the above issues by enabling users to forcefully set the order of loads
via environment variables:

$> export NUMPY_BLAS_ORDER=openblas,mkl,atlas
$> python setup.py config ...

would first try OpenBLAS (if existing), then MKL, and finally ATLAS.
In this case the build would fail if neither of OpenBLAS, MKL or ATLAS is present.
I.e. this can also be easierly used to test whether a linking would work. This
is because specifying a single library forces only one library check and has
no fall-back procedure (as requested by the user!).

The same applies to:

NUMPY_LAPACK_ORDER=openblas,mkl,atlas

This has meant that the blas_opt_info and lapack_opt_info classes in
system_info.py has completely changed.

Effectively there is only ONE change:

A fall-back of LAPACK was previously using get_info('blas') to get
the BLAS library to correctly link LAPACK. However, this may be undesirable
when the user has OpenBLAS/BLIS/ATLAS in a BLAS only installation but wants
to use the NetLIB LAPACK. Hence now lapack_opt_info uses get_info('blas_opt')
which does change the fall-back routine slightly. But perhaps for an easier build?

@zerothi
Copy link
Copy Markdown
Contributor Author

zerothi commented Mar 15, 2019

I would be happy to create a test, but it seems extremely build specific and probably difficult in a testing environment?

Do you have a CI just for testing python setup.py config commands?

Also, sorry I created a commit with ENH, it should have been BLD, I would be happy to change this if so desired. (this PR however has the correct BLD prefix).

@tylerjereddy
Copy link
Copy Markdown
Contributor

The same applies to OpenBLAS vs. ATLAS etc.

Does it? ATLAS=None should do the trick, right?

We can also do BLAS=None and LAPACK=None. I'm not saying those solve all problems, but curious as to why they aren't discussed in context above re: circumventing backends you don't want to use for building.

@rgommers
Copy link
Copy Markdown
Member

I would be happy to create a test, but it seems extremely build specific and probably difficult in a testing environment?

Yeah, it's not really testable on CI. If it passes our existing CI (which uses OpenBLAS and lapack_lite IIRC) and some local testing by devs, then it's fine.

Do you have a CI just for testing python setup.py config commands?

There's a few things in numpy/distutils/tests/test_system_info.py, but nothing for BLAS/LAPACK currently. I don't think there's much you could test (easily) there, except perhaps that NPY_LAPACK_ORDER is handled correctly.

Also, sorry I created a commit with ENH, it should have been BLD, I would be happy to change this if so desired. (this PR however has the correct BLD prefix).

No worries. It is ENH anyway arguably, it's a distutils enhancement.

@rgommers
Copy link
Copy Markdown
Member

The two CI failures are the same - lapack_lite build not handled.

Building with BLAS=None LAPACK=None ATLAS=None should still work.

@rgommers
Copy link
Copy Markdown
Member

Actually, checking that any of BLAS, LAPACK, ATLAS work still when set explicitly would also be good.

@zerothi
Copy link
Copy Markdown
Contributor Author

zerothi commented Mar 15, 2019

The same applies to OpenBLAS vs. ATLAS etc.

Does it? ATLAS=None should do the trick, right?

Only if MKL is not installed.

We can also do BLAS=None and LAPACK=None. I'm not saying those solve all problems, but curious as to why they aren't discussed in context above re: circumventing backends you don't want to use for building.

Agreed, it is probably more meant as a developer thing. And it would also be way easier to have system installed BLAS/LAPACK versions and letting users control this without complicated mixtures of ATLAS=None MKL=None BLIS=None ....

This PR tries to streamline this in a unified way. A second benefit is that the blas/lapack_opt_info's restructure makes it a bit easier to add new libraries.

@zerothi
Copy link
Copy Markdown
Contributor Author

zerothi commented Mar 15, 2019

Actually, checking that any of BLAS, LAPACK, ATLAS work still when set explicitly would also be good.

I'll have another look during next week!

Thanks for both your comments!

@charris charris changed the title BLD: allowed external users to select BLAS and LAPACK library link order BLD: Allow users to specify BLAS and LAPACK library link order Mar 16, 2019
@rgommers rgommers added this to the 1.17.0 release milestone Mar 18, 2019
zerothi added 3 commits March 18, 2019 21:27
Prior to this enhancement compiling numpy would forcefully check BLAS/LAPACK
libraries in the following order:

BLAS:
- mkl
- blis
- openblas
- atlas
- accelerate
- NetLIB BLAS

- LAPACK
- mkl
- openblas
- atlas
- accelerate
- NetLIB LAPACK

This is problematic if a user want to build using, say, OpenBLAS but MKL is installed.
Even populating the site.cfg correspondingly one would get a successfull build, but
using MKL, if present.

The same applies to OpenBLAS vs. ATLAS etc.

Especially for developers this may be desirable to check performance with various
BLAS/LAPACK libraries.

This fixes the above issues by enabling users to forcefully set the order of loads
via environment variables:

  $> export NUMPY_BLAS_ORDER=openblas,mkl,atlas
  $> python setup.py config ...

would first try OpenBLAS (if existing), then MKL, and finally ATLAS.
In this case the build would fail if neither of OpenBLAS, MKL or ATLAS is present.
I.e. this can also be easierly used to test whether a linking would work. This
is because specifying a single library forces only one library check and has
no fall-back procedure (as requested by the user!).

The same applies to:

 NUMPY_LAPACK_ORDER=openblas,mkl,atlas

This has meant that the blas_opt_info and lapack_opt_info classes in
system_info.py has *completely* changed.

Effectively there is only ONE change:

A fall-back of LAPACK was previously using get_info('blas') to get
the BLAS library to correctly link LAPACK. However, this may be undesirable
when the user has OpenBLAS/BLIS/ATLAS in a BLAS only installation but wants
to use the NetLIB LAPACK. Hence now lapack_opt_info uses get_info('blas_opt')
which does change the fall-back routine slightly. But perhaps for an easier build?

Signed-off-by: Nick Papior <[email protected]>
Also added a test to travis (apparently ATLAS=None... is not tested
on circleCI).

Signed-off-by: Nick Papior <[email protected]>
When a user requests NPY_BLAS/LAPACK_ORDER they can omit Netlib
BLAS/LAPACK. In that case there will not be raised anything.
This commit fixes this issue so that there will always be
issues raised if the user hasn't requested the basic libraries.

Signed-off-by: Nick Papior <[email protected]>
@zerothi
Copy link
Copy Markdown
Contributor Author

zerothi commented Mar 18, 2019

@rgommers regarding the lapack_lite fail, it seems that this is due to a missing source in f2c_[cz]_lapack.c source? Or am I missing something completely? I.e. it seems not to have anything to do with my changes? I can't see why suddenly a missing name zungqr_ should stem from my changes?

Also do you prefer NPY_LAPACK or NPY_LAPACK_ORDER? The former could also be used since it is not taken, and 2ndly because the value may be a single value or a comma-separated list?

@charris
Copy link
Copy Markdown
Member

charris commented Mar 18, 2019

I see zungqr_ in numpy/linalg/lapack_lite/f2c_z_lapack.c.

@zerothi
Copy link
Copy Markdown
Contributor Author

zerothi commented Mar 18, 2019

@charris oh yeah, there it was! 👍

I will fix the bug (in my code ;) )!

@rgommers
Copy link
Copy Markdown
Member

Also do you prefer NPY_LAPACK or NPY_LAPACK_ORDER? The former could also be used since it is not taken, and 2ndly because the value may be a single value or a comma-separated list?

I don't have strong feelings on that one either way. However, does it make sense for it to be a single value given that we already have LAPACK for that?

@zerothi
Copy link
Copy Markdown
Contributor Author

zerothi commented Mar 19, 2019

Yes and no, if people want the control its main usage will probably be single value uses. Only in special cases can I see that users want to use it multi-value.
Also this value does not reflect any linking step as it is a value equal to the name of the library. So perhaps it is fine to have it as it is now.

You'll also note I have amended the build documentation a bit which I think clarifies its use.

@zerothi
Copy link
Copy Markdown
Contributor Author

zerothi commented Mar 19, 2019

I think this is ready, I think it is fine to keep the names as is. :)

@mattip mattip requested a review from rgommers April 26, 2019 23:27
Copy link
Copy Markdown
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to do some testing, but want to submit my comments already.

@mattip mattip requested a review from rgommers April 30, 2019 11:29
Copy link
Copy Markdown
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the __doc__ or '' fix, nice and compact.

This all looks good. With distutils it's always hard to be really sure, but let's merge it and see how it does. Nice improvement overall.

@rgommers rgommers merged commit 0f19dae into numpy:master May 1, 2019
@rgommers
Copy link
Copy Markdown
Member

rgommers commented May 1, 2019

Merged, thanks @zerothi. And thanks @mattip for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants