Skip to content

Fix: initialize DSv4 decode buffers on device instead of the orchestrator - #1899

Merged
ChaoWao merged 1 commit into
hw-native-sys:perf/hbg-orchfrom
lwDavid:fix/dsv4-device-side-init
Aug 20, 2026
Merged

ChaoWao merged 1 commit into
hw-native-sys:perf/hbg-orchfrom
lwDavid:fix/dsv4-device-side-init

Conversation

@lwDavid

@lwDavid lwDavid commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What

Replaces the six orchestration-side set_initial_value(0) calls in the DeepSeek-V4 FLASH decode cases with device-side initialization, so the TMR and HBG orchestrations are now identical here and the host never writes a GM-heap device address (previously a segfault under HBG, worked around by dropping the calls and leaving mixes_raw undefined).

  • h_tile_i8 padding rows: each of the five sh_gate_up_act_q* AIV kernels now clears the two padded rows owned by its logical block (zero_h_tile_i8_padding) before producing its output.
  • mixes_raw split-K destination: a new hc_head_mixes_zero AIV kernel (func_id 367) clears one up-to-16-row chunk per logical block; an explicit task dependency orders every hc_head_linear AtomicAdd store after the seed task. All three orchestrations (decode_fwd.cpp, decode_fwd_hostbuild.cpp, decode_fwd_graph.cpp) submit it in place of the plain alloc_tensors + set_initial_value.

This closes the "AtomicAdd destinations cannot currently be initialized correctly by HBG" runtime gap recorded in the HBG README.

Both full-network cases remain manual (368-kernel compile); READMEs and docstrings are updated for the new kernel count and status.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4cf5b2dc-fb2f-493c-a0b0-321c6a60e86c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@lwDavid lwDavid self-assigned this Aug 19, 2026
@lwDavid lwDavid added the enhancement New feature or request label Aug 19, 2026
@lwDavid lwDavid added the code health Technical debt, robustness, code quality label Aug 19, 2026
@lwDavid lwDavid moved this to Done in pto project Aug 19, 2026
@lwDavid
lwDavid force-pushed the fix/dsv4-device-side-init branch 2 times, most recently from f34cfeb to 2b8a0f0 Compare August 19, 2026 09:31
…ator

Replace the six orchestration-side set_initial_value(0) calls in the
DeepSeek-V4 FLASH decode cases with device-side initialization, making
the TMR and HBG orchestrations identical here and removing the last
host write to a GM-heap device address (which segfaulted under HBG):

- Each sh_gate_up_act_q* producer now clears the two padded h_tile_i8
  rows owned by its logical block before producing its output.
- A new hc_head_mixes_zero AIV kernel (func_id 367) seeds the dynamic
  mixes_raw split-K destination; an explicit task dependency orders
  every hc_head_linear AtomicAdd store after it.
- decode_fwd.cpp, decode_fwd_hostbuild.cpp and decode_fwd_graph.cpp
  submit the seed task in place of the plain alloc + set_initial_value.

Update both READMEs and test docstrings for the new kernel count (368)
and the now-closed "AtomicAdd destinations cannot be initialized under
HBG" runtime gap.
@ChaoWao
ChaoWao merged commit 9db53fb into hw-native-sys:perf/hbg-orch Aug 20, 2026
3 checks passed
ChaoZheng109 added a commit that referenced this pull request Aug 20, 2026
…r to valid rows (#1922)

* Fix: initialize DSv4 decode buffers on device instead of the orchestrator

Replace the six orchestration-side `set_initial_value(0)` calls in the
DeepSeek-V4 FLASH decode cases with device-side initialization, so the TMR
and HBG orchestrations are identical here and the host never writes a GM-heap
device address. Under HBG that write segfaults the chip subprocess, which is
why the calls were simply dropped when the case landed on main — leaving the
`mixes_raw` AtomicAdd destination undefined.

- `h_tile_i8` padding rows: each of the five `sh_gate_up_act_q*` AIV kernels
  clears the two padded rows owned by its logical block
  (`zero_h_tile_i8_padding`) before producing its output.
- `mixes_raw` split-K destination: a new `hc_head_mixes_zero` AIV kernel
  (func_id 367) clears one up-to-16-row chunk per logical block; an explicit
  task dependency orders every `hc_head_linear` AtomicAdd store after the seed
  task. `decode_fwd.cpp`, `decode_fwd_hostbuild.cpp` and `decode_fwd_graph.cpp`
  submit it in place of the plain `alloc_tensors` + `set_initial_value`.

Both full-network cases remain `manual` (368-kernel compile); READMEs and
docstrings are updated for the new kernel count and for the closed HBG
initialization gap.

Ported from #1899, which landed on `perf/hbg-orch` rather than `main`.

* Doc: name the shipped HBG orchestration variant correctly

The HBG DSv4 test points at `decode_fwd_graph.cpp`, the Graph form. Its
docstring and ring-sizing comment still described the predicated-dispatch
variant with a static tile grid, which the README's ruled-out table records as
an earlier form that stalls at the same task and is not what the case builds.

The ring sizing itself is unchanged: `HBG_RECV_ROWS_PER_EXPERT` holds every
per-expert tile loop at a constant trip count, so tile scratch is still
allocated for all 32 experts per MoE layer.

* Fix: bound hc_head_linear to valid input rows

`x_flat [8,16384]` is a valid 512 KiB allocation, but both TLOAD views were
hard-coded as `Shape<...,16,256>` with a 16384-element row stride, covering an
almost 1 MiB range and reading rows 8-15 out of bounds. HBG's exact-size
per-tensor allocation surfaces the over-read as an MTE out-of-range fault at
task 15959; TMR's retained bump allocation keeps it inside a larger mapping and
masks the same kernel bug.

Derive `valid_rows = clamp(t_dim - row_base, 0, 16)` and use it for the two
`x_flat` views and load tiles, the dependent matmul and accumulator tiles, and
the `mixes_raw` AtomicAdd store. Cube tile capacity stays at 16.

The HBG README records the completed non-Graph device body, corrects the
earlier 13-of-16 dispatch reading of the stall, and keeps the original failure
signature under its own heading.

Ported from #1871, which landed on `perf/hbg-orch` rather than `main`. The
teardown-budget reference is respelled as `_CLOSE_CHILD_REAP_TIMEOUT_S`, whose
branch-local commit id does not exist on `main`.

* Remove the unbuilt non-Graph HBG DSv4 orchestration

`decode_fwd_hostbuild.cpp` was never a build input: the case points at
`decode_fwd_graph.cpp`, and nothing else read the file. Its investigation value
is spent now that the tail fault it was used to isolate is root-caused and fixed
in `hc_head_linear`.

The README loses the stall narrative that only described this form — the
per-task dump, the ruled-out table and the two-orchestration provenance — and
keeps the Graph-activation blocker, the reason the kernel carries a row-tail
bound, and the `get_tensor_data` runtime gap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code health Technical debt, robustness, code quality enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants