Skip to content

Optimize AVX2/VNNI inference with channel-major projections and gated quantize4 - #23

Open
varyagnord wants to merge 7 commits into
ceva-ip:optimized-inferencefrom
varyagnord:perf/vnni-cm64-20261110
Open

varyagnord wants to merge 7 commits into
ceva-ip:optimized-inferencefrom
varyagnord:perf/vnni-cm64-20261110

Conversation

@varyagnord

@varyagnord varyagnord commented Nov 10, 2026 •

Copy link
Copy Markdown

Eligible INT8 K64N64 pointwise projections now execute directly in channel-major layout on AVX2 and optional VEX-encoded AVX-VNNI. Retain the accepted exact AVX2 four-row quantizer, and make the new range-reuse/empty-row refinement an explicitly opt-in experiment. This PR targets ceva-ip/DPDFNet:optimized-inference, refreshed against 98df765; it includes the previously unpublished AVX2 batching/CM commits and their direct cumulative evidence.

Relationship to earlier pull requests

#20 (automatic VNNI dispatch) and #21 (per-model runtime optimizations) are already merged into the target branch. #22 (AVX2 four-row quantization and channel-major kernels) is still open. This branch contains every commit from #22, then adds VNNI CM, the gated refinement, reusable laboratory tooling and the latest qualification evidence. Thus #23 is a cumulative superset of #22, not a competing implementation. No earlier PR is closed or merged by this publication.

Runtime behavior and defaults

Both model sizes AVX2 AVX-VNNI
Eligible channel-major K64N64 projections enabled enabled
Legacy row-major four-row quantization enabled disabled
New range-reuse / empty-row refinement disabled disabled
  • DPDF_ENABLE_AVX_VNNI=ON builds hardware-dispatched VNNI when supported by the compiler. AVX2/FMA remains the fallback; no AVX-512 requirement is introduced.
  • DPDF_ENABLE_QUANTIZE4_REFINEMENT=OFF and DPDF_ENABLE_VNNI_QUANTIZE4=OFF are the selected defaults for both models. The VNNI experiment requires the refinement option. Disabling four-row VNNI quantization does not disable ordinary model quantization.
  • The experimental implementation computes each range once, shares exact range/packing helpers, bypasses all-empty groups, and neutralizes empty lanes before exact SIMD divisions. Nonzero constant rows remain active because ranges include zero. No approximate reciprocal or fast-math is introduced.
  • Preserve both model weights, numerical outputs/state, seven public exports, state ABI and libc/libm-only runtime dependencies. The NumPy audio adapter belongs to research/QA tools and adds no runtime dependency to libdpdfnet.

Why quantize4 remains experimental

The new native model-8 implementation has a confirmed incremental benefit in specific workloads. That does not establish a universal benefit for model 2, AVX2, complete audio callbacks, or dynamic Boost operation. Preserve positive and negative observations and failed A/A precision gates rather than promote a global switch from selected favorable conditions.

The following six conditions pass every preregistered precision, useful-effect and operational gate in the final study. All are on the fast Ryzen core at a verified steady nominal 2 GHz. These isolate the VNNI CM increment and the further quantize4 increment; they are not cumulative speedups against this PR's upstream base, and their percentages must not be added.

Contrast Model Workload Time reduction Family-adjusted interval
pre-VNNI-CM -> CM 2 continuous 3.127% [2.887, 3.366]%
pre-VNNI-CM -> CM 8 continuous 1.429% [1.307, 1.550]%
pre-VNNI-CM -> CM 8 paced10 1.472% [1.255, 1.687]%
pre-VNNI-CM -> CM 8 FFT/NN/IFFT, 10 ms 1.448% [1.136, 1.758]%
CM -> CM + refined quantize4 8 continuous 0.810% [0.683, 0.937]%
CM -> CM + refined quantize4 8 paced10 0.863% [0.513, 1.213]%

Only 10/72 A/A conditions meet the predefined 0.5% precision limit. No quantize4 model-2, AVX2 or complete-audio condition passes every superiority gate. Compact-core/Boost native model-8 continuous passes the separate 0.5% practical noninferiority margin, not useful superiority. An unqualified condition is inconclusive; neither absence of benefit nor absence of harm is asserted. Earlier power/layout cohorts are retained separately without pooling. Secondary direct cumulative comparisons are explicitly exploratory reconstructions of existing nonadjacent block observations, not additional primary acceptance tests.

Reproducible measurement tools

Add repository-root just recipes and a laboratory controller/worker/study split. Discover and reserve the complete L3 domain, put ordinary work on a separate domain, park the worker's SMT sibling, steer movable IRQ/workqueues, and verify actual CPPC frequency under load. Save settings before mutation, arm an independent restoration timer, run workers unprivileged with zero capabilities/no-new-privileges, and verify rollback even on failure. Unsupported isolation/frequency backends fail explicitly. Residual kernel/package interference is recorded, not claimed eliminated.

The final fixed plan spans 72 contrasts: both models, three code contrasts, fast/compact Ryzen cores, steady/Boost profiles, and continuous spectral/paced spectral/full FFT-inference-IFFT callbacks. Each condition has eight identical-binary A/A pairs and sixteen A/B pairs with balanced input/order and fresh processes. Inference uses paired process log ratios and family-72 adjusted Student intervals; serial calls are not independent replicates. Fixed process layout is checked without changing global ASLR. Retain call/process sample SD, tails, frequency, faults, switches, every slow call and input/order diagnostics.

Total: 3,456 unprofiled processes / 811,008 calls, plus 288 separate warmed PMU jobs with fully scheduled user-event groups and counter mean/SD normalized per call. Profiled durations never enter speed estimates. Observed maximum was 2.787454 ms, with no 10 ms deadline misses, late completions or major faults. All four sessions and independent final readback verify restored CPU/power/idle/IRQ/workqueue/watchdog settings, active irqbalance, no temporary cgroup/workers, inactive restoration timer and unchanged global ASLR. Preparation-only failures and recovery are retained; no measured samples were recollected or extended. A separately tested post-study error-path fix preserves controller failure/rollback JSON in future logs.

Correctness and publication verification

  • Full regenerated public/stress corpus: 65 fixtures / 147,711 hops per model. All 130 spectrum/state/reset/four-alias jobs match bitwise across five ready libraries on Ryzen.
  • Full PCM: another 130 jobs reproduce frozen FFT inputs exactly and yield bitwise equal output/state and synthesized PCM across all five libraries.
  • Red i7-7700T: 130 stream jobs across four ready libraries pass; all 130 cross-host stream digests match. This verifies AVX2 numerical portability only: red lacks VNNI and a separate housekeeping L3. Its eight service health checks remain healthy; no production service is changed or restarted.
  • Independent quantizer oracle covers all empty masks, rounding modes, FTZ/DAZ settings, guarded placements and packing/scales/zero points. Refined helper contracts run even when experiments default OFF.
  • Ready refined candidates: 42 native + 32 AVX2 CTests pass. Existing unchanged-source sanitizer/static/ISA/fresh-PGO gates are retained in the evidence.
  • Fresh selected default PGO build: 43 CTests pass, including the laboratory target's 17 behavioral tests. The resulting SO is byte-identical to the measured selected CM artifact: 26efac06d424e8907a680cbda0ce61ac30a18a557b11cdb3f27f29466288c7ae.
  • All 1,728 primary A/A and A/B pairs are published with input/order, process means, call SD, log ratios and raw-sample hashes. All 144 adjusted intervals were recomputed and checked from that portable export before publication.

The original historical reference corpus was unavailable; these checks certify the regenerated public/stress corpus. No new perceptual scores, WCET bound, arbitrary-CPU speedup or production device/audio-server/service-concurrency result is claimed. Per-call arrays and complete infrastructure journals remain in the local archive rather than being bundled. No private backlog, weight changes, service deployment or GitHub Release is included.

Review references

Most diff volume is machine-readable validation evidence; the runtime selection remains deliberately conservative.

Verified CI for published head

Both the fork push workflow and the upstream PR workflow completed successfully for head 6a078955909c29d857d8ad2bf02bdc01c9aa0a57. Every job log was inspected. Counts below distinguish passed contracts from explicit CPU-feature skips; skipped VNNI tests are not presented as execution coverage.

Configuration Fork passed / skipped Upstream passed / skipped
Shared PGO GENERATE 34/9; release 34/9 GENERATE 34/9; release 34/9
Static PGO GENERATE 33/9; release 33/9 GENERATE 33/9; release 33/9
Plain static 42/0 33/9
AVX2 fallback 33/0 33/0
ASan/UBSan 34/9 43/0

The nine explicit skips are VNNI-specific contracts on hosts without the required instruction. All VNNI contracts execute successfully in the fork plain-static job and the upstream sanitizer job, as well as in the local fresh default build. Both PGO generation/use phases pass, shared/static consumers link correctly, and each workflow retains configuration/CTest logs as artifacts. CI verifies compatibility/correctness, not the reported Ryzen speedups.

varyagnord and others added 6 commits November 7, 2026 23:20
Quantize eight frequency positions directly and transpose outputs in registers,
avoiding sixteen full float transposes per graph. Preserve exact arithmetic,
AVX2/FMA requirements, original fallback paths, weights and state ABI.

Add guarded FP-mode and all-mask regression coverage, and preserve the paired
measurement records for the precision repeats and rejected optimization trials.
Compare the pre-i7 baseline with the final runtime in 288 paired blocks per model and power condition. Preserve SD, SE, adjusted intervals, A/A discrepancies, raw block observations and isolation verification.
- Share exact channel-major quantization and output stores across AVX2/VNNI for both models.
- Reuse matrix ISA selection and retain bounded-shape/overlap fallback guards without extra context state.
- Add guarded VNNI CM oracles and an object-code contract rejecting accidental EVEX requirements.

Checks: Release/PGO/ASan/static/AVX2 contracts; 130 bitwise model-stream comparisons; CPU-mask and VEX/negative-EVEX checks; unchanged weights/public ABI. All temporary CPU/IRQ settings restored.

Measured on one Ryzen HX 470 high-frequency core: continuous-call reductions 2.765%/1.545%; paced 10-ms gains were not confirmed. No general-platform or cumulative VNNI claim.
- Retain channel-major projections for both models and legacy AVX2 batching.
- Keep exact range-reuse and VNNI four-row experiments disabled by default.
- Reuse ranges, bypass all-empty divisions and safely neutralize mixed lanes.
- Preserve an independent oracle across masks, rounding, FTZ/DAZ and guards.
- Add reversible L3/SMT isolation, hardware frequency checks and paired studies.
- Record conditional gains without promoting noisy or unqualified outcomes.

Checks:
- Fresh default PGO: 43 contracts pass; library byte-identical to measured CM.
- Ready refined candidates: 42 native and 32 AVX2 contracts pass.
- All 17 unprivileged laboratory behavioral tests pass.
- Full regenerated streams/PCM and red AVX2 portability pass for both models.
- 811008 unprofiled calls, 288 separate PMU jobs; restoration verified.
- Publish all 1728 primary A/A and A/B process pairs with input/order and SD.
- Independently reproduce all 144 adjusted intervals from portable evidence.
- Distinguish legacy AVX2 batching from disabled quantize4 refinements.
- Describe qualified CM/model8 gains and retain noisy Boost outcomes honestly.
- Record fresh default PGO identity, 43 passing contracts and restored settings.

Checks:
- Portable paired intervals match published summaries within 1e-10.
- Fresh selected PGO SO matches the measured SHA-256 byte for byte.
- git diff --cached --check.
Keep the validation summary and link to the preserved reports at the original branch revision. Runtime and test sources are unchanged. Verified with a Release build and CTest.

This branch has not been deployed

No deployments
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