[MLAS][KleidiAI] Integrate Depthwise 3x3 Conv Kernel - #29441
Jonathan Clohessy (JonathanC-ARM) wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR integrates an Arm® KleidiAI™ SME2-backed FP32 depthwise 3x3 convolution path into MLAS, wires it into the existing KleidiAI CPU convolution routing (Depthwise → IGemm → SGemmFallback → NoKleidiAi), and enables NHWC graph transformation when the new depthwise channels-last capability is available. It also adds an MLAS unit test to validate both the direct KleidiAI depthwise entrypoint and end-to-end routing through MlasConv in channels-last mode.
Changes:
- Added a new KleidiAI FP32 depthwise convolution implementation and ukernel selection plumbing.
- Integrated a new
ConvRoute::Depthwiseinto KleidiAI conv prepare/dispatch and enabled NHWC transform gating for supported depthwise shapes. - Added MLAS unit tests covering direct depthwise invocation and
MlasConvchannels-last routing.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/test/mlas/unittest/test_dwconv_kleidiai.cpp | Adds unit tests for KleidiAI depthwise conv (direct call and MlasConv NHWC path). |
| onnxruntime/core/optimizer/nhwc_transformer.cc | Extends NHWC transform filtering to consider depthwise channels-last support constraints. |
| onnxruntime/core/mlas/lib/kleidiai/mlasi_kleidiai.h | Adds depthwise support/entrypoint declarations and introduces ConvRoute::Depthwise selection. |
| onnxruntime/core/mlas/lib/kleidiai/dw_conv_kleidiai.cpp | Implements the FP32 depthwise 3x3 kernel path, including layout conversions and packing. |
| onnxruntime/core/mlas/lib/kleidiai/convolve_kleidiai.cpp | Wires depthwise routing into KleidiAI conv prepare/dispatch and refactors IGEMM capability checks. |
| onnxruntime/core/mlas/lib/kai_ukernel_interface.h | Generalizes the ukernel wrapper type and adds a depthwise ukernel wrapper typedef and accessor. |
| onnxruntime/core/mlas/lib/kai_ukernel_interface.cpp | Registers the SME2 depthwise ukernel and exposes it via GetKleidiAIDepthwiseConvUKernel(). |
| onnxruntime/core/mlas/lib/convolve.cpp | Enables MlasConvSupportsDepthwiseChannelsLast2DFloatKernel for KleidiAI-supported shapes to unlock NHWC transforms. |
| cmake/onnxruntime_mlas.cmake | Adds the new depthwise source file to the KleidiAI MLAS build. |
Review —
|
Signed-off-by: Jonathan Clohessy <Jonathan.Clohessy@arm.com>
9a52413 to
80524ec
Compare
Signed-off-by: melkap01 <melike.kaptan@arm.com>
…ts, refactor cleaned Signed-off-by: melkap01 <melike.kaptan@arm.com>
Signed-off-by: melkap01 <melike.kaptan@arm.com>
Head branch was pushed to by a user without write access
Signed-off-by: melkap01 <melike.kaptan@arm.com>
There was a problem hiding this comment.
🟡 Changes recommended
The new route has disabled-backend correctness issues, regresses symbolic dense transformation, and leaves an SME2 optimizer test stale.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 3
- Review effort level: Balanced
| const bool depthwise_nhwc_fastpath = | ||
| wants_channels_last && !sum_present && MlasConvSupportsDepthwiseChannelsLast2DFloatKernel(kernel_rank, narrow<size_t>(N), group_count, input_channels_per_group, input_shape_size_t.data(), kernel_shape_size_t.data(), dilations_size_t.data(), pads_size_t.data(), strides_size_t.data(), filter_count_per_group, | ||
| /*Beta*/ 0.0f); |
| parameters.StrideShape[dim] = StrideShape[dim]; | ||
| } | ||
|
|
||
| return ArmKleidiAI::DepthwiseConvKleidiAISupported(¶meters); |
| !TryGetDimValueAsSizeT(*input_shape, 2, input_spatial_shape[0]) || | ||
| !TryGetDimValueAsSizeT(*input_shape, 3, input_spatial_shape[1]) || | ||
| !TryGetDimValueAsSizeT(*weight_shape, 0, total_filter_count) || | ||
| !TryGetDimValueAsSizeT(*weight_shape, 1, input_channels_per_group) || |
|
After threading added , threaded vs non threaded version is benchmarked: Apple M4 Pro Machine:
Android X300 Device
|
Description
This PR adds a Arm® KleidiAI™ backed f32 depthwise convolution path in MLAS and wires it into the CPU/KleidiAI convolution routing flow.
The new path targets eligible depthwise convolutions using the KleidiAI SME2 depthwise ukernel. It is integrated as a first-class KleidiAI convolution route so depthwise dispatch is handled consistently with the existing IGEMM / SGEMM fallback routing.
Changes
onnxruntime/core/mlas/lib/kleidiai/dw_conv_kleidiai.cppConvRoute::Depthwise.DepthwiseIGemmSGemmFallbackNoKleidiAiSupported depthwise shape envelope
The current KleidiAI depthwise route supports f32 depthwise convolution with:
3x3kernelThe implementation handles NHWC directly and can fall back to internal NCHW to NHWC conversion when needed.
Example Performance Results
mobilenet_v1_f32.onnxmobilenetv1_ssd_f32.onnxretinaface_f32.onnxdeeplabv3_mobilenetv2_f32.onnxde_efficientnetlitev3_f32.onnx