Skip to content

Add AVX512BF16 bf16_f32 igemm micro-kernels - #11946

Open
JakeStevens wants to merge 4 commits into
google:masterfrom
JakeStevens:bf16-conv-4
Open

JakeStevens wants to merge 4 commits into
google:masterfrom
JakeStevens:bf16-conv-4

Conversation

@JakeStevens

@JakeStevens JakeStevens commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Adds VDPBF16PS c2 bf16_f32 igemm micro-kernels (1-8 x 16/32) and uses 7x32
and 1x32 for bf16 convolutions on CPUs with AVX512BF16.

Genoa, 1 thread pinned, batch 1, subgraph-convolution-bench BF16Convolution,
median of 5; the fp32 fallback is the parent commit:

shape (W=H, CI->CO, 3x3) fp32 fallback native speedup peak memory
112, 32->16 860 us 643 us 1.34x 3.2 -> 1.6 MiB
56, 96->24 1195 us 461 us 2.59x 1.8 -> 0.6 MiB
14, 576->160 1344 us 685 us 1.96x 6.9 -> 1.7 MiB
7, 960->320 885 us 434 us 2.04x 21.3 -> 5.3 MiB

Stacked on #11945; only the last commit is new.

Authored with Claude Code.

Adds bf16 x bf16 -> fp32 scalar depthwise and c2 igemm micro-kernels, their
weight packers and micro-kernel tests, as the base for a native bf16
convolution. The scalar micro-kernels are reference implementations that test
the packers and aren't dispatched; the SIMD micro-kernels and the operator
follow in separate changes.

    bf16-f32-dwconv-minmax-test   # Apple M4 Max: [  PASSED  ] 60 tests.
    bf16-f32-igemm-minmax-test    # Apple M4 Max: [  PASSED  ] 52 tests.
Adds xnn_{create,reshape,setup}_convolution2d_nhwc_bf16_f32 and lets
xnn_define_{depthwise_,}convolution_2d accept bf16 inputs and filters, which
they previously rejected with xnn_status_unsupported_parameter (e.g. the
causal conv1d in Qwen3.5). The bf16 fallback keeps a convolution native, with
an fp32 output, when a bf16_f32 micro-kernel is available on a CPU with
hardware bf16 other than Apple's and its bias is absent or fp32. No configs
have micro-kernels yet, so for now bf16 convolutions run through the existing
fp32 rewrite. Also adds bf16_f32 operator tests (skipped until a config has
micro-kernels), BF16Convolution and BF16DepthwiseSeparable subgraph
benchmarks, and the CMake target for the existing subgraph convolution
benchmark.

    convolution-2d-test             # Apple M4 Max: [  PASSED  ] 30 tests.
    depthwise-convolution-2d-test   # Apple M4 Max: [  PASSED  ] 25 tests.
    convolution-nhwc-test           # Apple M4 Max: [  PASSED  ] 911 tests (bf16_f32 skipped).
Adds widen-and-FMA AVX512SKX bf16_f32 depthwise micro-kernels. The subgraph
uses them for depthwise bf16 convolutions on CPUs with AVX512BF16; the
operator API uses them on any AVX512SKX CPU.

Genoa, 1 thread pinned, batch 1, subgraph-depthwise-separable-bench
BF16DepthwiseSeparable, median of 5; the fp32 fallback is the parent commit.
The pointwise convolution runs in fp32 either way, because its input is the
depthwise convolution's fp32 output:

| shape (W=H, CI->CO, 3x3) | fp32 fallback | native | speedup | peak memory |
|---|---:|---:|---:|---|
| 112, 32->16 | 296 us | 267 us | 1.11x | 3.4 -> 2.6 MiB |
| 14, 576->160 | 182 us | 177 us | 1.03x | 1.5 -> 1.2 MiB |
| 7, 960->320 | 113 us | 103 us | 1.09x | 2.7 -> 2.5 MiB |

bf16-f32-dwconv-minmax-test passed on the Genoa (GCC 15) before these
changes were split up. At this commit an x86-64 build runs under Rosetta on an
Apple M4, where the AVX512SKX tests are skipped and the rest pass.
Adds VDPBF16PS c2 bf16_f32 igemm micro-kernels (1-8 x 16/32) and uses 7x32
and 1x32 for bf16 convolutions on CPUs with AVX512BF16.

Genoa, 1 thread pinned, batch 1, subgraph-convolution-bench BF16Convolution,
median of 5; the fp32 fallback is the parent commit:

| shape (W=H, CI->CO, 3x3) | fp32 fallback | native | speedup | peak memory |
|---|---:|---:|---:|---|
| 112, 32->16 | 860 us | 643 us | 1.34x | 3.2 -> 1.6 MiB |
| 56, 96->24 | 1195 us | 461 us | 2.59x | 1.8 -> 0.6 MiB |
| 14, 576->160 | 1344 us | 685 us | 1.96x | 6.9 -> 1.7 MiB |
| 7, 960->320 | 885 us | 434 us | 2.04x | 21.3 -> 5.3 MiB |

bf16-f32-igemm-minmax-test passed on the Genoa (GCC 15) before these changes
were split up. At this commit an x86-64 build runs under Rosetta on an Apple
M4, where the AVX512 tests are skipped and the rest pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant