Hubbry Logo
Basic Linear Algebra SubprogramsBasic Linear Algebra SubprogramsMain
Open search
Basic Linear Algebra Subprograms
Community hub
Basic Linear Algebra Subprograms
logo
7 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Basic Linear Algebra Subprograms
Basic Linear Algebra Subprograms
from Wikipedia

BLAS
Stable release
3.11.0 / 11 November 2022; 2 years ago (2022-11-11)
Written independs on implementation
PlatformCross-platform
TypeLibrary
Websitewww.netlib.org/blas/

Basic Linear Algebra Subprograms (BLAS) is a specification that prescribes a set of low-level routines for performing common linear algebra operations such as vector addition, scalar multiplication, dot products, linear combinations, and matrix multiplication. They are the de facto standard low-level routines for linear algebra libraries; the routines have bindings for both C ("CBLAS interface") and Fortran ("BLAS interface"). Although the BLAS specification is general, BLAS implementations are often optimized for speed on a particular machine, so using them can bring substantial performance benefits. BLAS implementations will take advantage of special floating point hardware such as vector registers or SIMD instructions.

It originated as a Fortran library in 1979[1] and its interface was standardized by the BLAS Technical (BLAST) Forum, whose latest BLAS report can be found on the netlib website.[2] This Fortran library is known as the reference implementation (sometimes confusingly referred to as the BLAS library) and is not optimized for speed but is in the public domain.[3][4]

Most libraries that offer linear algebra routines conform to the BLAS interface, allowing library users to develop programs that are indifferent to the BLAS library being used.

Many BLAS libraries have been developed, targeting various different hardware platforms. Examples includes cuBLAS (NVIDIA GPU, GPGPU), rocBLAS (AMD GPU), and OpenBLAS. Examples of CPU-based BLAS library branches include: OpenBLAS, BLIS (BLAS-like Library Instantiation Software), Arm Performance Libraries,[5] ATLAS, and Intel Math Kernel Library (iMKL). AMD maintains a fork of BLIS that is optimized for the AMD platform.[6] ATLAS is a portable library that automatically optimizes itself for an arbitrary architecture. iMKL is a freeware[7] and proprietary[8] vendor library optimized for x86 and x86-64 with a performance emphasis on Intel processors.[9] OpenBLAS is an open-source library that is hand-optimized for many of the popular architectures. The LINPACK benchmarks rely heavily on the BLAS routine gemm for its performance measurements.

Many numerical software applications use BLAS-compatible libraries to do linear algebra computations, including LAPACK, LINPACK, Armadillo, GNU Octave, Mathematica,[10] MATLAB,[11] NumPy,[12] R, Julia and Lisp-Stat.

The C++ std::linalg library, introduced in C++26, is based on BLAS.

Background

[edit]

With the advent of numerical programming, sophisticated subroutine libraries became useful. These libraries would contain subroutines for common high-level mathematical operations such as root finding, matrix inversion, and solving systems of equations. The language of choice was FORTRAN. The most prominent numerical programming library was IBM's Scientific Subroutine Package (SSP).[13] These subroutine libraries allowed programmers to concentrate on their specific problems and avoid re-implementing well-known algorithms. The library routines would also be better than average implementations; matrix algorithms, for example, might use full pivoting to get better numerical accuracy. The library routines would also have more efficient routines. For example, a library may include a program to solve a matrix that is upper triangular. The libraries would include single-precision and double-precision versions of some algorithms.

Initially, these subroutines used hard-coded loops for their low-level operations. For example, if a subroutine needed to perform a matrix multiplication, then the subroutine would have three nested loops. Linear algebra programs have many common low-level operations (the so-called "kernel" operations, not related to operating systems).[14] Between 1973 and 1977, several of these kernel operations were identified.[15] These kernel operations became defined subroutines that math libraries could call. The kernel calls had advantages over hard-coded loops: the library routine would be more readable, there were fewer chances for bugs, and the kernel implementation could be optimized for speed. A specification for these kernel operations using scalars and vectors, the level-1 Basic Linear Algebra Subroutines (BLAS), was published in 1979.[16] BLAS was used to implement the linear algebra subroutine library LINPACK.

The BLAS abstraction allows customization for high performance. For example, LINPACK is a general purpose library that can be used on many different machines without modification. LINPACK could use a generic version of BLAS. To gain performance, different machines might use tailored versions of BLAS. As computer architectures became more sophisticated, vector machines appeared. BLAS for a vector machine could use the machine's fast vector operations. (While vector processors eventually fell out of favor, vector instructions in modern CPUs are essential for optimal performance in BLAS routines.)

Other machine features became available and could also be exploited. Consequently, BLAS was augmented from 1984 to 1986 with level-2 kernel operations that concerned vector-matrix operations. Memory hierarchy was also recognized as something to exploit. Many computers have cache memory that is much faster than main memory; keeping matrix manipulations localized allows better usage of the cache. In 1987 and 1988, the level 3 BLAS were identified to do matrix-matrix operations. The level 3 BLAS encouraged block-partitioned algorithms. The LAPACK library uses level 3 BLAS.[17]

The original BLAS concerned only densely stored vectors and matrices. Further extensions to BLAS, such as for sparse matrices, have been addressed.[18]

Functionality

[edit]

BLAS functionality is categorized into three sets of routines called "levels", which correspond to both the chronological order of definition and publication, as well as the degree of the polynomial in the complexities of algorithms; Level 1 BLAS operations typically take linear time, O(n), Level 2 operations quadratic time and Level 3 operations cubic time.[19] Modern BLAS implementations typically provide all three levels.

Level 1

[edit]

This level consists of all the routines described in the original presentation of BLAS (1979),[1] which defined only vector operations on strided arrays: dot products, vector norms, a generalized vector addition of the form

(called "axpy", "a x plus y") and several other operations.

Level 2

[edit]

This level contains matrix-vector operations including, among other things, a generalized matrix-vector multiplication (gemv):

as well as a solver for x in the linear equation

with T being triangular. Design of the Level 2 BLAS started in 1984, with results published in 1988.[20] The Level 2 subroutines are especially intended to improve performance of programs using BLAS on vector processors, where Level 1 BLAS are suboptimal "because they hide the matrix-vector nature of the operations from the compiler."[20]

Level 3

[edit]

This level, formally published in 1990,[19] contains matrix-matrix operations, including a "general matrix multiplication" (gemm), of the form

where A and B can optionally be transposed or hermitian-conjugated inside the routine, and all three matrices may be strided. The ordinary matrix multiplication A B can be performed by setting α to one and C to an all-zeros matrix of the appropriate size.

Also included in Level 3 are routines for computing

where T is a triangular matrix, among other functionality.

Due to the ubiquity of matrix multiplications in many scientific applications, including for the implementation of the rest of Level 3 BLAS,[21] and because faster algorithms exist beyond the obvious repetition of matrix-vector multiplication, gemm is a prime target of optimization for BLAS implementers. E.g., by decomposing one or both of A, B into block matrices, gemm can be implemented recursively. This is one of the motivations for including the β parameter,[dubiousdiscuss] so the results of previous blocks can be accumulated. Note that this decomposition requires the special case β = 1 which many implementations optimize for, thereby eliminating one multiplication for each value of C. This decomposition allows for better locality of reference both in space and time of the data used in the product. This, in turn, takes advantage of the cache on the system.[22] For systems with more than one level of cache, the blocking can be applied a second time to the order in which the blocks are used in the computation. Both of these levels of optimization are used in implementations such as ATLAS. More recently, implementations by Kazushige Goto have shown that blocking only for the L2 cache, combined with careful amortizing of copying to contiguous memory to reduce TLB misses, is superior to ATLAS.[23] A highly tuned implementation based on these ideas is part of the GotoBLAS, OpenBLAS and BLIS.

A common variation of gemm is the gemm3m, which calculates a complex product using "three real matrix multiplications and five real matrix additions instead of the conventional four real matrix multiplications and two real matrix additions", an algorithm similar to Strassen algorithm first described by Peter Ungar.[24]

Implementations

[edit]
Accelerate
Apple's framework for macOS and iOS, which includes tuned versions of BLAS and LAPACK.[25][26]
Arm Performance Libraries
Arm Performance Libraries, supporting Arm 64-bit AArch64-based processors, available from Arm.[5]
ATLAS
Automatically Tuned Linear Algebra Software, an open source implementation of BLAS APIs for C and Fortran 77.[27]
BLIS
BLAS-like Library Instantiation Software framework for rapid instantiation. Optimized for most modern CPUs. BLIS is a complete refactoring of the GotoBLAS that reduces the amount of code that must be written for a given platform.[28][29]
C++ AMP BLAS
The C++ AMP BLAS Library is an open source implementation of BLAS for Microsoft's AMP language extension for Visual C++.[30]
cuBLAS
Optimized BLAS for Nvidia-based GPU cards, requiring few additional library calls.[31]
NVBLAS
Optimized BLAS for Nvidia-based GPU cards, providing only Level 3 functions, but as direct drop-in replacement for other BLAS libraries.[32]
clBLAS
An OpenCL implementation of BLAS by AMD. Part of the AMD Compute Libraries.[33]
clBLAST
A tuned OpenCL implementation of most of the BLAS api.[34]
Eigen BLAS
A Fortran 77 and C BLAS library implemented on top of the MPL-licensed Eigen library, supporting x86, x86-64, ARM (NEON), and PowerPC architectures.
ESSL
IBM's Engineering and Scientific Subroutine Library, supporting the PowerPC architecture under AIX and Linux.[35]
GotoBLAS
Kazushige Goto's BSD-licensed implementation of BLAS, tuned in particular for Intel Nehalem/Atom, VIA Nanoprocessor, AMD Opteron.[36]
GNU Scientific Library
Multi-platform implementation of many numerical routines. Contains a CBLAS interface.
HP MLIB
HP's Math library supporting IA-64, PA-RISC, x86 and Opteron architecture under HP-UX and Linux.
Intel MKL
The Intel Math Kernel Library, supporting x86 32-bits and 64-bits, available free from Intel.[7] Includes optimizations for Intel Pentium, Core and Intel Xeon CPUs and Intel Xeon Phi; support for Linux, Windows and macOS.[37]
MathKeisan
NEC's math library, supporting NEC SX architecture under SUPER-UX, and Itanium under Linux[38]
Netlib BLAS
The official reference implementation on Netlib, written in Fortran 77.[39]
Netlib CBLAS
Reference C interface to the BLAS. It is also possible (and popular) to call the Fortran BLAS from C.[40]
OpenBLAS
Optimized BLAS based on GotoBLAS, supporting x86, x86-64, MIPS and ARM processors.[41]
PDLIB/SX
NEC's Public Domain Mathematical Library for the NEC SX-4 system.[42]
rocBLAS
Implementation that runs on AMD GPUs via ROCm.[43]
SCSL
SGI's Scientific Computing Software Library contains BLAS and LAPACK implementations for SGI's Irix workstations.[44]
Sun Performance Library
Optimized BLAS and LAPACK for SPARC, Core and AMD64 architectures under Solaris 8, 9, and 10 as well as Linux.[45]
uBLAS
A generic C++ template class library providing BLAS functionality. Part of the Boost library. It provides bindings to many hardware-accelerated libraries in a unifying notation. Moreover, uBLAS focuses on correctness of the algorithms using advanced C++ features.[46]

Libraries using BLAS

[edit]
Armadillo
Armadillo is a C++ linear algebra library aiming towards a good balance between speed and ease of use. It employs template classes, and has optional links to BLAS/ATLAS and LAPACK. It is sponsored by NICTA (in Australia) and is licensed under a free license.[47]
LAPACK
LAPACK is a higher level Linear Algebra library built upon BLAS. Like BLAS, a reference implementation exists, but many alternatives like libFlame and MKL exist.
Mir
An LLVM-accelerated generic numerical library for science and machine learning written in D. It provides generic linear algebra subprograms (GLAS). It can be built on a CBLAS implementation.[48]

Similar libraries (not compatible with BLAS)

[edit]
Elemental
Elemental is an open source software for distributed-memory dense and sparse-direct linear algebra and optimization.[49]
HASEM
is a C++ template library, being able to solve linear equations and to compute eigenvalues. It is licensed under BSD License.[50]
LAMA
The Library for Accelerated Math Applications (LAMA) is a C++ template library for writing numerical solvers targeting various kinds of hardware (e.g. GPUs through CUDA or OpenCL) on distributed memory systems, hiding the hardware specific programming from the program developer
MTL4
The Matrix Template Library version 4 is a generic C++ template library providing sparse and dense BLAS functionality. MTL4 establishes an intuitive interface (similar to MATLAB) and broad applicability thanks to generic programming.

Sparse BLAS

[edit]

Several extensions to BLAS for handling sparse matrices have been suggested over the course of the library's history; a small set of sparse matrix kernel routines was finally standardized in 2002.[51]

Batched BLAS

[edit]

The traditional BLAS functions have been also ported to architectures that support large amounts of parallelism such as GPUs. Here, the traditional BLAS functions provide typically good performance for large matrices. However, when computing e.g., matrix-matrix-products of many small matrices by using the GEMM routine, those architectures show significant performance losses. To address this issue, in 2017 a batched version of the BLAS function has been specified.[52]

Taking the GEMM routine from above as an example, the batched version performs the following computation simultaneously for many matrices:

