Bibliotecas de Álgebra Lineal
Introducción
BLAS (Basic Linear Algebra Subprograms) y LAPACK (Linear Algebra PACKage) son rutinas que proporcionan bloques de compilación estándar para rendimiento en un intervalo ancho de operaciones de álgebra linear. Existen aplicaciones de referencia estables desde Netlib escritos en Fortran, con interfaces C disponibles (invocados CBLAS y LAPACKE respectivamente), así como varias implementaciones optimizadas proporcionando subconjuntos rápidos de estas API.
Implementaciones disponibles
-
blas
,lapack
- Netlib’s reference implementation of the Fortran and C interfaces. -
atlas
- Automatically Tuned Linear Algebra Software. -
blis
- BLAS-like Library Instantiation Software framework. -
openblas
- OpenBLAS, an optimized BLAS based on GotoBLAS2.
ATLAS, BLIS and OpenBLAS provide BLAS and a subset of LAPACK. Both BLIS and OpenBLAS provide several flavors: a sequential version, a threaded one, and another with OpenMP support (all of them with or without support for 64-bit integers).
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 via FlexiBLAS.
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 exchangeable 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 and BLIS, as well as non-free alternatives such as Intel MKL, ACML…
-
Flexible per-system/user/host configuration files.
-
Basic profiling support.
Fedora ships |
Packaging BLAS/LAPACK dependent packages
Consumidores de cualquier subconjunto de BLAS y/o LAPACK DEBE compilar frente a FlexiBLAS (a no ser que no está admitido; consulte a continuación).
Excepciones
|
Requisitos de compilación
Primero, solo el paquete de desarrollo de FlexiBLAS DEBE estar listado en BuildRequires
:
BuildRequires: flexiblas-devel
lo cual proporciona todos los archivos de desarrollo necesarios, ambos para el de 32-bit (el más usual) y el entero de 64-bit del interfaz.
If the package only supports the interface for 64-bit integers, then 32-bit architectures MUST be excluded (see Arch-Specific Runtime and Build-Time Dependencies). |
Configuración
The packager MUST specify flexiblas
or flexiblas64
(for the 32-bit or 64-bit interface respectively) as both the BLAS and LAPACK library names where applicable, and packages using pkg-config
will automatically obtain the proper flags for the headers and libraries. Similarly, CMake-based projects using FindBLAS
will automatically detect and configure the proper flags for FlexiBLAS (since CMake v3.19), and no further action will be required from the packager.
Unfortunately, many upstream projects present heterogeneous ways of accessing these APIs. In a best-case scenario, the building framework may define specific options to explicitly set the BLAS and/or LAPACK libraries. More commonly, the packager MUST ensure that %{_includedir}/flexiblas
and %{_libdir}/flexiblas
(or %{_includedir}/flexiblas64
and %{_libdir}/flexiblas64
) are injected as header and library locations in the proper flags and configuration files, and/or -lflexiblas
(or -lflexiblas64
) is provided to the linker. In rare occasions, hardcoded paths in source files MUST be modified, and patches MAY be required. The packager SHOULD work with upstream to standardize the way in which these libraries are detected and configured.
To ensure that the program has been properly linked against FlexiBLAS, the packager MUST check that the |
Pruebas
Optimized BLAS/LAPACK backends are much faster than Netlib’s reference implementation, but in return results may vary a little. Consequently, tests that are too tight (with too small tolerances) may fail. In these cases, the packager SHOULD enable the reference implementation in the %check
section as follows:
export FLEXIBLAS=netlib
or, alternatively, via FLEXIBLAS64
for builds using 64-bit integers.
Backend selection
Selección de nivel del sistema
A package compiled against FlexiBLAS pulls out the corresponding flexiblas-netlib(64)
subpackage, which in turn requires the default optimized backend (i.e., flexiblas-openblas-openmp(64)
). This is set via the "default=IMPLEMENTATION-NAME" key (by default, default=openblas-openmp
), present in the main configuration file shipped in the main subpackages, %{_sysconfdir}/flexiblasrc
and %{_sysconfdir}/flexiblas64rc
.
To allow system-level selection of other BLAS/LAPACK implementations, more backends must be installed in the first place (e.g., flexiblas-atlas, flexiblas-blis-serial…), and then they can be swapped system-wide via the flexiblas
CLI tool, or just by modifying the "default" key in the configuration file by hand.
Selección de nivel de usuario
Selección de nivel de usuario persistente de implementación del proveedor del sistema BLAS/LAPACK puede ser hecho por vía de la herramienta CLI:
$ flexiblas set NOMBRE-IMPLEMENTACIÓN $ flexiblas64 set NOMBRE-IMPLEMENTACIÓN
proporcionó el sub-paquete para NOMBRE-IMPLEMENTACIÓN
está instalado.
Selección de nivel-usuario no persistente puede ser disparado por medio de una variable del entorno:
$ FLEXIBLAS=NOMBRE-IMPLEMENTACIÓN ./yourapp $ FLEXIBLAS64=NOMBRE-IMPLEMENTACIÓN ./yourapp64
La selección a nivel de usuario de bibliotecas BLAS/LAPACK propiedad del usuario se puede lograr simplemente cambiando IMPLEMENTATION-NAME
con una ruta a cualquier biblioteca personalizada compatible con BLAS/LAPACK en los ejemplos anteriores.
Want to help? Learn how to contribute to Fedora Docs ›