Skip to content

hexagon: Op Fusion refactoring, optimizations and new fusions like BINARY_NX (back-to-back ADDs, etc) - #30843

Merged
max-krasnyansky merged 35 commits into
ggml-org:masterfrom
qualcomm:hexagon-opfusion-v2
Oct 23, 2026
Merged

max-krasnyansky merged 35 commits into
ggml-org:masterfrom
qualcomm:hexagon-opfusion-v2

Conversation

@max-krasnyansky

@max-krasnyansky max-krasnyansky commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Overview

Another round of overdue cleanup and refactoring.
ggml-hexagon ops collection have been growing and we've accumulated lots of duplicate logic and special cases.
This PR cleans most of that up. Lots of changes but mostly refactoring and de-dup.

  • Added/expanded op fusion infrastructure: new htp-fusion.{h,cpp}, fusion logic pulled out of ggml-hexagon.cpp, with
    new fusions for GELU+MUL, REPEAT+GET_ROWS, BINARY_NX chains, RMS_NORM+MUL, SSM_CONV+SILU, and more GLU variants.

  • Complete refactoring of Kernel Params : new htp-kparams.{h,cpp}, less exposed API, templated/check wrapper cleanup, fewer casts, and wider use across UNARY, GLU, SSM_CONV, PAD, DIAG, etc.

  • Simplified op dispatch and batching, de-duplicated op dispatch switches

  • Reworked GLU/UNARY op plumbing: act-ops.c renamed into glu-ops.c, added glu-ops.h, broader kernel param use, unary dim collapsing, and cleaner op formatting/runtime checks.

  • Flash Attention fixes: large FA scratch state moved off small callback-thread stacks into DDR scratch, and moved DMA caches into htp_ops_context so FA no longer stores those cache structs on stack.

Additional information

New fusions improve performance across the board in 20-30% range.
Tested on all supported platforms: single-NPU v73...v85 and dual-NPU v73, quad-NPU v81.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes, Anti.G and Codex for code review, log analysis, writing new fusions, refactoring

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning Hexagon labels Oct 20, 2026
@max-krasnyansky
max-krasnyansky force-pushed the hexagon-opfusion-v2 branch 2 times, most recently from 1247e27 to 7b74bb4 Compare October 20, 2026 22:32
@github-actions github-actions Bot added the testing Everything test related label Oct 20, 2026
ebateni added a commit to ebateni/llama.cpp that referenced this pull request Oct 22, 2026
@max-krasnyansky
max-krasnyansky marked this pull request as ready for review October 22, 2026 06:41
@max-krasnyansky
max-krasnyansky requested review from a team and ggerganov as code owners October 22, 2026 06:41
@max-krasnyansky

Copy link
Copy Markdown
Member Author

@lhez for review and ack

@max-krasnyansky max-krasnyansky added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 22, 2026
@max-krasnyansky
max-krasnyansky merged commit 643b0cd into ggml-org:master Oct 23, 2026
33 of 38 checks passed
danielhanchen added a commit to unslothai/llama.cpp that referenced this pull request Oct 23, 2026
- ggml-hexagon.cpp: upstream replaced the per-op supports_op switch with htp_kparams_check() (ggml-org#30843); the page-table refusal is
  re-applied as a FLASH_ATTN_EXT case in the new switch, refusing src[5] before the kparams check
- tests/CMakeLists.txt: upstream's behavior labels (ggml-org#31036) kept; the pin's tests added beside them with their labels unchanged
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 24, 2026
…INARY_NX` (back-to-back ADDs, etc) (ggml-org#30843)

* hex-fusion: support for GELU+MUL, REPEAT+GET_ROWS and BINARY_NX (back-to-back ADD/MUL/...)

* hex-fusion: factor out fusion logic into separate .h and .cpp and update all related code

* hex-fusion: allow for RMS_NORM+MUL fusions for non-contig tensors

* hex-fusion: streamline fusion eligibility checks and cover missing corner cases

* hex-fusion: streamline fusion flow

* hex-opbatch: make n_tensors limit more scalable

* hex-bufs: adjust the trace buff sizing

* hex-glu: cleanup glu-ops interfaces and add kernel_params

* hex-kparams: clean up kparams handling in unary, ssm-conv, and other ops

* hex-kparams: update the rest of the ops PAD,DIAG,... to use kparams

* hex-unary: add support for collapsing dims

* hex-ops: cleanup redundant runtime checks

* hex-ops: consistent use of kernel_type in all kparams

* hex-fusion: remove redundant check in gdn+cpy

* hex-fusion: further streamlining of fusion rules and code

* hex-fusion: cleanup naming

* hex-opfmt: cleanup op formatting

* hex-fusion: bump fusion lookahead to 64

* hex-fusion: fuse SSM_CONV+SILU

* hex-fusion: fix hvx register spills in fused ssm_conv+silu

* hex-fusion: add more GLU fusions

* hex-fusion: remove duplicate checks and use ggml-common helpers

* hex-kparams: refactor kparams into htp-kparams.h/cpp

* hex-fusion: fix binary-nx fusion regression

* hex-kparams: another pass at cleaning up kparams (removing unused, etc)

* hex-kparams: streamling nameing and move _check_ wrappers into .h

* hex-kparams: templetize htp_kparams_check_<op> to reduce code bloat

* hex-ops: de-duplicate op dispatch switches

* hex-kparams: trim down exposed kparams calls

* hex-kparams: simplify type casting of kparams structs

* hex-fence: de-dup fence tensor construction

* hex-opbatch: simplify tensor shape init/checks

* hex-mm: cleanup leftovers of the original QK defines

* hex-fa: fix stack overflow on older npu firmware

* hex-ctx: move dma_caches into ops_ctx
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
…INARY_NX` (back-to-back ADDs, etc) (ggml-org#30843)

* hex-fusion: support for GELU+MUL, REPEAT+GET_ROWS and BINARY_NX (back-to-back ADD/MUL/...)

* hex-fusion: factor out fusion logic into separate .h and .cpp and update all related code

* hex-fusion: allow for RMS_NORM+MUL fusions for non-contig tensors

* hex-fusion: streamline fusion eligibility checks and cover missing corner cases

* hex-fusion: streamline fusion flow

* hex-opbatch: make n_tensors limit more scalable

* hex-bufs: adjust the trace buff sizing

* hex-glu: cleanup glu-ops interfaces and add kernel_params

* hex-kparams: clean up kparams handling in unary, ssm-conv, and other ops

* hex-kparams: update the rest of the ops PAD,DIAG,... to use kparams

* hex-unary: add support for collapsing dims

* hex-ops: cleanup redundant runtime checks

* hex-ops: consistent use of kernel_type in all kparams

* hex-fusion: remove redundant check in gdn+cpy

* hex-fusion: further streamlining of fusion rules and code

* hex-fusion: cleanup naming

* hex-opfmt: cleanup op formatting

* hex-fusion: bump fusion lookahead to 64

* hex-fusion: fuse SSM_CONV+SILU

* hex-fusion: fix hvx register spills in fused ssm_conv+silu

* hex-fusion: add more GLU fusions

* hex-fusion: remove duplicate checks and use ggml-common helpers

* hex-kparams: refactor kparams into htp-kparams.h/cpp

* hex-fusion: fix binary-nx fusion regression

* hex-kparams: another pass at cleaning up kparams (removing unused, etc)

* hex-kparams: streamling nameing and move _check_ wrappers into .h

* hex-kparams: templetize htp_kparams_check_<op> to reduce code bloat

* hex-ops: de-duplicate op dispatch switches

* hex-kparams: trim down exposed kparams calls

* hex-kparams: simplify type casting of kparams structs

* hex-fence: de-dup fence tensor construction

* hex-opbatch: simplify tensor shape init/checks

* hex-mm: cleanup leftovers of the original QK defines

* hex-fa: fix stack overflow on older npu firmware

* hex-ctx: move dma_caches into ops_ctx
@BrewTestBot BrewTestBot mentioned this pull request Oct 28, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning Hexagon merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants