TOC »
array-morphisms-blas
A system-BLAS backend for array-morphisms, through the blas egg (OpenBLAS, Intel MKL, reference BLAS, ...).
Description
array-morphisms computes matrix products and convolutions via a pluggable BLAS backend. The default backend is a bundled copy of microBLAS. This egg is separate from array-morphisms, so that array-morphisms does not depend on the blas egg or on a system BLAS library. Install it when you want the performance of a system BLAS library such as OpenBLAS.
Requirements
- array-morphisms 3.0 or later
- blas, and a system BLAS library that the blas egg can find
Usage
(import array-morphisms-blas-exec array-morphisms-blas-egg-backend) (register-blas-backend! (make-blas-egg-backend))
Registering this backend replaces the microBLAS backend that array-morphisms registers by default; the last register-blas-backend! call wins.
- make-blas-egg-backendprocedure
Return a blas-backend record (see array-morphisms-blas-exec) with:
- GEMM, GEMV, DOT and AXPY for f32 and f64, through the sgemm!, dgemm!, ... procedures of the blas egg;
- the convolution hooks of array-morphisms, for NCHW and NHWC images: im2col, GEMM and bias addition for the forward pass, and the two backward passes, with the im2col and col2im steps in C;
- the optional offset kernels: GEMM and DOT on matrices and vectors that start at an offset into their vectors. They call cblas_sgemm, cblas_dgemm, cblas_sdot and cblas_ddot directly, with the same arguments as the other kernels apart from the start addresses, so their results are the same. array-morphisms uses them to run the cells of a batched product and the rows of a framed sum in place.
Which BLAS library is used
The blas egg does not choose a BLAS implementation itself; it links with -lblas and falls back to other names. On Debian-based systems, what -lblas resolves to is decided by update-alternatives. Installing the OpenBLAS development packages registers OpenBLAS at a higher priority than the reference BLAS, so the blas egg and this egg then run on OpenBLAS.
update-alternatives --display libblas.so.3-x86_64-linux-gnu # run-time selection update-alternatives --display libblas.so-x86_64-linux-gnu # link-time selection update-alternatives --config libblas.so.3-x86_64-linux-gnu # switch
Threads
OpenBLAS uses all the processors it finds by default. To limit the number of threads, set OPENBLAS_NUM_THREADS, which works for every OpenBLAS variant; OMP_NUM_THREADS affects only the OpenMP variant.
OPENBLAS_NUM_THREADS=4 csi -s your-script.scm
Author
Repository
https://github.com/iraikov/array-morphisms-blas
License
LGPL-3
Version History
- 1.1
- Offset GEMM and DOT kernels for batched products; the im2col kernels write zeros at padding positions, so convolutions can share a column buffer; links the BLAS library directly; requires array-morphisms 3.0
- 1.0
- Initial release