Repository navigation
Conversation
These use every thread as soon as the problem passes a small fixed size. On one socket of a Xeon 6 (86 cores), past ~8-16 threads, waking and synchronizing them costs more than the work: ddot with n = 1e5 takes 4 us on 8 threads and 26 us on 64, dgetrf 1000 takes 5 ms on 8 threads and 44 ms on 64. Size the thread count by the problem, and only when the result is below a third of the threads: busying every core on Xeon 6 raises the uncore frequency, and on hybrid CPUs a count just above the number of P cores is slower than all of them. gesv only caps the factorization, since the solve scales with the number of right-hand sides. Co-Authored-By: Claude Opus 5.5 <[email protected]>
a3de802 to
d851ca8
Compare
|
I ran this PR against develop c2fc6cf on more machines, including Arm servers. Speed-up in GFLOP/s (median over 3 interleaved rounds, PR / develop), all cores of each machine, threads pinned, conda-forge build flags:
The cap gives 10 threads for n = 2000 and 20 for n = 4000, where the best counts are 24 and 48. So Other notes:
Machines: the two Intel client machines from the description, AWS Graviton4 (Neoverse V2) m8g.4xlarge and m8g.16xlarge, EPYC 7R13 Milan m6a.8xlarge (2 NUMA nodes), EPYC 9R45 Turin m8a.16xlarge (no SMT, OpenBLAS picks its Cooperlake kernels there), and one socket of the Xeon 6787P for reference. "whole grid" is the range over every shape of the run at that thread count. Data and scripts: LOG.md, exp 31. |
…ev0/OpenBLAS#8, cakedev0/OpenBLAS#11, cakedev0/OpenBLAS#10 (he's interested) Co-Authored-By: Claude Opus 5.5 <[email protected]>
ddot,daxpy,dgetrfanddgesvuse every thread as soon as the problem passes a small fixed size (n > 10000 for dot/axpy). Past ~8-16 threads, waking and synchronizing them costs more than the work. On one socket of a Xeon 6 (86 cores),ddotwith n = 1e5 takes 4 µs on 8 threads and 25 µs on 86.dgetrf1000x1000 takes 43 ms on 86 threads and 8 ms on this PR's 8. This PR sizes the thread count by the problem instead:ddot(x86_64 kernel) andaxpy:min(T, max(8, n/25000))threads (axpy: 200 kB of x per thread), and all T once that reaches a third of T. So nothing changes with 24 threads or fewer.getrf: at mostmax(8, sqrt(m*n)/200)threads, but only when that is below a third of T, like dot/axpy. On hybrid CPUs, a count just above the number of P cores is slower than using all cores: on a Core Ultra 9 285,getrf2000 at 24 threads was ~9% slower with 10 threads.gesv: the same cap, for the factorization only. The solve splits over the right-hand sides, so it scales with them, and capping it made nrhs = 10n 2-2.4x slower.It only changes thread counts, no kernels. Other architectures' dot kernels and
sdotare unchanged.Only calls above 24 threads change, so I measured two large CPUs: a Xeon 6787P and an EPYC 9555P. I'd still like to see an Arm server.
Results
Best time of 2 rounds, develop c2fc6cf vs this branch, both built with the conda-forge flags, threads pinned. One socket of a Xeon 6787P:
The
gesvgrid (n = 1000-2000, 1 to 20000 right-hand sides, 32-86 threads) is 1.03-5.68x faster, with no slower cell.saxpyn = 1e5 is 3.8x faster at 43 threads and 15x at 86, and n = 1e6 is 1.05-1.37x.EPYC 9555P, a cloud VM with 48 of its 64 cores:
Nothing changes at 24 threads there (0.98-1.13x on these calls). Calls the cap doesn't reach, like
getrf4000 at 48 threads, stay within noise (0.97x).saxpyn = 1e5 is 1.7-2.2x faster at 32-48 threads.zgesvalso gets the cap, through the same file (complexgetrfis a different file and doesn't). On a previous version with all right-hand sides capped,zgesvwith one right-hand side was up to 9x faster at n = 500, and 1.06-1.84x at n = 2000.On the previous version, including the
symvchange of #11, scikit-learn 1.9.1 / scipy / numpy from conda-forge with this library swapped in, 43-86 threads:Lasso20000x100 (20 epochs): 56-94 → 13-19 ms.Lasso100000x1000, X larger than L3: 183-268 → 113-119 ms.scipy.linalg.solve1000: 22-55 → 10 ms;solve4000 at 64-86 threads: 401-414 → 309-316 ms.8-24 threads are unchanged.
Checks
Checks against a 1-thread call pass (relative difference < 1e-10) on the previous version. On the final code, the exact gemm/syrk checks pass on the laptop and on the EPYC VM with this PR merged, which only shows nothing else broke: these routines have no new test here.
Known caveats
ddot1e6 16 → 36 µs afterdaxpy5e5 on 20 threads. Measured alone or for 2 s, they match develop. The socket has Efficiency Latency Control on: the uncore runs at full speed only when >95% of the cores are busy. Develop's idle threads spin on every core, while with this PR most of them sleep, and the uncore takes a few hundred ms to come back up.getrf4000 at 43 threads (71 vs 51 ms) andgetrf8000 at 86 threads (434 vs 290 ms). I preferred the same rule as dot/axpy and no change on small machines.gesv4000x100 2 s instead of 62 ms). The EPYC VM hits it too at 48 threads on 48 vCPUs. Both builds hit it at random, so the tables take the best of the rounds. It is unrelated to this PR.Code and data: probabl-ai/scikit-learn-benchmarks, branch gemm-experiments (
LOG.mdexp20-23,scripts/run_tc.sh,scripts/run_sklearn_e2e.sh).🤖 Generated with Claude Code