[erlang-questions] Vector instructions, BLAS, FFI

Alceste Scalas <>
Tue Apr 8 11:56:20 CEST 2008


Il giorno mar, 08/04/2008 alle 16.13 +1000, jm ha scritto:
> The reason I initially stated vec:add/3 as an example is that this could 
> be implemented as a C-port module. Then if this proves successful the 
> atomic could be rolled into the VM eventually and the rest moved to a 
> normal library. At which point any changes needed to erlang syntax would 
> be readily apparent.
> 
> Where would you recommend starting? Any good references on parallel 
> vector and matrix operations/algorithms?

Instead of reimplementing everything, I'd suggest to start here:

        http://www.netlib.org/blas/
        http://math-atlas.sourceforge.net/

The BLAS interface does not support integer arithmetics, but it's a
well-estabished standard.  Furthermore, if the Erlang VM is dynamically
linked against a BLAS library (either directly or through a driver),
then users/developers could choose their highly-optimized
hardware-dependant implementation without recompiling everything.

Here at CRS4 we are still experimenting with Erlang as a tool for
developing distributed numerical applications.  We've developed a BLAS
binding, based on the Erlang Foreign Function Interface EEP [1,2] ---
and in fact, we've created and proposed the Erlang FFI just to make it
easier to interface libraries with tens or hundreds of functions.  In
general, if you plan to use Erlang for numerical and scientific
computation, then you'll definitely need an easy way to interface to
existing code.

Our current BLAS interface is something like:

        blas:init(),
        
        %% Create an identity matrix
        I = blas:eye(s,    % Precision: 's'ingle or 'd'ouble
                     3),   % Rows and columns
        V = blas:vector(s, 3, [1.0, 2.0, 3.0]),
        
        V2 = blas:mul(blas:mul(2.0, I), V),
        
        VL = blas:to_list(blas:transpose(V2)).
        %% VL is:
        %% [[2.00000,4.00000,6.00000]]

Matrices and vectors are implemented as records containing some
information (dimensions, row/column ordering, transposition...) and a
binary with floating point values.  The BLAS binding consists of ~950
lines of Erlang code (the 'blas' module) and ~300 lines of C (various
helper functions).

Regards,

alceste

References:
  [1] http://muvara.org/crs4/erlang/ffi
  [2] http://erlang.org/eeps/eep-0007.html

-- 
Alceste Scalas <>
CRS4 - http://www.crs4.it/




More information about the erlang-questions mailing list