Skip to content

ub->gm传递l2_cache_ctl参数#920

Open
and0d0 wants to merge 7 commits into
hw-native-sys:mainfrom
and0d0:489-ub-gm-l2-cache
Open

ub->gm传递l2_cache_ctl参数#920
and0d0 wants to merge 7 commits into
hw-native-sys:mainfrom
and0d0:489-ub-gm-l2-cache

Conversation

@and0d0

@and0d0 and0d0 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

增加兼容性,保持默认l2_cache_ctl=0,显式传值时则使用显式值

  • dsl层面使用str表明l2_cache_ctl
  • 高层 pto.mte_ub_gm 增加了 l2_cache_ctl参数
  • 底层 pto.copy_ubuf_to_gm 里原来的 reserved 语义改成 l2_cache_ctl
  • 更新相关 VPTO emitter/接口处的字段命名和语义,使它表示 reserved -> L2 cache policy

@reedhecre

reedhecre commented Jul 9, 2026

Copy link
Copy Markdown

Codex Review

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

  • PR: ub->gm传递l2_cache_ctl参数 #920 ub->gm传递l2_cache_ctl参数
  • Author: and0d0
  • Base/Head: main / 489-ub-gm-l2-cache
  • Head SHA: 3303d502cf53
  • Trigger: PR 有新提交
  • Generated At: 2026-07-13T13:56:04Z
  • Previous Head SHA: 20fafd57d44b
  • Status: failed at codex-review (exit=1)

Summary

Review failed at stage codex-review: exit=1

Findings

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

Log Tail

Switched to branch 'pr-920'
3303d502cf53ff86a8fe9d0684ae11fa0d70e9c3
 docs/isa/micro-isa/01-pipeline-sync.md             | 12 ++--
 docs/isa/micro-isa/02-dma-copy.md                  | 19 ++---
 docs/isa/micro-isa/17-simt.md                      |  8 +--
 docs/vpto-spec.md                                  |  4 +-
 include/PTO/IR/VPTOOps.td                          |  9 ++-
 lib/PTO/IR/VPTO.cpp                                | 48 ++++++++++---
 lib/PTO/Transforms/VPTOCANN900LLVMEmitter.cpp      | 10 +--
 lib/PTO/Transforms/VPTOExpandWrapperOps.cpp        |  3 +-
 lib/PTO/Transforms/VPTOLLVMEmitter.cpp             | 10 +--
 ptodsl/docs/user_guide/07-data-movement-ops.md     | 12 +++-
 ptodsl/ptodsl/_ops.py                              | 68 +++++++++++++++++-
 ptodsl/tests/test_jit_compile.py                   | 14 ++++
 test/lit/vpto/mte_ub_gm_l2_cache_ctl.pto           | 54 +++++++++++++++
 .../docs/user_guide/08-sync-dma-operations.md      |  9 ++-
 tilelang-dsl/python/tilelang_dsl/frontend_ast.py   |  2 +-
 tilelang-dsl/python/tilelang_dsl/lowering.py       | 11 +--
 tilelang-dsl/python/tilelang_dsl/semantic.py       | 58 +++++++++++++++-
 tilelang-dsl/tests/test_tilelang_dsl_v1.py         | 80 ++++++++++++++++++++++
 18 files changed, 376 insertions(+), 55 deletions(-)
===== END STAGE clone rc=0 @ 2026-07-13 21:55:56 =====

===== STAGE codex-review @ 2026-07-13 21:55:56 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260713_215548_pr920/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260713_215548_pr920/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/20260713_215548_pr920/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260713_215548_pr920/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260713_215548_pr920/review_prompt.txt'
[monitor] stage timeout: 1800s
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260713_215548_pr920/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019f5bc3-58dd-7c72-9aa7-1f3d4267239f
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#920 ub->gm传递l2_cache_ctl参数
作者:and0d0
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 #920 存在问题,并返回 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: a1a8c9c92eb15397-LAX, request id: b7e3efb9-6489-4fff-ae54-3aef8ec61cd6)
Reconnecting... 2/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1a8c9cbcff2d7ab-LAX, request id: b37e2c98-1612-453b-9140-d9985d3da480)
Reconnecting... 3/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1a8c9cfff21f3df-LAS, request id: a102ca11-033d-473b-b6c1-9bbc383c4891)
Reconnecting... 4/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1a8c9d6499f2f70-LAX, request id: dd6ae730-7d60-4d3b-b784-0f50a905fa82)
Reconnecting... 5/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1a8c9e16bf80d77-LAX, request id: b70f5f47-0da5-4443-b286-6cd79fc81edb)
ERROR: unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1a8c9f54c4a13e6-LAX, request id: cbf4c908-6c26-4aad-8d56-fa3fbf75fcfd
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260713_215548_pr920/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-07-13 21:56:04 =====

@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 introduces support for GM store-side L2 cache control in the pto.mte_ub_gm and pto.copy_ubuf_to_gm operations by replacing a previously reserved field with the l2_cache_ctl parameter. The changes include updates to the dialect definition, parser, printer, verifier (ensuring constant values fit in the [0, 15] range), LLVM emitters, and documentation. Existing tests and examples have been updated to include the new parameter, and a new test file has been added to verify its roundtrip and expansion. There are no review comments, so I have no feedback to provide.

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.

@zhangstevenunity zhangstevenunity left a comment

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.

Reviewed the full cross-layer change: the ODS operand add (l2_cache_ctl as the 3rd operand of pto.mte_ub_gm), the reserved -> l2_cache_ctl rename on low-level pto.copy_ubuf_to_gm, both LLVM emitters (bit 60), ExpandDmaStorePattern forwarding, the [0,15] verifier, PTODSL _ops.py, docs, and the golden .pto updates.

Most of it is sound and backward compatible: default l2_cache_ctl=0 keeps the emitted config bits identical to the old reserved=0; bit 60 matches the load-direction copy_gm_to_ubuf packing; the docs "4 bits" field is consistent with the [0,15] check and shl 60; C++ has only two MteUbGmOp::build callers (both updated) and one CopyUbufToGmOp creator (forwards getL2CacheCtl()); PTODSL threads it as keyword-only, preserving existing positional callers, and the new regexes assert the operand position for both default (%c0) and explicit (%c7) cases.

One blocking issue: a second cross-layer emitter of pto.mte_ub_gm was missed.

[Blocker] TileLang DSL renderer still emits the old 3-operand form -> generated IR no longer parses

tilelang-dsl/python/tilelang_dsl/lowering.py _render_mte_ub_gm (around line 2528) reads args[2] as len_burst and renders:

pto.mte_ub_gm %src, %dst, %len_burst nburst(...) : !pto.ptr<..,ub>, !pto.ptr<..,gm>, i64, i64, i64, i64

(3 operands, 6 types). With l2_cache_ctl now a required 3rd operand, the updated parser puts %len_burst into the l2_cache_ctl slot and then fails at parseOperand(lenBurst) on the nburst keyword; the type list is also one short (6 vs the required 7). So any TileLang DSL v1 program using pto.mte_ub_gm(...) now produces IR that fails to parse/verify in ptoas.

The load counterpart in the same file, _render_mte_gm_ub, already emits ..., %l2_cache_ctl, %len_burst ... plus the matching type -- that is the pattern the store renderer should mirror. Since _analyze_mte_ub_gm only accepts 3 positional args + nburst/loops, the fix is to materialize a default 0 : i64 constant and emit it as the 3rd operand and 3rd type.

No test covers this: the only mte_ub_gm references under tilelang-dsl/tests/ are feature-tier/registration asserts, and tinsert_acc2vec.pto (correctly updated here) is a hand-authored ST input, not produced by this renderer -- so the break ships green.

Minor (non-blocking):

  • The [0,15] range check is only on the store MteUbGmOp::verify. The load MteGmUbOp::verify and low-level CopyUbufToGmOp::verify still do not range-check l2_cache_ctl; the store path is safe because the wrapper forwards a verified value, but a hand-written copy_ubuf_to_gm with l2_cache_ctl > 15 would overflow into/past bit 63. A shared check would be more robust.
  • Surface asymmetry: mte_gm_ub/mte_load take l2_cache_ctl positionally (3rd arg), while mte_ub_gm/mte_store take it keyword-only at the tail. Reasonable for back-compat, but worth a doc note.
  • docs/isa-legacy/02-dma-copy.md still labels the low-level 6th operand %reserved "Reserved field (set to 0)"; it is now l2_cache_ctl.

Comment thread include/PTO/IR/VPTOOps.td Outdated
let arguments = (ins
PTO_BufferLikeType:$source,
PTO_BufferLikeType:$destination,
I64:$l2_cache_ctl,

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.

Cross-layer emitter missed: TileLang DSL still renders the pre-l2_cache_ctl form.

Adding l2_cache_ctl as a required 3rd operand here also requires updating every emitter of the textual pto.mte_ub_gm. tilelang-dsl/python/tilelang_dsl/lowering.py:2528 _render_mte_ub_gm still emits:

pto.mte_ub_gm %src, %dst, %len_burst nburst(...) : ptr, ptr, i64, i64, i64, i64

(3 operands / 6 types). With this operand added, that IR fails to parse -- the parser puts %len_burst into the l2_cache_ctl slot and then hits the nburst keyword at parseOperand(lenBurst), and the type list is one short. Mirror _render_mte_gm_ub in the same file, which already emits ..., %l2_cache_ctl, %len_burst ... and the extra type; since the DSL surface does not expose l2_cache_ctl, materialize a default 0 : i64. No test exercises this render->parse path today, so it fails silently.

Comment thread include/PTO/IR/VPTOOps.td Outdated
let arguments = (ins
PTO_BufferLikeType:$source,
PTO_BufferLikeType:$destination,
I64:$l2_cache_ctl,

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.

PR中提到:保持默认l2_cache_ctl=0,但是这里是强制要求参数?

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.

只在py引用的dsl接口层面非强制,后续没有值的话会补齐0,暂没考虑兼容旧.pto,可以改

Comment thread docs/isa/micro-isa/02-dma-copy.md Outdated
- **syntax:**
```mlir
pto.mte_ub_gm %ub_src, %gm_dst, %len_burst
pto.mte_ub_gm %ub_src, %gm_dst, %l2_cache_ctl, %len_burst

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.

通常,接口参数会按照参数热度排序。现在指令中的l2_cache_ctl参数,和上层接口/底层指令的参数位置都不太匹配:

  • 上层dsl中是在末尾;
  • 底层硬件指令copy_ubuf_to_gm_align_v2中,是在nBurst, lenBurst之后;
  • 建议考虑下参数位置

@and0d0 and0d0 force-pushed the 489-ub-gm-l2-cache branch from 74a4d0a to 20fafd5 Compare July 13, 2026 09:07
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.

4 participants