{"id":13699350,"url":"https://github.com/explosion/cython-blis","last_synced_at":"2025-05-14T08:09:29.788Z","repository":{"id":37734426,"uuid":"107000608","full_name":"explosion/cython-blis","owner":"explosion","description":"💥 Fast matrix-multiplication as a self-contained Python library – no system dependencies!","archived":false,"fork":false,"pushed_at":"2025-04-03T12:23:34.000Z","size":8545,"stargazers_count":226,"open_issues_count":14,"forks_count":39,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-11T03:38:10.052Z","etag":null,"topics":["blas","blas-libraries","blis","cython","linear-algebra","matrix-multiplication","neural-network","neural-networks","numpy","openblas"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/explosion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-10-15T09:56:16.000Z","updated_at":"2025-04-04T04:04:21.000Z","dependencies_parsed_at":"2022-09-15T05:40:32.575Z","dependency_job_id":"7d3e0d39-40ce-4460-96fe-e2df0da71ff5","html_url":"https://github.com/explosion/cython-blis","commit_stats":{"total_commits":584,"total_committers":14,"mean_commits":"41.714285714285715","dds":"0.15753424657534243","last_synced_commit":"4833b10c34e3cfc484a1a974f9eb57cec663f8d0"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explosion%2Fcython-blis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explosion%2Fcython-blis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explosion%2Fcython-blis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/explosion%2Fcython-blis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/explosion","download_url":"https://codeload.github.com/explosion/cython-blis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253722930,"owners_count":21953541,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blas","blas-libraries","blis","cython","linear-algebra","matrix-multiplication","neural-network","neural-networks","numpy","openblas"],"created_at":"2024-08-02T20:00:31.160Z","updated_at":"2025-05-14T08:09:24.768Z","avatar_url":"https://github.com/explosion.png","language":"C","funding_links":[],"categories":["C","Others"],"sub_categories":[],"readme":"\u003ca href=\"https://explosion.ai\"\u003e\u003cimg src=\"https://explosion.ai/assets/img/logo.svg\" width=\"125\" height=\"125\" align=\"right\" /\u003e\u003c/a\u003e\n\n# Cython BLIS: Fast BLAS-like operations from Python and Cython, without the tears\n\nThis repository provides the\n[Blis linear algebra](https://github.com/flame/blis) routines as a\nself-contained Python C-extension.\n\nCurrently, we only supports single-threaded execution, as this is actually best\nfor our workloads (ML inference).\n\n[![tests](https://github.com/explosion/cython-blis/actions/workflows/tests.yml/badge.svg)](https://github.com/explosion/cython-blis/actions/workflows/tests.yml)\n[![pypi Version](https://img.shields.io/pypi/v/blis.svg?style=flat-square\u0026logo=pypi\u0026logoColor=white)](https://pypi.python.org/pypi/blis)\n[![conda](https://img.shields.io/conda/vn/conda-forge/cython-blis.svg?style=flat-square\u0026logo=conda-forge\u0026logoColor=white)](https://anaconda.org/conda-forge/cython-blis)\n[![Python wheels](https://img.shields.io/badge/wheels-%E2%9C%93-4c1.svg?longCache=true\u0026style=flat-square\u0026logo=python\u0026logoColor=white)](https://github.com/explosion/wheelwright/releases)\n\n## Installation\n\nYou can install the package via pip, first making sure that `pip`, `setuptools`,\nand `wheel` are up-to-date:\n\n```bash\npip install -U pip setuptools wheel\npip install blis\n```\n\nWheels should be available, so installation should be fast. If you want to\ninstall from source and you're on Windows, you'll need to install LLVM.\n\n### Building BLIS for alternative architectures\n\nThe provided wheels should work on x86_64 architectures. Unfortunately we do not\ncurrently know a way to provide different wheels for alternative architectures,\nand we cannot provide a single binary that works everywhere. So if the wheel\ndoesn't work for your CPU, you'll need to specify source distribution, and tell\nBlis your CPU architecture using the `BLIS_ARCH` environment variable.\n\n#### a) Installing with generic arch support\n\n```bash\nBLIS_ARCH=\"generic\" pip install spacy --no-binary blis\n```\n\n#### b) Building specific support\n\nIn order to compile Blis, `cython-blis` bundles makefile scripts for specific\narchitectures, that are compiled by running the Blis build system and logging\nthe commands. We do not yet have logs for every architecture, as there are some\narchitectures we have not had access to.\n\n[See here](https://github.com/flame/blis/blob/0.5.1/config_registry) for list of\narchitectures. For example, here's how to build support for the ARM architecture\n`cortexa57`:\n\n```bash\ngit clone https://github.com/explosion/cython-blis \u0026\u0026 cd cython-blis\ngit pull \u0026\u0026 git submodule init \u0026\u0026 git submodule update \u0026\u0026 git submodule status\npython3 -m venv env3.6\nsource env3.6/bin/activate\npip install -r requirements.txt\n./bin/generate-make-jsonl linux cortexa57\nBLIS_ARCH=\"cortexa57\" python setup.py build_ext --inplace\nBLIS_ARCH=\"cortexa57\" python setup.py bdist_wheel\n```\n\nFingers crossed, this will build you a wheel that supports your platform. You\ncould then [submit a PR](https://github.com/explosion/cython-blis/pulls) with\nthe `blis/_src/make/linux-cortexa57.jsonl` and\n`blis/_src/include/linux-cortexa57/blis.h` files so that you can run:\n\n```bash\nBLIS_ARCH=cortexa57 pip install --no-binary=blis\n```\n\n## Usage\n\nTwo APIs are provided: a high-level Python API, and direct\n[Cython](http://cython.org) access, which provides fused-type, nogil Cython\nbindings to the underlying Blis linear algebra library. Fused types are a simple\ntemplate mechanism, allowing just a touch of compile-time generic programming:\n\n```python\ncimport blis.cy\nA = \u003cfloat*\u003ecalloc(nN * nI, sizeof(float))\nB = \u003cfloat*\u003ecalloc(nO * nI, sizeof(float))\nC = \u003cfloat*\u003ecalloc(nr_b0 * nr_b1, sizeof(float))\nblis.cy.gemm(blis.cy.NO_TRANSPOSE, blis.cy.NO_TRANSPOSE,\n             nO, nI, nN,\n             1.0, A, nI, 1, B, nO, 1,\n             1.0, C, nO, 1)\n```\n\nBindings have been added as we've needed them. Please submit pull requests if\nthe library is missing some functions you require.\n\n## Development\n\nTo build the source package, you should run the following command:\n\n```bash\n./bin/update-vendored-source\n```\n\nThis populates the `blis/_src` folder for the various architectures, using the\n`flame-blis` submodule.\n\n## Updating the build files\n\nIn order to compile the Blis sources, we use jsonl files that provide the\nexplicit compiler flags. We build these jsonl files by running Blis's build\nsystem, and then converting the log. This avoids us having to replicate the\nbuild system within Python: we just use the jsonl to make a bunch of subprocess\ncalls. To support a new OS/architecture combination, we have to provide the\njsonl file and the header.\n\n### Linux\n\nThe Linux build files need to be produced from within the manylinux1 docker\ncontainer, so that they will be compatible with the wheel building process.\n\nFirst, install docker. Then do the following to start the container:\n\n    sudo docker run -it quay.io/pypa/manylinux1_x86_64:latest\n\nOnce within the container, the following commands should check out the repo and\nbuild the jsonl files for the generic arch:\n\n    mkdir /usr/local/repos\n    cd /usr/local/repos\n    git clone https://github.com/explosion/cython-blis \u0026\u0026 cd cython-blis\n    git pull \u0026\u0026 git submodule init \u0026\u0026 git submodule update \u0026\u0026 git submodule\n    status\n    /opt/python/cp36-cp36m/bin/python -m venv env3.6\n    source env3.6/bin/activate\n    pip install -r requirements.txt\n    ./bin/generate-make-jsonl linux generic --export\n    BLIS_ARCH=generic python setup.py build_ext --inplace\n    # N.B.: don't copy to /tmp, docker cp doesn't work from there.\n    cp blis/_src/include/linux-generic/blis.h /linux-generic-blis.h\n    cp blis/_src/make/linux-generic.jsonl /\n\nThen from a new terminal, retrieve the two files we need out of the container:\n\n    sudo docker ps -l # Get the container ID\n    # When I'm in Vagrant, I need to go via cat -- but then I end up with dummy\n    # lines at the top and bottom. Sigh. If you don't have that problem and\n    # sudo docker cp just works, just copy the file.\n    sudo docker cp aa9d42588791:/linux-generic-blis.h - | cat \u003e linux-generic-blis.h\n    sudo docker cp aa9d42588791:/linux-generic.jsonl - | cat \u003e linux-generic.jsonl\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexplosion%2Fcython-blis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexplosion%2Fcython-blis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexplosion%2Fcython-blis/lists"}