[Numpy-discussion] NumPy's BLAS library on macOS?

Jerry Morrison jerry.morrison+numpy at gmail.com
Wed Jul 7 19:23:24 EDT 2021


Got it!

*Summary:*
* Installing a numpy wheel (e.g. `pip install numpy==1.21.0`) uses its
embedded OpenBLAS on every platform that has a wheel.
  That OpenBLAS is always compiled with gcc/gfortran.
  In this case, `np.show_config()` reports `library_dirs =
['/usr/local/lib']` even though there's no libblas in that directory.

* Installing numpy from source (e.g. `pip install numpy==1.21.0 --no-binary
numpy)` looks for BLAS & LAPACK libraries at build time as influenced by
the environment vars NPY_BLAS_ORDER/NPY_LAPACK_ORDER or by the file
~/.numpy-site.cfg.
  On macOS, 'accelerate' is in the default search order after 'openblas'.
  On macOS < 11.3, importing numpy that's linked to Accelerate will detect
an Accelerate bug and raise a RuntimeError.

On Wed, Jul 7, 2021 at 1:32 PM Ralf Gommers <ralf.gommers at gmail.com> wrote:

>
>
> On Wed, Jul 7, 2021 at 9:56 PM Jerry Morrison <
> jerry.morrison+numpy at gmail.com> wrote:
>
>> Would someone please answer installation questions about NumPy's BLAS on
>> macOS? I'm not finding the answers in the release notes
>> <https://github.com/numpy/numpy/releases>, the PR
>> <https://github.com/numpy/numpy/pull/18874> source, the docs
>> <https://numpy.org/doc/1.21/>, or Stack Overflow
>> <https://stackoverflow.com/search?tab=newest&q=%5bnumpy%5d%20openblas>.
>>
>>
>> Q1. The NumPy 1.21.0 release note
>> <https://github.com/numpy/numpy/releases/tag/v1.21.0> says "This change
>> enables the Accelerate Framework as an option on macOS." How to set
>> that option on/off?
>>
>
> It's autodetected at build time. If you have no other BLAS installed, it
> will be used. Or explicitly select it with NPY_BLAS_ORDER/NPY_LAPACK_ORDER
>
>
>> Q2. How to determine if NumPy uses Accelerate vs. its internal copy of
>> OpenBLAS?
>> After installing a wheel, `numpy.show_config()` shows the openblas_info
>> library_dirs et al as '/usr/local/lib'. Neither '/usr/local/lib/' nor
>> 'site-packages/numpy/' contains a *blas*.so library (for Python 3.8.* on
>> macOS 10.14.6) but the doc <https://numpy.org/install/> says "The
>> OpenBLAS libraries are included in the wheel."
>>
>
> It's a build-time option, you cannot select it at runtime.
>
>
>> Q3. How to pip install NumPy 1.21.0 in a way that ensures it uses its
>> embedded OpenBLAS on macOS as on Linux? I'm aiming for as portable results
>> as possible. Or should we link NumPy to an external OpenBLAS via `pip
>> install numpy --no-binary numpy==1.21.0` with `~/.numpy-site.cfg`? (Ditto
>> for SciPy.)
>>
>
> If you install a wheel, you will always get the bundled OpenBLAS on every
> platform for which we have binary wheels.
>
>
>>
>> Q4. Can the new NPY_* environment variables select specific BLAS & LAPACK
>> libraries through pip install, and perhaps install faster than building
>> NumPy, SciPy, etc. from source? How to do that?
>>
>
> This question seems a little bit confused. Those env vars just select the
> BLAS/LAPACK library. It will not affect build time - we're never building
> BLAS or LAPACK itself from source.
>
>
>> Q5. Is NumPy's embedded OpenBLAS compiled by gcc or clang? Is that
>> controllable via `pip install`?
>>
>
> gcc/gfortran. and no, you cannot control it through pip
>
> Cheers,
> Ralf
>
>
>> Thank you!
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at python.org
>> https://mail.python.org/mailman/listinfo/numpy-discussion
>>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210707/8376a51c/attachment-0001.html>


More information about the NumPy-Discussion mailing list