Skip to content

[PTODSL] Redesign TileOp single-core helper ABI#937

Open
jimmychou0 wants to merge 3 commits into
hw-native-sys:mainfrom
jimmychou0:ptodsl-tileop-single-core
Open

[PTODSL] Redesign TileOp single-core helper ABI#937
jimmychou0 wants to merge 3 commits into
hw-native-sys:mainfrom
jimmychou0:ptodsl-tileop-single-core

Conversation

@jimmychou0

@jimmychou0 jimmychou0 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rebase the PTODSL TileOp redesign onto canonical main at a1371bc7, including the new wheel-first TileLib framework.
  • Redesign @pto.tileop around a Tile plus PTO scalar parameter ABI. TileOp helpers remain void; results are written through mutable Tile parameters.
  • Keep the original pto.section.vector/cube ABI unchanged: no operands, no results, no pto.section.yield, and the original Python constructors remain valid.
  • Infer one Vector or Cube execution kind, support explicit SIMT helper launch, and reject MTE, pipe synchronization, direct SIMT micro-ops, high-level TileOps, nested TileOp calls, and mixed Vector/Cube bodies.
  • Retire named legacy @pto.cube and @pto.simd decorators with an actionable migration diagnostic. Inline with pto.cube(): and with pto.simd(): scopes remain supported.
  • Keep InsertSync, VPTO pointer normalization, CV split, and PlanMemory synchronized. PlanMemory models generic MemoryEffectOpInterface buffer operands used by TileOp micro-instructions such as vlds and vsts.
  • Preserve operation attributes before replacing TLog/TMrgSort ops in PTOViewToMemref. The latest main TileLib templates exposed the previous use-after-free during rebase validation.

Compatibility and existing coverage

  • Existing section-sugar syntax and constructors are retained without ABI adaptation.
  • Existing PTODSL JIT, docs, FlashAttention, subkernel, vector/cube, dsl-st, and tilelib-st coverage remains enabled.
  • Existing tests that exercise the new TileOp contract were adapted to use Tile/scalar parameters and mutable Tile outputs while preserving void helper returns.
  • Pure compute helpers use @pto.tileop. MTE, pipe synchronization, allocation, and orchestration remain in @pto.jit.
  • test/samples has no net diff from main for this section ABI change.
  • test/tilelib-st/a5/tmatmul/case.py only removes an unused named legacy @pto.cube helper; the tmatmul simulator case still passes.

Validation

All validation was rerun after the PlanMemory fix, the final void-return decision, the rebase onto a1371bc7, and the PTOViewToMemref attribute-lifetime fix.

Validation Result
Local ptoas and Python modules rebuild PASS
PTODSL CTest 22/22 PASS
Independent frontend verifier PASS
Focused TileOp/section lit 10/10 PASS
TLog/TMrgSort rebase regressions 4/4 PASS
Full lit suite 857/857 PASS
Wheel import and CLI smoke PASS
144 simulator test/dsl-st 9/9 PASS
144 simulator test/tilelib-st/a5 7/7 PASS

The 144 validation used the installed PTOAS wheel and /opt/llvm/lib. It did not add llvm-project-vpto21/build-assert/lib to LD_LIBRARY_PATH.

@reedhecre

reedhecre commented Jul 14, 2026

Copy link
Copy Markdown

Codex Review

该评论由 review 机器人自动更新。

  • PR: [PTODSL] Redesign TileOp single-core helper ABI #937 [PTODSL] Redesign TileOp single-core helper ABI
  • Author: jimmychou0
  • Base/Head: main / ptodsl-tileop-single-core
  • Head SHA: 1ded269cf2b2
  • Trigger: PR 有新提交
  • Generated At: 2026-07-15T01:56:31Z
  • Previous Head SHA: 0c9f0b237f7b
  • Status: failed at codex-review (exit=1)

Summary

Review failed at stage codex-review: exit=1

Findings

未生成结构化 findings,因为 review 过程提前失败。

Log Tail

 ptodsl/ptodsl/_subkernels.py                       |  82 +++++-
 ptodsl/ptodsl/_tracing/runtime.py                  |   2 +-
 ptodsl/ptodsl/_tracing/session.py                  |   5 +
 ptodsl/ptodsl/pto.py                               |   2 +-
 ptodsl/tests/CMakeLists.txt                        |   2 +-
 ptodsl/tests/support/docs_fragment_fixtures.py     | 104 ++++---
 ptodsl/tests/test_jit_compile.py                   | 118 ++++----
 ptodsl/tests/test_subkernel_diagnostics.py         |  95 ++++---
 ptodsl/tests/test_tileop.py                        | 123 +++++++++
 .../lit/pto/ptodsl_tileop_native_kind_sections.pto |  45 ++++
 .../pto/ptodsl_tileop_reject_contract_edges.pto    |  52 ++++
 test/lit/pto/ptodsl_tileop_reject_pipe_sync.pto    |  17 ++
 test/lit/pto/ptodsl_tileop_sections.pto            |  50 ++++
 test/lit/vpto/ptodsl_tileop_simt_ptr_vpto.pto      |  42 +++
 test/lit/vpto/ptodsl_tileop_split_simt_entry.pto   |  34 +++
 test/lit/vpto/section_sugar_duplicate_invalid.pto  |   8 +-
 test/lit/vpto/section_sugar_helper_funcs.pto       |  16 +-
 test/lit/vpto/section_sugar_multi_func.pto         |  16 +-
 test/tilelib-st/a5/tmatmul/case.py                 |  32 +--
 tools/ptoas/ptoas.cpp                              |  13 +-
 51 files changed, 1831 insertions(+), 573 deletions(-)
