[Experimental] LLVM-accelerated Generic Linear Algebra Subprograms
LLVM-accelerated Generic Linear Algebra Subprograms (GLAS)
GLAS is a C library written in Dlang. No C++/D runtime is required but libc, which is available everywhere.
The library provides
CBLAS API can be provided by linking with Netlib's CBLAS library.
GLAS can be used with DMD and LDC but
LDC (LLVM D Compiler) >= 1.1.0 beta 6
should be installed in common path anyway.
Note performance issue https://github.com/libmir/mir-glas/issues/18.
GLAS can be included automatically in a project using dub (the D package manager). DUB will build GLAS and CPUID manually with LDC.
{
...
"dependencies": {
"mir-glas": "~><current_mir-glas_version>",
"mir-cpuid": "~><current_mir-cpuid_version>"
},
"lflags": ["-L$MIR_GLAS_PACKAGE_DIR", "-L$MIR_CPUID_PACKAGE_DIR"]
}
$MIR_GLAS_PACKAGE_DIR
and $MIR_CPUID_PACKAGE_DIR
will be replaced automatically by DUB to appropriate directories.
mir-glas
can be used like a common C library. It should be linked with mir-cpuid
.
A compiler, for example GCC, may require mir-cpuid
to be passed after mir-glas
: -lmir-glas -lmir-cpuid
.
GLAS API is based on the new ndslice
from mir-algorithm.
Other languages can use simple structure definition.
Examples are available for C and for Dlang.
C/C++ headers are located in include/
.
D headers are located in source/
.
There are two files:
glas/fortran.h
/ glas/fortran.d
- for Netilb's BLAS APIglas/ndslice.h
/ glas/ndslice.d
- for GLAS APILDC (LLVM D Compiler) >= 1.1.0 beta 6
is required to build a project.
You may want to build LDC from source or use LDC 1.1.0 beta 6.
Beta 2 generates a lot of warnings that can be ignored. Beta 3 is not supported.
LDC binaries contains two compilers: ldc2 and ldmd2. It is recommended to use ldmd2 with mir-glas.
Recent LDC packages come with the dub package manager. dub is used to build the project.
Mir CPUID is CPU Identification Routines.
Download mir-cpuid
dub fetch mir-cpuid --cache=local
Change the directory
cd mir-cpuid-<current-mir-cpuid-version>/mir-cpuid
Build mir-cpuid
dub build --build=release-nobounds --compiler=ldmd2 --build-mode=singleFile --parallel --force
You may need to add --arch=x86_64
, if you use windows.
Copy libmir-cpuid.a
to your project or add its directory to the library path.
Download mir-glas
dub fetch mir-glas --cache=local
Change the directory
cd mir-glas-<current-mir-glas-version>/mir-glas
Build mir-glas
dub build --config=static --build=target-native --compiler=ldmd2 --build-mode=singleFile --parallel --force
You may need to add --arch=x86_64
if you use windows.
Copy libmir-glas.a
to your project or add its directory to the library path.
We are open for contributing! The hardest part (GEMM) is already implemented.
A := alpha*x*y' + A
A := alpha*x*conjg( y' ) + A
A := alpha*x*conjg(x') + A
A := alpha*x*conjg( x' ) + A
x = a*x
. Note: requires addition optimization for complex numbers.y = a*x + y
. Note: requires addition optimization for complex numbers.Five steps
cpuid_init
function for mir-cpuid
. This function should be implemented per platform or OS. Already implemented targets are
GLAS is a lower level library than Eigen. For example, GLAS can be an Eigen BLAS back-end in the future
Lazy Evaluation and Aliasing can be easily implemented in D.
Explicit composition of operations can be done using mir.ndslice.algorithm
and multidimensional map
from mir.ndslice.topology
, which is a generic way to perform any lazy operations you want.