Repository navigation
Conversation
cakedev0
force-pushed
the
syrk-fewer-threads
branch
from
November 2, 2026 15:05
4edf4cc to
7fb5523
Compare
cakedev0
added a commit
to cakedev0/my-scikit-learn-backlog
that referenced
this pull request
Nov 2, 2026
done: Blog: [blog#231](scikit-learn/blog#231) (match Substack's font size), merged todo: move [blog#228](scikit-learn/blog#228) from Waiting to Now: address lorentzenchr's review and answer jjerphan on the OpenBLAS threading layers todo: move [sklearn#35181](scikit-learn/scikit-learn#35181) from Now to Waiting, adam2392's and antoinebaker's questions answered add: Maintenance: follow up on [sklearn#35254](scikit-learn/scikit-learn#35254): settle option B with dherrera1911 and betatim (LDA solvers disagree with custom priors) add: Maintenance: follow up on [sklearn#35209](scikit-learn/scikit-learn#35209): newton-cg LogisticRegressionCV test fails on the macOS x86_64 wheels add: Maintenance: re-review [sklearn#34619](scikit-learn/scikit-learn#34619) (faster PCA mle; jberg5 addressed my comments) add: Benchmarks: review [benchmarks#142](probabl-ai/scikit-learn-benchmarks#142) (cuML config) with the results of the AWS L4 run add: Upstream: upstream to OpenBLAS or close [cakedev0/OpenBLAS#3](cakedev0/OpenBLAS#3) and [cakedev0/OpenBLAS#4](cakedev0/OpenBLAS#4) todo: since dates on [sklearn#35062](scikit-learn/scikit-learn#35062) and [sklearn#35053](scikit-learn/scikit-learn#35053), and virchan's question on the latter todo: lorentzenchr's note on [sklearn#35029](scikit-learn/scikit-learn#35029) in the fork#38 line Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 4, 2026
For threaded paths that can do something useful instead of waiting. Co-Authored-By: Claude Opus 5.5 <[email protected]>
When n < nthreads * switch_ratio, level3_syrk_threaded.c ran the single-threaded kernel, so for example dsyrk with n = 990 dropped from ~980 to ~80 GFLOP/s between 60 and 62 threads on a Xeon 6787P. Use n / switch_ratio threads instead, capped so that each thread gets enough work, and keep one thread when that leaves fewer than 4 threads (8 in single precision), where a few threads are slower than one. If another caller holds the level 3 lock, also keep one thread: waiting for the lock would make concurrent callers take turns on calls that develop runs side by side. Co-Authored-By: Claude Opus 5.5 <[email protected]>
cakedev0
force-pushed
the
syrk-fewer-threads
branch
from
November 6, 2026 22:59
7fb5523 to
89e6216
Compare
Owner
Author
|
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:
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. "whole grid" is the range over every shape of the run at that thread count. Data and scripts: LOG.md, exp 31. |
cakedev0
added a commit
to cakedev0/my-scikit-learn-backlog
that referenced
this pull request
Nov 25, 2026
…ev0/OpenBLAS#8, cakedev0/OpenBLAS#11, cakedev0/OpenBLAS#10 (he's interested) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Threaded syrk falls back to the single-threaded kernel when
n < nthreads * switch_ratio. With many threads that turns a parallel call into a one-core call:X.T @ Xwith 990 features on one socket of a Xeon 6787P (86 cores) runs at ~980 GFLOP/s with 60 threads and at 81 GFLOP/s from 62 threads up.In that case this PR uses
min(n / switch_ratio, n * n * k / 3.5e6)threads instead, like the gemm driver lowers its thread count, and keeps one thread when that leaves fewer than 4 threads (8 in single precision). A few threads are slower than one on small calls (dsyrk 64 x 2000: 46 GFLOP/s on one thread, 21 on four), more so in single precision, where one thread is about twice as fast. If another caller holds the level 3 lock, it also keeps one thread (see "Concurrent callers").Calls that develop already runs threaded are unchanged. This driver also serves complex syrk/herk and the trailing updates of
potrf, so those change too, and they gain.Impact
Median GFLOP/s, threads pinned to cores (except on macOS), conda-forge build flags:
The laptop and EPYC rows are from short runs of the final code (2 rounds, best time) on develop c2fc6cf. Laptop cells that run develop's unchanged code moved 0.86-1.38x in that run, so read them as rough, and EPYC cells on that path moved 0.82-1.08x. The other rows are from the previous version on develop b8d14a6. The concurrency check below is the only change on these paths since then, and it doesn't apply to a single caller.
I compared develop and this PR on a grid of n from 32 to 512 and k from 1000 to 100000 (plus a few large shapes), f32 and f64, at 4 to 86 threads on the Xeon, 2 to 16 on the laptop and 2 to 24 on the Core Ultra 9 285 (threads fill the P cores first, so 12 to 24 threads include E cores). Where the PR keeps one thread the result matches develop, and no case is slower beyond run-to-run noise (a rerun of the few 0.86-0.95x cells with the order reversed gave 0.97-1.21x; they all run develop's code path). On the M2 (static VORTEX build, which uses the default switch_ratio of 2), the fallback only happens for n < 2 * nthreads, so the only affected calls are
X.T @ Xwith fewer than 16 features. They now use 4-7 threads instead of one at about the same speed (memory-bound): 8 to 15 columns at 8 threads measured 0.93-0.99x on the final code, within noise on this unpinned machine. Everything else is unchanged beyond noise.The worst case I found is on the EPYC VM, where one thread is fast: d 100 x 20000 runs on 6 threads and moves between 0.88x and 1.14x from round to round, with the same thread count in both modes, so I think it depends on thread placement. d 64 x 5000 moves between 0.97x and 1.55x, and d 96 x 5000 between 1.10x and 1.73x.
Other callers of this driver, on one socket of the Xeon:
zsyrkandzherk, n = 64-120, k = 5000-20000: 2.1-3.6x faster at 16 threads and 1.6-2.5x at 86. Shapes that stay on one thread (32 x 20000, 96 x 1000) don't change. On the EPYC VM, up to 3.3x at 16 threads and 3.5x at 48.dpotrfat 64-86 threads: n = 4000 is 1.32x faster, n = 2000 1.16-1.18x, n = 8000 1.03-1.11x. n = 500 stays within noise. This run also had the split-K and thread-count PRs merged, which don't touchpotrf's path. On the EPYC VM with this PR alone, 48 threads, n = 500 to 8000: 0.96-1.10x.The work threshold isn't scaled for complex types, so some complex calls stay on one thread where more would help: on the laptop,
zherk96 x 1000 takes ~0.75 ms at 16 threads and ~0.2 ms at 12, where develop's path applies. I left that out to keep this change small.Concurrent callers
A threaded syrk holds the level 3 lock for the whole call. Develop runs these small calls on one thread per caller, so they run side by side. Simply threading them made callers take turns: with 8 callers, 64 x 5000 dropped to 0.19x of develop's throughput at 86 threads.
So this PR adds
blas_level3_thread_try_enterand keeps one thread when the lock is taken. One round on one socket of the Xeon, throughput against develop:On the EPYC VM, 8 callers stay at 0.98-1.04x at both 16 and 48 threads.
Thread count changes
Changing the thread count from one call to the next costs little. Cycles of syrk calls that alternate between thread counts (e.g. n = 32 and n = 160 with k = 2000: 1 and 10 threads at 86) are as fast as or faster than develop with pthreads, LLVM libomp and GNU libgomp. The worst case is that shortest cycle (0.37 ms): waking the threads after the single-threaded call adds 0.03-0.1 ms, and the cycle is still 2.4x faster than on develop, where both calls run on one thread.
Checks
utest/test_syrk_threads.ccompares dsyrk and ssyrk at 16 threads to a naive reference, both triangles, N and T, beta 0 over NaN and beta 0.5. Inputs are small integers, so results must match exactly. It passes with pthreads and OpenMP, and fails when I inject a bug in the driver (k - 1).I also ran a larger exact check against naive references, not included here: real and complex syrk/herk, Upper and Lower, row and column major, padded lda and ldc, alpha != 1, beta 0 over NaN, writes outside the triangle or the padding, at 8-86 threads on the Xeon, 8-16 on the laptop and 8-48 on the EPYC VM, including 4 concurrent callers. Zero failures. The EPYC run also passes the unit test.
This PR sends more calls through the threaded syrk driver, which is the code in OpenMathLib#6224 (corruption in threaded dsyrk). As I read that issue, it's considered fixed by OpenMathLib#6105. My exact checks show nothing with or without this PR, but I didn't run that issue's reproducer.
Not tested: the CMake build (the only CMake change is one test file in a list), and Arm servers. The Core Ultra 9 285 wasn't rerun on the final code, and the EPYC is a VM with 48 of its 64 cores.
Side note
Under
DYNAMIC_ARCHthe threading drivers use the single-precisionSWITCH_RATIOfor double too (the gotoblas table is filled in a file compiled withoutDOUBLE), which is why the Xeon cliff is at 16 columns per thread and not 8. I looked at fixing that separately (#4), but on this Xeon the double-precision values make small dgemm 2-2.5x slower at 64-86 threads, so it needs more work first.Data and scripts: https://github.com/probabl-ai/scikit-learn-benchmarks/blob/gemm-experiments/gemm-experiments/LOG.md (exps 15-19).
🤖 Generated with Claude Code