GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — CPU aarch64: NEON + i8mm variant for 128-bit SVE cores (Neoverse N2 / V2: Q4_0 / Q8_0 / Q4_K repack 1.3x) by danielhanchen · Pull Request #58 · unslothai/stable-diffusion.cpp Conversation
|
| weight | path | #49 ms | this PR ms | speedup |
|---|---|---|---|---|
| Q4_0 | repack 4x4 dotprod -> 4x8 smmla | 39.8 (13.0) | 30.9 (10.1) | 1.29x (1.29x) |
| Q8_0 | repack 4x4 -> 4x8 | 48.7 (15.8) | 37.3 (12.2) | 1.30x (1.30x) |
| Q4_K | repack 8x4 -> 8x8 | 72.7 (23.6) | 56.8 (18.2) | 1.28x (1.30x) |
| Q5_K | repack 8x4 -> 8x8 | 80.9 (26.4) | 68.8 (22.4) | 1.18x (1.18x) |
| Q6_K | repack 8x4 -> 8x8 | 75.8 (25.0) | 74.2 (24.3) | 1.02x (1.03x) |
| Q4_1 | vec_dot -> two-row smmla vec_dot |
202.1 (67.0) | 133.4 (44.0) | 1.52x (1.52x) |
| F16, BF16, IQ4_NL, Q5_0, Q5_1, Q2_K, Q3_K, IQ* | unchanged | 1.00x |
Errors vs an F64 GEMM over the dequantized weights are unchanged (same activation quantization, normalised MSE 2.6e-05 / 3.9e-05). test-backend-ops test -b CPU -o MUL_MAT: 2510/2510 on #49 and on this PR's variant.
Emulated-CPU gate (cpu_dispatch_gate.sh, the prebuilt workflow's Linux legs on staging, together with #56 / #57): neoverse-v1-sve128 and max-sve128 load armv8.6_0, neoverse-v1 keeps armv8.6_1, max keeps armv9.2_2, max-sve128+keep (GGML_CPU_ARM_SVE128=1) keeps armv9.2_2, cortex-a76 keeps armv8.2_2, cortex-a53 keeps armv8.0_1; iqk enabled in every dotprod variant; no illegal instruction anywhere. The x86 leg (Nehalem to Sapphire Rapids under Intel SDE) is unchanged and green.
With #56 on top, its BF16 / Q5_0 / Q5_1 kernels also run in this variant (#56 keeps the tinyBLAS hook in i8mm builds): BF16 3117 -> 166 ms, Q5_0 1.27x, Q5_1 1.38x on the same runner.
End to end on the same runner (FLUX.2-klein-4B, 512 x 512, 2 steps, --backend cpu, with #56 / #57 on top, 2 reps each, reps within 1%):
| run | #49 (armv8.2_2) | this PR (armv8.6_0) | speedup |
|---|---|---|---|
| Q4_0 DiT (Q4_0 / Q4_K / Q6_K weights), s/step | 31.55 | 23.07 | 1.37x |
| Q4_K_M DiT, s/step (3 reps) | 48.98 | 37.08 | 1.32x |
Q4_1 DiT, s/step (3 reps, smmla vec_dot) |
110.85 | 72.70 | 1.52x |
| Qwen3-4B Q4_K_M text encoder, s | 12.96 | 10.18 | 1.27x |
| Qwen3-4B Q8_0 text encoder, s | 9.97 | 7.44 | 1.34x |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…t on Linux The sysfs loop read /sys/devices/system/cpu<N>/topology/thread_siblings (missing the /cpu path component), never opened a file, and always fell back to half of std::thread::hardware_concurrency(). That halves every core count on a host without SMT and ignores taskset / container cpusets (a 8-CPU cpuset on a 192-CPU host ran 96 threads). Count the distinct thread-sibling sets among the CPUs in the process affinity mask instead, falling back to the old estimate over the allowed CPUs when sysfs has no topology.
…ical) The CPU CONV_2D / CONV_3D kernels (--conv-direct) gathered each patch element by element across all input planes, and wrote each GEMM output element into a different output plane. Process up to 64 consecutive patches of one output row at a time instead: each source row segment is read once per run and each output plane gets a contiguous row segment. Same values and the same fp32 -> fp16 conversions in the same slots, so results are bit-identical to the per-patch loops.
… AVX-VNNI 0008 dropped the AVX512 variants on every CPU without AVX-VNNI because Zen 4 ran them 15 to 50% slower than AVX2. That also took them from Intel Skylake-SP, Cascade Lake and Ice Lake, which run them much faster: on a 6-core Cascade Lake VM the cascadelake variant (AVX512-VNNI) cut Z-Image Turbo sampling from 50.2 s to 29.3 s and FLUX.2 klein from 63.8 s to 39.3 s against haswell. Only AMD without AVX-VNNI (Zen 4) keeps the AVX2 variant now.
…fer) --conv-direct auto now picks the direct CONV_2D / CONV_3D kernels on the CPU backend. ggml-cpu computes them with the same fp16 patches and the same GEMM as im2col + mul_mat, so outputs are bit-identical, but through a fixed 16 MB patch buffer instead of the whole im2col matrix (2.8 GB for one 128-channel conv of a 1024x1024 VAE decode, 5.6 GB for a 256-channel one). With the row-run fill from the previous commit they are also faster than im2col. Direct convolution is only taken for F16 / F32 weights, which is all the direct kernels accept; any other weight type keeps im2col instead of aborting in ggml-cpu (also for an explicit --conv-direct on).
… mask - ggml-patches/0014 also defines GGML_CPU_CONV_DIRECT_ROW_RUNS in ggml-cpu.h. CPU auto selects direct convolution only when it is defined, so a source build without the fork's ggml patches keeps the old off default instead of the slower per-element direct loops. - The comment and docs now say bit-identical holds for F16 conv weights (every Conv2d / Conv3d block); F32 LoRA tensors and depthwise convs keep F32 activations in the direct kernels and come out closer to exact. - sd_get_num_physical_cores sizes the affinity mask with CPU_ALLOC and grows it on EINVAL, for kernels built for more than 1024 CPUs. - docs/backend.md and docs/performance.md describe the CPU auto rule.
…ggml-patches/0017) (cherry picked from commit f627101079f843f63f16e3fa9a873ddb26cb3d04)
…_SGEMM_TYPES=q8_0 restores Q8_0 only)
…tches/0018) Ports the classic iqk GEMM kernels of ik_llama.cpp (commit 009dce19, MIT, Iwan Kawrakow) into ggml-cpu as src/ggml-cpu/iqk/: Q2_K, Q3_K, Q4_K, Q5_K, Q6_K, IQ4_XS, IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S, IQ1_S and IQ1_M weights times Q8_K activations, for AVX2, AVX512 (F/BW/DQ/VL/VNNI) and NEON with dotprod. They read the upstream block layouts and the Q8_K rows ggml already makes, form the same integer products as vec_dot and only accumulate the floats in another order; ik's re-quantizing Q8_K_R8 conversion path is not ported. Several activation rows share each weight block decode (up to 8), instead of one row by one column per vec_dot call. Hooked in ggml_compute_forward_mul_mat after src1 is converted to Q8_K, in place of the vec_dot loop. On x86 the tiled K-quant path keeps taking ne11 >= 8 first; on ARM, which has no tiled path, these kernels take every ne11. Variants without AVX2 (or NEON dotprod) and MSVC builds compile a stub and keep vec_dot. Repacked weights do not reach this code. GGML_CPU_IQK=0 disables, GGML_CPU_IQK=2 runs them ahead of the tiled path, GGML_CPU_IQK_TYPES=q2_K,iq2_xs,... restricts the types, GGML_CPU_IQK_DEBUG=1 logs the first use per type.
…64 kernels (no lax vector conversions)
…path measured faster), on for ARM
…-aarch64) before shipping ggml dlopens every CPU variant library while scoring them, so a static initializer vectorised with a variant's AVX512 (or AVX2) flags crashes every host without that ISA. The runner's own CPU has the newest ISA and cannot see it. Replay sd-cli startup under SDE (Nehalem .. Sapphire Rapids) and qemu-aarch64 (Cortex-A53 .. max); fail on a crash, an SDE chip-check error, or a loaded variant that needs a feature the emulated CPU lacks.
…VX2 hosts On AMD the AVX2 F16 kernels ran slower than vec_dot from the release toolchains (SD1.5 F16 sampling, GitHub runners: Zen 3 0.78x and Zen 4 0.88x with GCC 11 on ubuntu-22.04, Zen 3 0.71x with MSVC), so F16 / BF16 stay opt-in there and in every MSVC build. Q8_0 stays on everywhere. GGML_CPU_SGEMM_TYPES still overrides the set.
The Windows x64 bundle's AVX512 variants measured 1.88x on a Xeon 8573C (SD1.5 F16 sampling), so the MSVC exclusion now covers only the AVX2 kernels, where AMD Zen 3 / Zen 5 measured 0.71x / 0.86x.
…/ V2) On a Neoverse N2 (GitHub ubuntu-24.04-arm, 4 cores) the default armv8.6_2 variant rendered SD1.5 at 256 px 1.29-1.38x slower than armv8.2_2 (F16 16.1 vs 12.0 s, Q8_0 13.6 vs 9.8 s, Q3_K 18.2 vs 14.0 s, Q4_K 14.9 vs 11.2 s, two runners), and armv8.2_3 / armv8.6_1 about 5x slower. With a 128-bit SVE vector length the SVE variants now score 0 and the best NEON variant is picked; GGML_CPU_ARM_SVE128=1 restores them.
Adds Intel AVX2 under MSVC (1.24-1.25x), AMD Zen 4 AVX2 under MSVC (1.03-1.11x), AMD Zen 5 AVX2 under GCC / clang (1.07-1.08x) and aarch64 builds without FP16 vector arithmetic, whose tinyBLAS kernel accumulates in F32 (armv8.0 1.35x on a Neoverse N2; tinyBLAS is now built on aarch64 too). Stays off on Zen 3 AVX2 (0.71-0.78x), Zen 4 AVX2 with GCC 11 (0.87-0.88x), Zen 5 AVX2 with MSVC (0.86x) and aarch64 FP16-vector builds (FP16 accumulation). Q8_0 stays on x86 only.
test-backend-ops MUL_MAT perf (m 4096, k 14336) on Zen 3, Zen 4, Zen 5, Xeon 8370C / 8573C and Core i7-8700B: iqk is 1.07-3.2x faster than vec_dot for 2-7 src1 rows and 1.15-2.9x faster than the tiled path at 8 rows (not iq2_xxs / iq3_s, 0.84x / 0.91x on Zen 5), and 1.01-2.3x for K-quants up to 12 rows; tiled wins from 16 rows up and vec_dot at 1 row. x86 now takes iqk exactly there when GGML_CPU_IQK is unset; GGML_CPU_IQK=0 / 1 / 2 keep their meaning.
Adds qemu neoverse-v1 / max with a 16-byte SVE vector length: ggml-patches/0020 must pick armv8.2_2 there, and an SVE variant again with GGML_CPU_ARM_SVE128=1. Fails when a variant that has the iqk GEMM kernels built does not enable them by default (ARM, and x86 AVX2 and up since ggml-patches/0018 picks them by batch size).
…gml-patches/0024) ggml-patches/0020 keeps the SVE variants off on 128-bit SVE cores (Neoverse N2 / V2), which left armv8.2_2 (dotprod + FP16) as the best variant there, without i8mm: the repack kernels fall back from the i8mm (smmla) layouts to the dotprod ones. On a Neoverse N2 that made Q4_0 / Q8_0 / Q4_K weights 1.29-1.31x slower and Q5_K 1.17x slower per mul_mat than on the armv8.6_2 variant. armv8.6_0 is DOTPROD + FP16_VECTOR_ARITHMETIC + MATMUL_INT8 without SVE (the Android armv8.6_1 feature set). Its score beats armv8.2_2 when the CPU has i8mm and loses to the SVE variants wherever those are offered (wider SVE, or GGML_CPU_ARM_SVE128=1). cpu_dispatch_gate.sh now expects armv8.6_0 on the 128-bit SVE models with i8mm (neoverse-v1-sve128, max-sve128) and armv8.2_2 otherwise.
…taken by other open branches)
|
@codex review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
# Conflicts: # docs/performance.md # scripts/unsloth/cpu_dispatch_gate.sh
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.