CFFI was available when I implemented "fricas-foreign-call".
At that time my conclusion was that CFFI handles easy parts, but
we also had to deal with nasty issues. Main thing is that
we want foreign call to do nontrivial amount of work, which
usually means some data aggregates. Clozure CL folks claimed
that only way to handle aggregates is to copy data between Lisp
and foreign memory. sbcl has 'pinned objects' which allows
safe passing Lisp data to foreign routines. IIUC ECL claims
that passing Lisp data to foreign routines is always safe
(without any special precautions).
For routines like matrix-vector multiplication cost of
copy is comparable to cost of operation and probably in
implementation needing copy using foreign call for
matrix-vector multiplication has no advantage (similarly,
we do _not_ use GMP add, only more expensive operations).
What I would like to call:
- matrix-matrix multiplication from BLAS
- routines like solve, SVD, eigenvalue decomposition from Lapack
- multiplication for polys over Z_p
That is rather small number of routines (of order of 20). Generating
signatures for them is not a problem. What remains to solve:
- detecting if there is BLAS/Lapack available and if yes in
which library (there are few competing BLAS libraries and
Lapack may be configured to use any of them). To make
things more "interesting" original BLAS and Lapack interface
was in Fortran 77, there are now C wrappers
- as I mentioned we need to solve problem of transfering data
to foreign routines
As I mentioned for sbcl we can use pinned objects, for Clozure CL
and Clisp we need copy, for GCL ATM we just pass pointer to C
side, but this is not guaranteed to work (basically we bet that
GCL will not run its garbage collector during foreign call, which
seem to work in current use. So the remaing part is avalability
of BLAS/Lapack. In other words, problem is not FFI itself but
managing dependencies. This affects binary distributions
because BLAS/Lapack tend to use machine specific instructions
(BLAS using say AVX will fail on machine without AVX instructions).
There is related, but different issue of making FFI easy to
use from Spad program. IMH here main issue is mapping
between Spad types and C types. In OpenAxion Gaby implemented
something, description is not clear but it seems that Gaby
decided that bunch of Spad types will map to C types (that
is user gives Spad types and interface uses corresponding
C types for call). AFAICS this has serious limitations
and for FriCAS I would like something better.
--
Waldek Hebisch