Skip to content

docs: design dual-output TEXTRACT support - #1289

Merged
zhangstevenunity merged 19 commits into
hw-native-sys:mainfrom
HecreReed:codex/textract-nd2xnz-design-only
Aug 25, 2026
Merged

docs: design dual-output TEXTRACT support#1289
zhangstevenunity merged 19 commits into
hw-native-sys:mainfrom
HecreReed:codex/textract-nd2xnz-design-only

Conversation

@HecreReed

@HecreReed HecreReed commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

这是一个 docs-only 设计 PR,目标是让 PTOAS 在现有 pto.textract / TExtractOp 上承载 PTO-ISA 的 ND -> 2xNZ 双输出 overload。

本 PR 不实现代码,不新增 MLIR op、dotted mnemonic、driver 参数或构建配置。

设计范围

  • 复用现有 pto.textract,通过完整 operand segment schema 和 tile layout 推断单输出/双输出 form。
  • 双输出固定为一个 ND source、四个 index、两个 NZ DPS destination;单输出的文本、语义和调用面保持兼容。
  • 完整定义 verifier、DPS、MemoryEffects、liveness、PlanMemory、no-alias、GraphSync、InsertSync、EmitC、TileLib/VPTO 和 Python facade 的承载要求。
  • A2/A3 EmitC 生成一次七参数 PTO-ISA 调用;A2/A3 VPTO 在现有 LowerPTOToUBufOps 内展开为两路 scalar pointer loop 和 V/S 内部同步,不能残留 pointer-form pto.textract
  • 单输出 EmitC 仍保持原有生成语义,但从 range adaptor 读取 operands;不依赖 range 化后不存在的旧 adaptor accessor。
  • 保留 C++/Python/textual IR/PTOBC v0 的单输出兼容要求,包括 legacy getters/properties、free-function wrapper 和 parse 后 facade 类型。
  • partial-valid、odd validCol、1x1 只作为 UB-only TEXTRACT 覆盖,禁止通过同址 alias generic TSTORE 导出未定义 NZ padding。
  • 明确跨函数、opaque call、mixed-backend child、peer import、nested child、runtime-bound tile provenance 和动态 level3 地址的首版安全边界。
  • A5 RowPlusOne 首版默认拒绝;只有所有 layout/access 消费者统一并通过精确 stride、payload、access-end、allocation 和 device 回归后才考虑开放。
  • RowPlusOne golden 只定义 payload;TEXTRACT raw-UB dump 忽略 gap,独立 TSTORE testcase 验证 gap 不被导出。RowPlusOne multi-buffer 在本设计中保持拒绝。

不在本 PR

  • 不新增 TExtractNd2xNzOp、第二个 IR mnemonic或 backend TEXTRACT op。
  • 不新增 capability manifest、--pto-isa-include-root、codegen environment 属性、compile probe 或其他 capability discovery 机制。
  • 不修改 PTO-ISA 依赖版本、pin、外部头文件或 backend 构建流程。
  • CPU-sim、cost-model 和其他 optional backend 的实例化能力继续由现有依赖和构建流程决定。
  • 不包含 ODS/C++/Python/TileLib/test/build-system 实现。

Review focus

请重点评审:现有 op 的 operand/schema 兼容性、A2/A3 VPTO lowering、双输出的内存与同步语义、partial-valid 的 TSTORE 安全边界、跨函数/跨 child 调用闭包、A5 physical layout 与 gap 观测边界,以及后续实现拆分和回归覆盖。

Scope

本分支只新增:

docs/designs/textract-nd-to-2xnz-design.md

没有代码、测试或依赖变更。

@HecreReed
HecreReed marked this pull request as ready for review August 21, 2026 03:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33964d4323

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +942 to +944
4. 任一 TSTORE source static range 与任一 partial destination range 相交即拒绝。TSTORE source
是 block argument/call operand 派生值而无法解析为唯一 static absolute range 时也保守拒绝;
首版不为此建立 argument-effect/range summary fixed point。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Compare address spaces before rejecting TSTORE aliases

Restrict this range-intersection check to sources in the same address space as the partial destination. TStoreOp accepts VEC, MAT, and ACC sources, and those local memories can legitimately reuse the same numeric offsets; therefore a component containing a partial VEC destination at address 0 and an unrelated MAT/ACC TSTORE source at address 0 would be rejected even though that store cannot expose the UB destination. The helper should carry the address space with each range and only report an alias when both the space and byte intervals overlap.

