From b7219a7d5dfed13b2d68f373611a56565bb676f5 Mon Sep 17 00:00:00 2001 From: Varyag Nord Date: Sun, 22 Nov 2026 00:26:37 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Enable=20fused=20K64=20projections?= =?UTF-8?q?=20for=20model=208=20on=20AVX-VNNI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reuse the validated four-row VNNI assembly for eligible batch and paired projections while preserving model 2, AVX2, and the public ABI. Extend the existing fused contract to run directly in the model-8 VNNI namespace and cover independent FTZ and DAZ combinations. Validation: 35 native PGO, 34 static ASan/UBSan and 28 AVX2-only CTests passed. --- optimized_inference/CMakeLists.txt | 6 ++++++ optimized_inference/docs/PERFORMANCE.md | 15 +++++++++++++++ optimized_inference/src/common/int8_kernels.inc | 16 +++++++++++----- optimized_inference/tests/pair_fused_contract.c | 6 +++--- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/optimized_inference/CMakeLists.txt b/optimized_inference/CMakeLists.txt index 1c88c8a..b78c71e 100644 --- a/optimized_inference/CMakeLists.txt +++ b/optimized_inference/CMakeLists.txt @@ -85,6 +85,10 @@ foreach(size IN ITEMS 2 8) if(size EQUAL 8) target_sources(backend8 PRIVATE src/models/dpdfnet2_48khz_hr/qaffine4pair64_fused_avx2.S) target_compile_definitions(backend8 PRIVATE DPDF_QBATCH_FUSED64_AVX2) + if(DPDF_ENABLE_AVX_VNNI AND DPDF_COMPILER_HAS_AVX_VNNI) + target_compile_definitions(backend8 PRIVATE DPDF_MODEL8_VNNI_FUSION) + target_sources(backend8 PRIVATE src/models/dpdfnet2_48khz_hr/qaffine4pair64_fused_vnni.S) + endif() endif() target_compile_options(backend${size} PRIVATE $<$:-fno-math-errno>) # Only model 8 had a confirmed incremental branch-alignment benefit. @@ -228,6 +232,8 @@ if(BUILD_TESTING) set(vnni_contracts fused_contract pair_contract) if(size EQUAL 2) list(APPEND vnni_contracts wide_contract pair_fused_contract) + else() + list(APPEND vnni_contracts pair_fused_contract) endif() foreach(test IN LISTS vnni_contracts) set(target "model${size}_${test}_vnni") diff --git a/optimized_inference/docs/PERFORMANCE.md b/optimized_inference/docs/PERFORMANCE.md index 33ac22a..19d809b 100644 --- a/optimized_inference/docs/PERFORMANCE.md +++ b/optimized_inference/docs/PERFORMANCE.md @@ -4,6 +4,21 @@ The current defaults were selected separately for models 2 and 8 on an Intel Core i7-7700T. The older i7-8700 latency/quality records below describe the historical package baseline; they were not remeasured for these defaults. +## Model 8 AVX-VNNI fused K64 projections + +On CPUs selected by the existing AVX-VNNI dispatch, model 8 reuses the +four-row fused kernel for eligible K64 batch and paired projections. It +combines the packed integer dot products with the existing floating-point +scale and bias. The existing shape guards, quantization arithmetic, and +model weights and public ABI are preserved. Model 2 and the AVX2 path keep +their existing kernel selection. + +In the [paired Ryzen qualification on the channel-major baseline](https://github.com/varyagnord/DPDFNet/blob/bd4138752e2c100ced0a59ecf78e4b203b4901f3/optimized_inference/docs/MODEL8_VNNI_EXPERIMENTS.md), +six model-8 workloads passed the useful-gain, precision, and operational +gates, with 0.80–1.21% lower inference or callback time in those conditions. +This range describes that measured configuration. Other conditions were +inconclusive, including the full-audio Boost runs. + ## i7-7700T final per-model selection (2026-10-27) G replaces depthwise gather with bounded loads/permutations; V combines an diff --git a/optimized_inference/src/common/int8_kernels.inc b/optimized_inference/src/common/int8_kernels.inc index 8fefbb2..2dd8cc0 100644 --- a/optimized_inference/src/common/int8_kernels.inc +++ b/optimized_inference/src/common/int8_kernels.inc @@ -10,9 +10,15 @@ _mm256_maddubs_epi16(a,w),_mm256_set1_epi16(1))) #endif -#if defined(DPDF_QPAIR_FUSED64) || (defined(DPDF_QBATCH_FUSED64_AVX2) && !defined(DPDF_INT8_VNNI)) +#if defined(DPDF_QPAIR_FUSED64) || (defined(DPDF_QBATCH_FUSED64_AVX2) && !defined(DPDF_INT8_VNNI)) || (defined(DPDF_MODEL8_VNNI_FUSION) && defined(DPDF_INT8_VNNI)) +#define DPDF_USE_QBATCH_FUSED64 +#endif +#if defined(DPDF_QPAIR_FUSED64) || (defined(DPDF_MODEL8_VNNI_FUSION) && defined(DPDF_INT8_VNNI)) #define DPDF_USE_QPAIR_FUSED64 #endif +#if defined(DPDF_USE_QBATCH_FUSED64) || defined(DPDF_USE_QPAIR_FUSED64) +#define DPDF_USE_FUSED4 +#endif static void quantize(const float *x,int8_t *out,int k,float *scale,int *zp) { __m256 lo=_mm256_setzero_ps(),hi=lo; @@ -256,9 +262,9 @@ static __attribute__((noinline)) void qdot4pair(const int8_t *activation, qdot4pair_generic(activation,packed0,packed1,k,out); } -#if DPDF_MODEL_SIZE == 2 || defined(DPDF_USE_QPAIR_FUSED64) +#if DPDF_MODEL_SIZE == 2 || defined(DPDF_USE_FUSED4) -#ifdef DPDF_USE_QPAIR_FUSED64 +#ifdef DPDF_USE_FUSED4 #include "pair_fused_args.h" static inline __attribute__((always_inline)) void qpair_fused4( const dpdf_qmatrix *q0,const dpdf_qmatrix *q1,const int8_t *activation, @@ -289,7 +295,7 @@ static void qaffine_batch_tiled(const dpdf_qmatrix *q,const float *x,const float #else for (int r=0;r