|lloda 4458d50f84 Generalize srfi4-type-size in (ffi cblas arrays)||1 year ago|
|mod||1 year ago|
|test||1 year ago|
|LICENSE||4 years ago|
|README.md||1 year ago|
|TODO||1 year ago|
This is a set of Guile FFI bindings for CBLAS, the library of linear algebra subprograms1.
To use the bindings, import
(ffi cblas). CBLAS will be loaded from the
default dynamic library path (see ‘Installation notes’ below). There are up to
three bindings for each function, here using
ZGEMM as an example:
cblas_zgemm (raw binding): the raw C function by
use this if you aren't familiar with Guile's FFI.
zgemm! (typed binding): takes array arguments of type
'c64 and operates by
effect, without making copies. All the arguments must be properly sized. The
return value is unspecified.
zgemm (functional binding): takes array arguments of compatible types and
returns a newly constructed array. The arguments will be converted as
necessary, which may result in copies. The returned array will be of
In principle, for the last two bindings, you don't need to care whether your array is row-major or column-major or what the strides are. The bindings will extract the required strides from the array arguments. However, since CBLAS doesn't support arbitrary strides (e.g. it only supports a column stride for matrix arguments, assuming column-major order), some array arguments will cause the typed binding to fail, or result in extra copies with the functional binding.
If the function doesn't return an array (e.g.
sdot) then we only provide
two bindings (e.g.
,help (ffi cblas) at the Guile REPL to list all the bindings
Note that this package is a work in progress and that there are bugs. For example, negative strides require specific handling for CBLAS and are not supported yet.
dynamic-link to load the dynamic libraries for
CBLAS. To do this, the names of the respective library files must be
known. The default name
libcblas can be configured with the environment
GUILE_FFI_CBLAS_LIBNAME. Some alternative names that I've seen are
If your CBLAS libraries are not installed in the default dynamic library
search path, you can configure specific paths for
guile-ffi-cblas with the
GUILE_FFI_CBLAS_LIBPATH. There are other variables that
dynamic-link searches for libraries (
LD_LIBRARY_PATH) and you may prefer to set those instead. See also
for notes on using
guile-ffi-cblas on Guix3.
The tests use SRFI-64.
$GUILE -L mod -s test/test-ffi-cblas.scm
Depending on your installation (see above) you might need
GUILE_FFI_CBLAS_LIBNAME=libotherblas \ GUILE_FFI_CBLAS_LIBPATH=/custom/path/lib \ $GUILE ... etc.
² Unfortunately this triggers a bug in the current version. ↩
³ A previous version of this library also included BLIS
bindings, but now I have moved those to a separate library
guile-ffi-blis). ↩ .
⁴ Some distributions of
libcblas do not provide
guile-ffi-cblas will still work, just without these bindings.