# 基础线性代数子程序

**基础线性代数子程序**（BLAS）是一组线性代数核心例程的规范，为基本的向量与矩阵运算提供标准构件。这些例程分为三个层级：第1层执行标量、向量及向量-向量运算，第2层执行矩阵-向量运算，第3层执行矩阵-矩阵运算。其高效性、可移植性与广泛可用性，使BLAS成为构建高质量线性代数软件（如LAPACK）的共同基础。<sup>[1](https://www.netlib.org/blas/)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 向量与矩阵运算核心例程的规范，附有从netlib分发的参考实现<sup>[1](https://www.netlib.org/blas/)</sup> |
| 层级 | 第1层：标量、向量及向量-向量运算；第2层：矩阵-向量；第3层：矩阵-矩阵<sup>[1](https://www.netlib.org/blas/)</sup> |
| 原始论文 | C. L. Lawson、R. J. Hanson、D. R. Kincaid 与 F. T. Krogh，*ACM数学软件汇刊* 5(3)：308–323，1979年9月<sup>[2](https://bishtref.com/articles/10.1145/355841.355847)</sup> |
| 原始范围 | 一套38个可被Fortran调用的例程，开发于1973–1977年间<sup>[3](https://ntrs.nasa.gov/api/citations/19780018835/downloads/19780018835.pdf)</sup> |
| 现代标准 | BLAS技术论坛标准（2002年），涵盖稠密与带状、稀疏，以及扩展与混合精度BLAS<sup>[4](https://netlib.org/blas/blast-forum/blast-forum.html)</sup> |
| 主要实现 | Netlib参考BLAS（未优化）、厂商库如Intel oneMKL与NVIDIA cuBLAS，以及开源项目ATLAS、OpenBLAS与BLIS<sup>[1](https://www.netlib.org/blas/)</sup><sup> • </sup><sup>[5](https://docs.nvidia.com/cuda/cublas/index.html)</sup><sup> • </sup><sup>[6](https://github.com/OpenMathLib/OpenBLAS)</sup> |
| 在LAPACK中的作用 | LAPACK尽可能通过BLAS调用来完成计算，因此其性能取决于所用的BLAS库<sup>[7](https://netlib.sandia.gov/lapack/)</sup> |

## 运算层级

这三个层级既反映了操作数的种类，也反映了计算与数据移动之间的平衡。第1层例程对向量执行加法与归约运算，如缩放与点积。第2层例程处理矩阵与向量的组合运算，包括矩阵乘向量、矩阵的秩1或秩2更新，以及求解三角方程组。第3层例程执行矩阵-矩阵运算，如矩阵乘法、秩k更新与三角方程组求解。<sup>[8](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2026-0/onemkl-library-overview.html)</sup>

在具有存储层次结构的机器上，第3层例程对性能最有价值，因为它们能在大量算术运算中复用数据。LAPACK利用这一点对其算法进行分块：诸如高斯消元之类的例程按列组处理矩阵，块级工作由第3层BLAS调用完成，而LAPACK例程中几乎所有的并行性都包含在第1、2、3层BLAS之中。<sup>[9](https://www.netlib.org/lapack/lawnspdf/lawn44.pdf)</sup><sup> • </sup><sup>[10](https://www.netlib.org/lapack/lapack-3.1.1/INSTALL/lawn81.pdf)</sup>

例程名以首字符编码数据类型：`s`与`d`分别表示单精度与双精度实数，`c`与`z`分别表示单精度与双精度复数，因此`sgemm`即单精度通用矩阵乘法。当BLAS例程遇到无效的输入参数时，会调用错误报告例程`xerbla`。<sup>[11](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-1/blas-and-sparse-blas-routines.html)</sup>

## 历史

BLAS源于1973–1977年间的一项工作，旨在为线性代数定义一套标准、可移植、可被Fortran调用的子程序包；最终形成的包包含38个例程。<sup>[3](https://ntrs.nasa.gov/api/citations/19780018835/downloads/19780018835.pdf)</sup> 1979年9月，喷气推进实验室的Charles L. Lawson、桑迪亚实验室的Richard J. Hanson、得克萨斯大学奥斯汀分校的D. R. Kincaid以及喷气推进实验室的Fred T. Krogh在*ACM数学软件汇刊* 5(3)第308–323页发表了《供Fortran使用的基础线性代数子程序》，同期刊出算法539。<sup>[2](https://bishtref.com/articles/10.1145/355841.355847)</sup><sup> • </sup><sup>[12](https://www.calgo.hosting.acm.org/)</sup>

最初的一套仅涵盖向量运算，即如今所称的第1层BLAS。后来的扩展增加了第2层（矩阵-向量）与第3层（矩阵-矩阵）例程，三个层级的定义在各自的出版物中得以正式确立。<sup>[13](https://netlib.org/lapack/lawn81-3.0/node7.html)</sup> Jack Dongarra于1976至1979年在阿贡国家实验室从事LINPACK工作，后来在田纳西大学领导LAPACK项目，他称LINPACK与BLAS紧密相连，而LAPACK构建在第2层与第3层BLAS之上，从而将高性能与在共享内存并行及向量架构上的可移植性结合起来。<sup>[14](https://history.siam.org/oralhistories/dongarra.htm)</sup>

## BLAS技术论坛标准

20世纪90年代末，BLAS技术论坛召开会议，将标准扩展到传统三个层级之外。会议从1995年11月于田纳西大学诺克斯维尔分校举行BLAS技术研讨会开始，持续至1999年3月，标准的最终草案于2002年发布。<sup>[4](https://netlib.org/blas/blast-forum/blast-forum.html)</sup> 该标准按章组织，涵盖稠密与带状BLAS、稀疏BLAS，以及扩展与混合精度BLAS，并包含传统BLAS的C接口，以及关于环境例程、分布式内存BLAS、Fortran 95瘦BLAS与区间BLAS的开发记录章节。<sup>[4](https://netlib.org/blas/blast-forum/blast-forum.html)</sup>

2002年，L. S. Blackford、James Demmel、Jack Dongarra、Iain Duff、Sven Hammarling、Greg Henry、Michael Heroux、Linda Kaufman、Andrew Lumsdaine、Antoine Petitet、Roldan Pozo、Karin Remington与R. Clint Whaley在*ACM数学软件汇刊* 28(2)第135–151页发表了一篇总结论文，描述了由此形成的范围：适用于稠密、带状与稀疏向量及矩阵运算的BLAS变体，其中部分例程支持扩展与混合精度。<sup>[15](https://www.nist.gov/publications/updated-set-basic-linear-algebra-subprograms-blas)</sup> 扩展精度的参考实现以XBLAS（额外精度基础线性代数子程序）分发。<sup>[16](https://netlib.sandia.gov/xblas/)</sup>

## 实现

BLAS是一种规范，许多库都实现了它。参考实现是从netlib分发的免费Fortran 77软件包，现已纳入LAPACK发布版；它定义了各项运算但未作优化，在性能重要的场合不鼓励使用。<sup>[1](https://www.netlib.org/blas/)</sup><sup> • </sup><sup>[7](https://netlib.sandia.gov/lapack/)</sup> C接口CBLAS也是LAPACK发布版的一部分。<sup>[1](https://www.netlib.org/blas/)</sup>

计算机厂商与独立软件厂商提供针对特定机器的优化库。Intel的oneMKL实现了BLAS与稀疏BLAS例程，并带有类BLAS扩展，在运行时于针对不同指令集调优的实现之间进行调度。<sup>[11](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-1/blas-and-sparse-blas-routines.html)</sup><sup> • </sup><sup>[8](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2026-0/onemkl-library-overview.html)</sup> NVIDIA的cuBLAS在GPU的CUDA运行时之上实现BLAS，采用列主存储与从1开始的索引以兼容Fortran环境，并额外提供API，包括cuBLASLt——一个专用于通用矩阵乘法、支持可编程算法选择的轻量级库。<sup>[5](https://docs.nvidia.com/cuda/cublas/index.html)</sup>

开源项目致力于性能的可移植性。ATLAS项目（自动调优线性代数软件）通过经验调优为给定架构生成优化的BLAS，其作者将这一方法称为软件的自动化经验优化，动机在于硬件的快速变化；经过调优的BLAS代码可比朴素编写的例程快若干个数量级。<sup>[17](https://www.sciencedirect.com/science/article/pii/S0167819100000879)</sup> OpenBLAS是基于GotoBLAS2 1.13 BSD版本的优化BLAS库，支持广泛的CPU架构与操作系统。<sup>[6](https://github.com/OpenMathLib/OpenBLAS)</sup> BLIS框架以一小套简单内核表达几乎所有第2层与第3层计算，因此插入高性能内核即可立即优化以这些内核表达的所有类BLAS运算；其作者展示的实现可与ATLAS、OpenBLAS及厂商库（包括AMD的ACML、IBM的ESSL与Intel的MKL）相竞争。<sup>[18](https://cir.nii.ac.jp/crid/1360017289754523904)</sup><sup> • </sup><sup>[19](https://research.ibm.com/publications/the-blis-framework-experiments-in-portability)</sup>

## 数值可重现性

以相同输入执行BLAS例程，每次运行可能产生略有不同的结果。由于舍入误差，浮点加法不满足结合律，因此求和结果取决于运算顺序，而该顺序可能随处理器数量、数据划分、向量指令的选择、数据对齐方式以及并行归约树的结构而变化。<sup>[20](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-dpcpp/2025-1/numerical-reproducibility.html)</sup><sup> • </sup><sup>[21](https://bebop.cs.berkeley.edu/reproblas/)</sup>

ReproBLAS（可重现基础线性代数子程序）通过使用“可重现累加器”来计算，从而解决这一问题。可重现累加器是一种分箱式浮点表示，默认大小为六个双精度字。它保证无论处理器数量、数据划分或求和顺序如何，结果都逐位相同，同时只需对数据做一次只读遍历和一次并行归约——这正是矩阵乘法等高效第3层运算所需的性质，其中乘积\( A_{ik} \cdot B_{kj} \)只计算一次便被丢弃。<sup>[21](https://bebop.cs.berkeley.edu/reproblas/)</sup> 在默认设置下，可重现地对\( n \)个浮点数求和约需\( 9n \)次浮点运算。<sup>[21](https://bebop.cs.berkeley.edu/reproblas/)</sup> 商业库提供较窄的保证：Intel oneMKL提供条件数值可重现（CNR）模式，在特定情况下给出逐位可重现性，在CPU上适用于所有BLAS DPC++ API，在GPU上适用于第3层例程及扩展。<sup>[20](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-dpcpp/2025-1/numerical-reproducibility.html)</sup>

## 相关接口

BLAS家族超越了稠密串行核心。稀疏BLAS为稀疏矩阵定义了第1、2、3层例程，其运算如\( y := \alpha \cdot \mathrm{op}(A) \cdot x + \beta \cdot y \)，其中\( A \)为稀疏矩阵，\( x \)与\( y \)为稠密向量。<sup>[22](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-1/routines-and-supported-operations.html)</sup> PBLAS例程对分布式向量与矩阵执行同类运算，其接口与ScaLAPACK包中的Netlib PBLAS相匹配。<sup>[8](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2026-0/onemkl-library-overview.html)</sup> 批量变体（如`gemm_batch`）可一次对许多小矩阵应用某例程，这种形式在机器学习工作负载中被大量使用。<sup>[23](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-dpcpp/2024-1/appendix-a-onemkl-functionality.html)</sup>

## References

1. [BLAS (Basic Linear Algebra Subprograms), Netlib](https://www.netlib.org/blas/)
2. [C. L. Lawson, R. J. Hanson, D. R. Kincaid, F. T. Krogh (1979). Basic Linear Algebra Subprograms for Fortran Usage. ACM TOMS 5(3):308–323](https://bishtref.com/articles/10.1145/355841.355847)
3. [Lawson et al., package description, NASA Technical Reports Server](https://ntrs.nasa.gov/api/citations/19780018835/downloads/19780018835.pdf)
4. [BLAS Technical Forum, Netlib](https://netlib.org/blas/blast-forum/blast-forum.html)
5. [cuBLAS introduction, NVIDIA CUDA documentation](https://docs.nvidia.com/cuda/cublas/index.html)
6. [OpenBLAS repository, OpenMathLib on GitHub](https://github.com/OpenMathLib/OpenBLAS)
7. [LAPACK — Linear Algebra PACKage, Netlib](https://netlib.sandia.gov/lapack/)
8. [oneMKL Library Overview, Intel](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2026-0/onemkl-library-overview.html)
9. [LAPACK Working Note 44: block size and tuning, Netlib](https://www.netlib.org/lapack/lawnspdf/lawn44.pdf)
10. [LAPACK Working Note 81, Netlib](https://www.netlib.org/lapack/lapack-3.1.1/INSTALL/lawn81.pdf)
11. [BLAS and Sparse BLAS Routines, Intel oneMKL Developer Reference](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-1/blas-and-sparse-blas-routines.html)
12. [Collected Algorithms of the ACM (Algorithm 539)](https://www.calgo.hosting.acm.org/)
13. [Level 1, 2, and 3 BLAS, LAPACK Working Note 81 node, Netlib](https://netlib.org/lapack/lawn81-3.0/node7.html)
14. [Jack Dongarra oral history, SIAM History of Numerical Analysis and Scientific Computing](https://history.siam.org/oralhistories/dongarra.htm)
15. [L. S. Blackford et al. (2002). An Updated Set of Basic Linear Algebra Subprograms (BLAS), NIST](https://www.nist.gov/publications/updated-set-basic-linear-algebra-subprograms-blas)
16. [XBLAS — Extra Precise Basic Linear Algebra Subroutines, Netlib](https://netlib.sandia.gov/xblas/)
17. [R. Clint Whaley, Jack Dongarra (2001). Automated empirical optimizations of software and the ATLAS project, Parallel Computing 27:3–35](https://www.sciencedirect.com/science/article/pii/S0167819100000879)
18. [Field G. Van Zee, Robert A. van de Geijn. BLIS: A Framework for Rapidly Instantiating BLAS Functionality, ACM TOMS 41(3), 2015](https://cir.nii.ac.jp/crid/1360017289754523904)
19. [The BLIS framework: Experiments in portability, IBM Research](https://research.ibm.com/publications/the-blis-framework-experiments-in-portability)
20. [Numerical Reproducibility, Intel oneMKL Developer Reference](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-dpcpp/2025-1/numerical-reproducibility.html)
21. [ReproBLAS — Reproducible Basic Linear Algebra Sub-programs, UC Berkeley](https://bebop.cs.berkeley.edu/reproblas/)
22. [Routines and Supported Operations (Sparse BLAS), Intel oneMKL Developer Reference](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-c/2024-1/routines-and-supported-operations.html)
23. [Appendix A: oneMKL Functionality, Intel oneMKL DPC++ Developer Reference](https://www.intel.com/content/www/us/en/docs/onemkl/developer-reference-dpcpp/2024-1/appendix-a-onemkl-functionality.html)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Linear and multilinear algebra › Numerical linear algebra › BLAS and basic linear algebra kernels

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/basic-linear-algebra-subprograms

English original: https://www.edgepedia.org/basic-linear-algebra-subprograms
