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).
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 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) Installing with generic arch support
BLIS_ARCH="generic" pip install spacy --no-binary blis
b) Building 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 ARM architecture cortexa57
:
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 env3.6
source env3.6/bin/activate
pip install -r requirements.txt
./bin/generate-make-jsonl linux cortexa57
BLIS_ARCH="cortexa57" python setup.py build_ext --inplace
BLIS_ARCH="cortexa57" 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-cortexa57.jsonl
and
blis/_src/include/linux-cortexa57/blis.h
files so that you can run:
BLIS_ARCH=cortexa57 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 manylinux1 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/manylinux1_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for blis-0.7.8-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f7bfdee74ac695c35360ace00f2630c1b47406dc0b99ba9211bfa8588bfbed9 |
|
MD5 | ef47f3e714871f99d11736d19b6992ef |
|
BLAKE2b-256 | 98f5ee5e00485508298508ba5c7850881932df7aa218db8c2ede8ed94d31741c |
Hashes for blis-0.7.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2778fe0ba0e25c157839fdd19ed66b9a340c92d4e92e707b7fa9aa21c51cb254 |
|
MD5 | 544e332dced1e56b36a49e8a80998799 |
|
BLAKE2b-256 | b212710a647337cde6f8012474c8535ac1b068925a022b29d172d730f43b4bd1 |
Hashes for blis-0.7.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 354cadff661a1452c886f541b84018770ddb4c134844c56e7c1a30aa4bcc473d |
|
MD5 | 191a4feb69a4b4d2568bdaf0797a0592 |
|
BLAKE2b-256 | a52433db45b701482fc70f84d8c92bcdade039cdf0ba12a9a313da66f5a3e742 |
Hashes for blis-0.7.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 294421b720c2de904908de841464c667e1a5c5e9f3db6931dfa29cf369d3653a |
|
MD5 | 1d65689cd9c6d4988812404f241d5141 |
|
BLAKE2b-256 | df93ed10cacbe22618758df5fbff5c5bc99b1524bca234b7511d428e52924408 |
Hashes for blis-0.7.8-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae5b06fe3b94645ac5d93cbc7c0129639cc3e0d50b4efb361a20a9e160277a92 |
|
MD5 | facf15a343517aaf31e3d71d9a719c0f |
|
BLAKE2b-256 | cfcca49d4fb7ae34afb9125f122e7afa60836900052bb0f5ed845d6db9e3ee2c |
Hashes for blis-0.7.8-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf60f634481c3d0faf831ac4f2d1c75343e98f714dc88e3fb3c329758577e772 |
|
MD5 | 34f6a8cbfbbe9b6cb517421542c56845 |
|
BLAKE2b-256 | 447a0f02d6e4e59fde80e0deccb61ce0794fa40c4b0db525008080aac6556b66 |
Hashes for blis-0.7.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66b8ca1a2eb8f1e0563a592aae4b8682b66189ad560e3b8221d93eab0cb76582 |
|
MD5 | 018f0e6713ca682d4a8a65373ad0ee8f |
|
BLAKE2b-256 | 6fb339bba4df07d6dc6dbd1e77e84e1118df3b7361ffc3d0d1f15ad0ae38fc01 |
Hashes for blis-0.7.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2056b0d9722f5505cfa94904c6248021197c63ecf45804dcf117f8f1c6160ab6 |
|
MD5 | f3c9371ad59cdc28575fa2c28541c949 |
|
BLAKE2b-256 | 73f7f60be90a49f9f6b8d612c9f210dfd0113709ad66374be00c374ef7346d70 |
Hashes for blis-0.7.8-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e7b7b8bc8cf5e82958bbc393e0167318a930d394cbbf04c1ba18cfabaef5818 |
|
MD5 | e4e8b7ddedcad6fdcaf9cdf6d54fc7e4 |
|
BLAKE2b-256 | 7937cecb361529a8cb42aeb385667223895e6e24d9e397e493f6285e4462e0b0 |
Hashes for blis-0.7.8-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f576ad64b772b6fd7df6ef94986235f321983dc870d0f76d78c931bafc41cfa4 |
|
MD5 | d61b2fcb723d9f63c4cf5f9a7783f4be |
|
BLAKE2b-256 | b5e360c64346b6de5256b3c5a8a6f963438d80870fc70cc5357048e452842abe |
Hashes for blis-0.7.8-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e970ba1eb12ca38fb5d57f379472125bc3f5106c8214dc847fe79b027212135 |
|
MD5 | a66f5c1b40eb3074d18875d3d9143c8e |
|
BLAKE2b-256 | 74f98d4fea3eb00a790ed5797a6ef0606659ee6b6d9bcad23c220878009096d9 |
Hashes for blis-0.7.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63735128c9cae44dc6cbf7557327385df0c4ed2dc2c45a00dabfde1e4d00802d |
|
MD5 | 4be9d52935b98f65cd87a5ef4b2e592b |
|
BLAKE2b-256 | e40b7b2c5b05de42de8706b582a37e5963477dcb264ceadaadabacba1ed8d173 |
Hashes for blis-0.7.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cac120e3c0517095d3c39278e8b6b1102b1add0e1f4e161a87f313d8ee7c12e1 |
|
MD5 | fb95096616e1a7724ba3ce734d21e1ae |
|
BLAKE2b-256 | 2593358ec400eea025413c124b252ba8e7e3607313d3ece32ce4d3f91da9fe4f |
Hashes for blis-0.7.8-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2db369a4f95927be37e11790dd1ccbf99fd6201eaffbcf408546db847b7b5740 |
|
MD5 | 8b450c073ba9841aeb44a2c3b98fe447 |
|
BLAKE2b-256 | 070d604c9b0d1e7ceac87fc2ded94611044f1cc1d2c2b0be93dbad4a4b96766b |
Hashes for blis-0.7.8-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96ff4c0c1ceab9f94c14b3281f3cef82f593c48c3b5f6169bd51cdcd315e0a6e |
|
MD5 | 63a17abfdd6ab422cd01f0a9e4482b57 |
|
BLAKE2b-256 | 3f098a691e903b2ca728a01853ddf20d41d9aaeb52dd0dec1c6159e78cd2a4aa |
Hashes for blis-0.7.8-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95d22d3007cb454d11a478331690629861f7d40b4668f9fccfd13b6507ed099b |
|
MD5 | 5be0303a06913e5660750aab98b89828 |
|
BLAKE2b-256 | 14eae3ed3df1d0e45ae7a6e15540fe254240a5c2fd6c0f6bdf7a824521ca2cf0 |
Hashes for blis-0.7.8-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17df5ac7d9a9dbbf0415f8f8392fbdf1790fa394f89d695bae5e2e7e361c852b |
|
MD5 | bf8b15d961a5269d1b32c7901d11799b |
|
BLAKE2b-256 | f0fb19a49b7e1c122dc915a039425546041daa39dc7416bfb2d4c1ba589ee835 |
Hashes for blis-0.7.8-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c3245e42c7c6ba0d68d7dff4171d11bb08174e639bc8edd52a1fd831de1d903 |
|
MD5 | 94a42a8b947fa1ffbf9c1c4cfc8d0c75 |
|
BLAKE2b-256 | c295f9ba755eea9982e1a17d8fdf50861e991e10c6218be1934d1764aef323c4 |
Hashes for blis-0.7.8-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfa56e7ef14ae607d8444eb344d22f252a2e0b0f9bfa4bdc9b0c48a9f96b5461 |
|
MD5 | 2254ee648b0a007b04980770bbf88011 |
|
BLAKE2b-256 | b9334deadee3c093442877eefd6e31778aed10b17642173ade222205e42044f7 |
Hashes for blis-0.7.8-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90f17543e0aa3bc379d139867467df2c365ffaf5b61988de12dbba6dbbc9fab4 |
|
MD5 | 7bdcd4ad2db3c545e32816170282552b |
|
BLAKE2b-256 | 2d9368c2564699637ac69a12cb46243bd304110894b46c6640dfbee1a5a93b59 |
Hashes for blis-0.7.8-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f5fa330ab66d0e92a845b1db361ec8bf3dc4bc7e0dc0ded94f36b8e9f731650 |
|
MD5 | 93dab7d2302476967e5c420a34b87f3b |
|
BLAKE2b-256 | 2a33cd99b36b2e72ca2f2ac9d2d650e1174833f546392b2cc6673df965049e68 |
Hashes for blis-0.7.8-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25cdb9775699c1b926df514a5d4c28016c11722a66211f1024b2f21373f50de2 |
|
MD5 | 2e843112c7b55c37e5170202ffb4190f |
|
BLAKE2b-256 | 205e83777722b2e1e71ef3d8ad94b2fdb8d3eef2bff30a3121b904e99201d8ef |
Hashes for blis-0.7.8-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 159a1a9b32213d99d1415789ac66ed8d23442a696d9d376c66d7b791d3eae575 |
|
MD5 | 40b438857bb535dcf1800accd22f31ec |
|
BLAKE2b-256 | ff68947e7839d7c274a2b82ebef461cd00c0540b234817ec8a466e0cb685b16b |