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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

blis-1.0.0a1-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.0a1-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.0a1-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.0a1-cp311-cp311-win_amd64.whl (6.3 MB view details)

Uploaded CPython 3.11 Windows x86-64

blis-1.0.0a1-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.0a1-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.0a1-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.0a1-cp310-cp310-win_amd64.whl (6.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

blis-1.0.0a1-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.0a1-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.0a1-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.0a1-cp39-cp39-win_amd64.whl (6.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

blis-1.0.0a1-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.0a1-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.0a1-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.0a1.tar.gz.

File metadata

  • Download URL: blis-1.0.0a1.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.0a1.tar.gz
Algorithm Hash digest
SHA256 ec3f9131a92e3fe6774f3016a754471ce42e1596fa6da48116d5f002b823b0e7
MD5 49cc26a7ea730ca48269655254236b2c
BLAKE2b-256 9e6b9bb5632d1704c47fc5aaaf1c0edc1bc31dbc33c7ac3b24f429694de56e94

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blis-1.0.0a1-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.0a1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2aeb796890dc7da4916d3eccabcc4db453d2029cf6c9c8fb47ea0e6f65d7a34a
MD5 4ddcd17fda15f478219f1d1085a12213
BLAKE2b-256 b9225bfa9ac286f380c472e44a7dcf37ea4e78878de75e1313c3997cd4f2d04d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2b9b51b6fcf8d327ec6ac046eacbcab0cbcbe3c2b527e9df99276553deafc690
MD5 a149920cfc31a7b9e2f7bf390612c921
BLAKE2b-256 c0c21ff1ed24cd76b7df2a629693af296b4c06be15e2b84b9c362cd002bc1cff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be8816ab0e9ba6ffe2a6399ed167342b2c0e0d116ad540feea5feacc9be93a0f
MD5 7aa1fa851c462bcda58fbba325e237fe
BLAKE2b-256 a6a02360478d87ca7906605aa0362032bc09a27acc88fb603a680244657e32bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3715dad86f21ddef19a33ec1c6255c85c5be9adb3ae08f56bb957b7bb757991b
MD5 92753870bd3aa09f499e100697201e83
BLAKE2b-256 8ae05491e978301af08977ef760f5b18bcf98588b7f7e21cdf803d2f4da8913e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blis-1.0.0a1-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.0a1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8ed4d0286d61b16a9fa5fc4117aea8aa8f5571672d32639542cec96ff9646cf7
MD5 76a12b9bab75e3169353bcb9a177625f
BLAKE2b-256 37db3216bf2068a0e93066b6b0bfbdcce71e510f842763918dd39a54a851d5d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6a99d4224367bffca97cf46b9a36f550888eee85a99489165446e295d64de8f6
MD5 0c5397ee1e8d5728b2d0f1b2daf00043
BLAKE2b-256 3a0b60f22c6afe18009d198cf82c205983475d4ea379f73a323561dcbacbdcc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f8d5b039a9b558ff15cb0c348163f4350b23fe2336d825b65c62bec03b738189
MD5 ae24d9584f7dea2d0d6f933eb5e75e20
BLAKE2b-256 f471f5cd0e1b4ec3c670ca13006abc02c96d0d78f82f51ae574739b3285817f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 72f52d144aeaf2078977509a596b44773309adf7c892c0f3137a5a9fac52b174
MD5 4f9a631c3e47ea577d6feeefcab61eb5
BLAKE2b-256 ab89ffb0c920ecd0faf73767dd90d931cccc59ae60d7892462e19a020a0d24d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blis-1.0.0a1-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.0a1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4f1ba2eb5fa5b9af71bf138d9c328545d2b98a93eb1800e727476cc2b1866b2c
MD5 054faca3631be6e6d73d2f488203a86f
BLAKE2b-256 8883758fa22a194cbcfb88e533777a70a09d45234ac97f91a3720d282ed918c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 737a2347212254ccf00ca292c89e23960a72b018b9454b888511567feacbb278
MD5 4a88bd3505e45b99c468a2140bd56244
BLAKE2b-256 2d793a41b53dd027bf945b120a97820b00434963a86102cef0a17605a1f05b2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ddacedf9fa42ca3f333c204efda85ca7fa9182d4ff68faf61e69c3c2e9b56add
MD5 1bc95207781ea8206de08f7b3a931a7c
BLAKE2b-256 a9d90e12fa4076ad730a9667102915b25ff77211e6d4280daf71e92b08b4d0b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cee88429766c490ade61317748a5a064f2425121bccce8ae0ad8e693b0380a58
MD5 5508edd3fd4f0f42e1a662c9a46ff9fc
BLAKE2b-256 caccca97fadc27caad2036bfbd6c2d72aae6d12028edfa64818d2cc200c4a6a4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blis-1.0.0a1-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.0a1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a87e5cc9fac94003bd66336a4b1e491812959014fea057e92bca798cf3a2c103
MD5 8c42da99e7f0e38eacae9bb8df037d02
BLAKE2b-256 fa9b8b7485a40da0f6c66e12bbe7daccdcc284b7936ea3c794c47f06aa1da0e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cc0b82cf87637b705fae9343773419f845c072725d71352a5eae2d0f5f3e2548
MD5 68e9bf09e63a36585be4aa71dca49dec
BLAKE2b-256 78d22be37a0e0edc93caafb7f724492038bb03aef3725261db84f1f3639d4d68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 caab5fd86b61c6cdd959fc3d6b0a40cff62217a00cf2351d92d2ce3bdf4095f7
MD5 38438b2aaaa05f35fbafb4c73130c1c9
BLAKE2b-256 e9326739e28f2f6422a58c5c134960cf95970048c33796e72106c068cf4533e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blis-1.0.0a1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a16385ab97ddbf3ddc5fd76c323ee9b6f7ba93d8e109af5ab851bab1de3eed68
MD5 69ddc22f8db616160bc0b5ab409a2814
BLAKE2b-256 15c9a11ece539257d240bf05794b972e9f92e7c2326e17c97ad0037bb78fd617

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