Skip to content

Add automatic AVX-VNNI dispatch for native W7A8 inference - #20

Merged
danielr55 merged 3 commits into
ceva-ip:optimized-inferencefrom
varyagnord:perf/avx-vnni-int8-dispatch
Oct 20, 2026
Merged

danielr55 merged 3 commits into
ceva-ip:optimized-inferencefrom
varyagnord:perf/avx-vnni-int8-dispatch

Conversation

@varyagnord

@varyagnord varyagnord commented Oct 12, 2026 •

Copy link
Copy Markdown

Quantized inference currently uses AVX2 multiply/add reductions even on CPUs with AVX-VNNI. This adds automatic, initialization-time selection of VEX-encoded VPDPBUSD kernels while retaining the same AVX2/FMA baseline, weights, quantization, floating-point instruction order, and seven-symbol public ABI.

This targets optimized-inference, which contains the maintained native runtime, rather than the Python-only default branch.

Implementation

  • Isolate AVX-VNNI in a separate translation unit and assembly specializations. Check compiler support; gracefully retain AVX2 when unsupported or when DPDF_ENABLE_AVX_VNNI=OFF.
  • Select private affine/paired function pointers when each quantized matrix is created. No CPU probing or allocation during inference, no global CPU-specific compiler flags, and no AVX-512 requirement.
  • Share the C algorithm between variants and derive checked-in VNNI assembly from unchanged AVX2 sources. A generator consistency check runs in CI.
  • Preserve numerical behavior: with unsigned activations ≤254 and signed weights in [-63,63], AVX2's intermediate pair sum is bounded by 32004 and cannot saturate. The non-saturating VNNI reduction produces the same integers.
  • Account for two additional private pointers per matrix: +4,016 bytes/model 2 and +5,552 bytes/model 8. Document dispatch, fallback builds, and regeneration.

Validation

  • Release with independently fresh model-8 PGO: 27/27 contracts passed.
  • ASan/UBSan: 27/27 passed; static AVX2-only build: 21/21 passed.
  • New dispatch contract compares single and paired outputs bitwise against AVX2 across 256 shape/pattern cases per model. Reuse guarded-page scalar assembly oracles for VNNI, including unaligned buffers and rounding/FTZ/DAZ modes.
  • The same VNNI-enabled binary, run with QEMU's Haswell CPU model, selects AVX2 and passes both dispatch contracts.
  • Three public HushMic fixtures (fan, café, keyboard): 3,668 hops/model, with every spectrum, recurrent state and synthesized PCM hop matching the unmodified baseline bitwise; reset replay and independent concurrent contexts also pass.
  • The upstream 65-fixture regression set is not distributed with the runtime and was not available for this run. No quality metric or full upstream fixture-suite claim is made.

Performance on Intel Core i7-1255U

GCC 16.2.1, Linux, powersave governor, one P core (logical CPU 2), identical deterministic synthetic spectra, 120 warm-up hops and 1,000 timed hops/fresh process. Alternate AB/BA ordering; eight runs/variant for continuous mode and four for 10 ms paced mode. Both builds use fresh independent PGO profiles; compilation and sanitizer checks completed before measurement. Values are mean ± SD of run means, in ms/hop.

Model Mode Baseline AVX-VNNI Mean reduction
2 continuous 0.799 ± 0.117 0.635 ± 0.056 20.5%
8 continuous 1.711 ± 0.219 1.365 ± 0.060 20.2%
2 paced 1.131 ± 0.060 0.996 ± 0.068 11.9%
8 paced 2.170 ± 0.129 1.678 ± 0.212 22.7%

Neither variant exceeded 10 ms in these runs. These are target-specific performance results, not a universal speedup or an end-to-end audio quality benchmark. Raw runs, fixture hashes and validation conditions are included in optimized_inference/validation/avx_vnni_alder_lake.json.

Baseline: 5d497fd9452225fff4bddb122c0595de4840aa6f. Existing public release measurements remain explicitly identified as historical AVX2 references.

CI

All four native CI configurations passed in the fork on this commit: shared PGO, static, explicit AVX2 fallback, and ASan/UBSan, using Ubuntu 22.04's GCC. The compiler VNNI check succeeds; the six direct VNNI assembly tests correctly skip on the runner's CPU without that feature. They all execute and pass on the local AVX-VNNI host. The upstream PR workflow currently awaits first-contributor approval. A source-directory path containing a space was also tested: the VNNI compiler/assembler probe, guarded fused oracle, and 256-case dispatch contract all pass.

Keep AVX2/FMA compatibility and the public API unchanged. Isolate VEX VNNI kernels, derive assembly from existing sources, and validate exact numerical output and guarded memory boundaries for both models.
Keep the VNNI feature probe nonconstant so it exercises instruction emission, and quote the test-only forced include when the source path contains spaces. Both dispatch and guarded fused contracts pass from a source directory containing a space.

@danielr55 danielr55 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting one build fix before approval. The core dispatch implementation and integer-equivalence argument look sound from source review.

  1. Fix PGO linking for the new model-8 VNNI tests. In optimized_inference/CMakeLists.txt around lines 160-168, the new test executables include backend8 object files directly but only link m. With DPDF_PGO_MODE=GENERATE and BUILD_TESTING=ON, those objects are instrumented with -fprofile-generate, so omitting that option at link time is expected to leave __gcov_* runtime references unresolved. Please apply the same conditional already used by the existing model-8 contract targets:
if(DPDF_PGO_MODE STREQUAL "GENERATE" AND size EQUAL 8)
  target_link_options(${target} PRIVATE -fprofile-generate=${DPDF_PROFILE_DIR})
endif()

Please verify this configuration on a GCC toolchain that passes the VNNI compiler probe:

cmake -S optimized_inference -B build/pr20-pgo-generate -DDPDF_PGO_MODE=GENERATE -DBUILD_TESTING=ON -DDPDF_ENABLE_AVX_VNNI=ON
cmake --build build/pr20-pgo-generate --parallel 2 --target model8_fused_contract_vnni model8_pair_contract_vnni

This finding comes from source inspection; the link failure was not reproduced in a native build environment. The recommended build driver disables tests during profile generation, so its successful CI run does not cover this combination. GCC requires the profile-generation flag during both compilation and linking: https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fprofile-generate

  1. Validate the revised commit. Please rerun the shared PGO, static, explicit AVX2 fallback, and ASan/UBSan configurations after the fix. The upstream workflow also needs maintainer authorization before it can provide the PR's CI result.

  2. Provide reproducible VNNI execution evidence. Please include commands and execution output for both dispatch contracts and all six direct VNNI assembly contracts on a VNNI-capable CPU. The fork CI logs confirm that the six direct VNNI tests were skipped. The reported local results are useful; reproducible execution output would make the new path easier to verify.

@danielr55 danielr55 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the PGO linking issue. All checks passed. Approved and merged.

@danielr55
danielr55 merged commit afa8292 into ceva-ip:optimized-inference Oct 20, 2026
4 checks passed
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.

2 participants