Skip to main content

('The Blis BLAS-like linear algebra library, as a self-contained C-extension.',)

Project description

This repository provides the Blis linear algebra routines as a self-contained Python C-extension.

Currently, we only supports single-threaded execution, as this is actually best for our workloads (ML inference).

Build Status Build Status pypi Version

Overview

You can install the package via pip:

pip install blis

Wheels should be available, so installation should be fast. If you want to install from source and you’re on Windows, you’ll need to install LLVM.

After installation, run a small matrix multiplication benchmark:

$ export OMP_NUM_THREADS=1 # Tell Numpy to only use one thread.
$ python -m blis.benchmark
Setting up data nO=384 nI=384 batch_size=2000. Running 1000 iterations
Blis...
Total: 11032014.6484
7.35 seconds
Numpy (Openblas)...
Total: 11032016.6016
16.81 seconds
Blis einsum ab,cb->ca
8.10 seconds
Numpy einsum ab,cb->ca
Total: 5510596.19141
83.18 seconds

The low numpy.einsum performance is expected, but the low numpy.dot performance is surprising. Linking numpy against MKL gives better performance:

Numpy (mkl_rt) gemm...
Total: 11032011.71875
5.21 seconds

These figures refer to performance on a Dell XPS 13 i7-7500U. Running the same benchmark on a 2015 Macbook Air gives:

Blis...
Total: 11032014.6484
8.89 seconds
Numpy (Accelerate)...
Total: 11032012.6953
6.68 seconds

Clearly the Dell’s numpy+OpenBLAS performance is the outlier, so it’s likely something has gone wrong in the compilation and architecture detection.

Usage

Two APIs are provided: a high-level Python API, and direct Cython access. The best part of the Python API is the einsum function, which works like numpy’s, but with some restrictions that allow a direct mapping to Blis routines. Example usage:

from blis.py import einsum
from numpy import ndarray, zeros

dim_a = 500
dim_b = 128
dim_c = 300
arr1 = ndarray((dim_a, dim_b))
arr2 = ndarray((dim_b, dim_c))
out = zeros((dim_a, dim_c))

einsum('ab,bc->ac', arr1, arr2, out=out)
# Change dimension order of output
out = einsum('ab,bc->ca', arr1, arr2)
assert out.shape == (dim_a, dim_c)
# Matrix vector product, with transposed output
arr2 = ndarray((dim_b,))
out = einsum('ab,b->ba', arr1, arr2)
assert out.shape == (dim_b, dim_a)

The Einstein summation format is really awesome, so it’s always been disappointing that it’s so much slower than equivalent calls to tensordot in numpy. The blis.einsum function gives up the numpy version’s generality, so that calls can be easily mapped to Blis:

  • Only two input tensors

  • Maximum two dimensions

  • Dimensions must be labelled a, b and c

  • The first argument’s dimensions must be 'a' (for 1d inputs) or 'ab' (for 2d inputs).

With these restrictions, there are ony 15 valid combinations – which correspond to all the things you would otherwise do with the gemm, gemv, ger and axpy functions. You can therefore forget about all the other functions and just use the einsum. Here are the valid einsum strings, the calls they correspond to, and the numpy equivalents:

Equation

Maps to

Numpy

'a,a->a'

axpy(A, B)

A+B

'a,b->ab'

ger(A, B)

outer(A, B)

'a,b->ba'

ger(B, A)

outer(B, A)

'ab,a->ab'

batch_axpy(A, B)

A*B

'ab,a->ba'

batch_axpy(A, B, trans1=True)

(A*B).T

'ab,b->a'

gemv(A, B)

A*B

'ab,a->b'

gemv(A, B, trans1=True)

A.T*B

'ab,ac->bc'

gemm(A, B, trans1=True, trans2=False)

dot(A.T, B)

'ab,ac->cb'

gemm(B, A, trans1=True, trans2=True)

dot(B.T, A)

'ab,bc->ac'

gemm(A, B, trans1=False, trans2=False)

dot(A, B)

'ab,bc->ca'

gemm(B, A, trans1=False, trans2=True)

