Skip to main content

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

Project description

Cython BLIS: Fast BLAS-like operations from Python and Cython, without the tears

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).

tests pypi Version conda Python wheels

Installation

You can install the package via pip, first making sure that pip, setuptools, and wheel are up-to-date:

pip install -U pip setuptools wheel
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.

Building BLIS for alternative architectures

The provided wheels should work on x86_64 and osx/arm64 architectures. Unfortunately we do not currently know a way to provide different wheels for alternative architectures, and we cannot provide a single binary that works everywhere. So if the wheel doesn't work for your CPU, you'll need to specify source distribution, and tell Blis your CPU architecture using the BLIS_ARCH environment variable.

a) Install with auto-detected CPU support

pip install spacy --no-binary blis

b) Install using an existing configuration

Provide an architecture from the supported configurations.

BLIS_ARCH="power9" pip install spacy --no-binary blis

c) Install with generic arch support

⚠️ generic is not optimized for any particular CPU and is extremely slow. Only recommended for testing!

BLIS_ARCH="generic" pip install spacy --no-binary blis

d) Build specific support

In order to compile Blis, cython-blis bundles makefile scripts for specific architectures, that are compiled by running the Blis build system and logging the commands. We do not yet have logs for every architecture, as there are some architectures we have not had access to.

See here for list of architectures. For example, here's how to build support for the Intel architecture knl:

git clone https://github.com/explosion/cython-blis && cd cython-blis
git pull && git submodule init && git submodule update && git submodule status
python3 -m venv venv
source venv/bin/activate
pip install -U pip setuptools wheel
pip install -r requirements.txt
./bin/generate-make-jsonl linux knl
BLIS_ARCH="knl" python setup.py build_ext --inplace
BLIS_ARCH="knl" python setup.py bdist_wheel

Fingers crossed, this will build you a wheel that supports your platform. You could then submit a PR with the blis/_src/make/linux-knl.jsonl and blis/_src/include/linux-knl/blis.h files so that you can run:

BLIS_ARCH="knl" pip install --no-binary=blis

Usage

Two APIs are provided: a high-level Python API, and direct Cython access, which provides 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/update-vendored-source

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

Updating the build files

In order to compile the Blis sources, we use jsonl files that provide the explicit compiler flags. We build these jsonl files by running Blis's build system, and then converting the log. This avoids us having to replicate the build system within Python: we just use the jsonl to make a bunch of subprocess calls. To support a new OS/architecture combination, we have to provide the jsonl file and the header.

Linux

The Linux build files need to be produced from within the manylinux2014 Docker container, so that they will be compatible with the wheel building process.

First, install docker. Then do the following to start the container:

sudo docker run -it quay.io/pypa/manylinux2014_x86_64:latest

Once within the container, the following commands should check out the repo and build the jsonl files for the generic arch:

mkdir /usr/local/repos
cd /usr/local/repos
git clone https://github.com/explosion/cython-blis && cd cython-blis
git pull && git submodule init && git submodule update && git submodule
status
/opt/python/cp36-cp36m/bin/python -m venv env3.6
source env3.6/bin/activate
pip install -r requirements.txt
./bin/generate-make-jsonl linux generic --export
BLIS_ARCH=generic python setup.py build_ext --inplace
# N.B.: don't copy to /tmp, docker cp doesn't work from there.
cp blis/_src/include/linux-generic/blis.h /linux-generic-blis.h
cp blis/_src/make/linux-generic.jsonl /

Then from a new terminal, retrieve the two files we need out of the container:

sudo docker ps -l # Get the container ID
# When I'm in Vagrant, I need to go via cat -- but then I end up with dummy
# lines at the top and bottom. Sigh. If you don't have that problem and
# sudo docker cp just works, just copy the file.
sudo docker cp aa9d42588791:/linux-generic-blis.h - | cat > linux-generic-blis.h
sudo docker cp aa9d42588791:/linux-generic.jsonl - | cat > linux-generic.jsonl

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-1.0.0.tar.gz (3.6 MB view details)

Uploaded Source

Built Distributions

blis-1.0.0-cp312-cp312-win_amd64.whl (6.4 MB view details)

Uploaded CPython 3.12 Windows x86-64

blis-1.0.0-cp312-cp312-musllinux_1_2_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

blis-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.2 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

blis-1.0.0-cp312-cp312-macosx_10_9_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.12 macOS 10.9+ x86-64

blis-1.0.0-cp311-cp311-win_amd64.whl (6.3 MB view details)

Uploaded CPython 3.11 Windows x86-64

