Skip to content

Use fewer threads for small symv - #11

Open
cakedev0 wants to merge 1 commit into
developfrom
symv-fewer-threads
Open

cakedev0 wants to merge 1 commit into
developfrom
symv-fewer-threads

Conversation

@cakedev0

@cakedev0 cakedev0 commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

symv uses every thread from n = 200, and the threads' partial results are summed serially, so small calls get slower with more threads. On one socket of a Xeon 6 (86 cores), dsymv with n = 200 takes 2 µs on 4 threads and 17 µs on 86.

This PR uses min(T, max(4, n / 64)) threads, and all T once that reaches half of T. On an M2 (4 P + 4 E cores), 4 of 8 threads were slower than 8 for n = 200, hence the half. Only the thread count changes.

Results

Best time of 2 rounds, develop c2fc6cf vs this PR, conda-forge build flags, double precision unless noted:

machine n threads develop this PR
Xeon 6787P, 1 socket 200 16 6 µs 3 µs
200 86 17 µs 2 µs
1000 43 33 µs 16 µs
1000 86 76 µs 19 µs
Core Ultra X7 358H (16 cores) 200 16 5 µs 2 µs
500 16 8 µs 6 µs
EPYC 9555P, 48 vCPU cloud VM 200 48 5 µs 2 µs
500 48 11 µs 3 µs
1000 32 14 µs 7 µs

ssymv on the Xeon at 43-86 threads is 3.6-3.9x faster for n = 200, 3.5-5.9x for n = 500 and 2.6-4.4x for n = 1000. On the EPYC VM at 32-48 threads, it is 2.6-3.5x, 3.3-4.3x and 3.8-4.5x.

Once the thread count reaches half of T, this PR runs develop's code path. Those cells stay within noise, including n = 4000 at 43 threads on the Xeon, which measured 0.79x in this short run. On the M2 at 8 threads, that's every size: 0.98-1.02x on the final code.

On the previous version, a Core Ultra 9 285 (8 P + 16 E cores) was 1.2-3.2x faster for n ≤ 500 at 12-24 threads, and end-to-end eigh stayed within noise on both Intel client machines (±3% laptop, ±5% desktop).

Caveats

  • On the Xeon at 86 threads, a call that still uses all threads measures slower when it runs right after one that used few: dsymv 4000 ~190 → ~222 µs after dsymv 2000 on 31 threads. Measured alone or for 2 s, it matches 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.
  • dsyevr 1000 eigenvectors differ from a 1-thread call by 1.07e-10, against 1-2e-11 on develop. dsymv itself is bitwise identical to 1 thread.

On the EPYC VM, 48 threads on 48 vCPUs sometimes hit a stall where two threads share a CPU (see the last caveat of #8), so dsymv 1000 took 1 ms on develop there. I don't count that as a gain.

Not tested: Arm servers. The Core Ultra 9 285 wasn't rerun on this rebase, which doesn't change the code, and the EPYC is a VM with 48 of its 64 cores.

Split out of #8, since symv is the one change there with data from several kinds of CPU.

Code and data: probabl-ai/scikit-learn-benchmarks, branch gemm-experiments (LOG.md exp20-23, scripts/run_tc.sh).

🤖 Generated with Claude Code

symv uses every thread from n = 200, and the threads' partial results are summed
serially. Use max(4, n / 64) threads, and all of them once that reaches half: on
an M2 (4 P + 4 E cores), symv n = 200 took 3.1 us on 4 of 8 threads and 2.8 us on
all 8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cakedev0

Copy link
Copy Markdown
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:

call Core Ultra X7 358H 16c Core Ultra 9 285 24c Graviton4 16c Graviton4 64c EPYC Milan 16c/32t EPYC Turin 64c Xeon 6787P 86c
dsymv 200 3.7x 2.1x 1.09x 2.2x 2.6x 2.5x 6.5x
dsymv 500 1.54x 2.3x 1.02x 1.72x 2.9x 3.1x 5.0x
dsymv 1000 1.01x 1.25x 1.01x 1.30x 1.74x 2.7x 4.1x
dsymv 4000 0.99x 0.95x 0.98x 1.00x 0.99x 1.09x 0.98x
whole grid 0.97-3.7x 0.95-2.3x 0.98-1.09x 1.00-2.2x 0.99-2.9x 1.09-3.1x 0.98-6.5x
  • Faster on the Core Ultra machines and on all the machines with 32 threads or more. Graviton4 gains less: develop's threaded symv costs less there (dsymv 500 at 16 threads runs at the same speed on both builds on the 16-core one).
  • Slower: on the 64-core Graviton4 at 16 threads, dsymv 500 is 0.77x (79 -> 62 GF/s, tight rounds). This PR uses 7 threads there, and 16 are faster on that machine.

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.

cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant