Make Android scheduling load-aware#666
Merged
Merged
Conversation
Pin Android threadpool workers to individual selected performance cores instead of giving every worker the full performance-core mask. This avoids workers collapsing onto the same core under default Android scheduling while preserving the existing topology detection and non-Android behavior. Route blocking Android parallel_for calls through the threadpool chunking path and split each worker request into a fixed set of smaller tasks. This lets faster cores pull additional chunks and prevents a single slow worker assignment from dominating decode and prefill latency. Keep the policy internal and deterministic: no environment variables, no debug logging, and no public API changes. Validation: - cactus build - cactus build --android - ./cactus-graph/build/cactus-kernels/test_matmul - ./cactus-graph/build/test_ops Signed-off-by: Noah Cylich <noahcylich@gmail.com>
Make the Android production entrypoints prepare the caller thread with load-aware performance-core affinity instead of relying on benchmark-only environment hooks. The caller affinity setup now initializes the worker pool before narrowing the caller mask, preserves the original allowed affinity per calling thread, and refreshes CPU load samples before selecting a target performance core. This prevents worker threads from inheriting a single-core mask while still letting repeated calls move away from a busy core. Signed-off-by: Noah Cylich <noahcylich@gmail.com>
1b46e26 to
e587035
Compare
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.
Summary
Make Android CPU scheduling load-aware for production inference on top of current
v2.Key changes:
parallel_forwork into smaller fixed internal chunks so faster cores can pull additional work.Base
This branch is based directly on current
v2after the orthogonal CQ4 LM-head layout PR merged. The PR diff againstv2is limited to:cactus-engine/src/complete.cppcactus-kernels/src/threading.hRationale
The LM-head kernel optimization recovered the kernel-level cost, but Android end-to-end performance was still sensitive to where the OS placed the caller thread and how evenly worker work was distributed across asymmetric cores.
The previous default behavior could leave important work on a slow or contended core. A naive main-thread pin helped in benchmarks, but it was not robust under contention. This PR makes the production path use the same general idea safely: workers stay distributed across selected performance cores, blocking work is chunked so faster cores naturally take more work, and the caller thread is placed using recent per-core load rather than a fixed core choice.
Implementation Details
Worker scheduling:
parallel_forcalls and divide each requested worker assignment into a fixed number of smaller tasks.Caller scheduling:
/proc/statsamples around a 20 ms interval to estimate recent per-core busy fraction.Validation
Build and native tests after the cleanup:
cactus buildcactus build --android./cactus-graph/build/cactus-kernels/test_matmul./cactus-graph/build/test_opsgit diff --checkPixel sanity check after the cleanup:
explain shrodingers catproduced coherent output.10.73 tok/s decode,69.06 tok/s prefill.cactus_chat,cactus_llm_bench, orcpu_contentionprocesses after the run.Earlier contention testing also verified the main bug: pinning the caller before worker-pool initialization could cause all workers to inherit a one-core affinity mask. Initializing the pool first fixes that collapse while preserving load-aware caller placement.