===== END STAGE clone rc=0 @ 2026-07-15 09:56:13 =====

===== STAGE codex-review @ 2026-07-15 09:56:13 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260715_095549_pr937/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260715_095549_pr937/repo' -s read-only -c 'model_provider="codereview"' -c 'model="gpt-5.4"' -c 'model_reasoning_effort="xhigh"' --output-schema '/tmp/ptoas-pr-review-monitor/runs/20260715_095549_pr937/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260715_095549_pr937/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260715_095549_pr937/review_prompt.txt'
[monitor] stage timeout: 1800s
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260715_095549_pr937/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019f637d-35a8-7961-b0c4-66072679da10
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#937 [PTODSL] Redesign TileOp single-core helper ABI
作者:jimmychou0
base branch:origin/main
head branch:HEAD(当前已 checkout 到 PR head)

要求:
1. 只审查这个 PR 相对 origin/main 的改动,必要时可以看上下文文件。
2. 重点找真实的 correctness / regression / contract mismatch / CI / runtime / compatibility 问题。
3. 不要提纯风格建议,不要提低价值猜测。
4. 严格按优先级输出:
   - P1:高概率会导致错误结果、编译/运行失败、严重回归、发布阻断
   - P2:重要缺陷、行为回归、遗漏校验/测试、较大兼容性问题
   - P3:次要但明确可改的问题
5. 如果没有问题,summary 直接写:未检查到 PR #937 存在问题,并返回 findings=[]。
6. 如果有问题,summary 简洁概括,findings 里每条都要给出:
   - severity
   - title
   - body(说明为什么是问题,尽量具体)
   - file(尽量给相对路径)
   - line(能确定就填整数,否则 null)

建议先查看:
- git status --short
- git diff --stat origin/main...HEAD
- git diff --unified=80 origin/main...HEAD

最终输出必须严格匹配 JSON schema。

mcp startup: no servers
Reconnecting... 1/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1b5266b7fdf6b8d-LAX, request id: 851869f8-ac7e-4566-b9f5-7236ee2e1960)
Reconnecting... 2/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1b52670f82b1e08-LAX, request id: 060ef7bb-436d-41b3-a157-ed263654b9cf)
Reconnecting... 3/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1b5267af88ab82e-LAX, request id: c358257a-859a-4e21-8bd9-fcd5a336f9ac)
Reconnecting... 4/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1b52683495b1d3e-LAX, request id: 3896bf08-3792-40d9-8f25-9e5aff1710b6)
Reconnecting... 5/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1b52691780d4adb-LAX, request id: 3e724a6a-3570-4db5-94be-cda082c1e185)
ERROR: unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1b526aa8864f210-LAX, request id: 27900e3e-8bfe-4c8b-af05-1dbab543164b
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260715_095549_pr937/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-07-15 09:56:31 =====

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request implements the PTODSL TileOp single-core pure UB redesign, introducing the @pto.tileop decorator and the PTOMaterializeTileOpSections compiler pass to wrap helper bodies in single compute sections with explicit SSA boundaries. It also updates memory planning, pointer normalization, and module splitting to support these explicit boundaries. The review feedback highlights critical issues in the validation and analysis passes: first, the Python validation for @pto.tileop return types can be bypassed when no return type is annotated due to inspect.Parameter.empty handling; second, the transitive dependency analysis in VPTOSplitCVModule fails to recurse into same-kind sections, potentially missing opposite-kind dependencies; and third, the cross-kind scalar dependency check should walk nested operations to catch implicit captures that are not part of the explicit section operands.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ptodsl/ptodsl/_subkernels.py Outdated
Comment thread lib/PTO/Transforms/VPTOSplitCVModule.cpp Outdated
Comment thread lib/PTO/Transforms/VPTOSplitCVModule.cpp Outdated
@jimmychou0
jimmychou0 force-pushed the ptodsl-tileop-single-core branch 3 times, most recently from 1ec0482 to 79b4284 Compare July 15, 2026 09:31
@jimmychou0
jimmychou0 marked this pull request as ready for review July 15, 2026 09:33
not require users or the frontend to manually partition every operation into a
final section.
rules. PTODSL exposes named `@pto.tileop` / `@pto.simt` helpers and inline
`with pto.simd():` / `with pto.cube():` scopes, but does not require users or

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

with pto.simd()和with pto.cube()本来就是@pto.simd/@pto.cube的一种特殊形式,现在@pto.simd/@pto.cube删掉了,这俩也可以删掉了。

可以提供一个with pto.tileop(),然后对捕获的边界变量做和@pto.tileop函数一样的约束

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

漏了, 已补充。 支持 with pto.tileop()。with pto.simd()、with pto.cube() 与对应 decorator 使用同一 legacy 接口诊断

@jimmychou0
jimmychou0 force-pushed the ptodsl-tileop-single-core branch 2 times, most recently from eaa0715 to 49e4214 Compare July 16, 2026 01:54
Comment thread ptodsl/examples/fa_dn_ptodsl.py Outdated
kL0BTile: pto.Tile,
qkAccTile: pto.Tile,
qkVecTileSub: pto.Tile,
rows: pto.index,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pto.index不是DSL手册里的数据类型,这里写pto.i32之类的吧

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

该示例已按本轮决定删除,因此这处 pto.index 签名随文件一并移除,无需单独引入 pto.i32 ABI 改动。

pto.wait_flag("MTE2", "V", event_id=0)

with pto.simd():
with pto.tileop():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

对于explicit的kernel,其实没必要加pto.tileop,因为我们的初衷就是给auto mode用的

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已将该 explicit 示例改为直接保留 Vector compute,不再展示 with pto.tileop。设计上仍保留 TileOp 跨 auto 和 explicit mode 的支持;inline TileOp 是可选的匿名 helper boundary,相关 explicit 正例已由测试覆盖。

cols = kMatTile.valid_shape[0]

pto.mte_l1_l0a(qMatTile.as_ptr(), qL0ATile.as_ptr(), rows, head)
pto.mte_l1_l0b(kMatTile.as_ptr(), kL0BTile.as_ptr(), head, cols, transpose=True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

然后这个example其实和我们现在的设计差得比较远了,只改这里也没办法让完整的kernel逻辑自洽,我感觉没有继续当做example的意义了,可以删掉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已删除 fa_dn_ptodsl.py。该样例只完成局部迁移且依赖缺失模块,不再作为用户示例保留。

pto.wait_flag("MTE2", "V", event_id=0)

with pto.simd():
with pto.tileop():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里也是类似的,explicit模式不用加pto.tileop

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已将该 explicit 示例改为直接保留 Vector compute,不再展示 with pto.tileop;TileOp 跨 mode 支持仍由明确的 API 合同和测试覆盖。

name.starts_with("pto.mgather") || name.starts_with("pto.mscatter");
}

static bool isVectorMicroOperation(StringRef name) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

用op name判断Section感觉不太优雅。能否用OP所属的PIPE来判断呢?参考一下自动infer section的pass,或者能不能和自动infer section的pass合并?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

通过ods 中增加tarit的方式识别op类型

@jimmychou0
jimmychou0 force-pushed the ptodsl-tileop-single-core branch 3 times, most recently from 2cdb2ce to 363e9e7 Compare July 16, 2026 09:12
@jimmychou0
jimmychou0 requested a review from Zhendong404 July 17, 2026 06:22
@jimmychou0
jimmychou0 force-pushed the ptodsl-tileop-single-core branch from 363e9e7 to c419a6e Compare July 17, 2026 08:54
@@ -1,4 +1,4 @@
// RUN: ! ptoas --pto-arch=a5 --pto-backend=vpto --emit-vpto %s -o - 2>&1 | FileCheck %s

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

测例名字也改一下比较好,现在这是一个正例了

// See LICENSE in the root of the software repository for the full text of the License.

// RUN: ptoas --pto-arch=a5 --pto-backend=vpto --emit-vpto %s -o - | FileCheck %s
// RUN: ptoas --pto-arch=a5 --emit-pto-ir %s -o - | FileCheck %s

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个lit用例改动没看懂,原来应该是想看护split cv module这个pass的,改了之后看护失效了

@@ -1,4 +1,4 @@
// RUN: ptoas --pto-arch=a5 --pto-backend=vpto --emit-vpto %s -o - | FileCheck %s
// RUN: ptoas --pto-arch=a5 --emit-pto-ir %s -o - | FileCheck %s

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

同上

static bool isPTODSLSubkernelHelperFunc(func::FuncOp fn) {
return fn->hasAttr("pto.ptodsl.subkernel_helper");
return fn->hasAttr("pto.ptodsl.subkernel_helper") ||
fn->hasAttr("pto.tileop.helper");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pto.ptodsl.subkernel_helper是旧方案,现在切到新方案只需要保留pto.tileop.helper就行了吧,函数名也可以改一下

Replace legacy cube/simd subkernel decorators with typed TileOp and SIMT helpers while keeping TileOp helpers void.

Materialize compute sections, preserve dynamic Tile metadata, summarize memory effects for synchronization, and update lowering, examples, docs, and regression coverage.
Use reusable ODS instruction-class interfaces to infer sections and classify TileOp helper contract violations without opcode-name matching.

Keep AST-rewrite example baselines aligned with explicit-mode inline compute.
@jimmychou0
jimmychou0 force-pushed the ptodsl-tileop-single-core branch from c419a6e to a3fbc09 Compare July 20, 2026 02:34
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