Skip to content

Feature/assert tensor dump - #1479

Open
kuri780 wants to merge 2 commits into
hw-native-sys:masterfrom
kuri780:feature/assert-tensor-dump
Open

Feature/assert tensor dump#1479
kuri780 wants to merge 2 commits into
hw-native-sys:masterfrom
kuri780:feature/assert-tensor-dump

Conversation

@kuri780

@kuri780 kuri780 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Summary

实现 issue #1386 中"条件 assert 和持久化 tensor dump"待办项:新增 pto.assert(条件 abort)与 pto.tdump(带元数据头的持久化 tensor dump),并明确与现有 pto.print / pto.tprint / pto.trap的边界。

pto.assert

  • ODS:pto.assert %cond {message = "..."} : i1,带 MemWrite effect 防 CSE/DCE;i1 由 ODS 类型约束保证,无需额外 verifier
  • VPTO lowering(beta1 + CANN900):条件取反 + scf.if 守护 llvm.hivm.TRAP,声明经既有 PlannedDecl 机制注入
  • EmitC lowering:DEBUG_CHECK(cond, msg)(pto-isa debug.h 现有宏,按需注入 include)
  • message 仅 EmitC 生效(VPTO 无设备 printf 通道,文档已注明);为 [Feature] 为 pto.trap 增加 message 接口 #1215(trap message)铺路
  • PTODSL:pto.assert_(cond, message=None)

pto.tdump(VPTO only)

  • 语义:把 UB tile 写入 host 传入的 GM buffer = 64B 小端元数据头(魔数 PTD0/version/elem_size/类型码/ndim/shape/valid_shape/data_offset)+ row-major 原始数据,host 无需预知形状即可解码
  • lowering:头部 16×i32 经 pto.stg 写入(包在 section.simt<<<1,1,1>>>,自动转阻塞 simt_launch 保证先于数据完成);数据复用 tstore 的 mte_ub_gm 链(llvm.hivm.MOV.UB.TO.OUT.*)
  • v1 范围:src 限 VEC tile(MAT/ACC staging 留作后续,verifier 有明确报错);EmitC 明确不支持(文档注明,不跨仓库改 pto-isa)
  • PTODSL:pto.tile.dump(src, dst) + vpto 后端 gate

测试

  • lit:assert_vpto_llvm.pto(双 RUN:默认 + CANN 9.0.0)、assert_emitc.pto、tdump_vpto_llvm.pto(双 RUN)、tdump_invalid.pto(verifier 负向)
  • simulator E2E:test/vpto/cases/kernels/tdump-vec/,host 端 compare.py 解码头部并比对 payload,实测通过
  • PTODSL doc-test fixture:sync_ops.assert、compute_ops.tdump

kuri780 and others added 2 commits September 7, 2026 17:20
Adds pto.assert %cond {message = "..."} : i1, the conditional form of
pto.trap, for issue hw-native-sys#1386.

- ODS: AssertOp with MicroOp/SimtOp interfaces and MemWrite effect so
  the check is never CSE'd or DCE'd; no verifier (i1 enforced by ODS)
- VPTO lowering (beta1 + CANN900): negate the condition and guard a
  call to the existing llvm.hivm.TRAP via scf.if; the declaration is
  injected through the existing PlannedDecl/materializeDecls machinery.
  The message attribute is ignored on this path: the VPTO backend has
  no device printf channel.
- EmitC lowering: DEBUG_CHECK(cond, "msg") from pto/common/debug.h
  (include injected only when an assert is present); message defaults
  to "pto.assert failed" and is escaped like pto.print's format string
- PTODSL: pto.assert_(cond, message=None) with i1 coercion
- Docs: PTO_IR_manual 4.20 and ptodsl user guide 10.8 (doc-test fixture)
- Tests: vpto LLVM IR emission (default + CANN 9.0.0) and EmitC output

Co-Authored-By: Claude Code <noreply@anthropic.com>
Adds pto.tdump ins(%tile) outs(%gm_view), a VPTO-only debug op that
writes a self-describing dump of a UB tile into a host-passed GM
buffer, for issue hw-native-sys#1386.

Dump layout: a 64-byte little-endian header (magic "PTD0", version,
element size/type, ndim, shape, valid_shape, data offset, reserved)
followed by the raw row-major tile data. The host can decode the dump
without knowing the tensor shape up front.

- ODS: PTO_TOp with OpPipeInterface (PIPE_MTE3) so tile-level sync
  insertion works like pto.tstore; verifier restricts v1 to vec-space
  tiles with dumpable element types (f16/bf16/f32/i8/i16/i32/i64)
- Lowering (LowerPTOToUBufOps, runs on every arch before the A2/A3
  phases): header written with 16 scalar GM stores (pto.stg, wrapped in
  a 1x1x1 pto.section.simt that PTOOutlineSIMTSections turns into a
  blocking simt_launch), then the data is copied with the same
  mte_ub_gm chain as tstore (llvm.hivm.MOV.UB.TO.OUT.*)
- Defensive exclusions: TileOpExpansionUtils and both emitter
  catch-alls reject a stray pto.tdump instead of leaking to LLVM
- PTODSL: pto.tile.dump(src, dst) with a vpto-backend gate; EmitC is
  documented as unsupported (no pto-isa changes)
- Docs: PTO_IR_manual 4.20 (header layout table) and ptodsl user guide
  8.1 (doc-test fixture)
- Tests: vpto LLVM IR emission (a3, default + CANN 9.0.0), verifier
  negative test, and an end-to-end simulator case
  (test/vpto/cases/kernels/tdump-vec) whose compare.py decodes the
  header and checks the payload against the golden data

Co-Authored-By: Claude Code <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant