~/bend-docscommunity

blas.bend relies on unsafe/foreign

raw source on the hub · import bend-blas-lapack@0.0.0.1/blas.bend as Blas

bend-blas: the CBLAS routines on Array<F32>, one def per routine, the names of CBLAS without the cblas_ prefix. Generated by gen/effs.py: edit the table there, not this file.

Conventions. Sizes and flags are U32 (an Array<F32> has no shape; ta and tb are 0 or 1 for a transpose), scalars F32, matrices row-major with their leading dimension equal to their row width. Every array operand is consumed (the effect drops it after reading it) and an answered array is a fresh block of the smallest power-of-two size holding the result, the tail zero. A routine answers IO(Result<&1, &1, U32 & String, A>): Fail{(code, message)} when no BLAS is found (2), an operand is smaller than its sizes claim (2), or a size passes 2^31 floats (2); a full heap is a fail-stop of the runtime, not a Fail. Its .try twin answers IO(A) and dies on failure.

The platform BLAS is opened at runtime (dlopen): Accelerate on macOS; OpenBLAS, else libcblas beside the system BLAS, on Linux, which must be installed. On the interpreter the JS twins run: plain loops, correct and slow, whose failures carry the code only.

1 import
import Base

Definitions

def Blas.sgemm.try source · line 30 · raw

@ta:U32 -> @tb:U32 -> @m:U32 -> @n:U32 -> @k:U32 -> @alpha:F32 -> @a:Array<F32> -> @b:Array<F32> -> @beta:F32 -> @c:Array<F32> -> IO(Array<F32>)

def Blas.sgemv.try source · line 40 · raw

@ta:U32 -> @m:U32 -> @n:U32 -> @alpha:F32 -> @a:Array<F32> -> @x:Array<F32> -> @beta:F32 -> @y:Array<F32> -> IO(Array<F32>)

def Blas.sger.try source · line 49 · raw

@m:U32 -> @n:U32 -> @alpha:F32 -> @x:Array<F32> -> @y:Array<F32> -> @a:Array<F32> -> IO(Array<F32>)

def Blas.sdot.try source · line 57 · raw

@n:U32 -> @x:Array<F32> -> @y:Array<F32> -> IO(F32)

def Blas.snrm2.try source · line 65 · raw

@n:U32 -> @x:Array<F32> -> IO(F32)

def Blas.sasum.try source · line 73 · raw

@n:U32 -> @x:Array<F32> -> IO(F32)

def Blas.isamax.try source · line 81 · raw

@n:U32 -> @x:Array<F32> -> IO(U32)

def Blas.saxpy.try source · line 89 · raw

@n:U32 -> @alpha:F32 -> @x:Array<F32> -> @y:Array<F32> -> IO(Array<F32>)

def Blas.sscal.try source · line 97 · raw

@n:U32 -> @alpha:F32 -> @x:Array<F32> -> IO(Array<F32>)

Effects (foreign code)

effect Blas.sgemm source · line 26 · raw

@ta:U32 -> @tb:U32 -> @m:U32 -> @n:U32 -> @k:U32 -> @alpha:F32 -> @a:Array<F32> -> @b:Array<F32> -> @beta:F32 -> @c:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Array<F32>>)

C = alpha op(A) op(B) + beta C. A is m x k as stored (k x m when ta = 1), B is k x n (n x k when tb = 1), C is m x n, all row-major. C is consumed and the updated copy answered; pass beta = 0 and any m x n block for a fresh product.

foreign: effs/blas_sgemm.c, effs/blas_sgemm.js

effect Blas.sgemv source · line 36 · raw

@ta:U32 -> @m:U32 -> @n:U32 -> @alpha:F32 -> @a:Array<F32> -> @x:Array<F32> -> @beta:F32 -> @y:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Array<F32>>)

y = alpha op(A) x + beta y. A is m x n as stored, row-major; ta = 1 applies A^T, so x has n elements (m when ta) and y has m (n when ta). y is consumed and the updated copy answered.

foreign: effs/blas_sgemv.c, effs/blas_sgemv.js

effect Blas.sger source · line 45 · raw

@m:U32 -> @n:U32 -> @alpha:F32 -> @x:Array<F32> -> @y:Array<F32> -> @a:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Array<F32>>)

A = alpha x y^T + A, the rank-1 update; A is m x n, x has m elements, y has n. A is consumed and the updated copy answered.

foreign: effs/blas_sger.c, effs/blas_sger.js

effect Blas.sdot source · line 53 · raw

@n:U32 -> @x:Array<F32> -> @y:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), F32>)

The dot product of the first n elements of x and y.

foreign: effs/blas_sdot.c, effs/blas_sdot.js

effect Blas.snrm2 source · line 61 · raw

@n:U32 -> @x:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), F32>)

The Euclidean norm of the first n elements of x.

foreign: effs/blas_snrm2.c, effs/blas_snrm2.js

effect Blas.sasum source · line 69 · raw

@n:U32 -> @x:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), F32>)

The sum of the absolute values of the first n elements of x.

foreign: effs/blas_sasum.c, effs/blas_sasum.js

effect Blas.isamax source · line 77 · raw

@n:U32 -> @x:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), U32>)

The index (from 0) of the element of largest absolute value among the first n of x.

foreign: effs/blas_isamax.c, effs/blas_isamax.js

effect Blas.saxpy source · line 85 · raw

@n:U32 -> @alpha:F32 -> @x:Array<F32> -> @y:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Array<F32>>)

y = alpha x + y over the first n elements; y is consumed and the updated copy answered.

foreign: effs/blas_saxpy.c, effs/blas_saxpy.js

effect Blas.sscal source · line 93 · raw

@n:U32 -> @alpha:F32 -> @x:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Array<F32>>)

x = alpha x over the first n elements; x is consumed and the scaled copy answered.

foreign: effs/blas_sscal.c, effs/blas_sscal.js