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

numpy: make numpy find openblas from Homebrew #29056

Closed
mwageringel opened this issue Jan 20, 2020 · 23 comments
Closed

numpy: make numpy find openblas from Homebrew #29056

mwageringel opened this issue Jan 20, 2020 · 23 comments

Comments

@mwageringel
Copy link

For numpy to find Homebrew's openblas on macOS, this ticket adds an [openblas] section to numpy's site.cfg if Sage is using openblas. This is also what Homebrew's numpy formula does. See also the upstream site.cfg.example.

Before this ticket, numpy would use the macOS Accelerate framework instead of openblas, as can be seen from the logs:

  FOUND:
    extra_compile_args = ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers']
    extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
    define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)]

After:

  FOUND:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/Cellar/openblas/0.3.7/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]

This problem was previously discussed on sage-devel.

Depends on #29051
Depends on #29071
Depends on #29084

CC: @dimpase @mkoeppe

Component: packages: standard

Keywords: numpy, scipy

Author: Markus Wageringel

Branch/Commit: eed1d19

Reviewer: Matthias Koeppe

Issue created by migration from https://trac.sagemath.org/ticket/29056

@mwageringel
Copy link
Author

Commit: b840c8c

@mwageringel
Copy link
Author

Author: Markus Wageringel

@mwageringel
Copy link
Author

comment:1

In order to test this, one currently needs to force-link Homebrew's readline to /usr/local (#29000) and configure Sage with

./configure LDFLAGS="-L/usr/local/opt/openblas/lib" CPPFLAGS="-I/usr/local/opt/openblas/include" PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"

as openblas is keg-only.


New commits:

b840c8c29056: make numpy find openblas from Homebrew

@mwageringel
Copy link
Author

Branch: u/gh-mwageringel/29056

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2020

Branch pushed to git repo; I updated commit sha1. New commits:

4d549f229056: fix block syntax

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2020

Changed commit from b840c8c to 4d549f2

@dimpase
Copy link
Member

dimpase commented Jan 22, 2020

comment:3

won't you be getting KeyError in the case of pkg-config not available (and so pkgconfig creating empty dicts)?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 25, 2020

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

052c06c29056: make numpy find openblas from Homebrew

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 25, 2020

Changed commit from 4d549f2 to 052c06c

@mwageringel
Copy link
Author

comment:5

Replying to @dimpase:

won't you be getting KeyError in the case of pkg-config not available (and so pkgconfig creating empty dicts)?

Is pkg-config not always present, possibly by installing the pkgconf spkg? In any case, I changed the relevant line to account for the possibility of an empty dictionary:

-    if 'openblas' in pc_blas['libraries']:
+    if 'openblas' in pc_blas.get('libraries', []):

I have tested this on 9.1.beta1 both using openblas from Homebrew and from Sage and in each case both numpy and scipy find the correct openblas.

@dimpase
Copy link
Member

dimpase commented Jan 26, 2020

comment:6

could this be made dependent on #29051 ?

@mwageringel
Copy link
Author

comment:7

Of course. Let us postpone this then.

@mwageringel
Copy link
Author

Dependencies: #29051

@dimpase
Copy link
Member

dimpase commented Jan 26, 2020

comment:8

perhaps MacOS with pkg-config and openblas may be handled the same way as the "generic" systems by this script.

@mwageringel
Copy link
Author

comment:9

Replying to @dimpase:

perhaps MacOS with pkg-config and openblas may be handled the same way as the "generic" systems by this script.

You mean by removing the Darwin if-case? I tried that first, but for some reason it did not work, possibly because Numpy has the preference: OpenBLAS > Accelerate > BLAS/LAPACK.

This preference can be changed using the variables NPY_BLAS_ORDER/NPY_LAPACK_ORDER, but setting these in Numpy's spkg-install did not seem to help either.

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 29, 2020

comment:10

I would suggest to also add #29071, #29084 as prereqs

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 29, 2020

Changed branch from u/gh-mwageringel/29056 to u/mkoeppe/29056

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 29, 2020

Reviewer: Matthias Koeppe

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 29, 2020

Changed commit from 052c06c to eed1d19

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 29, 2020

comment:12

I've merged in the tickets mentioned above and tested using tox -e local-homebrew-macos-standard from #29104.


New commits:

06f46ebAdd blas to fflas_ffpack linked libraries so that openblas is picked up on Arch
eed1d19Merge branch 'u/arojas/make_fflas_ffpack_detect_and_use_system_openblas_on_arch' of git://trac.sagemath.org/sage into t/29056/29056

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 29, 2020

Changed dependencies from #29051 to #29051, #29071, #29084

@mwageringel
Copy link
Author

comment:14

Thank you.

@vbraun
Copy link
Member

vbraun commented Jan 31, 2020

Changed branch from u/mkoeppe/29056 to eed1d19

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

No branches or pull requests

4 participants