From 74f0391fc23ea2d9897ef22422987bc70b4b4bb3 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 3 Sep 2026 08:09:34 +0000 Subject: [PATCH] Add BMM_Theory: bmm_theory/hardware/ascend950pr.py --- .../bmm_theory/hardware/ascend950pr.py | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 BMM/BMM_Theory/bmm_theory/hardware/ascend950pr.py diff --git a/BMM/BMM_Theory/bmm_theory/hardware/ascend950pr.py b/BMM/BMM_Theory/bmm_theory/hardware/ascend950pr.py new file mode 100644 index 0000000..5683c07 --- /dev/null +++ b/BMM/BMM_Theory/bmm_theory/hardware/ascend950pr.py @@ -0,0 +1,92 @@ +"""Ascend950PR (DAV_3510) 硬件规格参数. + +数值来源: 《BMM算子优化分析 v0.98》§二 + 昇腾950 NPU架构白皮书. +换芯片时逻辑结构不变, 只需新增一份同结构参数表. + +单位约定: 算力 FLOP/s, 带宽 Byte/s, 容量 Byte, 时延 秒. +""" + +from __future__ import annotations + +from dataclasses import dataclass + + +@dataclass(frozen=True) +class NpuSpec: + name: str = "Ascend950PR" + + # ---- 核数与算力 ---- + aic_num: int = 32 # C: AIC (Cube) 核数 + aiv_num: int = 64 # AIV (Vector) 核数 + cube_peak_tflops: float = 486.0 # 全芯片 Cube BF16 标称算力 (乘加各计一次) + aiv_freq_ghz: float = 1.65 + aiv_fp32_per_cycle: int = 128 # 单 AIV 每拍 fp32 求和吞吐 + + # ---- 片上存储 (每核) ---- + l1_bytes: int = 512 * 1024 # L1 Buffer 512KB + l0a_bytes: int = 64 * 1024 # L0A 64KB + l0b_bytes: int = 64 * 1024 # L0B 64KB + l0c_bytes: int = 256 * 1024 # L0C 256KB (fp32 累加, 4B/元素) + + # ---- L2 / GM ---- + l2_bytes: int = 128 * 1024 * 1024 # L2 Cache 128MB + bw_l2: float = 5.2e12 # L2 读写带宽 5.2TB/s + bw_gm: float = 1.6e12 # GM(HBM) 带宽 1.6TB/s (读写共享) + + # ---- 搬移效率经验约束 (950PR 实测总结) ---- + dvalue_recommend: int = 512 # dValue 推荐值 (Byte), 更大无额外收益 + dvalue_min: int = 128 # dValue 下限 (Byte) + dvalue_hw_min: int = 256 # DMA 硬件突发下限 (Byte) —— 尾轮文档 §2.3 + min_tile_size: int = 16 * 1024 # min_TileSize: 单块搬移最小量 16KB + min_datamount_per_core: int = 480 * 1024 # min_DatamountPerCore: 单核搬移总量下限 480KB + min_core_num_ratio: float = 0.8 # minCoreNum ≈ 0.8 * C + + # ---- DMA 固定开销 ---- + t_cmd_ns: float = 50.0 # T_cmd: 单次 GM->L1 DMA 命令固定开销 (ns, 估计值, 需实测标定) + + # ---- Cube 计算粒度 ---- + fractal: int = 16 # 16x16x16 基本块 + + # ---- 派生量 (属性) ---- + @property + def q16(self) -> float: + """单核 Cube BF16 峰值算力 (FLOP/s).""" + return self.cube_peak_tflops * 1e12 / self.aic_num + + @property + def q_aiv(self) -> float: + """AIV 向量求和吞吐 (元素/s), 64 核合计.""" + return self.aiv_num * self.aiv_fp32_per_cycle * self.aiv_freq_ghz * 1e9 + + @property + def bw_pc(self) -> float: + """单核 GM 带宽份额 (Byte/s) = W_GM / C = 50GB/s.""" + return self.bw_gm / self.aic_num + + @property + def bw_l2_pc(self) -> float: + """单核 L2 带宽份额 (Byte/s) = W_L2 / C ≈ 162.5GB/s.""" + return self.bw_l2 / self.aic_num + + @property + def r16(self) -> float: + """16bit 位宽平衡点算存比 R_16 = Cube峰值 / (GM带宽/2B) ≈ 607.5 FLOP/元素.""" + return self.cube_peak_tflops * 1e12 / (self.bw_gm / 2) + + @property + def min_core_num(self) -> int: + """确保高带宽利用率的并行搬移核数下限.""" + return round(self.min_core_num_ratio * self.aic_num) + + @property + def t_cmd(self) -> float: + """T_cmd (秒).""" + return self.t_cmd_ns * 1e-9 + + @property + def l0c_elems(self) -> int: + """L0C 容量 (fp32 元素数) = 65536.""" + return self.l0c_bytes // 4 + + +ASCEND950PR = NpuSpec()