Repository navigation
Add NEON-BF16 bf16 binary elementwise micro-kernels - #11952
Merged
2 commits merged intoNov 13, 2026
Merged
2 commits merged into
2 commits merged into
Conversation
Adds bf16 binary elementwise configs (add, sub, mul, div, max, min, prelu, sqrdiff, with broadcast and reversed variants) and ARM64 NEON micro-kernels that compute in fp32 and round to nearest even once. The bf16 -> fp32 fallback now keeps bf16 binary nodes native when a config exists; ARM32 and x86 keep the fp32 fallback. The micro-kernel tests check results bit for bit, and the binary subgraph benchmark gets bf16 cases and a CMake target. Pixel 6 Pro (Cortex-X1 core pinned, no BF16), NDK r29 clang 21.0.0, single thread, 8192 elements: a native bf16 add takes 1748 ns, an f32 add 931 ns, and a bf16 add through the fp32 fallback ~4900 ns. subgraph-binary-bench BF16Binary on the same core, median of 3, bf16 nodes forced through the fp32 fallback vs native: | op | shape | fp32 fallback | native | speedup | |---|---|---:|---:|---:| | add | 1x256 | 0.27 us | 0.095 us | 2.8x | | add | 1x4096 | 2.70 us | 1.02 us | 2.6x | | add | 256x4096 | 1069 us | 278 us | 3.8x | | multiply | 256x4096 | 1107 us | 295 us | 3.8x | | divide | 256x4096 | 1112 us | 396 us | 2.8x | | prelu | 256x4096 | 1094 us | 422 us | 2.6x | Tests: bf16-v* (bit-exact, including subnormal, tie, overflow, signed-zero and infinity cases), binary-test and binary-elementwise-nd-test pass on an Apple M4 Max. NativeBinaryOpsStayBf16 is in the Bazel-only bf16_to_fp32_fallback_test (it depends on litert/tensor, which CMake doesn't build), so it hasn't been run locally.
Adds bf16 binary micro-kernels that round with BFCVTN/BFCVTN2 instead of the software round to nearest even, and uses them on ARM64 CPUs with FEAT_BF16. vbinary-bench, u16 kernels (the ones the configs use), 8192 elements, median of 5, ns. Pixel 10: Cortex-X4 core pinned, NDK r29 clang 21.0.0; M4 Max: Apple clang 17.0.0, unpinned: | op | Pixel 10 NEON | Pixel 10 NEON-BF16 | speedup | M4 Max NEON | M4 Max NEON-BF16 | speedup | |---|---:|---:|---:|---:|---:|---:| | add | 1268 | 977 | 1.30x | 927 | 530 | 1.75x | | mul | 1388 | 976 | 1.42x | 937 | 534 | 1.75x | | sqrdiff | 1588 | 1080 | 1.47x | 1123 | 681 | 1.65x | | prelu | 2165 | 1597 | 1.36x | 1745 | 1149 | 1.52x | | div | 2859 | 2590 | 1.10x | 1040 | 697 | 1.49x | Tests: bf16-v*, binary-test and binary-elementwise-nd-test pass on an Apple M4 Max.
This was referenced Nov 9, 2026
Collaborator
|
This looks overlapping with #11951 . I approved that one first. Let's merge that, then rebase this. Approving them all at once is going to result in a lot of code migration machinary churning on conflicts. |
694850e
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.
Title: Add NEON-BF16 bf16 binary elementwise micro-kernels
Stacked on #11951; only the last commit is new.
Adds bf16 binary micro-kernels that round with BFCVTN/BFCVTN2 instead of the software round to nearest even, and uses them on ARM64 CPUs with FEAT_BF16.
vbinary-bench, u16 kernels (the ones the configs use), 8192 elements, median of 5, ns. Pixel 10: Cortex-X4 core pinned, NDK r29 clang 21.0.0; M4 Max: Apple clang 17.0.0, unpinned:
Tests: bf16-v*, binary-test and binary-elementwise-nd-test pass on an Apple M4 Max.
Authored with Claude Code.