Repository navigation
Add native bf16 convolution (x86 AVX512/AVX2, Arm NEON and BF16) - #11292
Closed
JakeStevens wants to merge 4 commits into
Closed
JakeStevens wants to merge 4 commits into
JakeStevens wants to merge 4 commits into
Conversation
This was referenced Sep 23, 2026
JakeStevens
force-pushed
the
bf16-conv
branch
from
November 5, 2026 20:30
ffc3d25 to
294410c
Compare
JakeStevens
marked this pull request as ready for review
November 5, 2026 20:31
JakeStevens
force-pushed
the
bf16-conv
branch
from
November 9, 2026 16:39
294410c to
e1d002e
Compare
Adds bf16 x bf16 -> fp32 depthwise (scalar, AVX2, AVX512SKX) and c2 igemm
(scalar, AVX512BF16) micro-kernels for native bf16 convolution, with their
packers and micro-kernel tests. Nothing dispatches them yet.
Tests on an AMD EPYC Genoa (GCC 15):
bf16-f32-dwconv-minmax-test # [ PASSED ] 300 tests.
bf16-f32-igemm-minmax-test # [ PASSED ] 364 tests.
Adds xnn_{create,reshape,setup}_convolution2d_nhwc_bf16_f32 and lets
xnn_define_{depthwise_,}convolution_2d accept bf16 filters, which previously
hit XNN_UNREACHABLE (e.g. the causal conv1d in Qwen3.5). The bf16 fallback
keeps a convolution native, with an fp32 output, only on CPUs with hardware
bf16 other than Apple's, and when its bias is absent or fp32; everything else
takes the existing fp32 rewrite.
Genoa (AVX512BF16 igemm, AVX512SKX dwconv), 1 thread pinned, batch 1,
subgraph-convolution-bench / subgraph-depthwise-separable-bench, median of 5;
the fp32 fallback is the same bf16 graph with the native path disabled:
| shape (W=H, CI->CO, 3x3) | fp32 fallback | native | speedup | peak memory |
|---|---:|---:|---:|---|
| conv 112, 32->16 | 860 us | 643 us | 1.34x | 3.2 -> 1.6 MiB |
| conv 56, 96->24 | 1195 us | 461 us | 2.59x | 1.8 -> 0.6 MiB |
| conv 14, 576->160 | 1344 us | 685 us | 1.96x | 6.9 -> 1.7 MiB |
| conv 7, 960->320 | 885 us | 434 us | 2.04x | 21.3 -> 5.3 MiB |
| dw-separable 112, 32->16 | 296 us | 267 us | 1.11x | 3.4 -> 2.6 MiB |
| dw-separable 14, 576->160 | 182 us | 177 us | 1.03x | 1.5 -> 1.2 MiB |
| dw-separable 7, 960->320 | 113 us | 103 us | 1.09x | 2.7 -> 2.5 MiB |
convolution-2d-test --gtest_filter='*BF16*' # passes
depthwise-convolution-2d-test --gtest_filter='*BF16*' # passes
Adds widen-and-FMA NEON bf16_f32 dwconv and AArch64 igemm micro-kernels, so the bf16 convolution operator API works on Arm cores without FEAT_BF16. The subgraph keeps the fp32 fallback on these cores because it is faster. Pixel 6 Pro (Cortex-X1, no BF16, NDK r29 clang 21.0.0), 1 thread pinned, bf16 graph, median of 3: | shape (W=H, CI->CO, 3x3) | fp32 fallback | native neonfma | peak memory | |---|---:|---:|---| | conv 112, 32->16 | 1797 us | 2621 us | 3.2 -> 1.6 MiB | | conv 14, 576->160 | 3946 us | 5396 us | 6.9 -> 1.7 MiB | | conv 7, 960->320 | 2875 us | 3808 us | 21.3 -> 5.3 MiB | | dw-separable 112, 32->16 | 760 us | 842 us | 3.4 -> 2.6 MiB | | dw-separable 7, 960->320 | 342 us | 338 us | 2.7 -> 2.5 MiB | Tests pass on the Pixel 6 Pro (neonbf16 cases skip) and an Apple M4 Max.
Adds BFDOT c2 igemm and BFMLALB/T dwconv micro-kernels and uses them on cores
with FEAT_BF16, where the subgraph now keeps bf16 convolutions native. Apple
cores keep the fp32 fallback: they issue BFDOT at ~2/3 of the FMLA rate, and on
an M4 (Apple clang 17.0.0, 1 thread) the native igemm convs below run at
0.65-0.69x of the fallback.
Pixel 10 (Tensor G5, NDK r29 clang 21.0.0), 1 thread pinned, bf16 graph,
median of 3:
| shape (W=H, CI->CO, 3x3) | fp32 fallback | native | speedup | peak memory |
|---|---:|---:|---:|---|
| conv 112, 32->16 | 1447 us | 1055 us | 1.37x | 3.2 -> 1.6 MiB |
| conv 56, 96->24 | 1574 us | 1115 us | 1.41x | 1.8 -> 0.5 MiB |
| conv 14, 576->160 | 3078 us | 2177 us | 1.41x | 6.9 -> 1.7 MiB |
| conv 7, 960->320 | 2753 us | 1533 us | 1.80x | 21.3 -> 5.3 MiB |
| dw-separable 112, 32->16 | 471 us | 364 us | 1.29x | 3.4 -> 2.6 MiB |
| dw-separable 14, 576->160 | 414 us | 382 us | 1.08x | 1.5 -> 1.2 MiB |
| dw-separable 7, 960->320 | 261 us | 249 us | 1.05x | 2.7 -> 2.5 MiB |
bf16-f32-dwconv-minmax-test # [ PASSED ] 300 tests.
bf16-f32-igemm-minmax-test # [ PASSED ] 312 tests.
convolution-2d-test # [ PASSED ] 30 tests.
depthwise-convolution-2d-test # [ PASSED ] 25 tests.
JakeStevens
force-pushed
the
bf16-conv
branch
from
November 9, 2026 17:03
e1d002e to
8cac8cc
Compare
This was referenced Nov 9, 2026
Contributor
Author
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.
Adds native bf16 convolution (bf16 input and filter, fp32 bias and output) through a new
xnn_*_convolution2d_nhwc_bf16_f32operator and bf16_f32 dwconv/igemm micro-kernels for AVX512BF16, AVX512SKX/AVX2, Arm BF16 and NEON. Previously a bf16 filter hitXNN_UNREACHABLEinxnn_define_convolution_2d. The subgraph keeps bf16 convolutions native only on CPUs with hardware bf16, except Apple's, which issue BFDOT at ~2/3 of the FMLA rate (0.65-0.69x of the fp32 fallback on an M4). Elsewhere the fp32 fallback is faster, and the non-BF16 kernels only serve the operator API.Native vs the same bf16 graph through the fp32 fallback, 1 thread pinned, batch 1 (Arm: NDK r29 clang 21.0.0):
Peak memory is 2-4x lower for dense convolutions. Each commit message has the full table.
Tests: the new bf16-f32 dwconv/igemm micro-kernel tests and the conv subgraph tests pass on Genoa, Pixel 10, Pixel 6 Pro and Apple M4 Max. The armeabi-v7a build compiles.
Authored with Claude Code.