Repository navigation
spacemit: fuse H32 GDN state transfers and write back in place - #97
Conversation
Assisted-by: Codex
|
Please extend the output-root check to the Please add a cross-split terminal gather-view regression that compares the exposed pre-update gather and the post-update persistent row separately. For the performance claim, please compare baseline, H32 with the state tail materialized, and H32 direct writeback on the same K3 setup. The reported +2.91% is smaller than the reported startup variation, so it doesn't isolate a stable gain yet. |
|
The terminal gather-view case is already protected when the output is marked with I extended the host planner fixture with exactly that construction: a terminal output view rooted at the gather, appended outside the local split, with no compute consumer. The planner keeps the gather materialized ( Directly setting only the view's output flag, without calling AI assistance: Codex assisted with tracing the source and running the host planner fixture; this reply was explicitly requested by the contributor. |
c9a0371
into
spacemit-com:mtmd-backend
Problem and behavior
Performance optimization following #88. Extend single-token GDN state-transfer fusion from H16 to H32 and avoid materializing/copying the large state tail when it can be written safely to the persistent cache row in place. This includes the direct writeback change, not only the original H32 dispatch extension.
Preserve full state materialization whenever an exported tensor, output view or another consumer needs it. In particular, the planner uses scheduler export information rather than assuming that absence of a local consumer means absence of a later backend consumer.
Change and design
ggml-spacemit.cpp: H32 matching, graph output/root and export checks, lifetime dependencies, and the private-state writeback flag. Missing scheduler information, callback slices and unsafe aliases keep the conservative path.ime.cpp: pass the validated writeback decision to the RVV executor.rvv_kernels.cpp/.h: accept direct writeback, preserve materialization when required, and avoid same-addressmemcpyin the narrow-vector fallback.The original upstream MTP multi-snapshot/transposed state path remains present. The added direct-writeback match is restricted to the supported single-token F32 state [128,128,32].
Scope is limited to
ggml/src/ggml-spacemit/. Impact classification: execution-path change. No changes to the retired CPU backend, model code, public API or test sources. Local validation fixtures are excluded. This independently based module commit preserves the target branch's common MTP graph/rollback paths; experimental noMTP-wide reversions are not submitted. No new external dependency is added.Validation
Base:
mtmd-backendat3f5ce5fd84f4dc6e7e621642cfef0143d49e7c24. Candidate:ee469bd010f77014e3276a083c7e4828dfe6cd47; source tree858480f8571ea48403233132b634a2ac2a52a54f.The exact submitted production source passed a RISC-V Release cross-build of
ggml-spacemitusing the SpacemiT v1.1.2 toolchain (GCC 14.3),cmake/riscv64-spacemit-linux-gnu-gcc.cmake,GGML_SPACEMIT=ON,GGML_RV_ZBA=ON,GGML_OPENMP=OFF, Spert 0.6.3 and SpacemiT ORT 2.0.6. Build target:cmake --build <build> --target ggml-spacemit --parallel 24. Backend DSO SHA-256:78c4cca917e11ccbb0750ab53ce82e515e405fb5037941a3b0eff2c02b8b40fc. Source hashes were checked before/after the build and against the committed files.The final publication source passed 9/9 host planner cases, re-extracted from this exact source: private H32 state, H16, exported GDN, exported gather, local output view, external output view, extra reader, eval callback and replanning. Only private H32 enabled tail elision. These tests check planner decisions, not numerical execution of RVV.
An earlier aggregate K3 build with direct writeback passed four numerical checks: private state, cross-backend tail reads, exported gather, and 16-token/16-snapshot state. A debugger verified that the real model state row was read and written at the same persistent address. The final narrow-vector same-address copy guard was added after that board run; no VLEN-256 numerical result is claimed.
git diff --check, UTF-8/LF and added-line whitespacePerformance
Two experiments answer different questions:
H32 ablation: fixed 10,240 prompt IDs, 128 generated tokens, MTP off, F16 KV, FA on,
-c 12288 -b 2048 -ub 512 -t 8, eight workers; two startups per arm. All output IDs matched. This experiment predates direct writeback. Run record:qwen36-h32-kcache-ab-20261202.Direct-writeback observation: 10,240 input tokens, 128 generated tokens, MTP off,
-c 32768 -b 2048 -ub 2048 -t 8, eight workers; 117.546 prefill tok/s and 9.228 decode tok/s. Run labelB179. The aggregate also contained other noMTP optimizations; it is not a standalone GDN A/B. Cross-board values must not be used to attribute a speedup to writeback.Risks and limits
The historical numerical/model runs exercised an aggregate package. The final standalone head, narrow-vector numerical fallback and wider MTP rollback workloads need board validation. Host guard tests do not replace those checks. The cross-split materialization concern from #88 is addressed by explicit export and output-root checks.
The historical module comparisons used the common noMTP experimental baseline on top of
3f5ce5fd; this PR instead preserves upstream common MTP behavior. Historical results are not claimed as new measurements of the final independent head. Raw build/test/benchmark archives are retained privately and are not publicly attached; the cases, results, artifact identities and limits above are the reviewable record here. Exact-input model replay is not provided by these summaries. Required final-head target evidence remains pending; this submission requests review, not a waiver or a claim of merge readiness. No maintainer exception has been granted. CI status is separate from the local results above.AI assistance and contributor responsibility
Codex assisted with source preparation, static review, local build/check execution, historical evidence analysis and this PR description. The contributor discussed the module design and explicitly requested publication. No unrecorded personal review, maintainer approval or target execution is asserted. The contributor remains responsible for reviewing the submitted code and claims and addressing review feedback.