fix(cpu): enforce max_units_per_cube loudly and fix sync_cube scheduling#1424
Merged
Conversation
marcantoinem
requested changes
Jul 13, 2026
Contributor
There was a problem hiding this comment.
There's no need to add yielding to sync_cube, the goal of the scheduler is to always put sync_cube in parallel, that's the goal of needs_parallelism
Contributor
There was a problem hiding this comment.
Same things no need to add yielding
Contributor
There was a problem hiding this comment.
It is normally launched as an error later, so the error handling is duplicated, maybe add the log to the other check?
Set `needs_parallelism` for `SyncCube` so the scheduler never queues two units of the same cube on one worker, which would deadlock the spin barrier. Clamp the hardcoded cube dims in the shared saturating and synchronization runtime tests to `max_units_per_cube` so they pass on machines with fewer than 16 cores (e.g. CPU CI). Drops the earlier unnecessary changes: the MLIR `thread_yield` extern in `sync_cube` (bad for a barrier that must resolve ASAP) and the loud `max_units_per_cube` launch enforcement. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
louisfd
force-pushed
the
fix/cpu-strict-cap-loud-errors
branch
from
July 13, 2026 20:55
7c6a155 to
e3e3ee4
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.
The CPU runtime caps max_units_per_cube at the machine's core count (units are pinned one per worker thread so the sync_cube spin barrier can make progress). Three bugs surrounded that contract:
Launches exceeding the cap were rejected into the stream error sink and never surfaced: reads returned the stale (usually zeroed) buffer, so downstream tests failed with silent wrong results instead of an error (misdiagnosed in cubek as a wgpu/Vulkan atomics regression). The server now validates cube dims at launch like every other backend, logs the refusal, and read drains the stream and returns any recorded error.
sync_cube did not set needs_parallelism, so barrier kernels went through the load-balancing scheduler and two units of the same cube could queue behind each other on one worker, deadlocking the barrier whenever the pool wasn't idle.
The shared runtime tests hardcoded 16-unit cube dims, which violates the (machine-dependent) cap on hosts with fewer than 16 cores; they now clamp to max_units_per_cube. The barrier wait loops also yield between iterations (only when actually waiting) so waiting units don't starve the rest of the process.