Skip to content

Relax thistogram verifier for ui32 byte 3#714

Merged
zhangstevenunity merged 1 commit into
hw-native-sys:mainfrom
FangRui0:fix_verify
May 28, 2026
Merged

Relax thistogram verifier for ui32 byte 3#714
zhangstevenunity merged 1 commit into
hw-native-sys:mainfrom
FangRui0:fix_verify

Conversation

@FangRui0
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown

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

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 the pto.thistogram verification logic and documentation to bypass layout and shape constraints on the idx operand when the source element type is ui32 and byte is set to 3. A test case is also added to verify this behavior. The reviewer suggested adding a range check for byte to ensure it falls within the valid [0, 3] range, preventing invalid values from bypassing the verification checks.

Comment thread lib/PTO/IR/PTO.cpp
if (!hasCompatibleKnownExtent(idxShape[0], expectedIdxRows) ||
!hasCompatibleKnownExtent(idxValid[0], expectedIdxRows))
return emitOpError("expects idx rows/valid rows to match the byte-selected filter depth when src element type is ui32");
if (byte != 3) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If byte is not validated to be within the valid range [0, 3] for ui32 inputs, an invalid value (such as 4 or negative values) could bypass the layout and shape checks, potentially leading to undefined behavior or compiler crashes downstream. Adding a range check for byte ensures robustness.

      if (byte < 0 || byte > 3)
        return emitOpError("expects byte to be in the range [0, 3] when src element type is ui32");

      if (byte != 3) {

@reedhecre
Copy link
Copy Markdown

reedhecre commented May 27, 2026

Codex Review

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

  • PR: Relax thistogram verifier for ui32 byte 3 #714 Relax thistogram verifier for ui32 byte 3
  • Author: FangRui0
  • Base/Head: main / fix_verify
  • Head SHA: 13c75cab9b52
  • Trigger: 检测到新的 open PR
  • Generated At: 2026-05-27T14:38:27Z
  • Status: completed

Summary

PR #714 放宽了 thistogramui32 + byte=3 场景下的前端约束,但下游 codegen/CI 没有同步证明这条新 contract 真实成立。

Findings

  1. P2 `byte=3` 的 verifier 放宽了 `idx` 约束,但 lowering 仍然把原始 `idx` 类型原样传给 `THISTOGRAM` lib/PTO/IR/PTO.cpp:6890

这里把 ui32 + byte=3idx 放宽成“任意 rank-2 ui8 vec tile 都可接受”,包括新测试里的 32x11col_major 形式。但 EmitC lowering 仍会在 lib/PTO/Transforms/PTOToEmitC.cpp:5709-5747idx 作为第三个操作数原样传给 THISTOGRAM,而该路径生成的 Tile<> C++ 类型会把 idx 的行列和布局编码进模板参数(见 getEmitCTileTypeString)。也就是说,这个 PR 扩大了 MLIR verifier 的 contract,却没有同步归一化/删除 byte=3idx,下游 C++/AscendC 侧是否真的接受任意 idx 类型并没有在实现里被保证。结果是:现在可能有 IR 能通过 verifier,但在后续 codegen/编译阶段才失败。

  1. P2 新增 lit 用例并不能真正覆盖这次放宽出来的新路径 test/lit/pto/thistogram_verify_u32_byte3_unused_idx_a5.pto:1

这个测试的 RUN 行是 ptoas ... | FileCheck %s,而文件里只有 CHECK-NOT: error:。在 lit 的普通 shell pipeline 下,这种写法即使 ptoas 提前失败、崩溃,或者后续阶段报了不含字面量 error: 的问题,FileCheck 仍然可能返回成功;同时它也没有任何正向检查去证明生成结果里真的走到了可接受的 THISTOGRAM<HistByte::BYTE_3> 路径。因此 CI 现在并不能捕获这次 verifier 放宽是否真的对 end-to-end codegen 有效。

@zhangstevenunity zhangstevenunity merged commit 58c8078 into hw-native-sys:main May 28, 2026
11 checks passed
@reedhecre
Copy link
Copy Markdown

A5 板测成功

  • 触发方式:merged
  • 源码提交:58c80788329f
  • 结果汇总:OK 21 / FAIL 0 / SKIP 0
  • 日志:/root/ptoas-board-monitor-a5/logs/20260528_104104_merged_pr714.log
  • 结果 TSV:/root/ptoas-board-monitor-a5/logs/20260528_104104_merged_pr714.tsv

@reedhecre
Copy link
Copy Markdown

A3 板测失败

  • 触发方式:merged
  • 源码提交:58c80788329f
  • 结果汇总:OK 217 / FAIL 2 / SKIP 1
  • 日志:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260528_121304_merged_pr714.log
  • 失败阶段:board-validation / exit=1

失败用例

  • syncall_binding (run, exit=1)
  • tprefetch_async_binding (run, exit=1)

@reedhecre
Copy link
Copy Markdown

A3 板测失败详情:PR #714

syncall_binding

stage=run info=exit=1

[ERROR] aclrtSynchronizeStream(stream) failed: 507014 (/home/zhongxuan/ptoas-board-monitor/runtime/runs/20260528_121304_merged_pr714/npu_validation/SyncAll/syncall_binding/main.cpp:84)
[ERROR] RecentErrMsg: EZ9999: Inner Error!
EZ9999[PID: 4024387] 2026-05-28-12:55:47.464.609 (EZ9999):  The error from device(chipId:2, dieId:0), serial number is 247, there is an exception of aicore error, core id is 3, error code = 0, dump info: pc start: 0x124800000000, current: 0x124800000188, vec error info: 0, mte error info: 0xc503000030, ifu error info: 0x212c200078980, ccu error info: 0x40a01900778000d8, cube error info: 0, biu error info: 0, aic error mask: 0x6500020bd00028c, para base: 0x12c100000000.[FUNC:PrintCoreInfo][FILE:device_error_core_proc.cc][LINE:645]
        TraceBack (most recent call last):
       The extend info: errcode:(0, 0, 0) errorStr: timeout or trap error. fixp_error0 info: 0x3000030, fixp_error1 info: 0xc5, fsmId:0, tslot:3, thread:0, ctxid:0, blk:0, sublk:0, subErrType:4.[FUNC:PrintCoreInfo][FILE:device_error_core_proc.cc][LINE:658]
       Kernel task happen error, retCode=0x25, [aicore timeout].[FUNC:PreCheckTaskErr][FILE:davinci_kernel_task.cc][LINE:1729]
       AICORE Kernel task happen error, retCode=0x25.[FUNC:GetError][FILE:stream.cc][LINE:1475]
       [AIC_INFO] after execute:args print end[FUNC:GetError][FILE:stream.cc][LINE:1475]
       [DFX_INFO]Aicore kernel execute failed, device_id=4, stream_id=46, report_stream_id=46, task_id=0, flip_num=0, fault kernel_name=_Z22syncall_binding_kernelPii, fault kernel info ext=_Z22syncall_binding_kernelPii, program id=0, hash=3129332313788381512.[FUNC:GetError][FILE:stream.cc][LINE:1475]
       rtStreamSynchronize execution failed, reason=aicore timeout[FUNC:FuncErrorReason][FILE:error_message_manage.cc][LINE:65]
       synchronize stream failed, runtime result = 507014[FUNC:ReportCallError][FILE:log_inner.cpp][LINE:148]
[2026-05-28 12:55:48] ERROR: testcase failed (exit 1): syncall_binding
tprefetch_async_binding

stage=run info=exit=1

[ERROR] aclrtSynchronizeStream(stream) failed: 507035 (/home/zhongxuan/ptoas-board-monitor/runtime/runs/20260528_121304_merged_pr714/npu_validation/TPrefetchAsync/tprefetch_async_binding/main.cpp:91)
[ERROR] RecentErrMsg: EZ9999: Inner Error!
EZ9999[PID: 37741] 2026-05-28-12:56:26.091.445 (EZ9999):  The error from device(chipId:2, dieId:0), serial number is 248, there is an exception of aivec error, core id is 17, error code = 0, dump info: pc start: 0x124800000000, current: 0x124800000160, vec error info: 0x1e000000a8, mte error info: 0xa50312808b, ifu error info: 0x212c081200180, ccu error info: 0x52, cube error info: 0, biu error info: 0, aic error mask: 0x6500020bd00028c, para base: 0x12c100000000.[FUNC:PrintCoreInfo][FILE:device_error_core_proc.cc][LINE:645]
        TraceBack (most recent call last):
       The extend info: errcode:(0, 0x200000000000000, 0) errorStr: The MPU address access is invalid. fixp_error0 info: 0x312808b, fixp_error1 info: 0xa5, fsmId:0, tslot:4, thread:0, ctxid:0, blk:0, sublk:0, subErrType:4.[FUNC:PrintCoreInfo][FILE:device_error_core_proc.cc][LINE:658]
       Kernel task happen error, retCode=0x31, [vector core exception].[FUNC:PreCheckTaskErr][FILE:davinci_kernel_task.cc][LINE:1729]
       AIV Kernel happen error, retCode=0x31.[FUNC:GetError][FILE:stream.cc][LINE:1475]
       [AIC_INFO] after execute:args print end[FUNC:GetError][FILE:stream.cc][LINE:1475]
       [DFX_INFO]Aicore kernel execute failed, device_id=4, stream_id=46, report_stream_id=46, task_id=0, flip_num=0, fault kernel_name=_Z30tprefetch_async_binding_kernelPfPa, fault kernel info ext=_Z30tprefetch_async_binding_kernelPfPa, program id=0, hash=8435686547367685641.[FUNC:GetError][FILE:stream.cc][LINE:1475]
       rtStreamSynchronize execution failed, reason=vector core exception[FUNC:FuncErrorReason][FILE:error_message_manage.cc][LINE:65]
       synchronize stream failed, runtime result = 507035[FUNC:ReportCallError][FILE:log_inner.cpp][LINE:148]
[2026-05-28 12:56:27] ERROR: testcase failed (exit 1): tprefetch_async_binding

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