Repository navigation
Add NEON bf16_f32 GEMM micro-kernels for Arm cores without BF16 - #11950
Open
JakeStevens wants to merge 2 commits into
Open
JakeStevens wants to merge 2 commits into
JakeStevens wants to merge 2 commits into
Conversation
This was referenced Nov 9, 2026
JakeStevens
force-pushed
the
bf16-fc-3
branch
from
November 23, 2026 16:57
7bc4616 to
3e0ca5b
Compare
Adds BFDOT c2 bf16_f32 GEMM micro-kernels and an AArch64 bf16_f32 GEMM config
that uses them on cores with FEAT_BF16, so the subgraph now keeps bf16
fully-connected nodes native there. Apple cores keep the fp32 fallback: on an
M4 (Apple clang 17.0.0, 1 thread, native forced by temporarily dropping the
Apple clause) native BFDOT is 1.05-1.15x faster at M=1 but 0.64-0.66x at M=16
and 128. The bf16_f32 GEMM tester now passes a real cn_stride (the existing
kernels ignore it), and the test is registered in CMake.
Pixel 10 (Tensor G5, Cortex-X4 core, NDK r29 clang 21.0.0), 1 thread pinned,
BF16FullyConnected, median of 3; "before" is master, which rewrites the node
to fp32:
| M | K | N | before | after | speedup | peak memory |
|--:|--:|--:|---:|---:|---:|---|
| 1 | 4096 | 512 | 216 us | 124 us | 1.74x | 16 -> 4 MiB |
| 1 | 512 | 4096 | 171 us | 114 us | 1.50x | 16 -> 4 MiB |
| 16 | 4096 | 512 | 1273 us | 690 us | 1.84x | 16 -> 4 MiB |
| 16 | 512 | 4096 | 1145 us | 701 us | 1.63x | 16 -> 4 MiB |
| 128 | 4096 | 512 | 7230 us | 5089 us | 1.42x | 18 -> 4 MiB |
| 128 | 512 | 4096 | 7576 us | 5227 us | 1.45x | 16 -> 4 MiB |
bf16-f32-gemm-minmax-test # Apple M4 Max: [ PASSED ] 132 tests.
fully-connected-test # Apple M4 Max: [ PASSED ] 83 tests.
bf16-f32-gemm-minmax-test # Pixel 10: [ PASSED ] 132 tests.
fully-connected-test # Pixel 10: [ PASSED ] 72 tests.
Adds widen-and-FMA AArch64 bf16_f32 GEMM micro-kernels as the non-BF16 branch
of the Arm bf16_f32 GEMM config, so the bf16 fully-connected and batch matrix
multiply operator APIs work on cores without FEAT_BF16.
xnn_init_bf16_f32_gemm_config() no longer requires BF16 hardware; the subgraph
still does, because the fp32 fallback is faster for batched inputs here.
Pixel 6 Pro (Cortex-X1, no BF16, NDK r29 clang 21.0.0), 1 thread pinned,
BF16FullyConnected, median of 3, at the shapes measured there; native neonfma
is forced by temporarily dropping the subgraph's hardware-bf16 check:
| M | K | N | fp32 fallback | native neonfma | peak memory |
|--:|--:|--:|---:|---:|---|
| 1 | 4096 | 512 | 320 us | 227 us | 16 -> 4 MiB |
| 1 | 512 | 4096 | 312 us | 219 us | 16 -> 4 MiB |
| 16 | 4096 | 512 | 1626 us | 1759 us | 16 -> 4 MiB |
| 128 | 512 | 4096 | 10135 us | 12664 us | 16 -> 4 MiB |
bf16-f32-gemm-minmax-test # Apple M4 Max: [ PASSED ] 242 tests.
fully-connected-test # Apple M4 Max: [ PASSED ] 83 tests.
bf16-f32-gemm-minmax-test # Pixel 6 Pro, before the split: [ PASSED ] 132 tests.
fully-connected-test # Pixel 6 Pro, before the split: [ PASSED ] 72 tests.
JakeStevens
force-pushed
the
bf16-fc-3
branch
from
November 24, 2026 15:16
3e0ca5b to
fcc9403
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #11949; only the last commit is new here.
Adds widen-and-FMA AArch64
bf16_f32GEMM micro-kernels as the non-BF16 branch of the Arm config, so the bf16 fully-connected and batch matrix multiply operator APIs work on cores without FEAT_BF16.xnn_init_bf16_f32_gemm_config()no longer requires BF16 hardware; the subgraph still does, because the fp32 fallback is faster for batched inputs on these cores.Pixel 6 Pro (Cortex-X1, no BF16, NDK r29 clang 21.0.0),
BF16FullyConnected, 1 thread pinned, median of 3, at the shapes measured there; native neonfma is forced by temporarily dropping the subgraph's hardware-bf16 check:Tests:
bf16-f32-gemm-minmax-test(242 tests),fully-connected-test,batch-matrix-multiply-test,fully-connected-nc-testandbatch-matrix-multiply-nc-testpass on Apple M4 Max and Pixel 10. Before the split,bf16-f32-gemm-minmax-test(132 tests) andfully-connected-test(72 tests) passed on the Pixel 6 Pro. The armeabi-v7a build compiles.Authored with Claude Code.