Useful? React with 👍 / 👎.

Comment on lines +1246 to +1248
该 helper 使用 `getBufferBitSize(alloc.getResult())` 填 `allocateSize`,从 tile memory space 填
`addressSpace`,把静态 byte `addr` 乘 `kBitsToByte` 后作为唯一 `addresses` 元素,并记录
`parentLoop`。地址不可折叠时写入 `ShapedType::kDynamic`,在同 address space 中保持保守冲突,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check overflow before converting GraphSync addresses to bits

Require checked multiplication when converting the byte address to GraphSync's bit units. Existing AllocTileOp verification only enforces non-negativity and alignment, so a level-3 constant greater than INT64_MAX / 8 can reach GraphSync; because GraphSync runs before the proposed post-planning helper, addr * kBitsToByte then overflows signed int64_t before the later range validation can reject it, potentially producing incorrect hazard decisions or undefined behavior. Reject the address or conservatively mark it dynamic when the conversion is not representable.

Useful? React with 👍 / 👎.

@HecreReed
HecreReed marked this pull request as draft August 22, 2026 06:51
@HecreReed
HecreReed marked this pull request as ready for review August 24, 2026 06:26

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc225c66ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +247 to +248
indexRow_k + dst_k.validRows <= src.physicalRows
indexCol_k + dst_k.validCols <= src.physicalCols

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bound extraction windows by the source valid region

When src.valid_shape is smaller than its physical shape, these checks accept a window entirely outside the valid region—for example, a physical 64x128 source with valid 16x16 and indexRow=32. The proposed A2/A3 scalar lowering and A5 template then read those padding elements and expose them through dst.valid_shape, producing undefined or stale output. Either require a full-valid source or check each window against src.validRows/src.validCols rather than its allocation extent.

Useful? React with 👍 / 👎.

@HecreReed
HecreReed force-pushed the codex/textract-nd2xnz-design-only branch from 9280ad6 to ddb76ef Compare August 24, 2026 08:40
@zhangstevenunity
zhangstevenunity merged commit ca7ccb4 into hw-native-sys:main Aug 25, 2026
12 checks passed
@reedhecre

Copy link
Copy Markdown

A3 板测失败

  • 触发方式:merged
  • 源码提交:ca7ccb409664
  • 结果汇总:OK 320 / FAIL 2 / SKIP 30
  • 日志:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260824_204225_merged_pr1289.log
  • 结果 TSV:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260824_204225_merged_pr1289.tsv
  • 失败阶段:board-validation / exit=1

失败用例

  • Ci/ci (run, exit=2)
  • Qwen3_14BPrefillA3/out_proj_aiv (run, exit=2)

HecreReed added a commit to HecreReed/PTOAS that referenced this pull request Aug 25, 2026
Design PR hw-native-sys#1289 sections 5.1 items 11-13 and 5.3.1:

- validateTExtractNd2xNzInputProvenance: runs after generic verification and
  before any planning pass; rejects runtime-bound tile provenance
  (DeclareTileOp/TAssignOp/TPop-derived and their views), allows only
  AllocTileOp roots and non-RowPlusOne alloc_multi_tile slots.
- validateTExtractNd2xNzPostPlanningSafety: runs after PTOResolveBufferSelect
  and before PTOInlineBackendHelpersPass; address-space-aware physical-range
  comparison rejects alias generic TSTORE of partial-valid destinations
  inside the same closed direct-call component; compile-unit-wide call-surface
  closure rejects call_indirect / external / unresolved / opaque calls while
  any partial producer exists.
- compilePTOASModule: main pipeline is split into two actually-run pass
  managers (pre-inline planning through resolve-buffer-select, then the
  post-validation backend-helper pass); both helper calls and the shared
  checkpoint are on the ordinary codegen and --emit-pto-ir paths.
- lit: provenance negative and partial-store-alias negative.
HecreReed added a commit to HecreReed/PTOAS that referenced this pull request Aug 25, 2026
…odel (stage 3)

Design PR hw-native-sys#1289 sections 6.3, 6.3.1 and 7:

- getSemanticNoAliasPairs: the dual-output form reports (src,dst0),
  (src,dst1) and (dst0,dst1) so legacy/modern PlanMemory and the semantic
  no-alias verifier treat all three pairs as disjoint.
- GraphSync MemInfo: ordinary pto.alloc_tile gets a single-address model
  (static byte addr * bits-to-byte as the sole address; dynamic entry when
  the addr is not foldable so the allocation stays conservative inside its
  address space instead of looking disjoint); getMemInfo(Value) dispatches
  AllocTileOp explicitly.
- TExtractOp SyncMacroModel: dual-output form declares one external PIPE_V
  phase plus an internal PIPE_S phase covering source read and both
  destination writes, with bidirectional hidden V<->S events reserved
  before event-id allocation (design 6.3.1). The model is shape-selected:
  A2/A3 scalar lowering and the A5 1x1 scalar path opt in; the ordinary A5
  vector template stays a pure PIPE_V op.
HecreReed added a commit to HecreReed/PTOAS that referenced this pull request Aug 25, 2026
…assembly, EmitC)

Extend the existing pto.textract TExtractOp to carry the PTO-ISA
ND-to-2xNZ dual-output overload on the same operation (design PR hw-native-sys#1289):

- ODS: indexRow/indexCol/dst become Variadic indices/dsts ranges with the
  fixed five-segment schema [src, indices, dsts, fp, preQuantScalar]; custom
  assembly keeps the single-output canonical text character-for-character.
- classifyForm(): typed-property schema inference (SingleOutput vs NdTo2xNz);
  legacy getIndexRow/getIndexCol/getDst accessors restored as wrappers.
- verifier: form dispatch; verifyNdTo2xNzForm covers the IR/shape/layout
  items 1-10 (incl. source valid/physical double bounds, A5 partial-valid
  physicalRows==align16(validRows) gate, RowPlusOne rejection).
- getEffects: dual-output Read(src)+Write(dst0)+Write(dst1); Invalid schema
  falls back to conservative Read+Write on all raw memory operands.
- EmitC: dual-output emits the public seven-operand TEXTRACT(dst0,dst1,src,
  row0,col0,row1,col1) exactly once; single-output path reads ranges.
- PTOBC v0: dual-output forced through the generic v0 record, legacy
  four/five-operand opcodes unchanged.
- lit: parse/emit roundtrip, undefined-padding negative, and seven-arg
  EmitC checks.

Compiled locally against LLVM 19-compatible APIs; full regressions run on
the main-branch LLVM 19 CI.
HecreReed added a commit to HecreReed/PTOAS that referenced this pull request Aug 25, 2026
Design PR hw-native-sys#1289 sections 5.1 items 11-13 and 5.3.1:

- validateTExtractNd2xNzInputProvenance: runs after generic verification and
  before any planning pass; rejects runtime-bound tile provenance
  (DeclareTileOp/TAssignOp/TPop-derived and their views), allows only
  AllocTileOp roots and non-RowPlusOne alloc_multi_tile slots.
- validateTExtractNd2xNzPostPlanningSafety: runs after PTOResolveBufferSelect
  and before PTOInlineBackendHelpersPass; address-space-aware physical-range
  comparison rejects alias generic TSTORE of partial-valid destinations
  inside the same closed direct-call component; compile-unit-wide call-surface
  closure rejects call_indirect / external / unresolved / opaque calls while
  any partial producer exists.
- compilePTOASModule: main pipeline is split into two actually-run pass
  managers (pre-inline planning through resolve-buffer-select, then the
  post-validation backend-helper pass); both helper calls and the shared
  checkpoint are on the ordinary codegen and --emit-pto-ir paths.
- lit: provenance negative and partial-store-alias negative.
HecreReed added a commit to HecreReed/PTOAS that referenced this pull request Aug 25, 2026
…odel (stage 3)

Design PR hw-native-sys#1289 sections 6.3, 6.3.1 and 7:

- getSemanticNoAliasPairs: the dual-output form reports (src,dst0),
  (src,dst1) and (dst0,dst1) so legacy/modern PlanMemory and the semantic
  no-alias verifier treat all three pairs as disjoint.
- GraphSync MemInfo: ordinary pto.alloc_tile gets a single-address model
  (static byte addr * bits-to-byte as the sole address; dynamic entry when
  the addr is not foldable so the allocation stays conservative inside its
  address space instead of looking disjoint); getMemInfo(Value) dispatches
  AllocTileOp explicitly.
- TExtractOp SyncMacroModel: dual-output form declares one external PIPE_V
  phase plus an internal PIPE_S phase covering source read and both
  destination writes, with bidirectional hidden V<->S events reserved
  before event-id allocation (design 6.3.1). The model is shape-selected:
  A2/A3 scalar lowering and the A5 1x1 scalar path opt in; the ordinary A5
  vector template stays a pure PIPE_V op.
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.

3 participants