Skip to content

docs: design dual-output TEXTRACT support - #1289

Open
HecreReed wants to merge 19 commits into
hw-native-sys:mainfrom
HecreReed:codex/textract-nd2xnz-design-only
Open

docs: design dual-output TEXTRACT support#1289
HecreReed wants to merge 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
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