Available Passes
Scalar-to-Symbol Promotion
Scalar to symbol promotion functionality.
- class dace.transformation.passes.scalar_to_symbol.AttributedCallDetector
Bases:
NodeVisitor
Detects calls to functions that are attributes.
- visit_Call(node)
- Return type:
Any
- class dace.transformation.passes.scalar_to_symbol.RemoveConstantAttributes
Bases:
NodeTransformer
Removes calls to functions that are attributes, if they point to a constant value for a cast.
- visit_Call(node)
- Return type:
Any
- class dace.transformation.passes.scalar_to_symbol.ScalarToSymbolPromotion(*args, **kwargs)
Bases:
Pass
-
CATEGORY:
str
= 'Simplification'
- apply_pass(sdfg, _)
Promotes all matching transient scalars to SDFG symbols, changing all tasklets to inter-state assignments. This enables the transformed symbols to be used within states as part of memlets, and allows further transformations (such as loop detection) to use the information for optimization.
- Parameters:
sdfg (
SDFG
) – The SDFG to run the pass on.ignore – An optional set of strings of scalars to ignore.
transients_only – If False, also considers global data descriptors (e.g., arguments).
integers_only – If False, also considers non-integral descriptors for promotion.
- Return type:
Set
[str
]- Returns:
Set of promoted scalars.
- ignore
Fields that should not be promoted.
- integers_only
Allow promotion of integer scalars only.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- properties()
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
Set
[str
]) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- transients_only
Promote only transients.
-
CATEGORY:
- class dace.transformation.passes.scalar_to_symbol.TaskletIndirectionPromoter(in_edges, out_edges, sdfg, defined_syms)
Bases:
NodeTransformer
Promotes indirect memory access in Tasklets to symbolic memlets. After visiting an AST, self.{in,out}_mapping will be filled with mappings from unique new connector names to sets of individual memlets.
- visit_Subscript(node)
- Return type:
Any
- class dace.transformation.passes.scalar_to_symbol.TaskletPromoter(connector, symbol)
Bases:
NodeTransformer
Promotes scalars to symbols in Tasklets. If connector name is used in tasklet as subscript, modifies to symbol name. If connector is used as a standard name, modify tasklet code to use symbol.
- visit_Name(node)
- Return type:
Any
- visit_Subscript(node)
- Return type:
Any
- class dace.transformation.passes.scalar_to_symbol.TaskletPromoterDict(conn_to_sym)
Bases:
NodeTransformer
Promotes scalars to symbols in Tasklets. If connector name is used in tasklet as subscript, modifies to symbol name. If connector is used as a standard name, modify tasklet code to use symbol.
- visit_Name(node)
- Return type:
Any
- visit_Subscript(node)
- Return type:
Any
- dace.transformation.passes.scalar_to_symbol.find_promotable_scalars(sdfg, transients_only=True, integers_only=True)
Finds scalars that can be promoted to symbols in the given SDFG. Conditions for matching a scalar for symbol-promotion are as follows:
Size of data must be 1, it must not be a stream and must be transient.
Only inputs to candidate scalars must be either arrays or tasklets.
All tasklets that lead to it must have one statement, one output, and may have zero or more array inputs and not be in a scope.
Scalar must not be accessed with a write-conflict resolution.
Scalar must not be written to more than once in a state.
If scalar is not integral (i.e., int type), it must also appear in an inter-state condition to be promotable.
These conditions must apply on all occurences of the scalar in order for it to be promotable.
- Parameters:
sdfg (
SDFG
) – The SDFG to query.transients_only (
bool
) – If False, also considers global data descriptors (e.g., arguments).integers_only (
bool
) – If False, also considers non-integral descriptors for promotion.
- Return type:
Set
[str
]- Returns:
A set of promotable scalar names.
- dace.transformation.passes.scalar_to_symbol.remove_scalar_reads(sdfg, array_names)
Removes all instances of a promoted symbol’s read accesses in an SDFG. This removes each read-only access node as well as all of its descendant edges (in memlet trees) and connectors. Descends recursively to nested SDFGs and modifies tasklets (Python and C++).
- Parameters:
sdfg (
SDFG
) – The SDFG to operate on.array_names (
Dict
[str
,str
]) – Mapping between scalar names to replace and their replacement symbol name.
- Note:
Operates in-place on the SDFG.
- dace.transformation.passes.scalar_to_symbol.remove_symbol_indirection(sdfg)
Converts indirect memory accesses that involve only symbols into explicit memlets.
- Parameters:
sdfg (
SDFG
) – The SDFG to run the pass on.- Note:
Operates in-place.
- dace.transformation.passes.scalar_to_symbol.translate_cpp_tasklet_to_python(code)
Dead Memory Elimination and Merging
- class dace.transformation.passes.array_elimination.ArrayElimination(*args, **kwargs)
Bases:
Pass
Merges and removes arrays and their corresponding accesses. This includes redundant array copies, unnecessary views, and duplicate access nodes.
-
CATEGORY:
str
= 'Simplification'
- apply_pass(*args, **kwargs)
Applies the pass to the given SDFG.
- Parameters:
sdfg – The SDFG to apply the pass to.
pipeline_results – If in the context of a
Pipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Returns:
Some object if pass was applied, or None if nothing changed.
- depends_on()
If in the context of a
Pipeline
, which other Passes need to run first.- Returns:
A set of Pass subclasses or objects that need to run prior to this Pass.
- merge_access_nodes(state, access_nodes, condition)
Merges access nodes that follow the same conditions together to the first access node.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- properties()
- remove_redundant_copies(sdfg, state, removable_data, access_nodes)
Removes access nodes that represent redundant copies and/or views.
- remove_redundant_views(sdfg, state, access_nodes)
Removes access nodes that contain views, which can be represented normally by memlets. For example, slices.
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
Set
[str
]) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
-
CATEGORY:
- class dace.transformation.passes.transient_reuse.TransientReuse(*args, **kwargs)
Bases:
Pass
Reduces memory consumption by reusing allocated transient array memory. Only modifies arrays that can safely be reused.
-
CATEGORY:
str
= 'Memory Footprint Reduction'
- apply_pass(sdfg, _)
Applies the pass to the given SDFG.
- Parameters:
sdfg (
SDFG
) – The SDFG to apply the pass to.pipeline_results – If in the context of a
Pipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Return type:
Optional
[Set
[str
]]- Returns:
Some object if pass was applied, or None if nothing changed.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- properties()
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
- verbose
Print information about the memory reduction.
-
CATEGORY:
Dead Code Elimination
- class dace.transformation.passes.dead_state_elimination.DeadStateElimination(*args, **kwargs)
Bases:
Pass
Removes all unreachable states (e.g., due to a branch that will never be taken) from an SDFG.
-
CATEGORY:
str
= 'Simplification'
- apply_pass(*args, **kwargs)
Applies the pass to the given SDFG.
- Parameters:
sdfg – The SDFG to apply the pass to.
pipeline_results – If in the context of a
Pipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Returns:
Some object if pass was applied, or None if nothing changed.
- find_dead_states(sdfg, set_unconditional_edges=True)
Finds “dead” (unreachable) states in an SDFG. A state is deemed unreachable if it is:
Unreachable from the starting state
Conditions leading to it will always evaluate to False
There is another unconditional (always True) inter-state edge that leads to another state
- Parameters:
sdfg (
SDFG
) – The SDFG to traverse.set_unconditional_edges (
bool
) – If True, conditions of edges evaluated as unconditional are removed.
- Return type:
Tuple
[Set
[SDFGState
],Set
[Edge
[InterstateEdge
]],bool
]- Returns:
A 3-tuple of (unreachable states, unreachable edges, were edges annotated).
- is_definitely_not_taken(edge, sdfg)
Returns True iff edge condition definitely evaluates to False.
- Return type:
bool
- is_definitely_taken(edge, sdfg)
Returns True iff edge condition definitely evaluates to True.
- Return type:
bool
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- properties()
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
Set
[Union
[Edge
[InterstateEdge
],SDFGState
]]) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
-
CATEGORY:
- class dace.transformation.passes.dead_dataflow_elimination.DeadDataflowElimination(*args, **kwargs)
Bases:
Pass
Removes unused computations from SDFG states. Traverses the graph backwards, removing any computations that result in transient descriptors that are not used again. Removal propagates through scopes (maps), tasklets, and optionally library nodes.
-
CATEGORY:
str
= 'Simplification'
- apply_pass(*args, **kwargs)
Applies the pass to the given SDFG.
- Parameters:
sdfg – The SDFG to apply the pass to.
pipeline_results – If in the context of a
Pipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Returns:
Some object if pass was applied, or None if nothing changed.
- depends_on()
If in the context of a
Pipeline
, which other Passes need to run first.- Return type:
Set
[Type
[Pass
]]- Returns:
A set of Pass subclasses or objects that need to run prior to this Pass.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- properties()
- remove_persistent_memory
If True, marks code with Persistent allocation lifetime as dead
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
Dict
[SDFGState
,Set
[str
]]) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
- skip_library_nodes
If True, does not remove library nodes if their results are unused. Otherwise removes library nodes without side effects.
-
CATEGORY:
- dace.transformation.passes.dead_dataflow_elimination.PROTECTED_NAMES = {'__pystate'}
A set of names that are not allowed to be erased
- class dace.transformation.passes.prune_symbols.RemoveUnusedSymbols(*args, **kwargs)
Bases:
Pass
Prunes unused symbols from the SDFG symbol repository (
sdfg.symbols
) and interstate edges. Also includes uses in Tasklets of all languages.-
CATEGORY:
str
= 'Simplification'
- apply_pass(*args, **kwargs)
Applies the pass to the given SDFG.
- Parameters:
sdfg – The SDFG to apply the pass to.
pipeline_results – If in the context of a
Pipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Returns:
Some object if pass was applied, or None if nothing changed.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- properties()
- recursive
Prune nested SDFGs recursively
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
Set
[str
]) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
- symbols
Limit considered symbols to this set
- used_symbols(sdfg)
- Return type:
Set
[str
]
-
CATEGORY:
Constant Propagation
- class dace.transformation.passes.constant_propagation.ConstantPropagation(*args, **kwargs)
Bases:
Pass
Propagates constants and symbols that were assigned to one value forward through the SDFG, reducing the number of overall symbols.
-
CATEGORY:
str
= 'Simplification'
- apply_pass(*args, **kwargs)
Applies the pass to the given SDFG.
- Parameters:
sdfg – The SDFG to apply the pass to.
pipeline_results – If in the context of a
Pipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Returns:
Some object if pass was applied, or None if nothing changed.
- collect_constants(sdfg, initial_symbols=None)
Finds all constants and constant-assigned symbols in the SDFG for each state.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- progress
Show progress
- properties()
- recursive
Propagagte recursively through nested SDFGs
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
Set
[str
]) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_apply(sdfg)
Fast check (O(m)) whether the pass should early-exit without traversing the SDFG.
- Return type:
bool
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
-
CATEGORY:
- class dace.transformation.passes.optional_arrays.OptionalArrayInference(*args, **kwargs)
Bases:
Pass
Infers the
optional
property of arrays, i.e., if they can be given None, throughout the SDFG and all nested SDFGs.An array will be modified to optional if its previous
optional
property was set toNone
and: * it is transient; * it is in a nested SDFG and its parent array was transient; or * it is definitely (unconditionally) read or written in the SDFG.-
CATEGORY:
str
= 'Simplification'
- apply_pass(*args, **kwargs)
Applies the pass to the given SDFG.
- Parameters:
sdfg – The SDFG to apply the pass to.
pipeline_results – If in the context of a
Pipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Returns:
Some object if pass was applied, or None if nothing changed.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- properties()
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
Set
[Tuple
[int
,str
]]) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
-
CATEGORY:
Memlet Consolidation
- class dace.transformation.passes.consolidate_edges.ConsolidateEdges(*args, **kwargs)
Bases:
Pass
Removes extraneous edges with memlets that refer to the same data containers within the same scope.
Memlet subsets are unioned in each scope. This effectively reduces the number of connectors and allows more transformations to be performed, at the cost of losing the individual per-tasklet memlets.
-
CATEGORY:
str
= 'Simplification'
- apply_pass(sdfg, _)
Consolidates edges on the given SDFG.
- Parameters:
sdfg (
SDFG
) – The SDFG to modify.pipeline_results – If in the context of a
Pipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Return type:
Optional
[int
]- Returns:
Number of edges removed, or None if nothing was performed.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- properties()
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
int
) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
-
CATEGORY:
State Fusion and SDFG Inlining
Contains implementations of SDFG inlining and state fusion passes.
- class dace.transformation.passes.fusion_inline.FixNestedSDFGReferences(*args, **kwargs)
Bases:
Pass
Fixes nested SDFG references to parent state/SDFG/node
-
CATEGORY:
str
= 'Cleanup'
- apply_pass(sdfg, _)
Applies the pass to the given SDFG.
- Parameters:
sdfg (
SDFG
) – The SDFG to apply the pass to.pipeline_results – If in the context of a
Pipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Return type:
Optional
[int
]- Returns:
Some object if pass was applied, or None if nothing changed.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- properties()
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
int
) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
-
CATEGORY:
- class dace.transformation.passes.fusion_inline.FuseStates(*args, **kwargs)
Bases:
Pass
Fuses all possible states of an SDFG (and all sub-SDFGs).
-
CATEGORY:
str
= 'Simplification'
- apply_pass(sdfg, _)
Fuses all possible states of an SDFG (and all sub-SDFGs).
- Parameters:
sdfg (
SDFG
) – The SDFG to transform.- Return type:
Optional
[int
]- Returns:
The total number of states fused, or None if did not apply.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- permissive
If True, ignores some race condition checks.
- progress
Whether to print progress, or None for default (print after 5 seconds).
- properties()
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
int
) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
-
CATEGORY:
- class dace.transformation.passes.fusion_inline.InlineSDFGs(*args, **kwargs)
Bases:
Pass
Inlines all possible nested SDFGs (and sub-SDFGs).
-
CATEGORY:
str
= 'Simplification'
- apply_pass(sdfg, _)
Inlines all possible nested SDFGs (and all sub-SDFGs).
- Parameters:
sdfg (
SDFG
) – The SDFG to transform.- Return type:
Optional
[int
]- Returns:
The total number of states fused, or None if did not apply.
- modifies()
Which elements of the SDFG (e.g., memlets, state structure) are modified by this pass, if run successfully.
- Return type:
- Returns:
A
Modifies
set of flags of modified elements.
- multistate
If True, include multi-state inlining.
- permissive
If True, ignores some checks on inlining.
- progress
Whether to print progress, or None for default (print after 5 seconds).
- properties()
- report(pass_retval)
Returns a user-readable string report based on the results of this pass.
- Parameters:
pass_retval (
int
) – The return value from applying this pass.- Return type:
str
- Returns:
A string with the user-readable report, or None if nothing to report.
- should_reapply(modified)
In the context of a
Pipeline
, queries whether this Pass should be rerun after other passes have run and modified the SDFG.- Parameters:
modified (
Modifies
) – Flags specifying which elements of the SDFG were modified.- Return type:
bool
- Returns:
True if this Pass should be rerun when the given elements are modified.
-
CATEGORY:
Analysis Passes
The Simplify Pass Pipeline
- class dace.transformation.passes.simplify.SimplifyPass(*args, **kwargs)
Bases:
FixedPointPipeline
A pipeline that simplifies an SDFG by applying a series of simplification passes.
-
CATEGORY:
str
= 'Simplification'
- apply_pass(sdfg, pipeline_results)
Applies the pipeline to the SDFG in repeated succession until the SDFG is no longer modified.
- Parameters:
sdfg (
SDFG
) – The SDFG to apply the pass to.pipeline_results (
Dict
[str
,Any
]) – If in the context of aPipeline
, a dictionary that is populated with prior Pass results as{Pass subclass name: returned object from pass}
. If not run in a pipeline, an empty dictionary is expected.
- Return type:
Optional
[Dict
[str
,Any
]]- Returns:
A dictionary of
{Pass subclass name: return value}
for applied passes, or None if no Passes were applied in the context of this pipeline.
- apply_subpass(sdfg, p, state)
Apply a pass from the pipeline. This method is meant to be overridden by subclasses.
- properties()
- skip
Set of pass names to skip.
- validate
Whether to validate the SDFG at the end of the pipeline.
- validate_all
Whether to validate the SDFG after each pass.
- verbose
Whether to print reports after every pass.
-
CATEGORY: