随机舍入(Stochastic Rounding):算法与硬件加速器
准大一 · 集成电路设计与集成系统 × 芯片架构 × 数值计算 —— 硬件加速器设计精读材料
📄 原文:arXiv:2001.01501
🗓️ 2020年1月6日发布
🏫 arXiv 预印本(cs.AR / math.NA)
✅ 随机舍入 × 定点算术 × SpiNNaker2 加速器
🔊 附英文摘要朗读音频
一、论文档案
| 英文标题 | Stochastic Rounding: Algorithms and Hardware Accelerator |
| 中文标题 | 随机舍入:算法与硬件加速器 |
| 作者 | Mantas Mikaitis(机构未在素材中标注) |
| 发布时间 | 2020年1月6日(v1)|分类:cs.AR(计算机体系结构)、math.NA(数值分析) |
| 原文链接 | arxiv.org/abs/2001.01501 · 全文 HTML 版 |
| 一句话概括 | 给神经形态芯片 SpiNNaker2 设计一个硬件加速器,用「随机舍入 + 饱和」代替软件模拟,让定点数运算更快、数值误差更小——随机舍入正在机器学习里越来越流行。 |
💡 为什么选这篇给你:① 芯片设计里「数值格式怎么选、舍入怎么做」是基本功,这篇把舍入算法做到了硅片级别;② 思路完整——从两位级(bit-level)算法到 22nm 电路实现再到漏电/面积对比,一条龙走通;③ 随机舍入如今在低精度机器学习训练里越来越常用,读这篇等于提前接触前沿数值格式;④ 作者把「为什么必须用硬件实现」讲得清清楚楚,是典型的体系结构思维训练。
二、核心术语表(先扫一遍再读正文)
| 英文术语 | 中文 | 大白话解释 |
| stochastic rounding (SR) | 随机舍入 | 舍入方向带随机性:按概率向上或向下取整。单次看是「错」的,长期看误差不系统累积,平均值更准。 |
| round to nearest | 就近舍入 | 最常用的舍入模式:取最近的可表示值,平局(0.5)时本文硬件采用向上舍入。 |
| bit truncation | 位截断 | 直接砍掉低位,最简单但会引入系统性向下偏差,误差会累积。 |
| fixed-point arithmetic | 定点算术 | 用固定「整数位 + 小数位」的格式表示数,没有浮点单元时更快、更省电。 |
| saturation | 饱和 | 溢出时把结果钳到最大可表示值(而不是回绕)。定点数动态范围窄,舍入后通常要接饱和。 |
| PRNG (pseudorandom number generator) | 伪随机数发生器 | 产生随机序列的电路/算法;随机舍入要靠它决定这次向上还是向下。 |
| SpiNNaker | —(专有名词) | 18 个 ARM968 核(仅整数)的芯片,用于仿真神经网络,包括神经元的常微分方程(ODE)。 |
| SpiNNaker2 | —(专有名词) | 下一代芯片,基于 ARM Cortex-M4F 处理器,本文的加速器将被集成进去,原计划 2020 年发布。 |
| ARM Cortex-M4F | —(专有名词) | 带单精度浮点(binary32)单元的 ARM 处理器核,但没有把定点数舍入到指定位数的指令。 |
| binary32 | 单精度浮点(binary32) | IEEE 754 单精度格式,占 32 位。 |
| bfloat16 | BF16 浮点格式 | 相当于 binary32 去掉低 16 位——1 符号位 + 8 指数位 + 7 尾数位;存储优雅,且能直接用 binary32 硬件运算。 |
| ODE solver | 常微分方程求解器 | 数值积分 ODE 的程序/电路;神经元模型常写成 ODE,舍入误差会让解偏离参考解。 |
| leakage | 漏电(静态功耗) | 晶体管关断时仍流过的电流造成的功耗,22nm 工艺下不可忽视。 |
| 22nm technology | 22 纳米工艺 | 本文三个加速器版本评估所用的 CMOS 工艺节点。 |
三、摘要中英对照(精读核心)
🎧 音频在文末,可先听一遍原文再读;每个英文句都配了逐句翻译。
摘要 Abstract
EN · 原文
Algorithms and a hardware accelerator for performing stochastic rounding (SR) are presented.
CN · 翻译
本文提出了执行
随机舍入(SR)的算法与一个
硬件加速器。
EN · 原文
The main goal is to augment the ARM M4F based multi-core processor SpiNNaker2 with a more flexible rounding functionality than is available in the ARM processor itself.
CN · 翻译
主要目标是为基于 ARM M4F 的多核处理器
SpiNNaker2 补上比 ARM 处理器自身
更灵活的舍入功能。
EN · 原文
The motivation of adding such an accelerator in hardware is based on our previous results showing improvements in numerical accuracy of ODE solvers in fixed-point arithmetic with SR, compared to standard round to nearest or bit truncation rounding modes.
CN · 翻译
用硬件加这个加速器的动机,来自我们之前的结果:在
定点算术的 ODE 求解器中,使用 SR 相比标准的
就近舍入或
位截断模式,
数值精度得到提升。
EN · 原文
Furthermore, performing SR purely in software can be expensive, due to requirement of a pseudorandom number generator (PRNG), multiple masking and shifting instructions, and an addition operation.
CN · 翻译
此外,
纯软件实现 SR 代价很高:需要伪随机数发生器(PRNG)、多条掩码与移位指令,还有一次加法操作。
EN · 原文
Also, saturation of the rounded values is included, since rounding is usually followed by saturation, which is especially important in fixed-point arithmetic due to a narrow dynamic range of representable values.
CN · 翻译
同时,还包含舍入后数值的
饱和处理——因为舍入之后通常跟着饱和;由于定点数可表示值的
动态范围很窄,这一点尤其重要。
EN · 原文
The main intended use of the accelerator is to round fixed-point multiplier outputs, which are returned unrounded by the ARM processor in a wider fixed-point format than the arguments.
CN · 翻译
加速器的主要用途是舍入
定点乘法器的输出——ARM 处理器会以比输入更宽的定点格式返回未舍入的结果。
听音频时重点抓数字与术语:SpiNNaker2、PRNG、round to nearest、bit truncation、saturation、fixed-point、wider fixed-point format。
四、引言精选(为什么这个问题重要)
① 背景:SpiNNaker 上的数值精度问题
EN · 原文
SpiNNaker is a 18-ARM968-core (integer only) chip for simulating neural networks, including ordinary differential equations (ODEs) of neurons [1]. Previous work on SpiNNaker [2] explored numerical accuracy issues in ODE solvers run in fixed-point arithmetic with the main conclusion that rounding errors are a major factor in divergence of the solution from the reference double precision solution, and that stochastic rounding (SR) helps in reducing divergence.
CN · 翻译
SpiNNaker 是一颗
18 核 ARM968(仅整数)芯片,用于仿真神经网络(包括神经元的常微分方程)。此前工作发现:定点算术下运行的 ODE 求解器存在数值精度问题,
舍入误差是解偏离双精度参考解的主要因素,而随机舍入(SR)有助于减小这种偏离。
② 痛点:新处理器没有「按指定位数舍入定点数」的能力
EN · 原文
The next generation SpiNNaker, SpiNNaker2 will be based on an ARM Cortex-M4F processor [3], which does not have a capability of rounding a fixed-point number to a specified number of bits. There are three instructions with rounding available: SMMLAR — multiply two numbers, add a third number to the top 32 bits of the result and return the rounded 32 top bits; SMMLSR — the same as SMMLAR, but subtract the third argument; and SMMULR — multiply and return the rounded 32 top bits of the result [4]. Rounding is done by adding 0x80000000 to the product, therefore the tie-breaking rule is round up [5].
CN · 翻译
下一代 SpiNNaker2 将基于 ARM Cortex-M4F 处理器,而它
没有把定点数舍入到指定位数的能力。只有三条带舍入的指令可用:SMMLAR(乘、加第三个数到结果高 32 位、返回舍入后的高 32 位)、SMMLSR(同 SMMLAR 但做减法)、SMMULR(乘并返回舍入后的高 32 位)。其舍入方式是对乘积加
0x80000000,因此平局规则是
向上舍入。
③ 软件实现的代价:多条指令 + 64 位寄存器操作
EN · 原文
To implement round to nearest (RN) and stochastic rounding would require multiple instructions, usually working on two registers containing a 64-bit unrounded value. Furthermore, there is no mention as to whether there are instructions available on the Cortex-M4F processor to perform saturation after rounding (return a maximum representable value on overflow). While saturation instructions for 32-bit values, with configurable saturation bit position and saturated addition, are available on the M4F, saturating a 64-bit value from the multiplication would need to be done by comparison and because it is a value across two registers, multiple instructions would be required to obtain a rounded and saturated value somewhere in the middle of a 64-bit value.
CN · 翻译
要实现就近舍入(RN)和随机舍入,通常需要
多条指令,对两个寄存器中的 64 位未舍入值操作。而且 M4F 是否有「舍入后饱和」(溢出时返回最大可表示值)的指令也不明确:32 位值有饱和指令可用,但
64 位乘积的饱和要靠比较实现——值横跨两个寄存器,要在 64 位中间得到舍入且饱和的结果需要很多条指令。
④ 附加需求:binary32 → bfloat16 的格式转换
EN · 原文
Additionally, since ARM M4F has a single-precision floating-point (binary32) [6] unit, it is beneficial to add binary32 to bfloat16 (equivalent to binary32 with the bottom 16 bits removed — 1 sign bit, 8 exponent bits and 7 significand bits) [7] rounding, which is an elegant format for storage and can be operated on using binary32 hardware.
CN · 翻译
此外,由于 ARM M4F 有单精度浮点(binary32)单元,值得加入
binary32 → bfloat16 的舍入——bfloat16 相当于 binary32 去掉低 16 位(1 符号位 + 8 指数位 + 7 尾数位),
存储优雅,而且能直接用 binary32 硬件运算。
💡 这是全文最有味道的一句:"performing SR purely in software can be expensive, due to requirement of a pseudorandom number generator (PRNG), multiple masking and shifting instructions, and an addition operation."——芯片设计者的思维就是「数指令、算代价」:当软件要花好几条指令时,就该问「这块硅片值不值得」。答案值得,于是有了这个加速器。
五、论文贡献(3 个要点)
EN · 原文
1. Two bit-level algorithms. Two bit-level algorithms for doing stochastic rounding and saturation (Section II).
CN · 翻译
1. 两个位级算法。提出两个
位级(bit-level)算法,用于执行随机舍入与饱和。
EN · 原文
2. Accelerator architecture. The architecture of the accelerator for doing rounding and saturation (Sections IV and V).
CN · 翻译
2. 加速器架构。给出执行舍入与饱和的
加速器架构设计。
EN · 原文
3. Silicon evaluation. Three accelerators with 8/16/32-bit random number precisions in stochastic rounding are evaluated in 22nm technology. Leakage and area comparisons are demonstrated (Section VI).
CN · 翻译
3. 硅片级评估。在
22nm 工艺下评估了三个加速器版本(随机数精度分别为
8/16/32 位),给出了
漏电与面积的对比。
六、结论中英对照
EN · 原文
We have presented algorithms and an accelerator for performing rounding and saturation of numbers up to 64 bits, including stochastic rounding which is becoming popular in machine learning. This includes rounding of fixed-point/integer values at any bit position as well as binary32 to bfloat16 rounding.
CN · 翻译
我们提出了对
最高 64 位数值执行舍入与饱和的算法和加速器,包括在机器学习中越来越流行的
随机舍入;覆盖任意位位置的定点/整数舍入,以及 binary32 到 bfloat16 的舍入。
EN · 原文
The chosen SR algorithm was tested on the harmonic series computed with a basic recursive summation, demonstrating how SR can help avoid numerical stagnation in fixed-point arithmetic. Evaluation of the accelerators with different precisions of SR step was performed, showing an order of magnitude of leakage improvement with 8-bit SR at f=150 MHz.
CN · 翻译
所选 SR 算法在
谐波级数(用基本递归求和计算)上做了测试,展示了 SR 如何帮助定点算术
避免数值停滞;对采用不同 SR 步进精度的加速器进行了评估,
8 位 SR、150 MHz 下漏电改善达到
一个数量级。
EN · 原文
The accelerator will be included in the SpiNNaker2 chip, which is scheduled for 2020 release and is based on an ARM Cortex-M4F processor. Since this processor does not provide a wide array of rounding and saturation instructions to support fast fixed-point arithmetic, especially mixed-format fixed-point arithmetic, this accelerator will complement it and provide that functionality. The presented results should also be applicable in implementing stochastic rounding of floating-point arithmetic, such as rounding the extended precision results from the floating-point adder or multiplier [22, 23].
CN · 翻译
该加速器将集成进 SpiNNaker2 芯片(基于 ARM Cortex-M4F,原计划
2020 年发布)。由于该处理器缺少支持快速定点算术(尤其是
混合格式定点算术)的成套舍入与饱和指令,此加速器将补足这一功能。文中的结果还应适用于实现
浮点算术的随机舍入,例如舍入浮点加法器或乘法器产生的扩展精度结果。
七、编者解读:这篇论文到底讲了什么(大白话版)
- 问题:用定点数做神经元仿真(求解 ODE)时,舍入误差会慢慢累积,让结果偏离「标准答案」。之前的研究发现随机舍入能显著改善,但纯软件做随机舍入太贵——要随机数、要掩码移位、要加法,好几条指令。
- 决策:那就造一块专用硬件!芯片设计者的典型思路——先数指令开销,再决定「这块硅片值不值得」。值得,于是设计一个加速器:吃进乘法器输出的 64 位未舍入结果,吐出一个「舍入 + 饱和」后的定点数。
- 设计:提出两个位级算法;随机性来自片上伪随机数发生器(做了 8/16/32 位三种精度版本);在 22nm 工艺下流片评估,比面积、比漏电——8 位随机数版本在 150 MHz 下漏电改善了一个数量级。
- 顺带:加速器还支持 binary32→bfloat16 转换——bfloat16 是后来深度学习低精度训练的主力格式之一,这篇 2020 年的论文其实踩在了趋势前面。
- 验证:用谐波级数递归求和做测试,证明 SR 能避免定点算术的「数值停滞」(误差不再累积到结果不动)。
🎯 对专业学习的启示:这篇论文是「体系结构思维」的绝佳示范——先算软件代价,再设计硬件,最后用面积/功耗数据说话。复试时若能讲出「为什么随机舍入必须进硬件、8/16/32 位随机数精度怎么影响面积与漏电、饱和为什么在定点里这么重要」,比背流水线定义更有说服力。数值格式(定点、bfloat16、FP8)正是当前 AI 芯片设计的核心议题。
八、给准大一的阅读路线图 & 延伸方向
📖 怎么读这篇论文(三遍法)
- 第一遍(10 分钟):只读摘要和术语表,回答三个问题——问题是什么?方法是什么?结果是什么?记住「软件太贵 → 加硬件」这条主线。
- 第二遍(20 分钟):读引言 + 结论,重点体会「为什么定点算术里舍入误差是大事」和「饱和为什么必不可少」,以及结论里「0x80000000 平局向上」这种细节。
- 第三遍(30 分钟):读方法文字部分(两个位级算法、加速器架构、8/16/32 位随机数精度对比),跳过所有公式与电路图编号,只看文字描述;遇到不懂的术语回查术语表。
🚀 这个方向你能延伸做什么
- 现在就能做:用 Python 写一个定点数累加循环,分别用「就近舍入 / 截断 / 随机舍入」三种模式累加 1/1+1/2+1/3+…(谐波级数),画出误差随步数增长的曲线——亲眼看看 SR 为什么不会「卡死」。
- 大一→大二:学好数字电路与 Verilog HDL;可以尝试用开源工具(如 Icarus Verilog)写一个 8 位随机舍入模块并仿真。
- 大二→大三:方向可扩展为计算机体系结构、低精度数值格式(bfloat16/FP8)、类脑芯片与脉冲神经网络、RISC-V 自定义指令扩展、AI 加速器量化——都是集成电路+体系结构的保研热门方向;国内可关注 IEEE TC(Transactions on Computers)、IEEE TCAD、《计算机学报》与 DATE/DAC/ISCA 会议。
九、英文摘要朗读(练听力用)
先盲听一遍→再看对照稿→再听一遍。目标是听出每个数字(18 核、64 位、8/16/32 位、22nm、150 MHz)和术语(stochastic rounding、PRNG、saturation、fixed-point、bfloat16)。