Fix #27-#30: dtype感知算力(Cube/AIV速率表) / GM首读下限与整芯片字节列口径+设计文档 / Fixpipe输出落点R4(整case驻留L2否则直写GM) / MergeBatch Cube公式复核注释

- docs/05_L2驻留GM读写与dtype算力口径_设计分析.md: R1-R6公理、S_A/S_B/S_C场景、输出落点R4、dtype速率表(白皮书出处+待标定假设)、逐分支GM/L2归属表 (issue#29/#30 先文档后代码)
- hardware: CUBE_DTYPE_FACTOR(f16/bf16=1, fp8=2x, fp4=4x, fp32=1/2假设) + AIV_DTYPE_FACTOR + q_cube/aiv_elem_rate (issue#28)
- 全分支 t_mmad/t_comp/drain/尾轮主导项/θ_c/R16 语义按输入dtype取算力; 混精度取慢侧; StreamK归约保持fp32(AIV fp32部分和)
- Fixpipe输出落点R4: to_l2 <=> V_in+V_out(+workspace)<=L2; 否则直写GM计入共享总线; ASW场景改S_A整case全驻留(原单batch驻留判定漏计整case输出累积逐出)
- 字节列统一整芯片口径(gm/l2/fix/cube_flops), dma_cmd_count注明单核; GM>=V_in不变量入测试; MergeBatch每步flops=2(b0M)(b0N)K公式注释显式化(#27复核与CSV一致无数值改动)
- tests 39->49 全过; 双压力seed7/6000+seed2024/4000: 0违规/0占位/0NaN/0GM<输入; examples三件套重生成且可复现0diff
This commit is contained in:
2026-09-04 16:26:10 +08:00
parent 4843053ad3
commit b9e07edc1d
15 changed files with 793 additions and 239 deletions

View File

@@ -10,7 +10,7 @@ from __future__ import annotations
from ..hardware import NpuSpec, ASCEND950PR
from ..models import BmmCase, ImplPlan, HardwareTiming
from ..timing import assemble_timing
from ..timing import assemble_timing, output_to_l2
from .base import Branch, ConditionCheck
@@ -68,32 +68,42 @@ class SpecialBranch(Branch):
# ------------------------------------------------------------------
def evaluate(self, case: BmmCase, plan: ImplPlan) -> HardwareTiming:
"""AIV 通路时延: 瓶颈在搬移 (AIV 算力远剩)."""
"""AIV 通路时延: 瓶颈在搬移 (AIV 算力远剩).
口径: AIV 逐元素通量按输入 dtype (issue#28); 输出落点 R4 (issue#30):
整 case 输入+输出 <= L2 -> 输出写 L2 (异步回写不占算子时延), 否则直写
GM 与读共享总线 (assemble 的 MTE2 链累加, issue#23).
"""
s = self.spec
b = case.batch_c
m, n, k = case.m, case.n, case.k
dt = case.dtype_in_bytes
out_b = case.dtype_out_bytes
out_l2 = output_to_l2(case, s)
w_fix = s.bw_l2 if out_l2 else s.bw_gm
cube_flops = 0.0
t_compute = 0.0
if k == 0:
# 纯写值: 仅写出
t_in, t_compute, t_out = 0.0, 0.0, b * m * n * out_b / s.bw_gm
in_bytes, cube_flops = 0.0, 0.0
# 纯写值: 仅写出 (R1 下 GM 读 = 0, 输入本身为空)
t_in = 0.0
t_out = b * m * n * out_b / w_fix
in_bytes = 0.0
else:
# 逐元素乘: 搬入 A+B, 搬出 C, AIV 算力远剩
# 逐元素乘: 搬入 A+B (GM 每字节一次), 搬出 C
in_bytes = b * (m * k + k * n) * dt
out_bytes = b * m * n * out_b
t_in = in_bytes / s.bw_gm
t_out = out_bytes / s.bw_gm
# AIV 求积吞吐 (近似按 Q_AIV)
t_compute = b * m * n / s.q_aiv
t_out = out_bytes / w_fix
# AIV 逐元素吞吐按输入 dtype 取通量 (issue#28: bf16/fp16 x2, int8 x4...)
t_compute = b * m * n / s.aiv_elem_rate(case.dtype_in)
cube_flops = float(b * m * n)
t_total = max(t_in, t_out, t_compute)
return assemble_timing(
t_mte2_gm=t_in, t_mte2_l2=0.0, t_dma_cmd=0.0,
t_mmad=t_compute, t_fixpipe=t_out, t_reduce=0.0, t_drain=0.0,
gm_read_bytes=in_bytes, l2_read_bytes=0.0, dma_cmd_count=0.0,
cube_flops=cube_flops,
fixpipe_bytes=b * m * n * out_b,
fixpipe_to_gm=(not out_l2),
)