Skip to content

Add: benchmark BGEMM on host build graph - #1771

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
doraemonmj:add/hbg-benchmark-bgemm
Aug 11, 2026
Merged

Add: benchmark BGEMM on host build graph#1771
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
doraemonmj:add/hbg-benchmark-bgemm

Conversation

@doraemonmj

Copy link
Copy Markdown
Contributor

Summary

  • Add the host_build_graph counterpart of benchmark_bgemm::Case0.
  • Keep the original parameters, callable signatures, tolerances, and golden
    implementation unchanged.
  • Reference the existing TMR orchestration and incore kernel sources directly,
    so both runtimes exercise the same 500-GEMM + 500-ADD compute graph without
    duplicating kernel code.
  • Keep C as INOUT because it is a zero-initialized read-before-write
    accumulator across grid_k iterations.

This is one workload-sized part of #1727. The remaining workloads and the
benchmark tooling/skill changes are intentionally left for separate PRs.

Performance methodology

Measured on a2a3 hardware through task-submit, using one locked NPU 7 at
simpler base revision 0fc77f21:

  • 8 adjacent TMR/HBG batch pairs
  • alternating order (TMR -> HBG, then HBG -> TMR)
  • 10 rounds per process
  • first round of each process excluded
  • 72 steady-state samples per runtime
Metric TMR mean / P50 / P95 HBG mean / P50 / P95 Mean change
Host total 15.007 / 14.537 / 18.618 ms 24.553 / 23.085 / 33.972 ms +63.61%
Bind 9.528 / 9.100 / 13.085 ms 17.115 / 15.601 / 25.857 ms +79.63%
Runner 1.718 / 1.724 / 1.950 ms 1.531 / 1.516 / 1.743 ms -10.90%
Validate 2.944 / 2.945 / 3.051 ms 5.079 / 4.957 / 5.987 ms +72.53%
Device wall 1.022 / 0.983 / 1.291 ms 0.813 / 0.811 / 0.935 ms -20.44%

Paired-batch geometric changes (95% confidence interval):

  • Device wall: -20.37% (-23.53% to -17.07%). All 8 pairs were
    faster with HBG; individual improvements were 12.43%-24.53%.
  • Host total: +62.36% (+42.28% to +85.26%). All 8 pairs were
    slower with HBG; the median paired increase was 58.84%.
  • Runner: -10.96% (-14.87% to -6.88%).
  • Validate: +72.19% (+61.84% to +83.20%).

The mean host-total delta is +9.545 ms. Its phase attribution is:

  • bind: +7.587 ms
  • validate: +2.135 ms
  • runner: -0.187 ms
  • unclassified remainder: approximately +0.011 ms

An HBG info-level attribution run (kept separate because logging perturbs the
benchmark) measured args_malloc_copy at 8.8 ms and
prebuilt_runtime_arena at 6.3 ms, with total_init_runtime_impl at 15.2 ms.
For comparison, steady TMR bind.prebuilt was about 0.005 ms. The HBG
prebuilt-runtime arena explains most of the bind increase.

Therefore this migration shows no device-side regression: HBG device wall is
consistently about 20% faster for Case0. Steady host latency is higher, mainly
from bind/runtime-arena preparation and validation. The workload keeps the
same graph instead of masking that runtime cost; future #1727 benchmark tooling
should report host total and device wall as separate guard metrics.

Performance job: task_20260810_192420_238922620377 (NPU 7, exit 0).

Testing

  • Simulation:
    python test_benchmark_bgemm.py -p a2a3sim
  • Onboard golden validation through task-submit on NPU 4:
    task_20260810_191738_183514219385 (exit 0)
  • Hardware performance comparison through task-submit on NPU 7:
    task_20260810_192420_238922620377 (exit 0)
  • All pre-commit hooks for the changed files

Port Case0 with the same parameters, signatures, and golden as the tensormap-and-ringbuffer benchmark. Reuse the existing orchestration and incore kernel sources directly so both runtimes exercise an identical compute graph.
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Added a host-build-graph BGEMM benchmark for A2A3. The test generates tensor inputs, computes a golden result across grid_k, and runs through SceneTestCase. Documentation and an orchestration comment were also updated.

Changes

Host-build-graph BGEMM benchmark

Layer / File(s) Summary
Benchmark definition and execution
examples/a2a3/host_build_graph/benchmark_bgemm/test_benchmark_bgemm.py, examples/a2a3/host_build_graph/benchmark_bgemm/README.md, examples/a2a3/tensormap_and_ringbuffer/benchmark_bgemm/kernels/orchestration/bgemm_orch.cpp
Adds the A2A3 test configuration, randomized flattened inputs, zeroed output storage, runtime arguments, grid_k golden computation, and module entry point. Documents simulation and hardware commands. Simplifies the orchestration comment.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related issues

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant TestBenchmarkBgemmHostBuildGraph
  participant SceneTestCase
  participant BGEMMOrchestration
  participant InCoreGemmAddKernels
  TestBenchmarkBgemmHostBuildGraph->>SceneTestCase: run_module
  SceneTestCase->>BGEMMOrchestration: execute orchestration metadata
  BGEMMOrchestration->>InCoreGemmAddKernels: process GEMM and ADD operations
  TestBenchmarkBgemmHostBuildGraph->>TestBenchmarkBgemmHostBuildGraph: compute golden output across grid_k
Loading

Poem

A rabbit hops through graphs of green,
With BGEMM sums in rows unseen.
A, B, and C align just right,
grid_k gathers each slice in flight.
The host now builds the path with care.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of the BGEMM benchmark for the host build graph.
Description check ✅ Passed The description directly explains the host build graph benchmark, source reuse, performance results, and testing performed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
examples/a2a3/host_build_graph/benchmark_bgemm/test_benchmark_bgemm.py (1)

25-59: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Declare benchmark configuration as class-level state.

Ruff reports RUF012 because CALLABLE and CASES are mutable class attributes. Add ClassVar annotations to declare that these are shared SceneTestCase definitions. Use a targeted suppression only if the framework requires these attributes to be instance-mutable.

Proposed fix
+from typing import ClassVar
+
 ...
-    CALLABLE = {
+    CALLABLE: ClassVar = {
 ...
-    CASES = [
+    CASES: ClassVar = [
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/a2a3/host_build_graph/benchmark_bgemm/test_benchmark_bgemm.py`
around lines 25 - 59, Annotate the mutable CALLABLE and CASES class attributes
with ClassVar, preserving their existing SceneTestCase definitions and values.
Add a targeted suppression only if the framework requires instance mutation of
either attribute.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@examples/a2a3/host_build_graph/benchmark_bgemm/test_benchmark_bgemm.py`:
- Around line 25-59: Annotate the mutable CALLABLE and CASES class attributes
with ClassVar, preserving their existing SceneTestCase definitions and values.
Add a targeted suppression only if the framework requires instance mutation of
either attribute.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e2e8eb3-e455-4ce9-977b-9314b568a5c9

📥 Commits

Reviewing files that changed from the base of the PR and between 0fc77f2 and 2b76511.

📒 Files selected for processing (3)
  • examples/a2a3/host_build_graph/benchmark_bgemm/README.md
  • examples/a2a3/host_build_graph/benchmark_bgemm/test_benchmark_bgemm.py
  • examples/a2a3/tensormap_and_ringbuffer/benchmark_bgemm/kernels/orchestration/bgemm_orch.cpp

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