Skip to content

fix(TileOps): correct nd2nz/dn2nz src_inner_stride to use src physical stride in bytes.#924

Open
TelGome wants to merge 3 commits into
hw-native-sys:mainfrom
TelGome:issue_903
Open

fix(TileOps): correct nd2nz/dn2nz src_inner_stride to use src physical stride in bytes.#924
TelGome wants to merge 3 commits into
hw-native-sys:mainfrom
TelGome:issue_903

Conversation

@TelGome

@TelGome TelGome commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

修复 issue #903 在 vpto 后端暴露的 TileOps stride / 约束缺陷,共三处改动,均在 lib/TileOps/

  • tload nd2nz/dn2nz src_inner_stride 改为源物理 stride × 字节宽tload_template.py

    • 修复前:src_inner_stride = k / m(dst 列/行数,元素单位)
    • 修复后:src_inner_stride = s3 * elem_bytes(ND)/ s4 * elem_bytes(DN),与 ND2ND 模板写法对齐
    • 依据:pto-isa a5/TLoad.hpploop1_src_stride = GetByteSize<DType>(gStride) 为字节单位
    • 约束函数改用静态 dst.shape 替代动态 dst.valid_shape 做模板消歧,避免 valid_shape[null, null] 时 ND2NZ/DN2NZ 同时匹配
  • tstore acc2gm src_stride/dst_stride 改用 tile 行数与 GM 物理 stridetstore_template.py

    • 修复前:src_stride = dst_stride = n(tile 列数)
    • 修复后:src_stride = src.shape[0](= TileData::Rows,L0C acc NZ 行 stride),dst_stride = s3(ND)/ s4(DN)(GM 物理行 stride)
    • 单位为元素(pto-isa a5/TStore.hppTStoreAccNDsrcStride/dstD 透传给 copy_matrix_cc_to_gm,不乘 GetByteSize,硬件内部按 dtype 转字节)
    • 覆盖 nz2nd / nz2dn / nz2nz(仅 src)/ fp_acc_to_gm 四个模板
  • tload 约束严格拒绝非 rank-5 源tload_template.py,回应 gemini code review)

    • 修复前:if hasattr(src, 'rank') and src.rank == 5: 非 5D 时跳过 shape 检查并返回 True,导致非 5D 张量匹配约束后在模板 g0..g4 = src.shape 处抛 ValueError
    • 修复后:if not (hasattr(src, 'rank') and src.rank == 5): return False,在约束阶段即拒绝

Repro

  • issue: [Bug] qwen3 incore2 run error #903
  • 现象:vpto 后端 qwen3_decode_incore_2.pto 第一条 pto.tload(16×128 bf16,mat)生成的 MOV_OUT_TO_L1_MULTI_ND2NZ 指令被发射但永不 retire,紧跟 BAR 永久等待,整机死锁;真机报 errcode 168 / L0C out of range
  • 根因:原 src_inner_stride = k(元素单位 + dst 列数),硬件按错误步进读 GM(应 16384 B/行,实按 128 B)
  • repro cmd:
    ptoas --pto-arch=a5 --pto-backend=vpto --enable-tile-op-expand --enable-insert-sync \
      test_for_ptoas_incore2/qwen3_decode_incore_2.pto -o /tmp/qwen3.ll

Validation

  • cmake --build build --target check-pto:785 lit 用例全过
  • cube_tile_ops_positive.pto(src 无显式 layout)未回归
  • CAModel(qwen3_decode_incore_2,vpto):tload nd2nz 正常 retire;tstore IR config dstD=1024 / srcStride=16 与 emitc 字段一致;cube pipeline 从第一条 tload 死锁推进到 matmul/sync 阶段
  • 非 5D 源现在在约束阶段被拒绝,不再进模板 unpack

@reedhecre

reedhecre commented Jul 9, 2026

Copy link
Copy Markdown

Codex Review

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

Summary

Review failed at stage codex-review: exit=1

Findings

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

Log Tail


===== STAGE clone @ 2026-07-12 15:40:27 =====
set -euo pipefail
rm -rf '/tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/repo'
git clone --branch 'main' --depth 50 'https://github.com/hw-native-sys/PTOAS.git' '/tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/repo'
cd '/tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/repo'
git fetch origin 'refs/pull/924/head:pr-924' --depth 50
git fetch origin 'main' --depth 50 || true
git checkout -f 'pr-924'
git rev-parse HEAD
git diff --stat 'origin/main...HEAD' || true
Cloning into '/tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/repo'...
From https://github.com/hw-native-sys/PTOAS
 * [new ref]           refs/pull/924/head -> pr-924
From https://github.com/hw-native-sys/PTOAS
 * branch              main       -> FETCH_HEAD
Switched to branch 'pr-924'
57801db92e126dc2b1b3562d6eee807bf1076243
 lib/TileOps/tload_template.py  | 65 +++++++++++++++++++++++++++++-------------
 lib/TileOps/tstore_template.py | 55 ++++++++++++++++++++++++++++-------
 2 files changed, 89 insertions(+), 31 deletions(-)
===== END STAGE clone rc=0 @ 2026-07-12 15:40:32 =====

===== STAGE codex-review @ 2026-07-12 15:40:32 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/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/20260712_154026_pr924/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/review_prompt.txt'
[monitor] stage timeout: 1800s
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019f5545-4ba2-7c13-a518-7e4b81227bf9
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#924 fix(TileOps): correct nd2nz/dn2nz src_inner_stride to use src physical stride in bytes.
作者:TelGome
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 #924 存在问题,并返回 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: a19e6680edbaefba-LAX, request id: 01f489b3-0f4d-4eb9-8235-265019681636)
Reconnecting... 2/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a19e668388867d9d-LAX, request id: e434888e-3ad7-4e2c-a5ab-202221ed96a1)
Reconnecting... 3/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a19e66879fdf7e92-LAS, request id: 99996e4d-212b-41cf-adb1-b7eae9a473a7)
Reconnecting... 4/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a19e668d9b335bf3-LAX, request id: f2721641-39d6-40bb-97ae-37d9b6b002ac)
Reconnecting... 5/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a19e66997bb02b5e-LAX, request id: 7886d2f1-571d-40b2-af80-36fcfd39d8c8)
ERROR: unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a19e66ad5d9a3efd-LAX, request id: cd3ac00c-3acd-44b1-89bc-658b5f12c26f
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260712_154026_pr924/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-07-12 15:40:40 =====

@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 updates lib/TileOps/tload_template.py to use static dst.shape instead of dynamic dst.valid_shape in constraints, and scales the inner stride by the element byte width using the physical strides of the source tensor. The review feedback points out a potential crash where non-5D tensors can bypass the constraints and cause a ValueError during unpacking in the templates, recommending that src.rank == 5 be strictly enforced. Additionally, it suggests simplifying the unpacking of unused shape and stride variables by directly indexing the required strides.

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 lib/TileOps/tload_template.py Outdated
Comment thread lib/TileOps/tload_template.py Outdated
Comment thread lib/TileOps/tload_template.py
Comment thread lib/TileOps/tload_template.py

@Zhendong404 Zhendong404 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.

后面需要切到PTODSL,等PR #894 合入再合吧,免得迁移漏掉了

@TelGome

TelGome commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

后面需要切到PTODSL,等PR #894 合入再合吧,免得迁移漏掉了

好的

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