Skip to content

perf(vmi): optimize carrier-preserving integer casts - #1077

Merged
mouliangyu merged 2 commits into
mainfrom
codex/optimize-integer-cast-layouts
Aug 3, 2026
Merged

perf(vmi): optimize carrier-preserving integer casts#1077
mouliangyu merged 2 commits into
mainfrom
codex/optimize-integer-cast-layouts

Conversation

@mouliangyu

@mouliangyu mouliangyu commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

背景

部分整数 cast 只改变逻辑元素解释,不需要执行实际的 vcvt

  • NOSAT narrowing 的 contiguous -> lane_stride=2/4 可以直接复用物理 carrier。
  • 当 unsigned widening 的输入已经是 lane_stride=2/4,且 carrier gap 中的高位已知为 0 时,vcvt EVEN/P0 也是冗余的。

仅凭 lane-stride layout 不能推断 gap 为 0,因此 widening 优化采用保守且单一的准入规则:只接受由 canonical zero-filling producer 构造的 carrier,不追踪普通计算的数据流。

修改

  • u16/u32 -> u8/u16 的 NOSAT 2x/4x narrowing 直接复用或 bitcast source carrier;SAT narrowing 继续生成 vcvt
  • VMI lowering 对 dense lane-stride narrowing 只分类一次,再按 NOSAT carrier forwarding 或 SAT vcvt emission 选择策略。
  • VPTOOptimizeVcvt 由独立的 part 规范化与 zero-gap extension folding patterns 组成,通过 greedy rewrite driver 执行;cast 形状匹配与 producer provenance 分层处理。
  • 新增 VPTOOptimizeVcvt pass,识别以下 unsigned zero-gap widening:
    • u8 lane_stride=2 -> u16 contiguous
    • u16 lane_stride=2 -> u32 contiguous
    • u8 lane_stride=4 -> u32 contiguous
  • widening 消除统一通过 isCanonicalZeroGapCarrier 准入,只接受:
    • vlds UNPK_B8/UNPK_B16/UNPK4
    • vzunpack
    • 对齐的真实 narrowing vcvt(2x 使用 EVEN,4x 使用 P0
  • 普通算术、常量、广播和其他未知来源不参与 provenance 推导,即使某组特定输入可能恰好保持 zero gap。
  • 要求全 mask、无 rnd/sat,并要求 2x widening 使用 EVEN、4x widening 使用 P0
  • unknown-gap 输入、signed extension、非全 mask 和错误 part 均保留 vcvt
  • 保持现有 layout assignment 的 lane_stride -> contiguous cast 关系,使一物理 chunk 的 load-extension-store 能自然选择 zero-fill unpack load。

测试

  • 新增 surface VMI 端到端 lit,确认三种 widening 分别生成 UNPK_B8UNPK_B16UNPK4 load,且不含 vcvt/vzunpack
  • 新增 VPTO provenance 正负向测试,覆盖 unpack load、vzunpack 链、真实 narrowing vcvt、unknown gap、signed、mask 和 part 条件。
  • narrowing vcvt 正向覆盖 u16 -> u8 -> u16u32 -> u8 -> u32;错误的 ODD part 不建立 aligned zero gap。
  • integer cast SIM runtime 覆盖 unsigned/signed 8/16/32-bit extension、SAT/NOSAT narrowing,以及三种 zero-gap widening。

验证

  • cmake --build build --target PTOASPythonCore pto-test-opt -j4
  • llvm-lit -sv -j 32 build/test/lit/vmi_new:446/446 passed
  • focused integer-cast/VPTO lit:9/9 passed
  • dav_3510 simulator:7 个 kernel、23 个 buffer 与 golden 精确一致
  • 最新 focused lit:vpto_optimize_vcvtvmi_zero_gap_extui_loadvmi_lane_stride_dense_load_store,3/3 passed
  • git diff --check

Relates to #1024.

@mouliangyu mouliangyu changed the title perf(vmi): optimize dense integer cast layouts perf(vmi): optimize same-layout integer casts Aug 3, 2026
@mouliangyu
mouliangyu force-pushed the codex/optimize-integer-cast-layouts branch from 2007527 to 388b787 Compare August 3, 2026 05:23
@mouliangyu mouliangyu changed the title perf(vmi): optimize same-layout integer casts perf(vmi): optimize carrier-preserving integer casts Aug 3, 2026
@mouliangyu
mouliangyu force-pushed the codex/optimize-integer-cast-layouts branch from c378bd5 to 6546355 Compare August 3, 2026 12:30
@mouliangyu
mouliangyu merged commit a79b90d into main Aug 3, 2026
10 checks passed
@reedhecre

Copy link
Copy Markdown

A5 板测成功

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

@reedhecre

Copy link
Copy Markdown

A3 板测失败

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

失败用例

  • comm_p2p_binding_variants (run, exit=1)
  • comm_p2p (run, exit=1)

@reedhecre

Copy link
Copy Markdown

A3 板测失败详情:PR #1077

comm_p2p_binding_variants

stage=run info=exit=1

[ERROR] aclrtSynchronizeStream(stream) failed: 507035 (/home/zhongxuan/ptoas-board-monitor/runtime/runs/20260803_071139_merged_pr1077/npu_validation/CommSync/comm_p2p_binding_variants/main.cpp:122)
[ERROR] RecentErrMsg: EZ9999: Inner Error!
EZ9999[PID: 3580661] 2026-08-03-07:45:38.861.135 (EZ9999):  The error from device(chipId:0, dieId:1), serial number is 2537, there is an exception of aivec error, core id is 11, error code = 0x10, dump info: pc start: 0x124200000000, current: 0x124200000164, vec error info: 0x4000000b7, mte error info: 0x6000099, ifu error info: 0x212c0d6200800, ccu error info: 0x40e008000000004f, 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:(0x10, 0, 0) errorStr: Illegal instruction, which is usually caused by unaligned UUB addresses. fixp_error0 info: 0x6000099, fixp_error1 info: 0, fsmId:1, tslot:6, 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=1, stream_id=46, report_stream_id=46, task_id=0, flip_num=0, fault kernel_name=comm_p2p_binding_variants_kernel, fault kernel info ext=comm_p2p_binding_variants_kernel, program id=0, hash=16541545288638093324.[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-08-03 07:45:41] ERROR: testcase failed (exit 1): comm_p2p_binding_variants
comm_p2p

stage=run info=exit=1

[ERROR] aclrtSynchronizeStream(stream) failed: 507035 (/home/zhongxuan/ptoas-board-monitor/runtime/runs/20260803_071139_merged_pr1077/npu_validation/CommSync/comm_p2p/main.cpp:122)
[ERROR] RecentErrMsg: EZ9999: Inner Error!
EZ9999[PID: 3596433] 2026-08-03-07:45:59.301.908 (EZ9999):  The error from device(chipId:0, dieId:1), serial number is 2538, there is an exception of aivec error, core id is 16, error code = 0x10, dump info: pc start: 0x124200000000, current: 0x124200000168, vec error info: 0xdf00005f59, mte error info: 0xfd060000d3, ifu error info: 0x20000ffa63dc0, ccu error info: 0x40e008000000004f, 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:(0x10, 0, 0) errorStr: Illegal instruction, which is usually caused by unaligned UUB addresses. fixp_error0 info: 0x60000d3, fixp_error1 info: 0xfd, fsmId:1, tslot:6, 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=1, stream_id=46, report_stream_id=46, task_id=0, flip_num=0, fault kernel_name=comm_p2p_kernel, fault kernel info ext=comm_p2p_kernel, program id=0, hash=6260346515940177617.[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-08-03 07:46:00] ERROR: testcase failed (exit 1): comm_p2p

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.

2 participants