Skip to content

Fix: 修正单元素维 stride 的连续性判定 - #2146

Open
nalinaly wants to merge 1 commit into
hw-native-sys:mainfrom
nalinaly:fix/singleton-stride-contiguity
Open

Fix: 修正单元素维 stride 的连续性判定#2146
nalinaly wants to merge 1 commit into
hw-native-sys:mainfrom
nalinaly:fix/singleton-stride-contiguity

Conversation

@nalinaly

@nalinaly nalinaly commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

shape=(64, 1)、stride=(1, 64) 是合法连续列向量,但上游将
单元素维的 stride 与行主序期望值比较,导致 ChipTensor 及
HBG/TMR Tensor 误判为不连续,零拷贝 reshape 随之触发断言。

  • 公共 ChipTensor 和 HBG/TMR 派生缓存统一忽略 size=1 维的 stride;其他维度继续严格检查,保持存储跨度与 ABI 不变。
  • HBG 图元数据校验使用相同规则,继续拒绝伪造连续标志、 跨步存储的错误标志及错误 extent,避免合法图记录被拒绝。
  • 增加 10 项 C++ 回归,覆盖外部参数转换、转置列向量、 零拷贝 reshape、真实空隙拒绝及图元数据校验;更新 ABI 文档。

上游验证:

  • PyPTO 747e1e4 固定 runtime 4e4d3a4 与 simpler 主线 d79c88c 均能复现:新增 10 项用例中 6 项失败、4 项通过。
  • 修复后新增 10 项全部通过;同时运行既有 buffer 和 child_memory 的 23 项用例,总计 33 项通过。
  • 使用当前独立工作树重新编译 CPU C++ 测试,无需 NPU。 本分支未执行 A5 真机、Python 套件或完整系统回归。

这是 0b852b1 修复语义在上游重构后的 Tensor 架构上的适配。
分支直接基于上游主线,不包含 fork 中其他 A5 L1 功能修改。

shape=(64, 1)、stride=(1, 64) 是合法连续列向量,但上游将
单元素维的 stride 与行主序期望值比较,导致 ChipTensor 及
HBG/TMR Tensor 误判为不连续,零拷贝 reshape 随之触发断言。

- 公共 ChipTensor 和 HBG/TMR 派生缓存统一忽略 size=1 维的
  stride;其他维度继续严格检查,保持存储跨度与 ABI 不变。
- HBG 图元数据校验使用相同规则,继续拒绝伪造连续标志、
  跨步存储的错误标志及错误 extent,避免合法图记录被拒绝。
- 增加 10 项 C++ 回归,覆盖外部参数转换、转置列向量、
  零拷贝 reshape、真实空隙拒绝及图元数据校验;更新 ABI 文档。

上游验证:
- PyPTO 747e1e4 固定 runtime 4e4d3a4 与 simpler 主线 d79c88c
  均能复现:新增 10 项用例中 6 项失败、4 项通过。
- 修复后新增 10 项全部通过;同时运行既有 buffer 和
  child_memory 的 23 项用例,总计 33 项通过。
- 使用当前独立工作树重新编译 CPU C++ 测试,无需 NPU。
  本分支未执行 A5 真机、Python 套件或完整系统回归。

这是 0b852b1 修复语义在上游重构后的 Tensor 架构上的适配。
分支直接基于上游主线,不包含 fork 中其他 A5 L1 功能修改。
@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: af5c36b6-b3ef-4c17-9f11-088513f320ea

📥 Commits

Reviewing files that changed from the base of the PR and between d79c88c and 247689f.

📒 Files selected for processing (8)
  • docs/buffer-abi.md
  • src/common/host_build_graph/graph_execution.h
  • src/common/host_build_graph/tensor.h
  • src/common/task_interface/tensor.h
  • src/common/tensormap_and_ringbuffer/tensor.h
  • tests/ut/cpp/CMakeLists.txt
  • tests/ut/cpp/types/test_tensor_contiguity.cpp
  • tests/ut/cpp/types/test_tmr_tensor_contiguity.cpp

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change aligns tensor contiguity checks across runtime types and graph validation. Singleton dimensions no longer constrain strides. New tests cover storage extent, zero-copy reshape, wire validation, and rejection of gapped storage.

Changes

Contiguity rule alignment

Layer / File(s) Summary
Runtime contiguity semantics
docs/buffer-abi.md, src/common/host_build_graph/tensor.h, src/common/task_interface/tensor.h, src/common/tensormap_and_ringbuffer/tensor.h
Contiguity checks now ignore strides for dimensions of size one. Non-singleton dimensions still require row-major strides. Documentation and cached-field comments describe the updated rule.
Graph validation and test coverage
src/common/host_build_graph/graph_execution.h, tests/ut/cpp/CMakeLists.txt, tests/ut/cpp/types/test_*contiguity.cpp
Graph wire validation accepts valid singleton strides and rejects forged flags or invalid extents. Tests cover runtime metadata, zero-copy reshaping, transposed singleton dimensions, and gapped storage.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 24768

Singleton-stride tensor views now use the intended contiguity semantics without changing storage layout or ABI. Covered runtime, reshape, extent, and graph-validation cases show no remaining merge-blocking risk.

Poem

A rabbit checks each stride in line
Singleton gaps are now benign
The graph accepts the matching view
Zero-copy paths stay true
Gapped storage still says “not you”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 6 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the singleton-dimension stride fix, affected tensor layers, validation rules, regression tests, and verification scope. It is directly related to the changeset.
Title check ✅ Passed The title concisely identifies the fix for contiguity判定 of singleton-dimension strides. It accurately summarizes the main change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 6 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant