Skip to content

[Engine] poly: opt-in --pin-workers (Linux): keep each CPU expert thread on one CPU - #486

Closed
drakarah wants to merge 1 commit into
simplexai-labs:mainfrom
drakarah:feat/poly-pin-workers
Closed

drakarah wants to merge 1 commit into
simplexai-labs:mainfrom
drakarah:feat/poly-pin-workers

Conversation

@drakarah

@drakarah drakarah commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Problem and result

On Linux strata-poly leaves its CPU expert threads to the scheduler (only the NUMA binding of stay_near() narrows where they may run). On a hybrid CPU the scheduler moves them between performance cores, efficiency cores and the second hardware threads of busy cores, and a user has no way to choose. --pin-workers (or STRATA_POLY_PIN_WORKERS) pins each worker thread to one CPU, either by a CPU list or by auto.

It is not faster. Qwen4-35B-A3B UD-IQ4_XS on an RTX 4060 Laptop with an i9-12900H, --kv q8_0, 300 tokens, the arms interleaved, 5 rounds each:

CPU energy preference Unpinned --pin-workers auto
balance_performance (the default) 80.85 ± 3.68 tokens/s (77.3-86.8) 80.24 ± 1.03 (78.6-81.2)
performance 77.31 ± 3.61 (74.9-83.7) 75.90 ± 3.01 (71.9-78.8)

With the default power setting the speed varied less from run to run (an earlier 5-round pair, with pinning through an experiment build, gave the same picture: 79.00 ± 6.61 against 78.73 ± 1.11); with performance it did not, and both arms were slower on this laptop. The option is for users who want to choose where the threads run (keep cores free for other programs, benchmark with less spread, try layouts), not a speed-up.

Related discussion

none (no issue).

Approach

  • Workers::pin(cpus): worker thread i goes to cpus[i % n] (pthread_setaffinity_np); the calling thread, which does a share of the work, is left alone. Returns the number pinned; 0 on other systems.
  • auto = worker_cpu_order(cpu_slots()): cpu_slots() reads the process's affinity mask (so it stays within the NUMA node stay_near() chose), /sys/devices/cpu_atom/cpus (a hybrid Intel CPU's efficiency cores) and each CPU's core_id / physical_package_id. The order: the first hardware thread of every performance core but the first (where the calling thread usually runs), then the efficiency cores, then the second hardware threads, then the first core's. On the i9-12900H, 13 workers: CPUs 2,4,6,8,10,12-19.
  • A list such as 2,4,6-9 pins in that order; a bad list (3-1, 2,,4, x) stops the load with a clear error. off or empty: nothing.
  • One log line says which CPUs the threads went to, or that they were not pinned (Windows, or no CPU to give them).
  • Registered in terminal/data/settings-register.json (opt-in), docs/SETTINGS.md regenerated, a row in the options table of docs/GLM.md.
  • Kept out: pinning the calling thread, Windows (SetThreadAffinityMask / CPU sets), a different kernel per core type.

Validation

Revision b490766d4 (the engine runs on the same code before the docs row was reworded). Linux, i9-12900H (6 P-cores with two threads each, 8 E-cores), RTX 4060 Laptop 8 GB, CUDA 13.4 build container; Qwen4-35B-A3B UD-IQ4_XS (Unsloth).

Passed:

  • poly_workers_test (built with -DSTRATA_BUILD_TESTS=ON): CPU list parsing (good and bad lists), the auto order for a hybrid Intel layout and an AMD-like one without efficiency cores, an empty layout, and pinning a real 8-thread pool (7 pinned); 4,000 checks passed.
  • Engine: --pin-workers auto logs "13 CPU threads pinned to CPUs 2,4,6,8,10,12,13,14,15,16,17,18,19"; a bad list stops with the error; the decode numbers above.
  • python3 tools/settings_register.py --check and python3 -m unittest tools.test_settings_register: OK.

Failed:

  • Pinning onto both hardware threads of the performance cores (an earlier experiment) was slower than the order above; that is why auto puts the second threads after the efficiency cores.

Not run:

  • Windows (the option only logs there), AMD CPUs and multi-socket / multi-NUMA machines (the order and the NUMA mask are tested with made-up layouts only).
  • HIP/SYCL builds (the files are CPU C++ shared by every build; I built the CUDA one).
  • Prompt speed, other models; reproduction by anyone else; the whole test suite.

Limits

  • Not faster on the one machine measured; less spread between runs only with the default power setting.
  • Linux only.

🤖 Generated with Claude Code

…ead on one CPU

strata-poly leaves its CPU expert threads to the scheduler on Linux. --pin-workers
(or STRATA_POLY_PIN_WORKERS) pins each worker thread to one CPU: `auto` puts one
thread on every performance core but the first (where the calling thread runs),
then the efficiency cores (/sys/devices/cpu_atom/cpus), then the cores' second
hardware threads; a list such as 2,4,6-9 pins them in that order. It reads the
process's own affinity mask, so it stays within the NUMA node the engine already
binds to. Default off: nothing changes unless it is set. Not on Windows (logs that
the threads are not pinned).

Qwen4-35B-A3B UD-IQ4_XS, RTX 4060 Laptop + i9-12900H, --kv q8_0, 300 tokens,
interleaved, 5 rounds each:
  balance_performance EPP (default): unpinned 80.85 +- 3.68, auto 80.24 +- 1.03 tok/s
  performance EPP:                   unpinned 77.31 +- 3.61, auto 75.90 +- 3.01 tok/s
Not faster; less run-to-run spread with the default power setting only.

workers_test: CPU list parsing, the order for a hybrid Intel and an AMD-like
layout, and pinning a real pool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW
@VecSzn

VecSzn commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator

Integrated on main in commit 1770e6a65 (live-verified on Linux; included in upcoming v0.2.20-poly.11). Thanks @drakarah!

@VecSzn VecSzn closed this Dec 6, 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.

2 participants