Skip to content

Support bf16 convolution in the subgraph and operator APIs - #11944

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

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

Conversation

@JakeStevens

Copy link
Copy Markdown
Contributor

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

Stacked on #11943; 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).
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