The index in square brackets indicates that the operation is performed for all matrices in a stack. Often, this operation is implemented for a strided batched memory layout where all matrices follow concatenated in the arrays , and .

Batched BLAS functions can be a versatile tool and allow e.g. a fast implementation of exponential integrators and Magnus integrators that handle long integration periods with many time steps.[53] Here, the matrix exponentiation, the computationally expensive part of the integration, can be implemented in parallel for all time-steps by using Batched BLAS functions.

See also

[edit]

References

[edit]

Further reading

[edit]
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
Basic Linear Algebra Subprograms (BLAS) are a specification defining a set of low-level, portable routines for fundamental operations in numerical linear algebra, including vector-vector, matrix-vector, and matrix-matrix computations. Developed to standardize and optimize basic linear algebra tasks, BLAS enables software libraries to achieve high performance across diverse hardware architectures without sacrificing portability. The origins of BLAS trace back to a 1979 proposal by C. L. Lawson, R. J. Hanson, D. R. Kincaid, and F. T. Krogh, who introduced the initial set of 38 subprograms focused on vector operations, now known as Level 1 BLAS. This foundational work addressed the need for efficient, reusable code in solving linear systems, eigenvalue problems, and other numerical tasks prevalent in scientific computing. Over time, the specification evolved with the addition of Level 2 BLAS in 1988, which extended functionality to matrix-vector operations, and Level 3 BLAS in 1990, targeting matrix-matrix multiplications for better exploitation of modern processors. BLAS has become a cornerstone of , integrated into major libraries such as , ATLAS, and vendor-optimized implementations like MKL and ESSL. The 2002 update by the BLAS Technical Forum further refined the standard, incorporating precision-independent naming conventions and support for additional operations, while maintaining . Subsequent extensions, including sparse and batched variants, continue to address emerging needs in large-scale simulations and .

History and Development

Origins in Numerical Computing

The development of the Basic Linear Algebra Subprograms (BLAS) originated in the early 1970s at the (JPL), driven by the growing need for portable and efficient computational kernels in scientific and engineering applications, particularly for solving large-scale linear systems and eigenvalue problems on emerging high-performance computers. Researchers recognized that numerical software libraries, such as those used in physics simulations and optimization, required standardized building blocks to ensure reliability and performance across diverse hardware architectures, avoiding the inefficiencies of ad hoc implementations. This initiative was led by C. L. Lawson, R. J. Hanson, D. R. Kincaid, and F. T. Krogh at JPL, with foundational work later integrated at for projects like LINPACK, where the focus was on creating modular routines that could abstract low-level vector mathematics, allowing higher-level algorithms to remain hardware-agnostic while benefiting from vendor-optimized code. Jack Dongarra at Argonne National Laboratory contributed to integrating BLAS into LINPACK, a comprehensive package for linear equation solving developed from 1976 to 1979 with collaborators including Jim Bunch, Cleve Moler, and others, that used these subprograms as its computational core. The University of Tennessee later became involved as Dongarra transitioned there, facilitating ongoing refinements. The emphasis was on vector operations—such as dot products, saxpy (scalar-vector multiplication and addition), and norms—essential for iterative methods in linear algebra, ensuring these kernels could be reused across multiple algorithms without redundancy. The first proposal emerged in as a collection of subroutines, implementing basic vector mathematics with a simple, callable interface that prioritized to enable machine-specific tuning without altering user-facing code. This design allowed implementers to replace generic versions with optimized ones tailored to particular processors, fostering portability while maximizing computational efficiency in resource-constrained environments. A final report was issued in , with publication in 1979. Early challenges centered on achieving portability across supercomputers like the vector machines and systems, which featured disparate instruction sets, memory models, and floating-point precisions that complicated uniform performance. At the time, numerical libraries suffered from a lack of standardized interfaces, leading to fragmented codebases that hindered collaboration and maintenance among research institutions; BLAS addressed this by proposing a through its integration into widely adopted tools like LINPACK. These efforts set the stage for subsequent expansions into higher-level operations, though the initial focus remained on foundational vector kernels.

Evolution of BLAS Levels and Standards

The Basic Linear Algebra Subprograms (BLAS) originated with Level 1 in 1979, providing a standardized set of vector-vector operations designed to serve as efficient building blocks for numerical software, particularly in response to the need for portable and optimized linear algebra routines. This initial specification, comprising 38 subprograms for operations such as dot products and vector scaling, was developed by C. L. Lawson, R. J. Hanson, D. R. Kincaid, and F. T. Krogh to address inefficiencies in implementations within packages like LINPACK and EISPACK, enabling developers to tune performance for specific hardware while maintaining interface consistency. As computational demands grew with the advent of vector processors in the mid-1980s, the BLAS evolved to include Level 2 in 1985, introducing matrix-vector operations to better exploit these architectures' capabilities for higher throughput in linear algebra tasks. This extension built on Level 1 by adding routines for operations like matrix-vector multiplication and rank-one updates, formalized in a 1988 standardization proposal that emphasized portability across emerging vector and early parallel machines. Level 3 followed in 1990, focusing on matrix-matrix operations to further optimize block-based algorithms on multiprocessor systems, driven by the integration needs of evolving numerical libraries like for dense linear systems. A pivotal milestone in BLAS standardization came in with a comprehensive proposal by Dongarra et al., which outlined the unified framework for Levels 1 through 3, promoting widespread adoption by establishing a interface for . The BLAS Technical Forum, with meetings beginning in 1995, led to discussions in the late and addressed limitations in precision and data types, resulting in an updated standard published in 2002 that incorporated support for extended and double-precision complex numbers to enhance accuracy in advanced scientific applications. This evolution reflected ongoing adaptations to hardware advancements, ensuring BLAS remained a foundational standard for linear algebra through the early .

Core Functionality

Level 1: Vector Operations

Level 1 BLAS routines provide the foundational operations for vector-vector computations in , focusing exclusively on manipulations between one or two vectors of length nn without involving matrices. These operations exhibit O(n)O(n) , making them efficient for sequential data access and essential as kernels in more complex algorithms. Originally specified as a set of 38 subprograms, the core Level 1 routines encompass basic manipulations like scaling, copying, and inner products, designed to be portable across computing platforms while allowing vendor-specific optimizations. The nine core routines are: vector scaling (SCAL), vector copy (COPY), vector swap (SWAP), vector addition with scaling (AXPY), (DOT), Euclidean norm (NRM2), sum of absolute values (ASUM), and index of maximum magnitude (IAMAX). These routines support both real and complex types, with interfaces following conventions where vectors are passed by reference and parameters specify the vector length nn, the scalar α\alpha where applicable, the vectors xx and yy, and increments incxincx and incyincy for non-contiguous storage (defaulting to 1 for contiguous). If n0n \leq 0, the routines return immediately without computation. All operations handle general increments to access vector elements at arbitrary strides, enhancing flexibility for strided data structures. SCAL multiplies each element of a vector xx by a scalar α\alpha, updating xx in place.
The mathematical formulation is:
xi:=αxi,i=1,,n.x_i := \alpha x_i, \quad i = 1, \dots, n. The interface is CALL SCAL(n, α, x, incx), where xx is modified. This routine is crucial for normalizing vectors or applying scaling factors in iterative processes. COPY copies the elements of vector xx into vector yy.
The mathematical formulation is:
yi:=xi,i=1,,n.y_i := x_i, \quad i = 1, \dots, n. The interface is CALL COPY(n, x, incx, y, incy), where yy receives the copy and xx remains unchanged. It facilitates initialization or duplication of vectors for subsequent operations. SWAP interchanges the elements of two vectors xx and yy.
The mathematical formulation is:
xiyi,i=1,,n.x_i \leftrightarrow y_i, \quad i = 1, \dots, n. The interface is CALL SWAP(n, x, incx, y, incy), exchanging contents between xx and yy. This supports efficient vector reordering without temporary storage. AXPY computes a of two vectors, adding a scaled xx to yy.
The mathematical formulation is:
yi:=αxi+yi,i=1,,n.y_i := \alpha x_i + y_i, \quad i = 1, \dots, n. The interface is CALL AXPY(n, α, x, incx, y, incy), where yy is updated in place. As a fundamental update operation, it forms the basis for accumulation steps in many algorithms. DOT computes the inner product of two vectors xx and yy.
The mathematical formulation for real vectors is:
p˙=i=1nxiyi.\dot{p} = \sum_{i=1}^n x_i y_i. For complex vectors, variants include the unconjugated product or Hermitian (conjugate) form. The interface is p = DOT(n, x, incx, y, incy), returning the scalar result pp. This routine is key for computing residuals or measures. NRM2 calculates the Euclidean (L2) norm of a vector xx.
The mathematical formulation is:
x2=i=1nxi2.\|x\|_2 = \sqrt{\sum_{i=1}^n |x_i|^2}.
Add your contribution
Related Hubs
User Avatar
No comments yet.