Skip to content

Add Arm BF16 (BFDOT) bf16_f32 GEMM micro-kernels - #11949

Open
JakeStevens wants to merge 1 commit into
google:masterfrom
JakeStevens:bf16-fc-2
Open

JakeStevens wants to merge 1 commit into
google:masterfrom
JakeStevens:bf16-fc-2

Conversation

@JakeStevens

Copy link
Copy Markdown
Contributor

Stacked on #11948; only the last commit is new here.

Adds BFDOT bf16_f32 GEMM micro-kernels and an AArch64 bf16_f32 GEMM config that uses them on cores with FEAT_BF16, so bf16 fully-connected nodes stay 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, and the test is registered in CMake.

Pixel 10 (Tensor G5, Cortex-X4 core, NDK r29 clang 21.0.0), BF16FullyConnected, 1 thread pinned, 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

Tests: bf16-f32-gemm-minmax-test (132 tests) and the fully-connected and batch-matrix-multiply subgraph and operator tests pass on Apple M4 Max. On the Pixel 10, where the native path runs, bf16-f32-gemm-minmax-test (132 tests) and fully-connected-test (72 tests) pass.

Authored with Claude Code.

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.
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