Skip to content

[WIP] Tile-native pointer_cast and PlanMemory rewiring (memref bridge removal phase)#348

Open
TaoTao-real wants to merge 2 commits intohw-native-sys:mainfrom
TaoTao-real:codex/tilebuf-replace-memref-pm-v1
Open

[WIP] Tile-native pointer_cast and PlanMemory rewiring (memref bridge removal phase)#348
TaoTao-real wants to merge 2 commits intohw-native-sys:mainfrom
TaoTao-real:codex/tilebuf-replace-memref-pm-v1

Conversation

@TaoTao-real
Copy link
Copy Markdown
Contributor

Summary

This WIP PR advances the memref->tilebuf migration on the clean branch by making the address-binding path tile-native.

What changed

  • pto.pointer_cast result type switched from memref to !pto.tile_buf.
  • Main pipeline no longer runs PTOViewToMemref in tools/ptoas/ptoas.cpp.
  • PlanMemory rewrite switched from memref.alloc -> pointer_cast to alloc_tile -> pointer_cast.
  • Added tile-native semantic extraction module:
    • lib/PTO/Transforms/TileBufferSemantics.h
    • lib/PTO/Transforms/TileBufferSemantics.cpp
  • Updated Sync translator pointer-cast memory info to consume tilebuf result types.
  • EmitC path updated:
    • alloc_tile -> pointer_cast pre-lowering
    • pointer_cast conversion consumes tilebuf result descriptors
    • view-like WIP bridging: subset/bitcast/treshape -> pointer_cast (currently zero-offset subset only)
  • Added/updated tests and samples for tilebuf + PlanMemory path.

Why

The current architecture goal is full-chain tilebuf semantics, avoiding memref as the central storage descriptor in PlanMemory and downstream lowering. This PR is the first WIP step that makes pointer binding and memory planning tile-native.

Tests run

  • Build:
    • ninja -C build ptoas
  • Basic coverage:
    • test/basic/tilebuf_semantic_smoke.pto
    • test/basic/tilebuf_root_trace.pto
    • test/basic/tilebuf_manual_addr_preserve.pto
    • test/basic/tilebuf_auto_addr_assign.pto
    • test/basic/set_validshape_local_lowering.pto
  • Sample regression subset:
    • test/samples/runop.sh -t planmemory

Known limitations (WIP)

  • subset->pointer_cast bridging currently supports only zero-offset subset.
  • Legacy memref-specific scenarios relying on old bridge behavior are not fully ported in this PR.
  • Sync/multibuffer full migration is intentionally out of scope for this phase.

Follow-ups

  • Complete non-zero-offset subset address rebasing for tile-native view lowering.
  • Remove remaining memref compatibility fallbacks in PlanMemory/EmitC.
  • Sync pipeline full tile-native migration.

@TaoTao-real
Copy link
Copy Markdown
Contributor Author

本次已推送提交:57a8883(Phase-2: PlanMemory 纯 TileBuf 核心收敛)

变更摘要

  1. PlanMemory 本地分配入口收敛为 tilebuf-only
  • 在 liveness/def-op 识别中,仅将 pto.alloc_tile 作为本地可分配定义点。
  • 本地 memref.alloc 在 PlanMemory 中直接报错并拒绝。
  1. 移除 BufferInfo 的 memref sizing fallback
  • UpdateOpBufferInfo / GenerateBufferInfo / GetBufferInfo 改为 LogicalResult 失败传播。
  • GetBufferInfo 只接受 TileBufferSemantics 作为输入语义源,不再回退 tracebackMemRef
  1. manual reserve_buffer 契约改为 tile 语义一致
  • reserve_buffer auto=false 下:
    • 本地 alloc_tile 若无 addr,直接拒绝。
    • 本地 memref.alloc 直接拒绝(tilebuf-only 诊断)。
  1. 语义层诊断加固
  • inferTileBufferSemantics 增加 failure reason 输出(scope/type/shape/bits 路径)。
  • PlanMemory 失败时在主错误信息中附带 reason,便于快速定位。
  1. 失败路径稳定性修复
  • MemLivenessAnalysis::build 改为返回 LogicalResult,失败时由 pass signalPassFailure() 返回,
    不再依赖 llvm_unreachable 异常终止。
  1. 调试输出去 memref 假设
  • MemLifeDebugInfo/ReportCurEntryDebugInfo 改为通用 value 打印,避免 memref::AllocOp 假设。

测试

已在本地通过:

  • 正向回归:
    • test/basic/tilebuf_semantic_smoke.pto
    • test/basic/tilebuf_root_trace.pto
    • test/basic/tilebuf_auto_addr_assign.pto
    • test/basic/tilebuf_manual_addr_preserve.pto
  • 新增/负向:
    • test/basic/planmemory_reject_local_memref_alloc.pto(新增)
    • test/basic/planmemory_manual_reserve_reject_unplanned_tile_alloc.pto(新增)
    • test/basic/planmemory_semantics_infer_fail_diag.pto(新增)
    • test/basic/plan_memory_reserve_buffer_manual_reject_nested_alloc.pto(文案更新)
  • 样例门禁:
    • test/samples/runop.sh -t planmemory 全绿。

如果 reviewer 同意,这个提交可以作为 Phase-2 PR-1 的核心收敛基线。

@TaoTao-real
Copy link
Copy Markdown
Contributor Author

/run A3

@reedhecre
Copy link
Copy Markdown

A3 板测失败

日志尾部

ipe_barrier.pto) FAIL ptoas failed: test_inject_sync_intra_pipe_barrier.pto
Sync(test_inject_sync_intra_pipe_barrier.py) OK   generated: test_inject_sync_intra_pipe_barrier-pto.cpp
Sync(test_inject_sync_loop_nest.py) FAIL ptoas failed: test_inject_sync_loop_nest-pto-ir.pto
Sync(test_inject_sync_loop.py) FAIL ptoas failed: test_inject_sync_loop-pto-ir.pto
Sync(test_inject_sync_two_event_id.py) FAIL ptoas failed: test_inject_sync_two_event_id-pto-ir.pto
Sync(test_intercore_sync_a3_missing_setffts.py) XFAIL ptoas failed as expected
Sync(test_intercore_sync_a3.py) OK   generated: test_intercore_sync_a3-pto.cpp
Sync(test_intercore_sync_a5.py) SKIP requires --pto-arch=a5
Sync(test_mem_inject_sync_basic.py) FAIL ptoas failed: test_mem_inject_sync_basic-pto-ir.pto
Sync(test_set_wait_unified_api.py) OK   generated: test_set_wait_unified_api-pto.cpp
Sync(tmatmulk_autosync.py) FAIL ptoas failed: tmatmulk_autosync-pto-ir.pto
TileScalar(tileScalar.py) FAIL ptoas failed: tileScalar-pto-ir.pto
TileSetGetValue(tile_getval_mat_invalid.py) XFAIL python failed as expected
TileSetGetValue(tileSetGetValue.py) FAIL ptoas failed: tileSetGetValue-pto-ir.pto
TInsert(tinsert.py) FAIL ptoas failed: tinsert-pto-ir.pto
Trans(trans.py) FAIL ptoas failed: trans-pto-ir.pto
Trap(trap.py) OK   generated: trap-pto.cpp
VectorAddition(vadd_pto_ir.py) FAIL ptoas failed: vadd_pto_ir-pto-ir.pto
VectorAddition(vadd_validshape_hyper.py) FAIL ptoas failed: vadd_validshape_hyper-pto-ir.pto
VectorAddition(vectorAddition.py) FAIL ptoas failed: vectorAddition-pto-ir.pto
Xors(xors.py) FAIL ptoas failed: xors-pto-ir.pto
Xor(xor.py)  FAIL ptoas failed: xor-pto-ir.pto
-----------------------------
OK=25  FAIL=152  SKIP=2
=============================
===== END STAGE sample-build-and-test rc=1 @ 2026-03-31 10:52:28 =====

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants