From Fedora Project Wiki
No edit summary
Line 1: Line 1:
{{Draft}}
{{Draft}}
= Introduction =
= Introduction =


Besides being implementations, BLAS and LAPACK are also API standards for basic linear algebra operations (such as vector and matrix multiplication).
Besides being implementations, BLAS and LAPACK are also API standards for basic linear algebra operations (such as vector and matrix multiplication). Many implementations of these API exist. The reference implementation of BLAS and LAPACK from Netlib is very stable but is not as fast as optimized ones such as ATLAS and OpenBLAS.
 
Many implementations of these API exist. The reference implementation of BLAS and LAPACK from netlib is very stable but is not as fast as optimized ones such as ATLAS and OpenBLAS.


Implementations of BLAS:
Implementations of BLAS:


*   blas - Reference implementation from netlib
* blas - Reference implementation from Netlib.
*   atlas - Automatically Tuned Linear Algebra Software
* atlas - Automatically Tuned Linear Algebra Software.
*   openblas - OpenBLAS, an optimized BLAS based on GotoBLAS2
* openblas - OpenBLAS, an optimized BLAS based on GotoBLAS2. It provides several flavors: a sequential version, a threaded one, and another with OpenMP support (all of them with or without support for 64-bit integers).


Implementations of LAPACK:
Implementations of LAPACK:


*   lapack - Reference implementation from netlib
* lapack - Reference implementation from Netlib.
*   ATLAS and OpenBLAS both provide an optimized subset of LAPACK
* ATLAS and OpenBLAS both provide an optimized subset of LAPACK.
 
Due to implementation differences, it is important that all components of a particular software stack link to the same BLAS/LAPACK implementation.  Also, users may want to choose a  particular implementation that works best for them at run time.  This guideline gives a structure that can enforce the first while allowing the second.
 
= BLAS/LAPACK implementations =
 
Implementations of a BLAS and/or LAPACK library must build versions of their libraries with the libblas.so.3 and liblapack.so3 sonames containing the appropriate symbols and ship them in %{_libdir}/IMPLEMENTATION-NAME/.  Each implementation may have multiple IMPLEMENTATION-NAMEs, e.g. for serial and parallel versions.


For example, atlas would have:
Due to implementation differences, it is important that all components of a particular software stack link to the same BLAS/LAPACK implementation. Also, users may want to choose a particular implementation that works best for them at run time.  This guideline gives a structure that can enforce the first while allowing the second, as well as providing a transparent fallback mechanism to Netlib's reference implementation for those symbols not included in the selected backend.


%files
= BLAS/LAPACK wrapper =
...
%{_libdir}/%{name}-serial/libblas.so.3
%{_libdir}/%{name}-serial/liblapack.so.3
%{_libdir}/%{name}-threaded/libblas.so.3
%{_libdir}/%{name}-threaded/liblapack.so.3


