Remove Views Pass#2335
Open
ThrudPrimrose wants to merge 4 commits into
Open
Conversation
Collaborator
|
What cases does your pass remove that the existing view removal transformations in array elimination doesn’t cover? |
Collaborator
Author
I compared
|
tbennun
requested changes
Apr 30, 2026
tbennun
left a comment
Collaborator
There was a problem hiding this comment.
Please add to simplification pipeline
Comment on lines
+12
to
+14
| Two strategies are used depending on the view kind: | ||
|
|
||
| Four strategies are tried in order until one succeeds: |
| @@ -206,9 +201,6 @@ def _delinearize_flat(flat, astrides: List[int], array_shape: List[int]): | |||
| return [(flat // astr) % shp for astr, shp in zip(astrides, array_shape)] | |||
Collaborator
There was a problem hiding this comment.
can you explain how this works, especially with complex permutations?
tbennun
requested changes
May 12, 2026
| from dace.sdfg import nodes as nd, utils as sdutil, graph as gr | ||
| from dace.transformation import pass_pipeline as ppl, transformation | ||
|
|
||
| _PASS = 'RemoveViews' |
| from dace.transformation import pass_pipeline as ppl, transformation | ||
|
|
||
| _PASS = 'RemoveViews' | ||
| _DEBUGPRINT = config.Config.get('debugprint') in (True, '1', 'true', 'yes') |
Collaborator
There was a problem hiding this comment.
this does not work. Also this does not conform to our API.
- It will only read it on import, so someone who sets the config temporarily will not observe this change.
- Call
config.Config.get_bool('debugprint')
So just call this function in the only place it is used.
ThrudPrimrose
added a commit
that referenced
this pull request
Jun 3, 2026
… MapToForLoop reparent Bundle of related canonicalize-pipeline improvements: * **`merge` -> `ITE` global rename**: the 3-input ternary blend used by branch_normalization, vectorization, and (now) `EarlyExitToFindIndex` is renamed throughout. `class ITE(sympy.Function)` is the sole class in `dace.symbolic`; `dace/runtime/include/dace/merge.h` is renamed to `ITE.h` and the C++ template is `ITE(c, a, b)`. Files moved: `lower_merge_to_fp_factor.py` -> `lower_ite_to_fp_factor.py`, `same_write_set_if_else_to_merge_cfg.py` -> `same_write_set_if_else_to_ite_cfg.py`, plus the matching test files under `tests/`. All call sites updated to emit `ITE(...)`. Tests: test_split_tasklets / test_ite_function / test_lower_ite_to_fp_factor / test_same_write_set_if_else_to_ite_cfg / test_branch_normalization 43/43 focused tests pass. * **`SplitTasklets`: lower Python `IfExp` to `ITE(c, t, e)`** in ASTSplitter so the tasklet body never carries a Python ternary and cppunparse never has to emit a `c ? t : e` ternary. * **`LowerITEToFpFactor` wired after `SplitTasklets` in 'clean'** so every `ITE(c, t, e)` call lowers to the FP-factor form `c * t + (1 - c) * e` at canonicalize time. * **EarlyExitToFindIndex** indicator-Map tasklet now emits `__out = ITE((cond), i, N)` (was `__out = i if (cond) else N`); also adds `_trace_transient_to_source_arrays` so the soundness check walks transient gather chains (`d_index = d[i]`) back to the underlying non-transient array. Three new tests: combo body_pre + body_post, cond/body overlap refusal pre+post, and the s481/s482 contracts. * **Scalar-slice fold passes wired into `_structural_cleanup`**: `CleanAccessNodeToScalarSliceToTaskletPattern` and its inverse `CleanTaskletToScalarSliceToAccessNodePattern` collapse the gather bridges so downstream matchers see the underlying array names. Wired between `RemoveViews` and `EmptyStateElimination`. Known regression set on the TSVC corpus (s314-s316, s3110/s3111/s31111, s352/s353, s421-s443, s4112-s4117) is being hardened separately at the LoopToReduce / LoopToScan / ArgMaxLift matchers; this commit lands the wiring + accepts the regressions. * **RemoveViews pass (PR #2335)** wired into `_structural_cleanup` between InlineSDFG and the scalar-slice folds; 16/16 new `tests/remove_views_test.py` tests pass. * **MapToForLoop `inline_after` successor-edge reparent**: when the inline migration is requested, the placeholder graph's pre-existing `graph -> *` interstate edges are now reparented onto the new `target_state` so the placeholder has exactly one out-edge. Without this, `control_flow_raising` later lifted the placeholder into a `ConditionalBlock` with the `else` branch not in the last position, and `DeadStateElimination._find_dead_branches` aborted. Three previously-failing tests now pass: `test_thomas_solve_value_preserving`, `test_thomas_solve_keeps_vertical_axis_sequential`, and `test_canonicalization_stages_apply_to_cloudsc`. Regression test `test_a6_multi_successor_reparent_on_inline` covers the contract. * **`control_flow_raising`** stable-sorts out-edges so unconditional edges fall at the tail before populating the `ConditionalBlock` branches, keeping the lift robust against future producers that emit out-edges in arbitrary order. Regression test `test_unconditional_edge_lifted_as_last_branch`. * **`tasklet_utils.classify_tasklet`**: unknown shapes (unknown function call, RHS not a recognised pattern) now report `type = TaskletType.UNKNOWN` instead of raising `NotImplementedError`. Adds `TaskletType.UNKNOWN` enum member. Existing callers using `info.get("type") in {...}` keep working; callers that want to explicitly skip unclassified tasklets now branch on `ttype == TaskletType.UNKNOWN`.
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.
This PR introduces a pass that removes views from the SDFG by folding them into the access patterns of the arrays they view.
Context: Reduced SDFG IR
This is the first PR toward a Reduced IR. A simplified subset of the full SDFG IR that limits the number of features transformations that need support. The Reduced IR eliminates views, WCR edges, other_subset on edges, dynamic thread-block maps, and persistent device maps by lowering each to a smaller set of primitives (e.g., WCR becomes a reduction library node, other_subset requiring copies becomes explicit copy nodes).
The goal of this PR is to be part of many to provide a lower pipeline from the full IR to the Reduced IR, removing as many of these features as possible. Alongside this pass, I have also extended the Copy library node and implemented a pass that inserts explicit copies where needed. (Separate PR)
What this pass does
The pass tries to remove as many views as possible by absorbing them into surrounding memlets. For example, a view that selects a strided column from a row-major array:
is removed with the following subset:
(It supports many other patterns as well).