dot(B.T, A.T)

'ab,ca->bc'

gemm(A, B, trans1=True, trans2=True)

dot(B, A.T)

'ab,ca->cb'

gemm(B, A, trans1=False, trans2=False)

dot(B, A)

'ab,cb->ac'

gemm(A, B, trans1=False, trans2=True)

dot(A.T, B.T)

'ab,cb->ca'

gemm(B, A, trans1=False, trans2=True)

dot(B, A.T)

We also provide fused-type, nogil Cython bindings to the underlying Blis linear algebra library. Fused types are a simple template mechanism, allowing just a touch of compile-time generic programming:

cimport blis.cy
A = <float*>calloc(nN * nI, sizeof(float))
B = <float*>calloc(nO * nI, sizeof(float))
C = <float*>calloc(nr_b0 * nr_b1, sizeof(float))
blis.cy.gemm(blis.cy.NO_TRANSPOSE, blis.cy.NO_TRANSPOSE,
             nO, nI, nN,
             1.0, A, nI, 1, B, nO, 1,
             1.0, C, nO, 1)

Bindings have been added as we’ve needed them. Please submit pull requests if the library is missing some functions you require.

Development

To build the source package, you should run the following command:

./bin/copy-source-files.sh

This populates the blis/_src folder for the various architectures, using the flame-blis submodule.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blis-0.2.4.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

blis-0.2.4-cp37-cp37m-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.7m Windows x86-64

blis-0.2.4-cp37-cp37m-manylinux1_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.7m

blis-0.2.4-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.7m macOS 10.10+ Intel (x86-64, i386) macOS 10.10+ x86-64 macOS 10.6+ Intel (x86-64, i386) macOS 10.9+ Intel (x86-64, i386) macOS 10.9+ x86-64

blis-0.2.4-cp36-cp36m-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.6m Windows x86-64

blis-0.2.4-cp36-cp36m-manylinux1_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.6m

blis-0.2.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.6m macOS 10.10+ Intel (x86-64, i386) macOS 10.10+ x86-64 macOS 10.6+ Intel (x86-64, i386) macOS 10.9+ Intel (x86-64, i386) macOS 10.9+ x86-64

blis-0.2.4-cp35-cp35m-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.5m Windows x86-64

blis-0.2.4-cp35-cp35m-manylinux1_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.5m

blis-0.2.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.5m macOS 10.10+ Intel (x86-64, i386) macOS 10.10+ x86-64 macOS 10.6+ Intel (x86-64, i386) macOS 10.9+ Intel (x86-64, i386) macOS 10.9+ x86-64

blis-0.2.4-cp27-cp27mu-manylinux1_x86_64.whl (3.2 MB view details)

Uploaded CPython 2.7mu

blis-0.2.4-cp27-cp27m-manylinux1_x86_64.whl (3.2 MB view details)

Uploaded CPython 2.7m

blis-0.2.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.0 MB view details)

Uploaded CPython 2.7m macOS 10.10+ Intel (x86-64, i386) macOS 10.10+ x86-64 macOS 10.6+ Intel (x86-64, i386) macOS 10.9+ Intel (x86-64, i386) macOS 10.9+ x86-64

File details

Details for the file blis-0.2.4.tar.gz.

File metadata

  • Download URL: blis-0.2.4.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for blis-0.2.4.tar.gz
Algorithm Hash digest
SHA256 2d4ca1508fd6229c7994fc17ba324083a5b83f66612c8ea62623a41a1768b030
MD5 48a11b3373b129a9dd0c68c06fd90b51
BLAKE2b-256 599e84a83616cbe5daa94909da38b780e93bf566dc2113c3dc35d7b4cad52f63

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: blis-0.2.4-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for blis-0.2.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 51a54bad6175e9b154beeb628a879ed492ee2247c9e40c77bdf6fc772145130c
MD5 7d7ead81640f930a9a974f4bc57ceddb
BLAKE2b-256 5e949da0eff97411b3e85933e8b955d2ffd353f97b65372a2861e57d59d9ad5d

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: blis-0.2.4-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for blis-0.2.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b9d6cef13d95e3752320cd942df25e09160a6f9dfc3d7b41af7cdc772ab18270
MD5 92d57d9b1784d343e3c71e2876eaae70
BLAKE2b-256 fa5f47b7b29ad202b2210020e2f33bfb06d1db2abe0e709c2a84736e8a9d1bd5

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for blis-0.2.4-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 039129410a338be8db8cf48c54334bd7c30da7e72bad2741e59313b1d242814b
MD5 b1b62ea1830e4cc5e8e004e572381ee0
BLAKE2b-256 36419e934e2b8a2cdae447ed1923a94f98c2d70c898b65af6635f5fe55f7ed4d

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: blis-0.2.4-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for blis-0.2.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 a54d4fa1908d586f8bce9851a453cb89d1542e9aca65b8b88e9bb9432d626f80
MD5 7ad292ff5f79f2ed44b8adce7a507881
BLAKE2b-256 840e35f8ce00fc3412aa3a888a3d8e040c4c65ccbad8310aa2981d3e6f379867

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: blis-0.2.4-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for blis-0.2.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 886b313f96d4e268a0587e98c1637d963c73defa8de51e2e6b0d0bd00f16afbb
MD5 3d2d85e54c8726e797e5a4edf9c59029
BLAKE2b-256 3446b1d0bb71d308e820ed30316c5f0a017cb5ef5f4324bcbc7da3cf9d3b075c

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for blis-0.2.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 058f9109aaea9d4f88cb623a44994d96c8cf36448de3e1bd30210628d6b52e9e
MD5 909db0948491ae41ce75adf8971aa87a
BLAKE2b-256 d19284e017b19d988c55ef2e6fa50e51522f3a23a6461ef21f308d20b19dbe0c

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: blis-0.2.4-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for blis-0.2.4-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 e6ae1986625af86f90f111f9d2d284b9e45fddfe56cf40524cdd9417a6a33b87
MD5 6bfb2758cebe660176769d2b2fb866f8
BLAKE2b-256 9976d8317d20a20d8f9afbbf0f9d167d4260ade12939ffb8f90cbae5a01a66d4

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: blis-0.2.4-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for blis-0.2.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d616d64c85e6be92d69a1410dc58146cb9603fd1eb148f9ee512b8fddfd789f6
MD5 c2cc65cf6817711df8f01539f374424f
BLAKE2b-256 f978ce96dfd9daee07023e2d47bbfd98e13a0e753f92a9bd8bc36fb47ddf9bbd

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for blis-0.2.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 e477c7eaacf7dcccbb190a29559579efb287ecf5c2a9a7a6f9acb0452899f033
MD5 a7c74e8b58a9e961a23dab84b61bfb88
BLAKE2b-256 299a214052f54d21ada1ae03a8b6687c044fff90176254ea8600bf539a77b71e

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

  • Download URL: blis-0.2.4-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 2.7mu
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for blis-0.2.4-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9f12e6f1e4b10dbb1e0e34e98f60e8435058a60d544a009cb761351fe1d12cad
MD5 78e218e3aae24753730fbd00f950c88d
BLAKE2b-256 61b76f32b1e2506937525802d94136eb73dec2cacd4a21c9bec9c90549e2b413

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

  • Download URL: blis-0.2.4-cp27-cp27m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: CPython 2.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for blis-0.2.4-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d571464d195a950e60bf1547c8914d4da50952e06a0f38cea7b0829d0a4b985a
MD5 c643bfd5b548c3a20851decc13e42516
BLAKE2b-256 a70cbb2531bc095d08e6c7392ffdb9cf17372e807448434d14066824fb684916

See more details on using hashes here.

File details

Details for the file blis-0.2.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for blis-0.2.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 278d7b95e56cf82a6bef91cd8283eadc9401f2d3bdbbf2cdfdb605cf9081c36e
MD5 3546aa6ca32fb3aedac314b44ad027e3
BLAKE2b-256 20a67561a69dfb20e8ba5e63abc763b44e793e61d3dc858fdbed31f875a0a5b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page