If ILP64 (64-bit integer) implementations are available, they should be provided as well. For openblas:
[https://www.mpi-magdeburg.mpg.de/projects/flexiblas FlexiBLAS] is a framework that wraps both BLAS and LAPACK APIs in a single library. BLAS/LAPACK consumers must link against FlexiBLAS, and this wrapper is able to redirect calls to a selected optimized backend with negligible overhead. It also provides transparent fallback to Netlib's reference implementation if a certain symbol is not present in the selected backend. These are the main features:


%files
* Provides a 100% BLAS and LAPACK compatible ABI/API, with interfaces for both 32- and 64-bit integers.
...
* Runtime exchangable BLAS and LAPACK backend without recompilation via an environment variable.
%{_libdir}/%[name}-serial/libblas64.so.3
* Integration of user-owned BLAS libraries without administrator privileges, even in system-wide installed programs.
%{_libdir}/%{name}-serial/liblapack64.so.3
* Works with OpenBLAS, ATLAS, Intel MKL, ACML, ...
%{_libdir}/%{name}-serial/libblas64_.so.3
* Flexible per-system/user/host configuration files.
%{_libdir}/%{name}-serial/liblapack64_.so.3
* Basic profiling support.


== System level BLAS/LAPACK selection ==
FlexiBLAS provides a common interface,


To allow system level selection of the desired BLAS/LAPACK implementation, alternatives are used, selecting which path is desired for /etc/ld.so.conf.d/blas-%{arch}.conf.
%files wrapper
%{_libdir}/flexiblas.so.x
%files wrapper64
%{_libdir}/flexiblas64.so.x


<pre>
as well as fallbacks to Netlib's reference implementation,
Requires(post): %{_sbindir}/update-alternatives
Requires(postun): %{_sbindir}/update-alternatives


%install
%files wrapper
...
%{_libdir}/flexiblas/libflexiblas_netlib.so
mkdir -p %{buildroot}%{_sysconfdir}/ld.so.conf.d
%{_libdir}/flexiblas/libflexiblas_fallback_lapack.so
touch %{buildroot}%{_sysconfdir}/ld.so.conf.d/blas-%{_arch}.conf
echo %{_libdir}/%{name}-serial > %{buildroot}%{_sysconfdir}/ld.so.conf.d/blas-%{_arch}.conf-%{name}-serial
%files wrapper64
%{_libdir}/flexiblas64/libflexiblas_netlib.so
%{_libdir}/flexiblas64/libflexiblas_fallback_lapack.so


%post
and, finally, several wrappers for different implementations under different names:
%{_sbindir}/update-alternatives --install %{_sysconfdir}/ld.so.conf.d/blas-%{_arch}.conf \
  blas %{_sysconfdir}/ld.so.conf.d/blas-%{_arch}.conf-%{name}-serial 60
/sbin/ldconfig


%postun
%files atlas
if [ $1 -eq 0 ] ; then
%{_libdir}/flexiblas/libflexiblas_atlas.so
  %{_sbindir}/update-alternatives --remove blas %{_sysconfdir}/ld.so.conf.d/blas-%{_arch}.conf-%{name}-serial
fi
%files openblas-serial
/sbin/ldconfig
%{_libdir}/flexiblas/libflexiblas_openblas.so
</pre>
%files openblas-threads
%{_libdir}/flexiblas/libflexiblas_openblas-pthreads.so
%files openblas-openmp
%{_libdir}/flexiblas/libflexiblas_openblas-openmp.so
%files openblas-serial64
%{_libdir}/flexiblas64/libflexiblas_openblas.so
%files openblas-threads64
%{_libdir}/flexiblas64/libflexiblas_openblas-pthreads.so
%files openblas-openmp64
%{_libdir}/flexiblas64/libflexiblas_openblas-openmp.so


Current established priorities are 30 for atlas and 60 for openblas.
These are sub-packaged separately to avoid pulling the whole stack of implementations. The wrapper and wrapper64 sub-packages require a default implementation:


Also, we provide libblas/liblapack:
%global default_backend openblas-serial
%package        wrapper
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:      %{name}-%{default_backend}%{?_isa} = %{version}-%{release}
%package        wrapper64
Requires:      %{name}%{?_isa} = %{version}-%{release}
Requires:      %{name}-%{default_backend}64%{?_isa} = %{version}-%{release}


%if %{_lib} == "lib64"
= Packaging guidelines =
Provides: libblas.so.3()(64bit)
Provides: liblapack.so.3()(64bit)
%else
Provides: libblas.so.3
Provides: liblapack.so.3
%endif


== User level BLAS/LAPACK selection ==
== BLAS/LAPACK implementations ==


Environment modules are used to provide user level selection of the desired BLAS/LAPACK implementation.  For each IMPLEMENTATION-NAME, the implementation package will provide an environment module, e.g.:
Implementations of BLAS and/or LAPACK available in Fedora do not need to change anything.


#%Module 1.0
== BLAS/LAPACK dependent packages ==
# ATLAS module for loading serial atlas library
conflict                blas
prepend-path            LD_LIBRARY_PATH /usr/lib64/atlas-serial


as %{_datadir}/modulefiles/blas/atlas-serial.  The implementation must then require an environment module implementation:
Consumers of any subset of BLAS and/or LAPACK must compile against FlexiBLAS:


  Requires: environment(modules)
  BuildRequires: pkgconfig(flexiblas)


Because many (all except the reference?) BLAS/LAPACK implementations are combined BLAS/LAPACK libraries, we do not support separate specification of BLAS and LAPACK, only combinations that are explicitly known to work.
or


== Consistent LAPACK versions ==
BuildRequires: pkgconfig(flexiblas64)


Most optimized BLAS implementations also offer a subset of optimized LAPACK functions.  They must then fill out the rest of the LAPACK API from the reference netlib LAPACK, either via static LAPACK library or a bundled version.  The reference LAPACK interface is slowly changing so it is important that the LAPACK API version be consistent across all LAPCK implementations on a specific release.  This is most easily handled by linking to the static LAPACK reference library.
and they will automatically benefit from any system/user/host-selected optimized subset of routines.


= BLAS/LAPACK dependent packages =
= Backend selection =


== Generic Usage ==
== System-level selection ==
If the BLAS/LAPACK consumer does not require special compile time configuration for different BLAS/LAPACK implementations, it should simply build against the reference implementation:


BuildRequires: blas-devel
To allow system-level selection of the desired BLAS/LAPACK implementation, a "default=IMPLEMENTATION-NAME" key must be added to the configuration files shipped with FlexiBLAS:
BuildRequires: lapack-devel


so that they end up linking to libblas.so.3 and liblapack.so.3, thus allowing the implementation to be switched at run time.
%files wrapper
%config(noreplace) %{_sysconfdir}/flexiblasrc
%files wrapper64
%config(noreplace) %{_sysconfdir}/flexiblasrc64


== Compile time configuration ==
== User-level selection ==


If the consumer requires special configuration for different implementations, it should provide versions compiled with each implementation.
Persistent user-level selection of system-provided BLAS/LAPACK implementations can be done via the CLI tool:


= End-User Documentation =
$ flexiblas set IMPLEMENTATION-NAME
$ flexiblas64 set IMPLEMENTATION-NAME


End users will load the implementation they desire with:
provided the sub-package for IMPLEMENTATION-NAME is installed.


module load blas/IMPLEMENTATION-NAME
Non-persistent user-level selection can be triggered via an environment variable:


TODO - choose a distribution default?
$ FLEXIBLAS=IMPLEMENTATION-NAME ./yourapp
$ FLEXIBLAS64=IMPLEMENTATION-NAME ./yourapp64


User-level selection of user-owned BLAS/LAPACK libraries can be achieved just by changing IMPLEMENTATION-NAME with a path to any custom BLAS/LAPACK-compatible library in the examples above.


[[Category:Packaging guidelines drafts]]
[[Category:Packaging guidelines drafts]]

Revision as of 16:32, 7 June 2020

Warning.png
This page is a draft only
It is still under construction and content may change. Do not rely on the information on this page.

Introduction

Besides being implementations, BLAS and LAPACK are also API standards for basic linear algebra operations (such as vector and matrix multiplication). Many implementations of these API exist. The reference implementation of BLAS and LAPACK from Netlib is very stable but is not as fast as optimized ones such as ATLAS and OpenBLAS.

Implementations of BLAS:

  • blas - Reference implementation from Netlib.
  • atlas - Automatically Tuned Linear Algebra Software.
  • openblas - OpenBLAS, an optimized BLAS based on GotoBLAS2. It provides several flavors: a sequential version, a threaded one, and another with OpenMP support (all of them with or without support for 64-bit integers).

Implementations of LAPACK:

  • lapack - Reference implementation from Netlib.
  • ATLAS and OpenBLAS both provide an optimized subset of LAPACK.

Due to implementation differences, it is important that all components of a particular software stack link to the same BLAS/LAPACK implementation. Also, users may want to choose a particular implementation that works best for them at run time. This guideline gives a structure that can enforce the first while allowing the second, as well as providing a transparent fallback mechanism to Netlib's reference implementation for those symbols not included in the selected backend.

BLAS/LAPACK wrapper

FlexiBLAS is a framework that wraps both BLAS and LAPACK APIs in a single library. BLAS/LAPACK consumers must link against FlexiBLAS, and this wrapper is able to redirect calls to a selected optimized backend with negligible overhead. It also provides transparent fallback to Netlib's reference implementation if a certain symbol is not present in the selected backend. These are the main features:

  • Provides a 100% BLAS and LAPACK compatible ABI/API, with interfaces for both 32- and 64-bit integers.
  • Runtime exchangable BLAS and LAPACK backend without recompilation via an environment variable.
  • Integration of user-owned BLAS libraries without administrator privileges, even in system-wide installed programs.
  • Works with OpenBLAS, ATLAS, Intel MKL, ACML, ...
  • Flexible per-system/user/host configuration files.
  • Basic profiling support.

FlexiBLAS provides a common interface,

%files wrapper
%{_libdir}/flexiblas.so.x

%files wrapper64
%{_libdir}/flexiblas64.so.x

as well as fallbacks to Netlib's reference implementation,

%files wrapper
%{_libdir}/flexiblas/libflexiblas_netlib.so
%{_libdir}/flexiblas/libflexiblas_fallback_lapack.so

%files wrapper64
%{_libdir}/flexiblas64/libflexiblas_netlib.so
%{_libdir}/flexiblas64/libflexiblas_fallback_lapack.so

and, finally, several wrappers for different implementations under different names:

%files atlas
%{_libdir}/flexiblas/libflexiblas_atlas.so

%files openblas-serial
%{_libdir}/flexiblas/libflexiblas_openblas.so

%files openblas-threads
%{_libdir}/flexiblas/libflexiblas_openblas-pthreads.so

%files openblas-openmp
%{_libdir}/flexiblas/libflexiblas_openblas-openmp.so

%files openblas-serial64
%{_libdir}/flexiblas64/libflexiblas_openblas.so

%files openblas-threads64
%{_libdir}/flexiblas64/libflexiblas_openblas-pthreads.so

%files openblas-openmp64
%{_libdir}/flexiblas64/libflexiblas_openblas-openmp.so

These are sub-packaged separately to avoid pulling the whole stack of implementations. The wrapper and wrapper64 sub-packages require a default implementation:

%global default_backend openblas-serial

%package        wrapper
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       %{name}-%{default_backend}%{?_isa} = %{version}-%{release}

%package        wrapper64
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       %{name}-%{default_backend}64%{?_isa} = %{version}-%{release}

Packaging guidelines

BLAS/LAPACK implementations

Implementations of BLAS and/or LAPACK available in Fedora do not need to change anything.

BLAS/LAPACK dependent packages

Consumers of any subset of BLAS and/or LAPACK must compile against FlexiBLAS:

BuildRequires: pkgconfig(flexiblas)

or

BuildRequires: pkgconfig(flexiblas64)

and they will automatically benefit from any system/user/host-selected optimized subset of routines.

Backend selection

System-level selection

To allow system-level selection of the desired BLAS/LAPACK implementation, a "default=IMPLEMENTATION-NAME" key must be added to the configuration files shipped with FlexiBLAS:

%files wrapper
%config(noreplace) %{_sysconfdir}/flexiblasrc

%files wrapper64
%config(noreplace) %{_sysconfdir}/flexiblasrc64

User-level selection

Persistent user-level selection of system-provided BLAS/LAPACK implementations can be done via the CLI tool:

$ flexiblas set IMPLEMENTATION-NAME
$ flexiblas64 set IMPLEMENTATION-NAME

provided the sub-package for IMPLEMENTATION-NAME is installed.

Non-persistent user-level selection can be triggered via an environment variable:

$ FLEXIBLAS=IMPLEMENTATION-NAME ./yourapp
$ FLEXIBLAS64=IMPLEMENTATION-NAME ./yourapp64

User-level selection of user-owned BLAS/LAPACK libraries can be achieved just by changing IMPLEMENTATION-NAME with a path to any custom BLAS/LAPACK-compatible library in the examples above.