Closed
[Bug-Report|缺陷反馈]: pl.make_tile 片上地址越界静默通过编译,运行期触发 AICore 硬件陷阱 (error 507015) #3181
zhengyaoff12Add on Aug 31Closed at Sep 8
Sep 3 Assign zhengyaoff12 as responsible person
Sep 8 changed custom state from 进行中 to 已完成
Sep 8 Close issue
Sep 8 Added label: resolved
Describe the current behavior / 问题描述 (Mandatory / 必填)
pl.make_tile/pl.make_tile_group指定片上 buffer(UB/L1/L0A/L0B/L0C)的addr/size时,若addr + size超出目标平台该 buffer 的物理容量,编译期不做任何校验,kernel 静默编译通过;上板运行时触发 AICore 硬件陷阱(device error type 3, error code 507015),只能从 npuSynchronizeDevice 的报错反推,难以定位到是哪个 tile 的地址越界。历史上 MR !5100 曾为 make_tile 增加过容量校验,但因取值接口(
pypto_impl.GetMemoryLimit→ Platform 进程级单例)在不同场景下返回错误平台的容量(解析期校验先于 soc_version 生效、同进程切换目标平台无重载路径、真机交叉编译取到本机容量、无设备时默认回落 A2A3.ini),且容量不可得时抛 RuntimeError 导致旧环境所有片上 make_tile 全部失败,被 !5163 回退。Environment / 环境信息 (Mandatory / 必填)
Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
a5 机器上(L0C 容量 262144 字节 = 0x40000)执行以下 kernel,c_l0c 的地址超出 L0C 容量(end=0x40200 > 0x40000):
import torch, torch_npu import pypto_pro.language as pl torch.npu.set_device("npu:0") @pl.jit(auto_mutex=True) def kernel( a: pl.Tensor[[64, 64], pl.DT_FP16], b: pl.Tensor[[64, 64], pl.DT_FP16], out: pl.Tensor[[64, 64], pl.DT_FP32], ): tt_mat = pl.TileType(shape=[64, 64], dtype=pl.DT_FP16, target_memory=pl.MemorySpace.Mat) tt_left = pl.TileType(shape=[64, 64], dtype=pl.DT_FP16, target_memory=pl.MemorySpace.Left) tt_right = pl.TileType(shape=[64, 64], dtype=pl.DT_FP16, target_memory=pl.MemorySpace.Right) tt_acc = pl.TileType(shape=[64, 64], dtype=pl.DT_FP32, target_memory=pl.MemorySpace.Acc) a_l1 = pl.make_tile_group(type=tt_mat, addrs=0x0000, mutex_ids=[0]) b_l1 = pl.make_tile_group(type=tt_mat, addrs=0x2000, mutex_ids=[1]) a_l0a = pl.make_tile_group(type=tt_left, addrs=0x0000, mutex_ids=[2]) b_l0b = pl.make_tile_group(type=tt_right, addrs=0x0000, mutex_ids=[3]) c_l0c = pl.make_tile_group(type=tt_acc, addrs=0x3C200, mutex_ids=[4]) # 越界: 0x3C200+0x4000=0x40200 > 0x40000 with pl.section_cube(): cur_a_l1 = a_l1.current(); cur_b_l1 = b_l1.current() cur_a_l0a = a_l0a.current(); cur_b_l0b = b_l0b.current() cur_c_l0c = c_l0c.current() pl.load(cur_a_l1, a, [0, 0]) pl.load(cur_b_l1, b, [0, 0]) pl.move(cur_a_l0a, cur_a_l1) pl.move(cur_b_l0b, cur_b_l1) pl.matmul(cur_c_l0c, cur_a_l0a, cur_b_l0b) pl.store(out, cur_c_l0c, [0, 0]) a = torch.randn([64, 64], device="npu:0", dtype=torch.float16) b = torch.randn([64, 64], device="npu:0", dtype=torch.float16) out = torch.zeros([64, 64], device="npu:0", dtype=torch.float32) kernel(a, b, out) torch.npu.synchronize()Describe the expected behavior / 预期结果 (Mandatory / 必填)
编译/解析期即拦截越界地址并给出明确定位,例如(修复后实测输出):
且校验所用容量必须是目标平台的容量(pl.jit(arch=...) 交叉编译、无设备解析等场景均正确),容量不可得时降级告警跳过而非阻断编译。
Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
无校验时的上板报错(难以定位):
Special notes for this issue/备注 (Optional / 选填)
修复 PR: #5779(重新合入 !5100 的容量校验并修复取值链路:新增无状态
GetMemoryLimitForSoc按目标平台 ini 现查容量,arch 来源对齐 pl.jit 编译流 PYPTOPRO_JIT_ARCH + 硬件探测,容量不可得告警跳过)。已在 DAV_3510 真机验证:合法地址 kernel 数值正确、越界地址解析期拦截、全量 pypto_pro UT 1282 passed。