Skip to content

Tracker issue for BLIS support in NumPy #7372

Closed

Description

@njsmith

Here's a general tracker issue for discussion of BLIS support in NumPy. So far we've had some discussions of this in two nominally unrelated threads:

So this is a new issue to consolidate future discussions like this :-)

Some currently outstanding issues to highlight:

CC: @tkelman @matthew-brett @fgvanzee

Activity

  1. homocomputeris commented on Jul 2, 2018

    @homocomputeris

    I see that BLIS has been included to site.cfg.
    Can libFLAME be also supported?

  2. rgommers commented on Jul 2, 2018

    @rgommers
    Member

    The description at https://www.cs.utexas.edu/%7Eflame/web/libFLAME.html may need fixing, but from that it's not clear to me that libFLAME actually implements the LAPACK API.

  3. fgvanzee commented on Jul 2, 2018

    @fgvanzee

    @rgommers libflame does indeed provide netlib LAPACK APIs, and implementations for everything that libflame does not provide natively.

  4. fgvanzee commented on Jul 2, 2018

    @fgvanzee

    FWIW, BLIS has made significant strides since this issue was opened. For example, BLIS now implements runtime configuration, and its configure-time configuration has been reimplemented in terms of the runtime infrastructure. BLIS now offers integrated BLAS test drivers in addition to its more comprehensive testsuite. Library self-initialization is also in place, as is monolithic header generation (single blis.h instead of 500+ development headers), which makes management of the installed product easier. It also follows a more standardized library naming convention for its static and shared library builds, includes an soname. Finally, its build system is a lot smarter vis-a-vis checking for compiler and assembler compatibility. And that's just what I can think of off the top of my head.

  5. rgommers commented on Jul 2, 2018

    @rgommers
    Member

    @fgvanzee thanks. In that case I'm +1 to add support for it in numpy.distutils.

    I'm really short on time at the moment, so cannot work on this probably till September at least. If someone else wants to tackle this, it should be relatively straightforward (along the same lines as gh-7294). Happy to help troubleshoot / review.

  6. rgommers commented on Jul 2, 2018

    @rgommers
    Member

    That sounds like major progress. How far would you say are you from being a viable alternative to OpenBLAS for numpy/scipy (performance & stability wise)?

    (Note that we still don't have a scipy-openblas on Windows for conda due to the Fortran mess: https://github.com/conda-forge/scipy-feedstock/blob/master/recipe/meta.yaml#L14)

  7. tkelman commented on Jul 2, 2018

    @tkelman
    Contributor

    If you want a MSVC ABI compatible BLAS and LAPACK, there still aren't any easy, entirely open source options. Though nowadays with clang-cl and flang existing, the problem isn't compiler availability like it used to be, now it's build system flexibility and trying to use combinations that library authors have never evaluated or supported before. Ref flame/blis#57 (comment)

  8. fgvanzee commented on Jul 2, 2018

    @fgvanzee

    @rgommers I would say that BLIS is presently a quite viable alternative to OpenBLAS. It is viable enough that AMD has abandoned ACML and fully embraced BLIS as the foundation of their new open-source math library solution. (We have corporate sponsors, and have been sponsored by the National Science Foundation for many years in the past.)

    Performance-wise, the exact characterization will depend on the operation you're looking at, the floating-point datatype, the hardware, and the problem size range you're interested in. However, generally-speaking, BLIS typically meets or exceeds OpenBLAS's level-3 performance for all but the smallest problem sizes (less than 300 or so). It also employs a more flexible level-3 parallelization strategy than OpenBLAS is capable of (due to their monolithic assembly kernel design).

    Stability-wise, I would like to think that BLIS is quite stable. We try to be very responsive to bug reports, and thanks to a surge of interest from the community over the last five or so months we've been able to identify and fix a lot of issues (mostly build system related). This has smoothed out the user experience for end-users as well as package managers.

    Also, keep in mind that BLIS has provided (from day zero) a superset of BLAS-like functionality, and done so via two novel APIs separate and apart from the BLAS compatibility layer:

    • an explicitly typed BLAS-like API
    • an implicitly typed object-based API

    This not only supports legacy users who already have software that needs BLAS linkage, but provides a great toolbox for those interested in building custom dense linear algebra solutions from scratch--people who may not feel any particular affinity towards the BLAS interface.

    Born out of a frustration with the various shortcomings in both existing BLAS implementations as well as the BLAS API itself, BLIS has been my labor of love since 2012. It's not going anywhere, and will only get better. :)

  9. rgommers commented on Jul 2, 2018

    @rgommers
    Member

    Ah thanks @tkelman. Cygwin:(:(

    It would be interesting to hear some experiences from people using numpy compiled against BLIS on Linux/macOS though.

    Thanks for the context @fgvanzee. Will be interesting for us to add libFLAME support and try on the SciPy benchmark suite.

  10. fgvanzee commented on Jul 2, 2018

    @fgvanzee

    @rgommers Re: libflame: Thanks for your interest. Just be aware that libflame could use some TLC; it's not in quite as good of shape as BLIS. (We don't have the time/resources to support it as we would like, and almost 100% of our attention over the last six years has been focused on getting BLIS to a place where it could become a viable and competitive alternative to OpenBLAS et al.)

    At some point, once BLIS matures and our research avenues have been exhausted, we will likely turn our attention back to libflame/LAPACK-level functionality (Cholesky, LU, QR factorizations, for example). This may take the form of incrementally adding those implementations to BLIS, or it may involve an entirely new project to eventually replace libflame. If it is the latter, it will be designed to take advantage of lower-level APIs in BLIS, thus avoiding some function call and memory copy overhead that is currently unavoidable via the BLAS. This is just one of many topics we look forward to investigating.

  11. homocomputeris commented on Jul 2, 2018

    @homocomputeris

    I've run the benchmark from this article with NumPy 1.15 and BLIS 0.3.2 on an Intel Skylake without multithreading (I had a hardware instruction error with HT):

    Dotted two 4096x4096 matrices in 4.29 s.
    Dotted two vectors of length 524288 in 0.39 ms.
    SVD of a 2048x1024 matrix in 13.60 s.
    Cholesky decomposition of a 2048x2048 matrix in 2.21 s.
    Eigendecomposition of a 2048x2048 matrix in 67.65 s.
    

    Intel MKL 2018.3:

    Dotted two 4096x4096 matrices in 2.09 s.
    Dotted two vectors of length 524288 in 0.23 ms.
    SVD of a 2048x1024 matrix in 1.11 s.
    Cholesky decomposition of a 2048x2048 matrix in 0.19 s.
    Eigendecomposition of a 2048x2048 matrix in 7.83 s.
    
  12. fgvanzee commented on Jul 2, 2018

    @fgvanzee

    Dotted two 4096x4096 matrices in 4.29 s.

    @homocomputeris Sorry, I've never heard the "dot" verb used to describe an operation on two matrices before. Is that a matrix multiplication?

  13. njsmith commented on Jul 2, 2018

    @njsmith
    MemberAuthor

    @fgvanzee What is the status of Windows support in BLIS these days? I remember getting it to build on Windows used to be mostly unsupported...

  14. 71 remaining items

  15. njsmith commented on Jul 18, 2018

    @njsmith
    MemberAuthor

    The BLAS G2 proposal has some consideration of double-double and "reproducible" computations in BLAS. (Reproducible here means deterministic across implementations, but IIUC also involves using higher-precision intermediate values.)

  16. honnibal commented on Jul 18, 2018

    @honnibal

    Excited to see this moving forward!

    For the record, I'm the one @njsmith was referring to who's been interested in controlling the threading from software. My workloads are embarrassingly parallel at prediction time, and my matrix multiplications are relatively small. So I'd rather parallelise larger units of work.

    I did some work about a year ago on packaging Blis for PyPi, and adding Cython bindings: https://github.com/explosion/cython-blis

    I found Blis quite easy to package as a C extension like this. The main stumbling block for me was Windows support. From memory, it was C99 issues, but I might be remembering wrongly.

    The Cython interface I've added might be of interest. In particular, I'm using Cython's fused types so that there's a single nogil function that can be called with either a memory-view or a raw pointer, for both the float and double types. Adding more branches for more types is no problem either. Fused types are basically templates: they allow compile-time conditional execution, for zero overhead.

    I would be very happy to maintain a stand-alone Blis package, keep the wheels built, maintain a nice Cython interface, etc. I think it would be very nice to have it as a separate package, rather than something integrated within numpy. We could then expose more of Blis's API, without being limited by what other BLAS libraries support.

  17. fgvanzee commented on Jul 31, 2018

    @fgvanzee

    @honnibal Sorry for the delay in responding on this thread, Matthew.

    Thanks for your message. We're always happy to see others get excited about BLIS. Of course, we would be happy to advise whenever is needed if you decided to further integrate into the python ecosystem (an application, a library, module, etc.).

    As for Windows support, please check out the clang/appveyor support for the Windows ABI that @isuruf recently added. Last I heard from him, it was working as expected, but we don't do any development on Windows here at UT so I can't keep tabs on this myself. (Though Isuru pointed out to me once that I could sign up for appveyor in a manner similar to Travis CI.)

    Also, please let me know if you have any questions about the per-call threading usage. (I've updated our Multithreading documentation to cover this topic.)

  18. fgvanzee commented on Apr 1, 2019

    @fgvanzee

    As of BLIS 0.5.2, we have a Performance document that showcases single-threaded and multithreaded performance of BLIS and other implementations of BLAS for a representative set of datatypes and level-3 operations on a variety of many-core architectures, including Marvell ThunderX2, Intel Skylake-X, Intel Haswell, and AMD Epyc.

    So if the numpy community is wondering how BLIS stacks up against the other leading BLAS solutions, I invite you to take a quick peek!

  19. rgommers commented on Apr 2, 2019

    @rgommers
    Member

    Very interesting, thanks @fgvanzee.

    I had to look up Epyc - seems that that is a brand name based on the Zen (possibly updated to Zen+ at some point?) architecture. Perhaps better to rename to Zen? For our user base Ryzen/Threadripper are the more interesting brands, they may recognize Zen but probably not Epyc.

  20. jeffhammond commented on Apr 2, 2019

    @jeffhammond

    Epyc is the name of the AMD server line. It is the successor to the AMD Opteron products of the past.

    There is, unfortunately, no unique way for BLIS to label its architectural targets, because the code depends on the vector ISA (e.g. AVX2), the CPU core microarchitecture (e.g. Ice Lake) and the SOC/platform integration (e.g. Intel Xeon Platinum processor). BLIS uses microarchitecture code names in some cases (e.g. Dunnington) but that isn't better for everyone.

    @fgvanzee You might consider adding the aliases that correspond to the GCC march/mtune/mcpu names...

  21. fgvanzee commented on Apr 2, 2019

    @fgvanzee

    @rgommers The subconfiguration within BLIS that covers Ryzen and Epyc is actually already named zen, as it captures both products.

    As for whether Ryzen/Threadripper or Epyc are more interesting brands (even to numpy users), I'll say this: if I could only benchmark one AMD Zen system, it would be the highest-end Epyc, because: (a) it uses a similar microarchitecture to that of Ryzen; (b) it gives me the maximum 64 physical cores (and, as a bonus, those cores are arranged in a somewhat novel, NUMA-like configuration); which (c) places maximal stress on BLIS and the other implementations. And that is basically what we did here.

    Now, thankfully, there is no rule saying I can only benchmark one Zen system. :) However, there are other hurdles, particularly with regards to gaining access in the first place. I don't have access to any Ryzen/Threadripper systems at the moment. If/when I do gain access, I'll be happy to repeat the experiments and publish the results accordingly.

    Jeff points out some of the naming pitfalls we face. Generally, we name our subconfigurations and kernel sets in terms of microarchitecture, but there is more nuance yet. For example, we use our haswell subconfiguration on Haswell, Broadwell, Skylake, Kaby Lake, and Coffee Lake. That's because they all basically share the same vector ISA, which is pretty much all the BLIS kernel code cares about. But that is an implementation detail that almost no users need to be concerned with. If you use ./configure auto, you will almost always get the best subconfiguration and kernel set for your system, whether they are named zen or haswell or whatever. For now, you still need to take a more hands-on approach when it comes to optimally choosing your threading scheme, and that's where the SoC/platform integration that Jeff mentions comes in.

    @jeffhammond Thanks for your suggestion. I've considered adding those aliases in the past. However, I'm not convinced it's worth it. It will add significant clutter to the configuration registry, and the people who will be looking at it in the first place likely already know about our naming scheme for subconfigurations and kernel sets, and thus won't be confused by the absence of certain microarchitectural revision names in that file (or in the config directory). Now, if BLIS required manual identification of subconfiguration, via ./configure haswell for example, then I think the scales definitely tip in favor of your proposal. But ./configure auto works quite well, so I don't see the need at this time. (If you like, you can open an issue on this topic so we can start a wider discussion among community members. I'm always open to changing my mind if there is sufficient demand.)

  22. rgommers commented on Apr 3, 2019

    @rgommers
    Member

    yes, naming is always complicated:) thanks for the answers @fgvanzee and @jeffhammond

  23. homocomputeris commented on May 16, 2019

    @homocomputeris

    #13132 and #13158 are related

  24. rth commented on Aug 30, 2019

    @rth
    Contributor

    The discussion got a bit carried away; what are the remaining issues that need to be resolved to officially support BLIS in numpy?

    Naively, I tried to run numpy tests with BLIS from conda-forge (cf #14180 (comment) ) and for me, on Linux, all tests passed (but maybe I missed something).

    Also tried to run test scipy test suite in the same env and there are a number of failures in scipy.linalg (cf scipy/scipy#10744) in case someone has comments on that.

  25. isuruf commented on Aug 30, 2019

    @isuruf
    Contributor

    Note that BLIS from conda-forge uses ReferenceLAPACK (netlib) as the LAPACK implementation which uses BLIS as the BLAS implementation and not libflame.

  26. echuber2 commented on Oct 2, 2020

    @echuber2

    About the BLIS option on conda-forge, am I right that it's single-threaded out of the box (unlike the OpenBLAS option)?

  27. jakirkham commented on Oct 2, 2020

    @jakirkham
    Contributor

    Probably better to move conda-forge discussions to conda-forge 🙂

  28. rgommers commented on Jan 6, 2022

    @rgommers
    Member

    We have had BLIS support in numpy.distutils for several years now. Conda-forge has the option to use BLIS at runtime, and we have thorough testing results for NumPy and SciPy that shows the full test suite passes with BLIS on multiple platforms:

    There's some discussion in this issue about control of threading - we decided not to deal with that in numpy directly, that's what threadpoolctl is for.

    I don't think there's anything left to do here. BLIS status is good. So I think we can close this issue and declare victory here.

    libflame is another story of course - there's some info on that in this issue, but I think that deserves its own tracking issue if we want to consider it. https://github.com/flame/libflame seems to have no new commits since May 2019, so it's unclear whether or not we need to actively look at it. It should be possible to build against libflame with a site.cfg right now, and auto-detection can always be added later (it's not hard).

    Thanks everyone for the long and interesting conversation.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions