{"added":null,"apiVersion":1,"behindSince":null,"buildDepends":[],"categories":["wip","math"],"comment":"Blis linear algebra routines as a self-contained Python C-extension","compare":null,"dependentCount":null,"description":"# Cython BLIS: Fast BLAS-like operations from Python and Cython,\nwithout the tears\n\nThis repository provides the [Blis linear\nalgebra](https://github.com/flame/blis) routines as a self-contained\nPython C-extension.\n\nCurrently, we only supports single-threaded execution, as this is\nactually best for our workloads (ML inference).\n\n[![Azure\nPipelines](https://img.shields.io/azure-devops/build/explosion-ai/public/6/master.svg?logo=azure-pipelines\u0026style=flat-square)](https://dev.azure.com/explosion-ai/public/_build?definitionId=6)\n[![pypi\nVersion](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\nwheels](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`,\n`setuptools`, and `wheel` are up-to-date:\n\n```bash pip install -U pip setuptools wheel pip install blis ```\n\nWheels should be available, so installation should be fast. If you\nwant to install from source and you're on Windows, you'll need to\ninstall LLVM.\n\n### Building BLIS for alternative architectures\n\nThe provided wheels should work on x86_64 architectures. Unfortunately\nwe do not currently know a way to provide different wheels for\nalternative architectures, and we cannot provide a single binary\nthat works everywhere. So if the wheel doesn't work for your CPU,\nyou'll need to specify source distribution, and tell Blis your CPU\narchitecture using the `BLIS_ARCH` environment variable.\n\n#### a) Installing with generic arch support\n\n```bash BLIS_ARCH=\"generic\" pip install spacy --no-binary blis ```\n\n#### b) Building specific support\n\nIn order to compile Blis, `cython-blis` bundles makefile scripts\nfor specific architectures, that are compiled by running the Blis\nbuild system and logging the commands. We do not yet have logs for\nevery architecture, as there are some architectures we have not\nhad access to.\n\n[See here](https://github.com/flame/blis/blob/0.5.1/config_registry)\nfor list of architectures. For example, here's how to build support\nfor the ARM architecture `cortexa57`:\n\n```bash git clone https://github.com/explosion/cython-blis \u0026\u0026 cd\ncython-blis git pull \u0026\u0026 git submodule init \u0026\u0026 git submodule update\n\u0026\u0026 git submodule status python3 -m venv env3.6 source 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\nFingers crossed, this will build you a wheel that supports your\nplatform. You could then [submit a\nPR](https://github.com/explosion/cython-blis/pulls) with the\n`blis/_src/make/linux-cortexa57.jsonl` and\n`blis/_src/include/linux-cortexa57/blis.h` files so that you can\nrun:\n\n```bash BLIS_ARCH=cortexa57 pip install --no-binary=blis ```\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,\nnogil Cython bindings to the underlying Blis linear algebra library.\nFused types are a simple template mechanism, allowing just a touch\nof compile-time generic programming:\n\n```python cimport blis.cy A = \u003cfloat*\u003ecalloc(nN * nI, sizeof(float))\nB = \u003cfloat*\u003ecalloc(nO * nI, sizeof(float)) C = \u003cfloat*\u003ecalloc(nr_b0\n* nr_b1, sizeof(float)) blis.cy.gemm(blis.cy.NO_TRANSPOSE,\nblis.cy.NO_TRANSPOSE,\n\t     nO, nI, nN, 1.0, A, nI, 1, B, nO, 1, 1.0, C, nO, 1)\n```\n\nBindings have been added as we've needed them. Please submit pull\nrequests if the 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,\nusing the `flame-blis` submodule.\n\n## Updating the build files\n\nIn order to compile the Blis sources, we use jsonl files that\nprovide the explicit compiler flags. We build these jsonl files by\nrunning Blis's build system, and then converting the log. This\navoids us having to replicate the build system within Python: we\njust use the jsonl to make a bunch of subprocess calls. To support\na new OS/architecture combination, we have to provide the jsonl\nfile and the header.\n\n### Linux\n\nThe Linux build files need to be produced from within the manylinux1\ndocker container, so that they will be compatible with the wheel\nbuilding 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\nthe repo and build the jsonl files for the generic arch:\n\n    mkdir /usr/local/repos cd /usr/local/repos git clone\n    https://github.com/explosion/cython-blis \u0026\u0026 cd cython-blis git\n    pull \u0026\u0026 git submodule init \u0026\u0026 git submodule update \u0026\u0026 git\n    submodule status /opt/python/cp36-cp36m/bin/python -m venv\n    env3.6 source env3.6/bin/activate pip install -r requirements.txt\n    ./bin/generate-make-jsonl linux generic --export\n    BLIS_ARCH=generic python setup.py build_ext --inplace # N.B.:\n    don't copy to /tmp, docker cp doesn't work from there.  cp\n    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\nthe container:\n\n    sudo docker ps -l # Get the container ID # When I'm in Vagrant,\n    I need to go via cat -- but then I end up with dummy # lines\n    at the top and bottom. Sigh. If you don't have that problem\n    and # sudo docker cp just works, just copy the file.  sudo\n    docker cp aa9d42588791:/linux-generic-blis.h - | cat \u003e\n    linux-generic-blis.h sudo docker cp aa9d42588791:/linux-generic.jsonl\n    - | cat \u003e linux-generic.jsonl","flavors":[],"html":"https://daemonports.org/netbsd/wip/py-cython-blis/","kind":"port","lastUpdate":null,"license":["modified-bsd"],"maintainer":"lntl@disroot.org","name":"cython-blis","newest":false,"newestVersion":null,"noVulnData":false,"origin":"wip/py-cython-blis","otherSystems":[],"packages":null,"pkgName":"cython-blis-v0.7.0nb1","related":null,"repository":"pkgsrc-wip","requiredBy":[],"requiredByCount":0,"runDepends":[],"status":null,"system":"netbsd","systemLabel":"NetBSD","version":"v0.7.0nb1","versions":null,"vulnerabilities":null,"www":"https://github.com/explosion/cython-blis/"}
