Use sorted set in SDFG construction#2398
Closed
edopao wants to merge 4 commits into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make parts of DaCe’s pass pipeline and SDFG construction/lowering deterministic by replacing unordered set usage with ordered alternatives (notably ordered_set.OrderedSet) and by switching Pass.depends_on() to return an ordered collection.
Changes:
- Add
ordered-setas a dependency and introduceOrderedSetin multiple passes/graph utilities to stabilize iteration order. - Change
Pass.depends_on()(and many implementations/tests) to return lists for deterministic dependency ordering. - Replace some internal
set-based collections used during analysis/lowering withOrderedSetor ordered sequences.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/passes/pipeline_test.py | Updates tests for depends_on() now returning lists. |
| setup.py | Adds ordered-set to install requirements. |
| requirements.txt | Pins ordered-set==4.1.0. |
| dace/transformation/passes/symbol_ssa.py | Updates dependency declaration to a list. |
| dace/transformation/passes/split_tasklets.py | Returns empty dependency list instead of {}. |
| dace/transformation/passes/scalar_fission.py | Updates dependency declaration to a list. |
| dace/transformation/passes/reference_reduction.py | Updates dependency declaration to a list. |
| dace/transformation/passes/pattern_matching.py | Refactors dependency aggregation (currently introduces a runtime bug). |
| dace/transformation/passes/loop_local_memory_reduction.py | Updates dependency declaration to a list. |
| dace/transformation/passes/lift_struct_views.py | Returns empty dependency list instead of {}. |
| dace/transformation/passes/full_map_fusion.py | Updates dependency declaration to a list. |
| dace/transformation/passes/dead_dataflow_elimination.py | Updates dependency return value (annotation mismatch remains). |
| dace/transformation/passes/array_elimination.py | Introduces OrderedSet for deterministic removable-data iteration. |
| dace/transformation/passes/analysis/scope_data_and_symbol_analysis.py | Returns empty dependency list instead of {}. |
| dace/transformation/passes/analysis/analysis.py | Broad adoption of OrderedSet (currently has set/OrderedSet operator/type issues). |
| dace/transformation/pass_pipeline.py | Changes base depends_on() contract and pipeline dependency aggregation (currently introduces a runtime bug). |
| dace/transformation/helpers.py | Switches post-state node collection from set to list (ordered). |
| dace/transformation/dataflow/map_fusion_vertical.py | Uses OrderedSet for deterministic edge/connector ordering. |
| dace/sdfg/state.py | Warns on set-based connector collections (typo in message). |
| dace/sdfg/scope.py | Uses OrderedSet in scope subgraph collection to preserve order. |
| dace/sdfg/graph.py | Makes all_edges deterministically ordered via OrderedSet. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+485
to
+486
| def depends_on(self) -> List[Type[Pass]]: | ||
| return list(dict.fromkeys([p.depends_on() for p in self.passes])) |
Comment on lines
+58
to
+64
| def depends_on(self) -> List[Union[Type['Pass'], 'Pass']]: | ||
| """ | ||
| If in the context of a ``Pipeline``, which other Passes need to run first. | ||
|
|
||
| :return: A set of Pass subclasses or objects that need to run prior to this Pass. | ||
| """ | ||
| return set() | ||
| return [] |
Comment on lines
+82
to
+83
| def depends_on(self) -> List[Type[ppl.Pass]]: | ||
| return list(dict.fromkeys([p.depends_on() for p in self.transformations])) |
Comment on lines
276
to
+279
| for sdfg in top_sdfg.all_sdfgs_recursive(): | ||
| arrays: Set[str] = set(sdfg.arrays.keys()) | ||
| arrays: OrderedSet[str] = OrderedSet(sdfg.arrays.keys()) | ||
| for block in sdfg.all_control_flow_blocks(): | ||
| readset, writeset = set(), set() | ||
| readset, writeset = OrderedSet(), OrderedSet() |
Comment on lines
232
to
234
| for block in region.nodes(): | ||
| # No symbols may be written to inside blocks. | ||
| result[block] = (block.free_symbols, set()) |
Comment on lines
47
to
+48
| def depends_on(self) -> Set[Type[ppl.Pass]]: | ||
| return {ap.ControlFlowBlockReachability, ap.AccessSets} | ||
| return [ap.ControlFlowBlockReachability, ap.AccessSets] |
| that use that data descriptor. | ||
| """ | ||
| top_result: Dict[int, Dict[str, Set[nd.AccessNode]]] = dict() | ||
| top_result: Dict[int, Dict[str, OrderedSet[nd.AccessNode]]] = dict() |
Comment on lines
687
to
689
| block_reach: Dict[ControlFlowBlock, | ||
| Set[ControlFlowBlock]] = pipeline_results[ControlFlowBlockReachability.__name__] | ||
| OrderedSet[ControlFlowBlock]] = pipeline_results[ControlFlowBlockReachability.__name__] | ||
|
|
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 replaces
setwithOrderedSetfrom https://github.com/rspeer/ordered-set in some places where order matters to ensure deterministic lowering.Pulls changes from GridTools#17