Check BLAS Library Installed For NumPy

April 9, 2023 Concurrent NumPy

You can check which BLAS library is used by NumPy by calling numpy.show_config().

In this tutorial, you will discover how to check which BLAS library numpy is used on your system.

Let's get started.

Need to Know Which BLAS Library NumPy is Using

NumPy is an array library in Python.

It makes use of third-party libraries to perform array functions efficiently. One example is the BLAS and LAPACK specifications used by NumPy to execute vector, matrix, and linear algebra operations.

You can learn more about BLAS and LAPACK in the tutorial:

We may install one of many different libraries that implement the BLAS and LAPACK specifications.

Most libraries that implement BLAS also implement LAPACK because LAPACK is built on top of BLAS. Therefore, we often refer to them simply as BLAS libraries.

Different libraries will have different capabilities and may optimize for different use cases or hardware.

Practically, we need to know which BLAS library is installed so that we can configure the number of threads used for some linear algebra operations.

We may also need to know in order to check if perhaps the wrong library is installed for our system, e.g. optimize for Intel CPUs when the system uses AMD CPUs.

How can we check which BLAS library is installed and used by NumPy?

How to Check Which BLAS Library is Used By NumPy

There are two ways we can explore which BLAS library is installed and used by NumPy.

They are:

  1. Estimate based on how numpy was installed.
  2. Check the numpy configuration.

Let's take a look at each approach in turn.

Estimate From NumPy Installation Method

When NumPy is installed, it will typically install a BLAS library as a dependency.

It does this so that the numpy installation can be customized specifically for the BLAS library that is installed.

There are many ways to install numpy. We can review some of the more common methods used to install numpy and look at the default BLAS library installed for each.

  1. Pip: Installs OpenBLAS by default.
  2. Homebrew: Installs OpenBLAS by default.
  3. MacPorts: Installs OpenBLAS by default.
  4. Conda: Installs MKL by default.

You can learn more about installing NumPy and BLAS libraries here:

Check NumPy Configuration

An alternate and preferred way to check which BLAS library is installed and used by NumPy is to check the NumPy configuration directly.

Because when numpy is installed it is compiled against a specific BLAS library, it records the BLAS library it was compiled against. We can then check this configuration at run time.

This can be achieved by calling the numpy.show_config() function.

The function takes no arguments and reports details of the system on which your numpy library was built.

Show libraries in the system on which NumPy was built. Print information about various resources (libraries, library directories, include directories, etc.) in the system on which NumPy was built.

-- numpy.show_config API

Example of Checking the BLAS Library Used By NumPy

I installed NumPy on my current system using Homebrew.

This suggests that I am probably using OpenBLAS.

We can confirm this by checking their NumPy configuration directly.

The complete program is listed below.

# report the details of the blas library
import numpy
numpy.show_config()

Running this program on my system reports that indeed I am using the OpenBLAS library.

What BLAS library do you have installed?
Post your output in the comments below.

blas_armpl_info:
  NOT AVAILABLE
blas_mkl_info:
  NOT AVAILABLE
blis_info:
  NOT AVAILABLE
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/opt/openblas/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/opt/openblas/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_armpl_info:
  NOT AVAILABLE
lapack_mkl_info:
  NOT AVAILABLE
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/opt/openblas/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/opt/openblas/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
Supported SIMD extensions in this NumPy install:
    baseline = SSE,SSE2,SSE3
    found = SSSE3,SSE41,POPCNT,SSE42,AVX,F16C,FMA3,AVX2
    not found = AVX512F,AVX512CD,AVX512_KNL,AVX512_SKX,AVX512_CLX,AVX512_CNL,AVX512_ICL

Takeaways

You now know how to check which BLAS library numpy is used on your system.



If you enjoyed this tutorial, you will love my book: Concurrent NumPy in Python. It covers everything you need to master the topic with hands-on examples and clear explanations.