Repository navigation
perf(runtime): mark settle partitions only when their inputs change - #2113
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a921068b00
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let old = alloc(unit, RegisterType::Logic { width }); | ||
| instructions.push(SIRInstruction::Load(old, address, offset.clone(), width)); | ||
| instructions.push(instruction); | ||
| let new = alloc(unit, RegisterType::Logic { width }); | ||
| instructions.push(SIRInstruction::Load(new, address, offset, width)); |
There was a problem hiding this comment.
Compare strided bulk writes element by element
With partitioning enabled on a native-host tiered build, these loads can miss changes made by a bulk store or commit to a padded unpacked array. Instrumentation runs after layout selection, which permits bulk zero stores and commits on element-strided arrays, but the Tier-0 interpreter's Machine::load reads a contiguous bit range rather than gathering the elements. For example, an eight-element one-bit array occupies eight bytes: an eight-bit comparison observes only the first element's byte, so clearing a previously set later element can leave its reader partition unmarked and its combinational output stale. Split comparisons at element boundaries, or mark strided bulk writes unconditionally.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in a5f5852 (amended into the PR commit).
Reproduction. tests/settle_partitions.rs::element_writes_to_a_padded_array_match_single_pass, in two- and four-state:
- The design has 13-bit elements stored two bytes apart in the element-strided layout. Element writes
m[idx] <= dpublish through one 104-bit commit of the whole array, andlast = m[7]reads only the last element. - Before the fix, the tiered build (Tier-0 interpreter, strided layout) failed:
laststayed stale after a write tom[7]. The interpreter'sMachine::loadreads one contiguous bit range, so the compare covered elements 0 to 6 plus padding. - Native passed the same test, because its strided loads expand element by element. The test asserts that both builds really stride the array.
Fix. Marker::spans_padded_elements: a store or commit that covers more than one element of a padded element-strided array marks its readers without comparing. The marks are exact and cheap; element-wise comparison can come later if C906 shows it matters.
Audit of the other compare-and-mark sites:
- The settle's own compares (scheduler,
PackedElementsoffsets for unpacked arrays) are emitted before layout selection. A multi-element load that is not a bulk transfer makescollect_strided_array_layoutskeep the array packed, unless the array is physically contiguous, and then contiguous reads are correct. So those compares never read across padding. The cost is that a settle-written unpacked array read by another partition loses striding. - Host writes, state loads and the cross-check mark or compare whole byte ranges,
plane_size× planes, which covers both padding and the mask plane. - Four-state mask planes in
Markerloads use the backend's own plane addressing (plane_sizefor strided arrays). They are covered by the four-state run of the new test.
A partition of a partitioned settle compares, before and after it runs, the objects it writes that other partitions read (both planes, in chunks of up to 4096 bits, whole elements of unpacked arrays), and sets their readers' flags only when they changed. Generated stores and commits outside the settle do the same per store. On rtlmeter C906 the simulation phase drops from 5.27 s to 1.28 s with partitioning on. The for-bound check ignores stores to the settle flags: they only decide what to recompute, and following them would taint every guarded store. A store across padded elements of an element-strided array marks its readers without comparing: not every backend gathers such a load. Partitioning stays opt-in (#2013). Change-Id: I3b84acbb10d581a372cb6bae34a4490d038a36a7
a921068 to
a5f5852
Compare
Merge Queue Status
This pull request spent 38 minutes 11 seconds in the queue, including 35 minutes 48 seconds running CI. Required conditions to merge
|
Part 2 of #2013, stacked on #2106: a partitioned settle marks the readers of state only when that state changes. It stays opt-in; part 3 adds adaptivity and turns it on by default.
What changes
Inside the settle. Each partition compares, before and after it runs, every object it writes that another partition reads:
It sets each reader's flag branchlessly (
Mux(changed, 1, flag)). Objects of unknown width still mark unconditionally.Outside the settle. Generated stores and commits to state the settle reads or writes compare the old and new value and mark only on a change. Stores wider than 4096 bits mark unconditionally.
MutableForBound analysis. The
forbound check (dynamic_for_check) ignores stores to the settle flags. The flags only decide what to recompute, and now that they depend on data, the bit-level taint would otherwise flow through the partition guards to every guarded store.C906 (rtlmeter hello)
Native, four-state, heliodor-dev. Build: this branch + master + #2087 (level lists), with partitioning forced on (
Estimated, 237 partitions) vs off. Sameprobe3.vtestbench, trace identical, TEST PASSED.Earlier per-function profile from the prototype of the same design:
eval_comb4.12 s → 0.74 s, with 12 of 248 partitions dirty at settle entry on average. A settle where every partition runs costs about 2x the single pass. Part 3 keeps such designs and phases on the single pass and looks at the compile time.Validation
celox --no-default-featuresis clean with-D warnings.celox+celox-test-suitewith partitioning forced on (Always) andsettle_checkon: same results as feat(runtime)!: opt-in partitioned combinational settle #2106 (expected snapshot changes and native raw-buffer harness tests; one$displayreported twice under the check).celox-sltunit test: two partitions compare their written objects before marking (NeCase), and the readers' flags are loaded before the conditional mark.tests/settle_partitions.rs(from feat(runtime)!: opt-in partitioned combinational settle #2106) covers the cases that matter here: a process writing two outputs with an intermediate write, and a copy of a process output read by another process. Both broke the C906 trace in the prototype before feat(runtime)!: opt-in partitioned combinational settle #2106 fixed the plan.--backend native, release), master vs branch: 4,212,004,002 / 4,165,403,896 Ir, same output. The JIT code is identical (2,777,200,097 Ir in both); the runtime difference is inlining (call_func_timed, as in feat(runtime)!: opt-in partitioned combinational settle #2106) and attribution under identical-code folding, not work.Depends-On: #2106