BLAS libraries on macOS

44 views
Skip to first unread message

Marc Culler

unread,
May 8, 2025, 6:26:33 PMMay 8
to sage-release
Sage specifies openBLAS as a dependency for several packages, but some of them do not use it anymore.  This is because they have an automated process for selecting which BLAS library to use, and that process selects the BLAS from Apple's Accelerate.framework. The list of packages to which this applies includes numpy and suitesparse.  On the other hand, Sage's scipy package selects openblas.

These packages allow overriding the automatic BLAS selection. But Sage does not do that.

There are bugs in the Accelerate.framework which have not been fixed.  The ones that I know about involve some BLAS functions which produce a scalar value, including the dot product.  When those functions are called in single-precision mode, Apple produces a double-precision result.  This can cause segfaults.  But apparently the numpy project and others have figured out a way to work around these bugs, or are choosing to ignore them.

Lastly, the openblas spkg creates a library that is more than twice as large as necessary on macOS.  OpenBLAS has an option for dynamic kernel selection, meaning that it detects which CPU it is running on and at runtime links in a kernel module which is optimized for the current CPU.  By default it builds kernels for many Intel and AMD CPU families.  But this is wasteful on macOS since about half of the kernels are for AMD CPUs and no model of Apple computer ever used an AMD CPU.  It is possible to provide a list of which CPU families to build kernels for.  But Sage does not do that.

- Marc

Dima Pasechnik

unread,
May 8, 2025, 7:17:58 PMMay 8
to sage-release

I am working on enabling the use of Accelerate framework as an option for macOS build, see

 
https://github.com/sagemath/sage/issues/40051

help is most welcome.

The current issue is to either write our own blas.pc (cblas.pc and lapack.pc will be basically copies of the latter) file to allow detention of Accelerate via pkg-config (I tried to avoid it, but it seems nontrivial).
Anyhow on this issue one can find a draft set of patches allowing all the required, and at least some optional, packages, to be built.


As well, it is more work to retain the ability to use openblas on macOS via a configure option than just hardcode the use of Accelerate.

I'm travelling for a week starting late tomorrow, so I won't have an easy access to macOS or much time in the coming 10 days or so.


Dima


--
You received this message because you are subscribed to the Google Groups "sage-release" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-release...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sage-release/e42f2261-5a50-4183-9a44-e5babd33d0a4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages