Skip to content

fix(cpu): enforce max_units_per_cube loudly and fix sync_cube scheduling#1424

Merged
louisfd merged 2 commits into
mainfrom
fix/cpu-strict-cap-loud-errors
Jul 14, 2026
Merged

fix(cpu): enforce max_units_per_cube loudly and fix sync_cube scheduling#1424
louisfd merged 2 commits into
mainfrom
fix/cpu-strict-cap-loud-errors

Conversation

@louisfd

@louisfd louisfd commented Jul 13, 2026

Copy link
Copy Markdown
Member

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.

@louisfd
louisfd requested a review from marcantoinem July 13, 2026 20:09

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same things no need to add yielding

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
louisfd force-pushed the fix/cpu-strict-cap-loud-errors branch from 7c6a155 to e3e3ee4 Compare July 13, 2026 20:55
@louisfd
louisfd requested a review from marcantoinem July 13, 2026 21:00
@louisfd
louisfd merged commit 24aedf0 into main Jul 14, 2026
3 checks passed
@louisfd
louisfd deleted the fix/cpu-strict-cap-loud-errors branch July 14, 2026 13:10
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