Skip to content

Add: [2B] declare HBG kernel resource capacity - #2172

Draft
TaoZQY wants to merge 1 commit into
hw-native-sys:mainfrom
TaoZQY:codex/hbg-pr-2b
Draft

Add: [2B] declare HBG kernel resource capacity#2172
TaoZQY wants to merge 1 commit into
hw-native-sys:mainfrom
TaoZQY:codex/hbg-pr-2b

Conversation

@TaoZQY

@TaoZQY TaoZQY commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

The HBG kernel path needs graph-dependent capacity before a context can allocate and freeze its execution slot. This revision rebases 2B on the current K1 lifecycle, the shared 2A contract, and the revised H1 Host-build boundary, then derives resource requirements directly from the completed GraphBuild.

What changed

  • GraphResourceRequirements records H1's measured GM heap, compact runtime image, Graph Definition block, and the A5 scheduler upper bound. The query performs no device allocation, address binding, or H2D, and leaves its output unchanged on failure.
  • RuntimeLayoutKey makes compatibility explicit across architecture, layout ABI, task capacity, and copied-arena boundaries. Equal byte totals cannot make incompatible A2/A3, A5, or task-window layouts share a slot.
  • GraphCapacityPlan takes the maximum of each independent region, then rebuilds one aligned runtime-slot layout. It does not treat the largest prepacked total as sufficient and does not represent committed HBM.
  • HBG-specific capacity and three-stream admission live under src/common/host_build_graph/; generic worker validation remains aligned with 2A. Only architecture-specific requirement generation stays in the A2/A3 and A5 runtime_maker.cpp files.
  • The kernel contract declares per-run GM heap and runtime-slot content plus a dedicated non-hidden AICPU stream and hidden AICore stream. bind_kernel_streams requires those two streams and the borrowed caller stream to be non-null and pairwise distinct.
  • Program mode continues through upload_for_program_mode. Kernel launch must consume a slot allocated and frozen during context prepare; this PR does not add launch-time allocation, blob transport, or restore fallback.

The resulting flow is: H1 Host build and validation → read-only requirements snapshot → combine all allowed workload snapshots into one capacity plan → a later context-prepare stage allocates/fixes the slot → each eager/captured invocation restores its own H2 blob into that slot and executes. ACLGraph replay reuses the captured blob and never repeats Host build.

Validation

  • Repository pre-commit suite passed, including clang-format, clang-tidy, cpplint, markdownlint, ruff, and pyright.
  • Runtime binaries rebuilt successfully for the available variants.
  • C++ unit suite: 147/147 executables passed, including both HBG architecture suites and pipeline-contract loader coverage.
  • Python K1/2A/H1 ABI and worker tests: 193 passed, 4 skipped.
  • A2/A3 HBG simulation: 20 passed, 7 skipped.
  • A5 HBG simulation: 21 passed.
  • A2/A3 onboard HBG runtime: 46 passed, 1 skipped through task-submit on an architecture-verified device.
  • A5 onboard was not run locally because the precheck identified this host as A2/A3; A5 behavior was covered by its C++ and simulator suites.

Dependency and review scope

Draft 2B. The PR still targets main and contains exactly one cumulative commit so it remains buildable while prerequisites are open. That commit carries the current K1 implementation from #2064, the current shared 2A contract from #2177, the revised H1 from #2171, and this HBG 2B layer. Their human authors are retained as co-authors.

Review the 2B-specific files first:

  • src/common/host_build_graph/kernel_resource_plan.h
  • src/common/host_build_graph/kernel_pipeline_contract.h
  • simpler::hbg::get_graph_resource_requirements in both HBG runtime makers
  • the kernel-requirement cases in tests/ut/cpp/common/test_hbg_host_graph_build.cpp

Actual stable-slot ownership, H2 blob serialization/transport, per-replay restore, and launch-time capacity enforcement remain in their later stages; 2B only supplies the complete declaration and admission inputs they must consume.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

@TaoZQY TaoZQY changed the title Add: declare HBG kernel resource requirements and stream contracts Add: [2B] declare HBG resource and stream contracts Sep 10, 2026
@TaoZQY TaoZQY changed the title Add: [2B] declare HBG resource and stream contracts Add: [2B] declare HBG kernel resource capacity Sep 11, 2026
Rebase the HBG declaration work on the current K1, shared 2A contract, and revised H1 host-build boundary. Derive graph requirements from H1 measurements without device side effects, reject incompatible runtime layouts, and repack per-region maxima into one aligned context-slot capacity.

Keep HBG-specific capacity and stream admission under common/host_build_graph while leaving architecture-only sizing in each runtime maker. Declare the dedicated non-hidden AICPU stream and hidden AICore stream as distinct from the borrowed caller stream.

Co-authored-by: sunkaixuan2018 <baiyi@mail.ustc.edu.cn>

Co-authored-by: Leaf-Salix <2503954024@qq.com>
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