Skip to content

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

Open
TelGome wants to merge 1 commit 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 1 commit into
hw-native-sys:mainfrom
TelGome:issue_903

Conversation

@TelGome

@TelGome TelGome commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • TLOAD.MAT ND2NZ/DN2NZ 模板的 src_inner_stride 改为源 view 物理 stride × 字节宽(s3 * elem_bytes / s4 * elem_bytes),与 ND2ND 模板写法对齐,匹配硬件 loop1_src_stride 的字节单位语义
  • ND 用 s3(对应 gStride3)、DN 用 s4(对应 gStride4),与 pto-isa TLoadCubeND2NZ 一致
  • 约束函数用静态 dst.shape 替代动态 dst.valid_shape 做模板消歧,避免 valid_shape[null, null] 时 ND2NZ/DN2NZ 同时匹配

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/m(元素单位 + dst 列行数),硬件按错误步进读 GM(应 16384B/行,实按 128B)

Validation

  • cmake --build build --target check-pto:785 lit 用例全过
  • cube_tile_ops_positive.pto(src 无显式 layout)未回归
  • CAModel:ND2NZ 正常 retire,cube pipeline 从第一条 tload 死锁推进到 matmul/sync 阶段

@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-09 16:50:28 =====
set -euo pipefail
rm -rf '/tmp/ptoas-pr-review-monitor/runs/20260709_165027_pr924/repo'
git clone --branch 'main' --depth 50 'https://github.com/hw-native-sys/PTOAS.git' '/tmp/ptoas-pr-review-monitor/runs/20260709_165027_pr924/repo'
cd '/tmp/ptoas-pr-review-monitor/runs/20260709_165027_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/20260709_165027_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'
1db5f2c61235fa667becf23e539e86991d9d5686
 lib/TileOps/tload_template.py | 47 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 12 deletions(-)
===== END STAGE clone rc=0 @ 2026-07-09 16:50:33 =====

===== STAGE codex-review @ 2026-07-09 16:50:33 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260709_165027_pr924/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260709_165027_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/20260709_165027_pr924/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260709_165027_pr924/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260709_165027_pr924/review_prompt.txt'
[monitor] stage timeout: 1800s
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260709_165027_pr924/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019f4612-5331-70b0-943f-c1e8a359a773
--------
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: a18614f33da60f19-LAX, request id: c4d1238b-3582-4791-be9c-388e57caa6cc)
Reconnecting... 2/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18614f5db4fc4eb-LAX, request id: ae538b02-cc74-4b0a-8399-480cec7379e0)
Reconnecting... 3/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18614f9cf4b9d5a-LAX, request id: 4aa230fc-4b5f-4921-8da0-b375e90f8094)
Reconnecting... 4/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18615001b73792b-LAX, request id: b9adf3bf-9580-4567-9d43-ef670a06f0d9)
Reconnecting... 5/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a186150bba2824e5-LAX, request id: 85064ca0-9334-460b-8c9c-571e8f2d0b19)
ERROR: unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a186152169e9d7a8-LAX, request id: 961750ea-5be0-4695-854b-6044b4ed6f12
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260709_165027_pr924/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-07-09 16:50:41 =====

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

if hasattr(src, 'rank') and src.rank == 5:
dst_valid_cols = dst.valid_shape[1] if hasattr(dst, 'valid_shape') and dst.valid_shape is not None else None
if dst_valid_cols is not None and hasattr(src, 'shape') and src.shape is not None:
dst_cols = dst.shape[1] if hasattr(dst, 'shape') and dst.shape is not None else None

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.

high

If the source tensor does not have rank 5, the outer condition if hasattr(src, 'rank') and src.rank == 5: is skipped, causing the constraint function to return True. This allows non-5D tensors to match this constraint, which will subsequently cause a ValueError during template execution when unpacking src.shape and src.strides into 5 variables.\n\nWe should strictly require src.rank == 5 by returning False if it is not met:\n\npython\nif not hasattr(src, 'rank') or src.rank != 5:\n return False\n

if hasattr(src, 'rank') and src.rank == 5:
dst_valid_rows = dst.valid_shape[0] if hasattr(dst, 'valid_shape') and dst.valid_shape is not None else None
if dst_valid_rows is not None and hasattr(src, 'shape') and src.shape is not None:
dst_rows = dst.shape[0] if hasattr(dst, 'shape') and dst.shape is not None else None

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.

high

If the source tensor does not have rank 5, the outer condition if hasattr(src, 'rank') and src.rank == 5: is skipped, causing the constraint function to return True. This allows non-5D tensors to match this constraint, which will subsequently cause a ValueError during template execution when unpacking src.shape and src.strides into 5 variables.\n\nWe should strictly require src.rank == 5 by returning False if it is not met:\n\npython\nif not hasattr(src, 'rank') or src.rank != 5:\n return False\n

Comment on lines +434 to +436
# rank-5 partition view metadata (g3 = M rows, g4 = K cols for ND source).
g0, g1, g2, g3, g4 = src.shape
s0, s1, s2, s3, s4 = src.strides

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.

medium

The variables g0, g1, g2, g3, g4 and s0, s1, s2, s4 are completely unused in this template. Unpacking them is unnecessary and can be simplified by directly accessing src.strides[3].

Suggested change
# rank-5 partition view metadata (g3 = M rows, g4 = K cols for ND source).
g0, g1, g2, g3, g4 = src.shape
s0, s1, s2, s3, s4 = src.strides
# rank-5 partition view metadata (g3 = M rows, g4 = K cols for ND source).\n s3 = src.strides[3]

Comment on lines +499 to +501
# rank-5 partition view metadata (g3 = K, g4 = M for DN col-major source).
g0, g1, g2, g3, g4 = src.shape
s0, s1, s2, s3, s4 = src.strides

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.

medium

The variables g0, g1, g2, g3, g4 and s0, s1, s2, s3 are completely unused in this template. Unpacking them is unnecessary and can be simplified by directly accessing src.strides[4].

Suggested change
# rank-5 partition view metadata (g3 = K, g4 = M for DN col-major source).
g0, g1, g2, g3, g4 = src.shape
s0, s1, s2, s3, s4 = src.strides
# rank-5 partition view metadata (g3 = K, g4 = M for DN col-major source).\n s4 = src.strides[4]

@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