Skip to content

perf(runtime): mark settle partitions only when their inputs change - #2113

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/perf/2013-settle-change-detection
Oct 26, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/perf/2013-settle-change-detection

Conversation

@tignear

@tignear tignear commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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:

    • in chunks of up to 4096 bits, whole elements for unpacked arrays;
    • with case inequality, so X/Z changes count.

    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 for bound 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. Same probe3.v testbench, trace identical, TEST PASSED.

simulation phase compile (to Init)
single pass 5.27 s 33.6 s
partitioned, change-detected 1.28 s (4.1x) 56.3 s

Earlier per-function profile from the prototype of the same design: eval_comb 4.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

  • Workspace with CI features, default (partitioning off): 17,476/17,476 pass. Clippy is clean; celox --no-default-features is clean with -D warnings.
  • Whole celox + celox-test-suite with partitioning forced on (Always) and settle_check on: same results as feat(runtime)!: opt-in partitioned combinational settle #2106 (expected snapshot changes and native raw-buffer harness tests; one $display reported twice under the check).
  • celox-slt unit 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.
  • b2_vm_dispatch_bit callgrind (--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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T06:47:31.089598Z a5f5852 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 26, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +252 to +256
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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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] <= d publish through one 104-bit commit of the whole array, and last = m[7] reads only the last element.
  • Before the fix, the tiered build (Tier-0 interpreter, strided layout) failed: last stayed stale after a write to m[7]. The interpreter's Machine::load reads 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, PackedElements offsets for unpacked arrays) are emitted before layout selection. A multi-element load that is not a bulk transfer makes collect_strided_array_layouts keep 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 Marker loads use the backend's own plane addressing (plane_size for strided arrays). They are covered by the four-state run of the new test.

@tignear tignear removed the merge-ready Request merging through Mergify after required checks label Oct 26, 2026
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
@tignear
tignear force-pushed the feature/perf/2013-settle-change-detection branch from a921068 to a5f5852 Compare October 26, 2026 06:45
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 26, 2026
Base automatically changed from feature/perf/2013-partitioned-settle to master October 26, 2026 06:58
@mergify mergify Bot added the queued Mergify queue entry label Oct 26, 2026
@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-26 07:10 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • ✅ Checks passed · on draft merge queue: checking #2113 on master (2a76ded) #2119
  • ✅ Merged — 2026-10-26 07:49 UTC · at 9bfcbf6e0607bb98b61ea00041b7d43e84d8f22e · merge

This pull request spent 38 minutes 11 seconds in the queue, including 35 minutes 48 seconds running CI.

Required conditions to merge
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • depends-on = celox-sim/celox#2106 [⛓️ feat(runtime)!: opt-in partitioned combinational settle #2106]
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify mergify Bot mentioned this pull request Oct 26, 2026
43 of 73 tasks
@mergify
mergify Bot merged commit 9bfcbf6 into master Oct 26, 2026
24 checks passed
@mergify
mergify Bot deleted the feature/perf/2013-settle-change-detection branch October 26, 2026 07:49
@mergify mergify Bot removed the queued Mergify queue entry label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant