Skip to content

Fix layout inference for column-vector tensor views#191

Merged
zhangstevenunity merged 2 commits into
hw-native-sys:mainfrom
TaoTao-real:codex/fix-190-layout-inference
Mar 4, 2026
Merged

Fix layout inference for column-vector tensor views#191
zhangstevenunity merged 2 commits into
hw-native-sys:mainfrom
TaoTao-real:codex/fix-190-layout-inference

Conversation

@TaoTao-real
Copy link
Copy Markdown
Contributor

Fixes #190.

What was wrong

For some 2D tensor views (e.g. shape (16 x 1) with contiguous strides (1, 1)), the emitted GlobalTensor<...> layout parameter could be inferred as ND even though the expected layout is DN (column-vector).

What this PR changes

  • Infer layout using a 5D right-aligned shape/stride view (pads leading dims with 1) to match the GlobalTensor ABI.
  • Add a vector-friendly rule: when minor dims are ambiguous (e.g. one dim is 1), prefer:
    • DN for (rows x 1)
    • ND for (1 x cols)
  • EmitC lowering now prefers the layout attribute inferred/propagated in IR, instead of re-inferring layout in multiple places.
  • Enable the layout inference pass by default (can still be disabled via --disable-infer-layout).

Tests

  • Added a regression sample test/samples/Layout/tensor_view_infer_layout_dn.py + guard in test/samples/runop.sh.

Make the explicit-DN layout sample use a DN-consistent stride pattern so InferPTOLayout verification passes when enabled by default.
@zhangstevenunity zhangstevenunity merged commit 08e0a2c into hw-native-sys:main Mar 4, 2026
9 checks passed
KurrinQu pushed a commit to KurrinQu/PTOAS that referenced this pull request Apr 25, 2026
KurrinQu pushed a commit to KurrinQu/PTOAS that referenced this pull request Apr 28, 2026
Zhendong404 pushed a commit to Zhendong404/PTOAS that referenced this pull request May 1, 2026
FangRui0 pushed a commit to FangRui0/PTOAS that referenced this pull request May 14, 2026
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.

[Bug] The correct layout can't be deduced and generated as expected

2 participants