[MLAS] AVX-512 16-wide Erf kernel and NCHWc reorder transpose for MobileClip-S0 model - #31958
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Adds AVX-512 optimizations for MobileClip-S0 FP32 CPU inference.
Changes:
- Adds a 16-lane AVX-512 Erf kernel and runtime dispatch.
- Adds AVX-512 NCHW↔NCHWc 16×16 transpose paths.
- Adds Erf and input-reorder correctness tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
cmake/onnxruntime_mlas.cmake |
Builds the new AVX-512 reorder source. |
onnxruntime/core/mlas/lib/gelu_avx512f.cpp |
Implements the AVX-512 Erf kernel. |
onnxruntime/core/mlas/lib/intrinsics/avx512/reorder_avx512f.cpp |
Implements 16×16 reorder transposes. |
onnxruntime/core/mlas/lib/mlasi.h |
Declares the new kernels. |
onnxruntime/core/mlas/lib/platform.cpp |
Dispatches Erf to AVX-512. |
onnxruntime/core/mlas/lib/reorder.cpp |
Uses AVX-512 reorder fast paths. |
onnxruntime/test/mlas/unittest/test_erf.cpp |
Tests Erf accuracy and kernel equivalence. |
onnxruntime/test/mlas/unittest/test_reorder_input.cpp |
Tests NCHW input reordering. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Review: PR #31958 — [MLAS] AVX-512 16-wide Erf kernel and NCHWc reorder transpose for MobileClip-S0 model (head
|
|
ARM64 compilation reaches unit tests for this new kernel and fails. Please make sure the build for the kernel test is configured as AVX512-only |
@microsoft-github-policy-service agree company="Multicoreware" |
1046c07 to
7aa0777
Compare
Addressed the comment |
…ileClip-S0 Two stacked, accuracy-neutral AVX-512 optimizations for FP32 MobileClip-S0 CPU inference. Top-1 unchanged (0.6500); ~8-10% latency improvement at 1T/2T/4T versus base. 1. Standalone Erf op -> 16-wide AVX-512 kernel. MobileClip's GELU is graph-decomposed into a standalone ONNX Erf op, which routes through ErfKernelRoutine. On AVX-512 hardware that pointer was left at the 8-wide MlasErfKernelFma3 (the AVX-512 branch overrides the fused GELU pointer but never ErfKernelRoutine). Add MlasErfKernelAvx512F, reusing the existing bit-identical 16-wide erf polynomial in gelu_avx512f.cpp, and wire it in the AVX-512 feature branch of platform.cpp. 2. NCHWc reorder 16x16 AVX-512 transpose. The reorder transpose was SSE2 4-wide, so on AVX-512 (NCHWc block size 16) it ran four sub-transposes per block. Add reorder_avx512f.cpp with a single-pass 16x16 transpose and Input/Output block-16 helpers, invoked from the reorder.cpp hot loops under a BlockSize==16 guard so non-AVX512 targets are byte-identical. Validated bit-exact against the scalar reference across spatial sizes including tails.
Covers the two kernel changes in commit 2a91595 with bit-exact / tolerance checks against scalar references. All MLAS unit tests pass. - test_reorder_input.cpp: MlasReorderInputNchw (NCHW -> NCHWc) versus a scalar reference via memcmp, sweeping channel counts 1..47 (exact 16-channel blocks exercise the new MlasReorderInputNchwBlock16Avx512F fast path; partial blocks exercise the scalar tail) across several spatial sizes. Complements the existing test_reorder_output.cpp which already covers the output path. - test_erf.cpp: MlasComputeErf versus std::erf within the polynomial's accuracy tolerance, sweeping buffer lengths that straddle the 16-lane boundary so the AVX-512 main loop and masked-tail path are both covered, plus an in-place case matching the MobileClip GELU usage.
The prior test only checked MlasComputeErf against std::erf within a tolerance, which proves math correctness but not accuracy-neutrality vs the base kernel this optimization replaced. Add a direct comparison of MlasErfKernelAvx512F against the base MlasErfKernelFma3 in the same binary, asserting <= 1 ULP agreement across the erf range plus special values (NaN propagation, +/-inf, denormals, saturation). Measured divergence on AVX-512 hardware is 0 ULP (bit-exact); the 1 ULP bound is kept as the cross-microarchitecture contract. This makes the Erf verification as strong as the reorder memcmp check.
- cmake: add reorder_avx512f.cpp to Linux/Mac x64 avx512f source list to fix link-time undefined reference on non-Windows platforms - reorder_avx512f: clean up file-header comment (remove oracle-test reference) and replace confusing inline comment with reviewer-suggested phrasing Co-Authored-By: Swetha B S <swetha@multicorewareinc.com>
MlasErfKernelAvx512F and MlasErfKernelFma3 are AMD64-only; wrap their test helpers and call sites so ARM64/RISC-V builds compile cleanly. TestMathInPlace (MlasComputeErf) remains cross-platform and unguarded.
7aa0777 to
93b4773
Compare
[MLAS] AVX-512 optimizations for MobileClip-S0 FP32 CPU inference
The performance numbers taken in STRIX 365 with different thread configurations:

NOTE: The performance numbers were tested on July 31st
STRIX 365 configuration:
AMD Ryzen AI 9 365 (Strix Point) w/ Radeon 880M
Target Model: MobileClip-S0 (FP32, CPU)
Unit tests were added:
test_erf.cpp
loop and masked-tail path
test_reorder_input.cpp
tail