blis-1.0.0-cp311-cp311-musllinux_1_2_x86_64.whl (11.8 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

blis-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

blis-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

blis-1.0.0-cp310-cp310-win_amd64.whl (6.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

blis-1.0.0-cp310-cp310-musllinux_1_2_x86_64.whl (11.6 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

blis-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

blis-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

blis-1.0.0-cp39-cp39-win_amd64.whl (6.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

blis-1.0.0-cp39-cp39-musllinux_1_2_x86_64.whl (11.6 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

blis-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

blis-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: blis-1.0.0.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for blis-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9ea14649ff07457e4112c7b94605e4aeb4f2fd5a8bd57c296ff8fbd154966ede
MD5 673a30a488381aefb2bf8ba5d4a411a1
BLAKE2b-256 b60ba73be025d991e8795626a830314984f7bda5de440e80b72a53bc316bb870

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: blis-1.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 6.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for blis-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9d5dbc72110f6d70593d9d8f88895d98add3df8b0cd6c3f54e2420465f1aaf16
MD5 d29a5cc7a97ccca6f9fa13df8f561347
BLAKE2b-256 c47caa43772c99e97e82308b21c14ce9e63a4edf464f63e05543f61787cd5f9a

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5f72ee08ad64c775dbeb4338b74ab0ad1955d8f41e0c0728993941a495ff6c7b
MD5 449c27555b7c01f837962e00136426b6
BLAKE2b-256 044eb8395e80a2b055d766c19face9768d319092e4dad55c1db8771a9ff3d2a7

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7654f78a5846b884a7813e88448f428b1deb93b31518d09779f5ab27755ae089
MD5 6dae4a832e2186d1bcd62e4b777990a7
BLAKE2b-256 7cb23c8a3412ac99bd08c2b4307df4a7a4f88e5aab3ef02401af10b1b6dac164

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 96d0eaeeb2343b47385bfc766162115db1a632910f75c8f6fde32ac999248c27
MD5 686c10e2bd9f4490e55952a302060d1f
BLAKE2b-256 dcab40045e9f8fc8a9af0ddacf7075248f83e782a09c88fb841d981f542a1bfa

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: blis-1.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 6.3 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for blis-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2dfcd69d629c3031f3db0e4752a95bead01d7502e8e3e28a05147c955aa00d0f
MD5 24da9ccfe42f51582de8159d5a3e65fa
BLAKE2b-256 e1f84a04b468482d4c7abcc9b9f6fae016124296f04d6f3deb9a430791a580a2

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 789ffa3d21a01c50098128934f5f7cf22f43e724753f86f5f4d6724990053e34
MD5 6681c27f7d9ec00a6e981a4d5c709643
BLAKE2b-256 db9998a2c730211d319ff63bb3eb57ddab3c743d6fbdf41535b524071f4dffa4

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 289a82a8358c17e3e4d9ffe6544b14b316908de7d1ba82b6ee0505e4a0fa1ebe
MD5 df3afff9a900c33209a0e96a71a73c73
BLAKE2b-256 83235f38d98e1c00dda077054983353c752eeb01b97bba6bf17f389c672dbe00

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8e5e82af5c5570b10ab27e3e8793a31358c23ac72bd51cd630f4a19ba29736cd
MD5 a4828ec02ca51bf51565146cb4fd62bf
BLAKE2b-256 cf41eda6f4b99996cff33bda6a8d84f21914d231d830c10f39016aecbea4ac93

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: blis-1.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 6.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for blis-1.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3222bc87cf55093c81fd59254b2a267a31bbc53effd2562a43500b9b29f7e21a
MD5 52bdc6d270e9c94a856553e3ac90cc7b
BLAKE2b-256 8d2a68c82173e686b6724145af88d857c4c6dc9846ca0e64d6f4766b3a5541d1

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 df5cfa7ba6156f812b3851bc943915eaf7118ddc85758d2bbff916545c464fea
MD5 7dba86c9cea6265d61241a36b96dfa6e
BLAKE2b-256 7f68f3fba9813f0333c614213e43712794dc48dca206b5eedbf7f1450180b60e

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 729cb5fbfdf4291da576259fe91f6909bc7134371c51ebcc9b50fbd986c0c914
MD5 068b99b244c0fca31b14af5559c16ed8
BLAKE2b-256 7c5cc6de02736aec9fe77e3286f453b734600599b90c521497bf8ea51b99c7c6

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 19a5cc21ba1f9e91ffe2e3f67ca350537ba872f8e63fa7fa7075774216192bda
MD5 5ac3d4952822ac154015d8a6ab6b0a08
BLAKE2b-256 c4707c2bd373ba2e9fccd01c1b67dd5268fc9b268b37d761c80524a01e75e9d9

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: blis-1.0.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 6.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for blis-1.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 76ec5c4508829543f986d08a9effe786c1ca34da62ef4dc44f73077cc6a032ff
MD5 800e5f382bb22225c0512df78d8af72f
BLAKE2b-256 5bad0927da1f30e83886e15cd68badd2dfc850f8dd0f9c3969e34c46ecb6bcf8

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7aee81f5b4125dffe9f7d2dc48cec55e8d012927bcadeff86b95b3c6c9af6c45
MD5 0e7812d0a24477e5727f2be59ed5c690
BLAKE2b-256 4d51f0f1c34e102ee04985da0e2a2bff153c4610a7cbde45023b580c6acd472c

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 88f8f2a2273ff92f3d0bcf7d4197ebb0064d4f833d146d05806b63e986ac79a4
MD5 486aecc954d7f353d83e78681711e3f9
BLAKE2b-256 042e50638b688564a015f8f84b19d6a38b8494c71fae9373361c16d1a75194e3

See more details on using hashes here.

File details

Details for the file blis-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for blis-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e2639c118dcd8596b6e850ccb59c02a753fd3d9fde7bb4a8c22937c1f44e8fbb
MD5 90e5aecca27526ba21b48dc0e8ed2aab
BLAKE2b-256 2d34fa6bb9cd532b64ae6e7f2d3ad8311153b9f7ef24de952ff883e6e6d8087f

See more details on using hashes here.

Supported by

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