Repository navigation
Backend: follow-up copies for kernel outputs that cannot share its layout - #44
Open
AdvaitTahilyani wants to merge 12 commits into
Open
AdvaitTahilyani wants to merge 12 commits into
AdvaitTahilyani wants to merge 12 commits into
Conversation
Correctness no longer depends on the solver's ties. After all metadata is final (solver, live arrays, scan/sort pins), resolve_kernel_layouts checks every fused kernel against the layout the executor writes in. A kept result R pinned elsewhere is written as X in the kernel's layout and redistributed by a follow-up node R = X (CONVERT to its own dtype); if a kernel's set_regions disagree with anything, each T[r] = v becomes X = v and a follow-up T[r] = X. Follow-ups run between the kernel and its children, so the kernel's reads still see values from before its writes; X retires after its follow-up. Kept results of different shapes abort. Unit tests: cross-kernel ties, COPY roots, a fixed target with a matmul operand, two fixed targets, whole + shifted set_regions, a renamed result read in its kernel, mixed shapes, 2-D and 3-D. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 9a55dcee7c32dd3f241dbca98a7782103fffcb6d)
1-D, 2-D and 3-D past the CPU and GPU minimum tiles: an earlier array at
a view offset written from a matmul operand (1-D), two earlier arrays at
different offsets written by one kernel, whole + shifted set_regions in
one kernel, results of different shapes, {a,b} kept by one kernel and a
written by the next, and copy() of a shifted result. Before the follow-up
nodes the matmul operand case was wrong and the test then hung.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2a8c976f1526e6e796a5798693b1ee4579e503b9)
…on mixed shapes resolve_kernel_layouts queued the set_region follow-ups T[r] = X before the whole-result copies R = X', so a kept result that is also a set_region target in its kernel (r = a+b; r[...] = c, with r renamed) ended with its value from before the set_region. The copies now run first: a kernel writes R before any set_region into it, and the copies only touch their own R. A kept result of another shape than the kernel's anchor is left as it is instead of aborting: R = X cannot reshape, and the frontend only fuses ops of one shape (check_fusible), so the executor writes every output over one iteration space anyway. Unit tests: two renamed results that are also set_region targets plus a fixed target (copies, then set_regions in kernel order), size-1 results (tiles are positive after the solver, no follow-ups), mixed shapes left alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit a2377d690397ab5b418d15c2cb63bf2c6fed4561)
q (a matmul operand, offset 0) and r (tied to an earlier array at offset 5) are kept by one kernel that also writes r[...] = c and u[...] = q + 1, so r is renamed and redistributed; r must end up as c. 1-D and 2-D; fails on 9a55dce. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit bbe8c04e41e6d7efc9c0f06c632b868335108289)
This was referenced Nov 6, 2026
Draft
adityapb
reviewed
Nov 6, 2026
adityapb
left a comment
Member
There was a problem hiding this comment.
Verdict: approve with nits, once #43's creation-grid fix is in. The layouts are consistent in that case, so resolve_kernel_layouts can't see that hang.
This is a static review, plus the solver fuzzer: 30k random DAGs gave 0 inconsistent kernels after resolve. Line numbers are at this PR's head.
These hold up:
- the pass runs after every layout-setting pass;
- the copies run before the set_region writes;
- readers come after the follow-up chain;
- temporaries retire after their follow-up;
- message counts come from metadata that is identical on every PE.
- [minor] Mixed-shape kept results are now silently left in the wrong layout (
decomposition_solver.hpp:2532).- Commit 4ccc979 replaced an error with a skip.
- The safety argument is the frontend's
check_fusible. Butexamples/ops/test_kernel_layouts.py:104never actually fuses mismatched shapes, andtest_kernel_layout_mixed_shapeslocks in the silent skip. - Please restore a
CkAbort.
- Nit:
resolveruns after the PE-locallive_array_metamerge (dag_group_receive.cpp:514→:542). The rewrite and thesynth_name/synth_node_idcounters therefore have to be identical on every PE. A debug assert would catch a divergence before it turns into a hang. - Nit: metadata for the synthetic temporaries is never removed from
array_meta, so it grows during long iterative runs.
…e across PEs - A fused kernel that keeps results of different shapes is an error again (detail::kept_shapes_differ, reported by resolve_kernel_layouts, CkAbort in receive_dag_now) instead of leaving them in the wrong layout. The unit test checks the detection and the reported error. - layout_hash hashes the solved DAG (roots and their layouts) and the synthetic name/node counters. Each PE sends it to the next PE, which aborts if it differs from its own, so a PE-local divergence fails loudly instead of hanging. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
#43's creation-grid fix (d31a115) is on #43 only. This head still needs it merged up. Validated: unit tests (standalone, CT_MIN_TILE=64); nc build of this head; CPU regress at +p1 and +p2: orig 15/15, ports 25/25, ops 37/37 at each PE count (with the hash check active at +p2). |
AdvaitTahilyani
added a commit
that referenced
this pull request
Nov 10, 2026
The solver keeps a zero-offset (matmul-pinned) kept result of a shifted set_region kernel off its grid; the assert now sits after same_shape. The executor writes such a result on the kernel's tiles, so it now aborts with a clear message instead of producing wrong values or a hang until #43/#44's follow-up copies land. TILE/DIAG receivers check that every piece comes from one source chare of the array_meta layout, and the sender-side offset check is always on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Correctness no longer depends on the solver unifying layouts.
resolve_kernel_layoutsruns after every layout-setting pass. For any kernel whose kept result or set_region target can't share the kernel's layout, it rewrites the kernel:No original, port or op test triggers a follow-up, apart from the new test. Before this fix, a matmul input fused with a shifted set_region gave wrong results and then hung.
Adds
test_kernel_layouts(47 checks) and solver unit tests. Validated with CPU regress at +p1, +p2 and +p4, and on 1 GPU and 4 GPUs.🤖 Generated with Claude Code