mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #626] [CLOSED] cpu: preserve full thread affinity on Windows and Linux #2727
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2727
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/626
Author: @Yasei-no-otoko
Created: 10/3/2026
Status: ❌ Closed
Base:
main← Head:fix/windows-cpu-processor-groups📝 Commits (8)
92ba396perf: select measured Windows 3990X gfx1030 worker defaultbc08391Fix Windows processor group affinity8f1885cFix Linux affinity token restorationfba17b6Test shared Windows affinity mappingd828e8eKeep CPU group fix independent of worker sizing and benchmark reporteb99676Keep hardware benchmark documentation in its separate PRd72bd06cpu: restore Windows host placement through reversible CPU Sets8145545cpu: preserve complete Linux affinity masks on large systems📊 Changes
9 files changed (+660 additions, -48 deletions)
View changed files
📝
CMakeLists.txt(+9 -0)📝
include/strata/core/session.hpp(+2 -1)📝
include/strata/kernels/cpu/pool.hpp(+18 -4)📝
src/core/session.cpp(+2 -2)📝
src/kernels/cpu/pool.cpp(+58 -41)➕
src/kernels/cpu/pool_affinity_linux.hpp(+69 -0)➕
src/kernels/cpu/pool_affinity_linux_test.cpp(+290 -0)➕
src/kernels/cpu/pool_affinity_test.cpp(+148 -0)➕
src/kernels/cpu/pool_affinity_win.hpp(+64 -0)📄 Description
Strata's CPU pinning lost part of the processor identity on Windows and part of the caller's saved CPU mask on Linux. Windows workers discarded the processor-group number; Linux host restoration retained only CPU IDs 0-63. This change preserves the full placement on both platforms without changing automatic worker sizing or explicit
--pool-workersvalues.On Windows, use
SetThreadGroupAffinityfor pool-owned workers, enumerate every core group mask and preserve group identity in fallback enumeration. On the tested 3990X, the previous 63-worker list collapsed to 32 distinct group-local masks becauseSetThreadAffinityMask(..., 1 << (core & 63))discarded the group.The caller-owned Windows host thread uses reversible CPU Set selection. Save its full explicit selection and restore it, or clear it when originally empty. This preserves process-default inheritance and Windows 11's implicit all-group eligibility without changing existing hard affinity. CPU Sets are soft placement constraints. See Microsoft's CPU Set API.
On Linux, retain the complete native affinity mask in
ThreadAffinity. UseCPU_ALLOCand the sized CPU-set macros, retry a query with a larger buffer onEINVAL, and share the dynamic-mask handling with topology enumeration and worker pinning. Restore the complete saved mask, including high-only and sparse selections, and report failed affinity operations using pthread's returned error number. See Linux CPU-set APIs. No Windows-style group IDs are needed on Linux.Validation:
pool_affinity_testafter the Linux addition; CTest passed. It covers worker pins, reversible host selections, process defaults, and continued execution in both processor groups. The earlier Windows change also completed a full Release HIP engine build; details are in #628.strata_kernels_cpuandpool_affinity_testwith GPU/native-ggml support disabled.-Wall -Wextra -Werrorsyntax checks passed for the changed Linux implementation and test. CTest passed with 64 available CPUs, and a separate run withtaskset -c 0,2,15passed. The high-CPU path correctly reports a skip on these WSL runs.6.6.36.3-microsoft-standard-WSL2exposed CPUs 0-127. The same statically linked regression test passed with--require-high-cpu, both with all 128 CPUs and with affinity restricted to CPUs 64-127. Tests include full-mask and sparse/nested restoration, a high-only saved mask, topology respecting the allowed CPU set, worker execution on CPU 127, invalid targets, and cleanup.Linux reproduction on a normal Linux checkout:
The Linux results establish affinity correctness in WSL / an emulated guest, not native Linux inference performance. CPU IDs above 1023 were not exercised. The AVX-512 pool self-test and
pool_stressskip their workloads on this 3990X; a zero exit code from those skips is not a stress-workload pass.Benchmark data remains in the separate PR #628. Its speed figures belong to the recorded earlier Windows revisions and predate both the Windows host CPU Set review follow-up and this Linux addition; inference throughput was not remeasured for this revision. The machine's one NUMA node spans two processor groups, so this is an application affinity correction, not a Windows Containers or OS NUMA fix.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.