mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5243] [Engine] perf(cpu): AVX-512 (Zen 4/5 & Intel) and Arm64 NEON/DotProd (Apple M, Oryon, Grace/DGX GB10) expert & quantizer kernels #5360
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5360
Loadingā¦
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
š Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/5243
Author: @bsorensen110
Created: 11/4/2026
Status: š Open
Base:
mainā Head:perf/cpu-avx512-zen5š Commits (4)
874185eperf(cpu): admit AMD Zen 5 (family 0x1A) into the AVX-512 gather gate; dpwssd in the IQ3 512-bit row dot2ee6c21build(x86): STRATA_X86_ISA=zen5 ggml target (VBMI/VNNI/BF16/AVX-VNNI/BMI2) + qk_dot_bench89e9b5eperf(cpu): implement AVX-512 VNNI/VBMI/VPOPCNTDQ expert kernels with Zen 4/5 & Intel gatingab90bb6perf(cpu-arm64): implement NEON/DotProd expert & quantizer kernels for Apple M, Oryon X1/X2, and Grace/GB10š Changes
19 files changed (+3439 additions, -421 deletions)
View changed files
š
CMakeLists.txt(+66 -0)š
include/strata/kernels/cpu/expert_layout.hpp(+10 -4)š
include/strata/kernels/cpu/iq_avx512.hpp(+25 -2)š
include/strata/platform/cpu_relax.hpp(+8 -1)š
metal/src/engine/stubs.cpp(+6 -0)š
src/core/expert_source.cpp(+1 -1)š
src/dsv41/ds4_gg_cpu.cpp(+20 -6)ā
src/kernels/cpu/arm_neon_parity.cpp(+228 -0)ā
src/kernels/cpu/arm_neon_sim.hpp(+201 -0)š
src/kernels/cpu/expert_layout.cpp(+169 -3)š
src/kernels/cpu/iq512_gather_parity.cpp(+1 -1)š
src/kernels/cpu/iq_avx512.cpp(+1256 -298)š
src/kernels/cpu/kq_avx2.cpp(+11 -0)š
src/kernels/cpu/native_arithmetic_parity.cpp(+5 -3)š
src/kernels/cpu/native_expert.cpp(+154 -24)š
src/kernels/cpu/portable.cpp(+1196 -77)š
src/kernels/cpu/q8k_quant_parity.cpp(+9 -1)ā
src/kernels/cpu/qk_dot_bench.cpp(+71 -0)š
tools/check_isa_guard.py(+2 -0)š Description
Summary
This draft PR overhauls and extends Strata's CPU expert, activation quantizer, and router kernels across x86-64 AVX-512 (AMD Zen 5, AMD Zen 4, Intel Sapphire Rapids / Emerald Rapids / Granite Rapids, and Intel Ice Lake / Tiger Lake / Rocket Lake) and Arm64 NEON +
FEAT_DotProd(SDOT) (Apple M1āM5, NVIDIA DGX Spark GB10 / Grace Neoverse-V2 / Vera, and Qualcomm Oryon X1/X2), while preserving bit-for-bit parity againstggml-cpuacross1..Ntokens.Request for Hardware Testing
This branch was developed and benchmarked on AMD Zen 5 (Ryzen 9 9950X3D + RTX 5080, Windows 11, MSVC 14.44). Hardware-specific dispatch gates and cross-ISA parity harnesses (
arm_neon_parityviaarm_neon_sim.hpp) have been verified locally across all dispatch modes, and we are requesting on-hardware testing and benchmark feedback on:0x19, double-pumped 256-bit AVX-512)vpgatherdd/vpgatherdqwithGDS_NO=1)#UDonvpopcntd/vpermbor AVX-512 turbo-license downclocking)FEAT_DotProdwhen running CPU-offloaded experts or CPU-only builds)GB10Cortex-X925 + Cortex-A725) & Grace (Neoverse-V2) (Linuxaarch64ā Arm64 NEON +FEAT_DotProd-DSTRATA_ARM64_ISA=gb10/grace)What Changed
1. x86-64 AVX-512 VNNI / VBMI / VPOPCNTDQ Kernels & Microarchitectural Gating (
874185e3b,2ee6c2169,89e9b5e25)expert_layout.cpp,tools/check_isa_guard.py):cpu_avx512_ok()now requires all 7 feature bits used byiq_avx512.cpp:AVX512F(EBX[16]),AVX512DQ(EBX[17]),AVX512BW(EBX[30]),AVX512VL(EBX[31]),AVX512_VBMI(ECX[1]),AVX512_VNNI(ECX[11]), andAVX512_VPOPCNTDQ(ECX[14]), plus OS stateXCR0 & 0xE6 == 0xE6. Pre-Ice Lake Intel CPUs (Skylake-X / Cascade Lake / Cooper Lake) lackVBMIandVPOPCNTDQand stay safely on 256-bit AVX2.std::vectortemporaries insideiq_avx512.cppwithScratchBytes/ fixed stack buffers so no weak/COMDATstd::vectorsymbols containing EVEX instructions are emitted into the binary, and registered the new public entry points inWIDE_PUBLIC(0check_isa_guard.pyviolations).cpu_gather_fast(),gather_for_type<TY>()):cpu_gather_fast()to admit AMD family>= 0x1A(Zen 5) using extended CPUID leaf0x80000000/0x80000001(leaf 0max_leaf=13on Zen 5 covers only basic leaves) and AMD'sEBX+EDX+ECX("Auth"+"enti"+"cAMD") vendor register order.GATHERa compile-time template parameter onFmt<TY>::decode<GATHER>()so MSVC never merges the 16-index scalar-load GPR pressure into the gather path.Fmt<21>::decode<false>(IQ3_S) androws_m(IQ1_M) ZMM-to-stackuint32_t ix[16]stores + scalar reloads (which caused 8 store-to-load forwarding stalls per block) with direct GPR bit-extraction (q[k] | ((h0 << (8 - k)) & 0x100)).!GATHER) beatvpgatherdq/vpgatherddacross all 5 I-quant grid formats (16, 17, 18, 21, 22) on AMD Zen 5 by 8ā41% (dual FP1/FP2 512-bit shuffle units + 4 load ports), as well as on AMD Zen 4 (microcoded gather) and Intel Ice Lake / Tiger Lake / Rocket Lake (GDS / Downfall microcode penalty).cpu_gather_fast() && !is_amd_cpu()), Golden Cove / Redwood Cove P-cores fuse Ports 0+1 for 512-bit execution, leaving Port 5 as the sole 512-bit shuffle unit while Ports 2 & 3 execute 2 gathers/cycle with hardwareGDS_NO=1;gather_for_type<TY>()therefore enablesGATHER=trueon Intel SPR+ andGATHER=falseon AMD and pre-SPR Intel (STRATA_IQ_GATHER=0/1overrides all types).nt == 1) Tier Gate (fast512_1t = cpu_gather_fast(), overrideSTRATA_AVX512_1T=0/1):nt == 1forIQ2_XXS,IQ2_XS,IQ2_S,IQ3_XXS,IQ3_S,Q5_K, andQ2_0.nt == 1only for theVPOPCNTDsign-mask formats (16, 17, 18:IQ2_XXS,IQ2_XS,IQ3_XXS) and engage 512-bit atnt >= 2forIQ3_S,IQ2_S,IQ4_XS,IQ4_NL,Q2_0, and K-quants.iq_avx512.cpp,native_expert.cpp,ds4_gg_cpu.cpp):VPOPCNTDQsign masks (sign_mask_from_idx): replaces 8 scalarksigns_iq2xstable loads + 16 shifts/ORs per block with_mm256_popcnt_epi32.row_gu_dot(I-quants16, 17, 18, 21, 22, 23) andgu_q4_k_512/gu_q5_k_512/gu_q6_k_512loady[t][i].qsandy[t][i].bsumsonce per token across Gate and Up projections.Q6_Kscale shuffle: replaced cross-lane_mm512_permutexvar_epi16(vpermw, 6 uops / 3c throughput on Zen 4) indot_q6_k_512andgu_q6_k_512with in-lane_mm512_shuffle_epi8(vpshufb, 1 uop).Fmt<23>(IQ4_XS),iq4nl512_down_rows(IQ4_NLdual-accumulator bit-exact),q2_512_down_rows(Q2_064-weight blocks),kq512_gu_rows&kq512_rows(Q4_K,Q5_K,Q6_K,Q5_0,Q5_1,Q8_0),q8k_quant_avx512(bit-exact 512-bitQ8_Kactivation quantizer), andbf16_rows_dot_512/bf16_rows_dot_multi_512(4-token-tiled AVX-512BF16router dot).-DSTRATA_X86_ISA=zen5CMake target (CMakeLists.txt,qk_dot_bench.cpp): works around MSVCFindSIMDprobing only/arch:AVX512without defining__AVX512VNNI__/__AVX512VBMI__/__AVX512BF16__/__AVXVNNI__/__BMI2__insideggml-cpu.2. Arm64 NEON +
FEAT_DotProd(SDOT) Kernels & Cross-OS Hardware Gating (ab90bb6cb)Q8_K&Q8_1Activation Quantizers (src/kernels/cpu/portable.cpp):ggml-cpu/arch/arm/quants.c's scalarquantize_row_q8_K_reffallback on Arm64 with a 4-way unrolled NEON quantizer (vmaxnmq_f32NaN-safe max, IEEE-75412582912.fround-to-even magic float,vmovn_s32/vmovn_s16narrowing, andvaddvq_s32bsums[16]), plus hardwareFCVTAS(vcvtaq_s32_f32) inact_quant_q8_1.1..8tokens) Arm64SDOTExpert Kernels (portable.cpp):portable.cppstubbed outiq256_gu_rows,iq256_rows,iq4nl256_down_rows,q2_0_gguf_rows_multi_avx2,kq256_gu_rows, andkq256_rows, forcingnative_expert.cppto callggml-cpu's single-tokenvec_dot2 * nttimes per Gate+Up row andnttimes per Down row.16, 17, 18, 21, 22, 23): vectorized NEONCNT(vcnt_u8) odd-parity sign generator (arm_signs4_from_idx7) eliminates 8 scalarkeven_signs_q2xs[128]table loads per 64 weights;arm_iq_gu_dotshares activation loads across Gate and Up and decodes weights once across1..4tokens usingvdotq_s32(SDOT).SDOTkernels forIQ4_NL(20),Q2_0(42),Q4_K(12, including fusedarm_gu_q4_k),Q5_K(13),Q6_K(14),Q5_0(6),Q5_1(7), andQ8_0(8), plus a 4-token-tiled NEONBF16router dot (bf16_rows_dot_multi).arm_neon_paritySimulator (expert_layout.cpp,cpu_relax.hpp,arm_neon_sim.hpp,arm_neon_parity.cpp):cpu_arm_neon_ok(),cpu_arm_dotprod_ok(),cpu_arm_i8mm_ok(), andcpu_arm_bf16_ok()across macOS (sysctlbyname), Linux (getauxval(AT_HWCAP)), and Windows 11 Arm64 (_M_ARM64IsProcessorFeaturePresent), plus_M_ARM64__yield()/__dmb()support incpu_relax.hpp.-DSTRATA_ARM64_ISA={apple-m1..m4,oryon-x1,oryon-x2,grace,gb10}CMake option.arm_neon_sim.hppand thearm_neon_parityCTest target so all 17 Arm64 NEON/SDOTkernels are tested bit-for-bit on x86-64 CI as well as native Arm64.Hardware Dispatch Summary
cpu_avx512_ok()/ Arm ProbeGATHER(gather_for_type)nt == 1(fast512_1t)nt >= 2Multi-Tokenfam >= 0x1A: Ryzen 9000, Strix, Turin)1)false(2Ć 512b shuffle + 4 load ports: +8ā41% faster than gather)IQ2_XXS/XS/S,IQ3_XXS/S,Q5_K,Q2_0,Q8_K,BF16IQ4_NL,Q2_0fam == 0x19: Ryzen 7000/8000, Genoa)1)false(avoids 32ā44 uop microcoded gather)VPOPCNTDtypes (IQ2_XXS/XS,IQ3_XXS),Q8_K,BF16; 256-bit for othersIQ4_NL,Q2_01)true(Ports 2&3 hardware gather,GDS_NO=1, offloads Port 5 shuffle)IQ2_XXS/XS/S,IQ3_XXS/S,Q5_K,Q2_0,Q8_K,BF16IQ4_NL,Q2_01)false(avoids GDS / Downfall microcode penalty)VPOPCNTDtypes (IQ2_XXS/XS,IQ3_XXS),Q8_K,BF16; 256-bit for othersIQ4_NL,Q2_00)iq256_*,kq256_*,q8k_quant_avx2)cpu_arm_dotprod_ok() == 1TBL/ GPR loads +CNT(vcnt_u8) parityarm_iq_gu_dot/arm_gu_q4_k, NEONQ8_K&Q8_1quantizersSDOT(1..8tokens) across all 14 formatsPerformance Measurements (AMD Ryzen 9 9950X3D + RTX 5080)
Test System: AMD Ryzen 9 9950X3D (Zen 5, family
0x1A, 16 threads in pool) + NVIDIA RTX 5080 (16 GB), Windows 11, MSVC 14.44 + CUDA 13.0 Release, comparingorigin/main(ffa80d731) vs this branch.1. End-to-End Live Server A/B (
Swift IQ3_XXS, 4 Alternating Sessions)Measured via live HTTP server A/B (4 interleaved sessions:
main r1 ā avx512 r1 ā main r2 ā avx512 r2, MTP speculative decoding enabled, ~16ā19% CPU expert cache miss rate during decode):origin/main(ffa80d731)perf/cpu-avx512-zen5122.6 tok/s144.8 tok/s+18.1%(-15.3%wall)302.1 tok/s329.1 tok/s+8.9%745.5 tok/s832.8 tok/s+11.7%(-10.9%wall)3016.7 tok/s3019.1 tok/s+0.1%(unchanged)152.8 tok/s166.8 tok/s+9.2%(MTP accept72.0% ā 71.7%)159.9 tok/s166.4 tok/s+4.1%144.6 tok/s160.1 tok/s+10.7%(-9.9%wall, MTP69.2% ā 69.9%)2. Activation Quantizer, Router &
ggml-cpuDot Microbenchmarks (1 Thread, Cache-Resident)origin/main)perf/cpu-avx512-zen5Q8_KActivation Quantizer (q8k_quant_avx512)543 ns(AVX2) /2160 ns(ggml-cpu)459 ns-15.5%(1.18Ćvs AVX2,4.70Ćvsggml-cpu)BF16Router Lookahead Dot (1 layer, 4 tokens)0.120 ms(AVX2)0.084 ms-30.0%(1.43Ć)qk_dot_benchq8_0 Ć q8_0(-DSTRATA_X86_ISA=zen5)1378ā1415 GB/s1791ā1854 GB/s+27% to +34%(__AVX512VNNI__vpdpbusd)qk_dot_benchq6_K Ć q8_K(-DSTRATA_X86_ISA=zen5)5789 GB/s6400 GB/s+10.6%3. Single-Thread Cache-Resident Expert Gate+Up Latency (
native_expert_parity --synthetic, 3-Rep Median)gu / down)nt)origin/mainperf/cpu-avx512-zen5iq3_s / iq4_nlnt = 1272 µs196 µs(7.19 GB/s)-27.9%(1.39Ć)iq3_s / iq4_nlnt = 3307 µs244 µs-20.5%(1.26Ć)iq3_xxs / iq4_nlnt = 1230 µs(iq512) /182 µs(ggml)144 µs-37.4%vsiq512/-20.9%vsggmliq3_xxs / iq4_nlnt = 3263 µs170 µs-35.4%(1.55Ć)iq2_xxs / iq4_nlnt = 1172 µs111 µs-35.5%(1.55Ć)iq2_xxs / iq4_nlnt = 3213 µs144 µs-32.4%(1.48Ć)iq4_xs / iq4_nlnt = 3279 µs115 µs-58.8%(2.43Ć)4. Full Expert Throughput (
kq_cpu_bench --mb 256 --reps 3, Interleaved Medians, GB/s of Weights)gu / down)nt=1, 1t(main ā branch)nt=1, 16t(main ā branch)nt=3, 1t(main ā branch)nt=3, 16t(main ā branch)iq3_s / iq4_nl8.7 ā 9.2 GB/s(+5.7%)57.1 ā 66.5 GB/s(+16.5%)5.9 ā 6.9 GB/s(+16.9%)44.5 ā 53.8 GB/s(+20.9%)iq4_xs / iq4_nl19.5 ā 19.7 GB/s(+1.0%)80.1 ā 75.9 GB/s(DRAM ceiling)7.5 ā 13.1 GB/s(+74.7%)52.2 ā 72.4 GB/s(+38.7%)q4_K / q5_127.8 ā 28.0 GB/s(+0.7%)75.6 ā 74.9 GB/s(DRAM ceiling)9.8 ā 17.0 GB/s(+73.5%)66.3 ā 76.1 GB/s(+14.8%)q5_K / q8_032.0 ā 37.8 GB/s(+18.1%)~75.5 GB/s(DRAM ceiling)11.4 ā 21.5 GB/s(+88.6%)71.5 ā 75.8 GB/s(+6.0%)q6_K / q8_043.4 ā 46.4 GB/s(+6.9%)~75.5 GB/s(DRAM ceiling)16.9 ā 26.7 GB/s(+58.0%)~75.5 GB/s(DRAM ceiling)q8_0 / q8_046.3 ā 48.3 GB/s(+4.3%)74.4 ā 74.1 GB/s(DRAM ceiling)16.0 ā 24.5 GB/s(+53.1%)74.2 ā 73.0 GB/s(DRAM ceiling)iq2_xxs/xs/s & iq3_xxs / iq4_nl+8% to +35%across all 4 pairs~65ā75 GB/s)+27% to +40%across all 4 pairs+10% to +22%Verification & How to Test on Target Hardware
Local Verification Completed (Ryzen 9 9950X3D, Windows 11, MSVC 14.44)
arm_neon_parity: 17/17 passed (bit-exactQ8_K/Q8_1quantizers + width-invariant multi-token parity across all 14 expert formats viaarm_neon_sim.hpp)native_arithmetic_parity: 5,197,824 finite bitwise comparisons passedq8k_quant_parity: 16 rows Ć 4 sizes bit-exact (identical)iq512_gather_parity:gather 0andgather 1passed across all 6 I-quant types (16, 17, 18, 21, 22, 23)iq_avx2_parity/iq_avx1_parity/router_dot_parity/nvfp4_avx512_parity: 0 failuresnative_expert_parity --synthetic(iq2_xxs/iq4_nl,iq3_xxs/iq4_nl,iq3_s/iq4_nl,iq4_xs/iq4_nl): 0 failures across all 4 dispatch configurations:fast512_1t=1,GATHER=0)STRATA_AVX512_1T=0,GATHER=0)STRATA_AVX512_1T=1,STRATA_IQ_GATHER=1)STRATA_FORCE_ISA=avx2)tools/check_isa_guard.py+tools.test_check_isa_guard: 0strata_kernels_cpuviolations, 10/10 unit tests pass.How to Test on Requested Hardware
1. AMD Zen 4 & Intel AVX-512 (Sapphire Rapids+, Ice Lake+, Skylake-X)
2. Apple M-Series (M1āM5) & NVIDIA DGX Spark (
GB10) / Grace (Neoverse-V2)š This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.