dace.transformation package

Subpackages

Submodules

dace.transformation.transformation module

Contains classes that represent data-centric transformations.

There are three general types of transformations:
  • Pattern-matching Transformations (extending Transformation): Transformations that require a certain subgraph structure to match.
  • Subgraph Transformations (extending SubgraphTransformation): Transformations that can operate on arbitrary subgraphs.
  • Library node expansions (extending ExpandTransformation): An internal class used for tracking how library nodes were expanded.
class dace.transformation.transformation.ExpandTransformation(*args, **kwargs)

Bases: dace.transformation.transformation.Transformation

Base class for transformations that simply expand a node into a subgraph, and thus needs only simple matching and replacement functionality. Subclasses only need to implement the method “expansion”.

This is an internal interface used to track the expansion of library nodes.

apply(sdfg, *args, **kwargs)

Applies this transformation instance on the matched pattern graph. :param sdfg: The SDFG to apply the transformation to. :return: A transformation-defined return value, which could be used

to pass analysis data out, or nothing.
static can_be_applied(graph: dace.sdfg.graph.OrderedMultiDiConnectorGraph, candidate: Dict[dace.sdfg.nodes.Node, int], expr_index: int, sdfg, strict: bool = False)

Returns True if this transformation can be applied on the candidate matched subgraph. :param graph: SDFGState object if this Transformation is

single-state, or SDFG object otherwise.
Parameters:
  • candidate – A mapping between node IDs returned from Transformation.expressions and the nodes in graph.
  • expr_index – The list index from Transformation.expressions that was matched.
  • sdfg – If graph is an SDFGState, its parent SDFG. Otherwise should be equal to graph.
  • strict – Whether transformation should run in strict mode.
Returns:

True if the transformation can be applied.

static expansion(node)
classmethod expressions()

Returns a list of Graph objects that will be matched in the subgraph isomorphism phase. Used as a pre-pass before calling can_be_applied. :see: Transformation.can_be_applied

static from_json(json_obj: Dict[str, Any], context: Dict[str, Any] = None) → dace.transformation.transformation.ExpandTransformation
classmethod match_to_str(graph: dace.sdfg.graph.OrderedMultiDiConnectorGraph, candidate: Dict[dace.sdfg.nodes.Node, int])

Returns a string representation of the pattern match on the candidate subgraph. Used when identifying matches in the console UI.

static postprocessing(sdfg, state, expansion)
properties()
to_json(parent=None) → Dict[str, Any]
class dace.transformation.transformation.PatternNode(nodeclass: Type[Union[dace.sdfg.nodes.Node, dace.sdfg.state.SDFGState]])

Bases: object

Static field wrapper of a node or an SDFG state that designates it as part of a subgraph pattern. These objects are used in subclasses of Transformation to represent the subgraph patterns.

Example use: ``` @registry.autoregister_params(singlestate=True) class MyTransformation(Transformation):

some_map_node = PatternNode(nodes.MapEntry) array = PatternNode(nodes.AccessNode)

```

The two nodes can then be used in the transformation static methods (e.g., expressions, can_be_applied) to represent the nodes, and in the instance methods to point to the nodes in the parent SDFG.

class dace.transformation.transformation.SubgraphTransformation(*args, **kwargs)

Bases: dace.transformation.transformation.TransformationBase

Base class for transformations that apply on arbitrary subgraphs, rather than matching a specific pattern.

Subclasses need to implement the can_be_applied and apply operations, as well as registered with the subclass registry. See the Transformation class docstring for more information.

apply(sdfg: dace.sdfg.sdfg.SDFG)

Applies the transformation on the given subgraph. :param sdfg: The SDFG that includes the subgraph.

classmethod apply_to(sdfg: dace.sdfg.sdfg.SDFG, *where, verify: bool = True, **options)

Applies this transformation to a given subgraph, defined by a set of nodes. Raises an error if arguments are invalid or transformation is not applicable.

To apply the transformation on a specific subgraph, the where parameter can be used either on a subgraph object (SubgraphView), or on directly on a list of subgraph nodes, given as Node or SDFGState objects. Transformation properties can then be given as keyword arguments. For example, applying SubgraphFusion on a subgraph of three nodes can be called in one of two ways: ``` # Subgraph SubgraphFusion.apply_to(

sdfg, SubgraphView(state, [node_a, node_b, node_c]))

# Simplified API: list of nodes SubgraphFusion.apply_to(sdfg, node_a, node_b, node_c) ```

Parameters:
  • sdfg – The SDFG to apply the transformation to.
  • where – A set of nodes in the SDFG/state, or a subgraph thereof.
  • verify – Check that can_be_applied returns True before applying.
  • options – A set of parameters to use for applying the transformation.
can_be_applied(sdfg: dace.sdfg.sdfg.SDFG, subgraph: dace.sdfg.graph.SubgraphView) → bool

Tries to match the transformation on a given subgraph, returning True if this transformation can be applied. :param sdfg: The SDFG that includes the subgraph. :param subgraph: The SDFG or state subgraph to try to apply the

transformation on.
Returns:True if the subgraph can be transformed, or False otherwise.
extensions()
static from_json(json_obj: Dict[str, Any], context: Dict[str, Any] = None) → dace.transformation.transformation.SubgraphTransformation
properties()
register(**kwargs)
sdfg_id

ID of SDFG to transform

state_id

ID of state to transform subgraph within, or -1 to transform the SDFG

subgraph

Subgraph in transformation instance

subgraph_view(sdfg: dace.sdfg.sdfg.SDFG) → dace.sdfg.graph.SubgraphView
to_json(parent=None)
unregister()
class dace.transformation.transformation.Transformation(*args, **kwargs)

Bases: dace.transformation.transformation.TransformationBase

Base class for pattern-matching transformations, as well as a static registry of transformations, where new transformations can be added in a decentralized manner. An instance of a Transformation represents a match of the transformation on an SDFG, complete with a subgraph candidate and properties.

New transformations that extend this class must contain static PatternNode fields that represent the nodes in the pattern graph, and use them to implement at least three methods:

  • expressions: A method that returns a list of graph
    patterns (SDFG or SDFGState objects) that match this transformation.
  • can_be_applied: A method that, given a subgraph candidate,
    checks for additional conditions whether it can be transformed.
  • apply: A method that applies the transformation
    on the given SDFG.

For more information and optimization opportunities, see the respective methods’ documentation.

In order to be included in lists and apply through the sdfg.apply_transformations API, each transformation shouls be registered with Transformation.register (or, more commonly, the @dace.registry.autoregister_params class decorator) with two optional boolean keyword arguments: singlestate (default: False) and strict (default: False). If singlestate is True, the transformation is matched on subgraphs inside an SDFGState; otherwise, subgraphs of the SDFG state machine are matched. If strict is True, this transformation will be considered strict (i.e., always beneficial to perform) and will be performed automatically as part of SDFG strict transformations.

annotates_memlets() → bool

Indicates whether the transformation annotates the edges it creates or modifies with the appropriate memlets. This determines whether to apply memlet propagation after the transformation.

apply(sdfg: dace.sdfg.sdfg.SDFG) → Optional[Any]

Applies this transformation instance on the matched pattern graph. :param sdfg: The SDFG to apply the transformation to. :return: A transformation-defined return value, which could be used

to pass analysis data out, or nothing.
apply_pattern(sdfg: dace.sdfg.sdfg.SDFG, append: bool = True, annotate: bool = True) → Optional[Any]

Applies this transformation on the given SDFG, using the transformation instance to find the right SDFG object (based on SDFG ID), and applying memlet propagation as necessary. :param sdfg: The SDFG (or an SDFG in the same hierarchy) to apply the

transformation to.
Parameters:append – If True, appends the transformation to the SDFG transformation history.
Returns:A transformation-defined return value, which could be used to pass analysis data out, or nothing.
classmethod apply_to(sdfg: dace.sdfg.sdfg.SDFG, options: Optional[Dict[str, Any]] = None, expr_index: int = 0, verify: bool = True, annotate: bool = True, strict: bool = False, save: bool = True, **where)

Applies this transformation to a given subgraph, defined by a set of nodes. Raises an error if arguments are invalid or transformation is not applicable.

The subgraph is defined by the where dictionary, where each key is taken from the PatternNode fields of the transformation. For example, applying MapCollapse on two maps can pe performed as follows:

` MapCollapse.apply_to(sdfg, outer_map_entry=map_a, inner_map_entry=map_b) `

Parameters:
  • sdfg – The SDFG to apply the transformation to.
  • options – A set of parameters to use for applying the transformation.
  • expr_index – The pattern expression index to try to match with.
  • verify – Check that can_be_applied returns True before applying.
  • annotate – Run memlet propagation after application if necessary.
  • strict – Apply transformation in strict mode.
  • save – Save transformation as part of the SDFG file. Set to False if composing transformations.
  • where – A dictionary of node names (from the transformation) to nodes in the SDFG or a single state.
can_be_applied(graph: Union[dace.sdfg.sdfg.SDFG, dace.sdfg.state.SDFGState], candidate: Dict[PatternNode, int], expr_index: int, sdfg: dace.sdfg.sdfg.SDFG, strict: bool = False) → bool

Returns True if this transformation can be applied on the candidate matched subgraph. :param graph: SDFGState object if this Transformation is

single-state, or SDFG object otherwise.
Parameters:
  • candidate – A mapping between node IDs returned from Transformation.expressions and the nodes in graph.
  • expr_index – The list index from Transformation.expressions that was matched.
  • sdfg – If graph is an SDFGState, its parent SDFG. Otherwise should be equal to graph.
  • strict – Whether transformation should run in strict mode.
Returns:

True if the transformation can be applied.

expr_index

Object property of type int

expressions() → List[dace.sdfg.graph.SubgraphView]

Returns a list of Graph objects that will be matched in the subgraph isomorphism phase. Used as a pre-pass before calling can_be_applied. :see: Transformation.can_be_applied

extensions()
static from_json(json_obj: Dict[str, Any], context: Dict[str, Any] = None) → dace.transformation.transformation.Transformation
match_to_str(graph: Union[dace.sdfg.sdfg.SDFG, dace.sdfg.state.SDFGState], candidate: Dict[PatternNode, int]) → str

Returns a string representation of the pattern match on the candidate subgraph. Used when identifying matches in the console UI.

print_match(sdfg: dace.sdfg.sdfg.SDFG) → str

Returns a string representation of the pattern match on the given SDFG. Used for printing matches in the console UI.

properties()
register(**kwargs)
sdfg_id

Object property of type int

state_id

Object property of type int

subgraph
to_json(parent=None) → Dict[str, Any]
unregister()
class dace.transformation.transformation.TransformationBase

Bases: object

Base class for data-centric transformations.

dace.transformation.transformation.strict_transformations() → List[Type[dace.transformation.transformation.Transformation]]
Returns:List of all registered strict transformations.

dace.transformation.helpers module

Transformation helper API.

dace.transformation.helpers.are_subsets_contiguous(subset_a: dace.subsets.Subset, subset_b: dace.subsets.Subset, dim: int = None) → bool
dace.transformation.helpers.constant_symbols(sdfg: dace.sdfg.sdfg.SDFG) → Set[str]

Returns a set of symbols that will never change values throughout the course of the given SDFG. Specifically, these are the input symbols (i.e., not defined in a particular scope) that are never set by interstate edges. :param sdfg: The input SDFG. :return: A set of symbol names that remain constant throughout the SDFG.

dace.transformation.helpers.contained_in(state: dace.sdfg.state.SDFGState, node: dace.sdfg.nodes.Node, scope: dace.sdfg.nodes.EntryNode) → bool

Returns true if the specified node is contained within the scope opened by the given entry node (including through nested SDFGs).

dace.transformation.helpers.extract_map_dims(sdfg: dace.sdfg.sdfg.SDFG, map_entry: dace.sdfg.nodes.MapEntry, dims: List[int]) → Tuple[dace.sdfg.nodes.MapEntry, dace.sdfg.nodes.MapEntry]

Helper function that extracts specific map dimensions into an outer map. :param sdfg: The SDFG where the map resides. :param map_entry: Map entry node to extract. :param dims: A list of dimension indices to extract. :return: A 2-tuple containing the extracted map and the remainder map.

dace.transformation.helpers.find_contiguous_subsets(subset_list: List[dace.subsets.Subset], dim: int = None) → Set[dace.subsets.Subset]

Finds the set of largest contiguous subsets in a list of subsets. :param subsets: Iterable of subset objects. :param dim: Check for contiguity only for the specified dimension. :return: A list of contiguous subsets.

dace.transformation.helpers.get_internal_scopes(state: dace.sdfg.state.SDFGState, entry: dace.sdfg.nodes.EntryNode, immediate: bool = False) → List[Tuple[dace.sdfg.state.SDFGState, dace.sdfg.nodes.EntryNode]]

Returns all internal scopes within a given scope, including if they reside in nested SDFGs. :param state: State in which entry node resides. :param entry: The entry node to start from. :param immediate: If True, only returns the scopes that are immediately

nested in the map.
dace.transformation.helpers.get_parent_map(state: dace.sdfg.state.SDFGState, node: Optional[dace.sdfg.nodes.Node] = None) → Optional[Tuple[dace.sdfg.nodes.EntryNode, dace.sdfg.state.SDFGState]]

Returns the map in which the state (and node) are contained in, or None if it is free. :param state: The state to test or parent of the node to test. :param node: The node to test (optional). :return: A tuple of (entry node, state) or None.

dace.transformation.helpers.gpu_map_has_explicit_threadblocks(state: dace.sdfg.state.SDFGState, entry: dace.sdfg.nodes.EntryNode) → bool

Returns True if GPU_Device map has explicit thread-block maps nested within.

dace.transformation.helpers.is_symbol_unused(sdfg: dace.sdfg.sdfg.SDFG, sym: str) → bool

Checks for uses of symbol in an SDFG, and if there are none returns False. :param sdfg: The SDFG to search. :param sym: The symbol to test. :return: True if the symbol can be removed, False otherwise.

dace.transformation.helpers.nest_state_subgraph(sdfg: dace.sdfg.sdfg.SDFG, state: dace.sdfg.state.SDFGState, subgraph: dace.sdfg.graph.SubgraphView, name: Optional[str] = None, full_data: bool = False) → dace.sdfg.nodes.NestedSDFG

Turns a state subgraph into a nested SDFG. Operates in-place. :param sdfg: The SDFG containing the state subgraph. :param state: The state containing the subgraph. :param subgraph: Subgraph to nest. :param name: An optional name for the nested SDFG. :param full_data: If True, nests entire input/output data. :return: The nested SDFG node. :raise KeyError: Some or all nodes in the subgraph are not located in

this state, or the state does not belong to the given SDFG.
Raises:ValueError – The subgraph is contained in more than one scope.
dace.transformation.helpers.offset_map(sdfg: dace.sdfg.sdfg.SDFG, state: dace.sdfg.state.SDFGState, entry: dace.sdfg.nodes.MapEntry, dim: int, offset: Union[sympy.core.basic.Basic, dace.symbolic.SymExpr], negative: bool = True)

Offsets a map parameter and its contents by a value. :param sdfg: The SDFG in which the map resides. :param state: The state in which the map resides. :param entry: The map entry node. :param dim: The map dimension to offset. :param offset: The value to offset by. :param negative: If True, offsets by -offset.

dace.transformation.helpers.permute_map(map_entry: dace.sdfg.nodes.MapEntry, perm: List[int])

Permutes indices of a map according to a given list of integers.

dace.transformation.helpers.reconnect_edge_through_map(state: dace.sdfg.state.SDFGState, edge: dace.sdfg.graph.MultiConnectorEdge[dace.memlet.Memlet][dace.memlet.Memlet], new_node: Union[dace.sdfg.nodes.EntryNode, dace.sdfg.nodes.ExitNode], keep_src: bool) → Tuple[dace.sdfg.graph.MultiConnectorEdge[dace.memlet.Memlet][dace.memlet.Memlet], dace.sdfg.graph.MultiConnectorEdge[dace.memlet.Memlet][dace.memlet.Memlet]]

Reconnects an edge through a map scope, removes old edge, and returns the two new edges. :param state: The state in which the edge and map reside. :param edge: The edge to reconnect and remove. :param new_node: The scope (map) entry or exit to reconnect through. :param keep_src: If True, keeps the source of the edge intact, otherwise

keeps destination of edge.
Returns:A 2-tuple of (incoming edge, outgoing edge).
dace.transformation.helpers.redirect_edge(state: dace.sdfg.state.SDFGState, edge: dace.sdfg.graph.MultiConnectorEdge[dace.memlet.Memlet][dace.memlet.Memlet], new_src: Optional[dace.sdfg.nodes.Node] = None, new_dst: Optional[dace.sdfg.nodes.Node] = None, new_src_conn: Optional[str] = None, new_dst_conn: Optional[str] = None, new_data: Optional[str] = None, new_memlet: Optional[dace.memlet.Memlet] = None) → dace.sdfg.graph.MultiConnectorEdge[dace.memlet.Memlet][dace.memlet.Memlet]

Redirects an edge in a state. Choose which elements to override by setting the keyword arguments. :param state: The SDFG state in which the edge resides. :param edge: The edge to redirect. :param new_src: If provided, redirects the source of the new edge. :param new_dst: If provided, redirects the destination of the new edge. :param new_src_conn: If provided, renames the source connector of the edge. :param new_dst_conn: If provided, renames the destination connector of the

edge.
Parameters:
  • new_data – If provided, changes the data on the memlet of the edge, and the entire associated memlet tree.
  • new_memlet – If provided, changes only the memlet of the new edge.
Returns:

The new, redirected edge.

Note:

new_data and new_memlet cannot be used at the same time.

dace.transformation.helpers.replicate_scope(sdfg: dace.sdfg.sdfg.SDFG, state: dace.sdfg.state.SDFGState, scope: dace.sdfg.scope.ScopeSubgraphView) → dace.sdfg.scope.ScopeSubgraphView

Replicates a scope subgraph view within a state, reconnecting all external edges to the same nodes. :param sdfg: The SDFG in which the subgraph scope resides. :param state: The SDFG state in which the subgraph scope resides. :param scope: The scope subgraph to replicate. :return: A reconnected replica of the scope.

dace.transformation.helpers.scope_tree_recursive(state: dace.sdfg.state.SDFGState, entry: Optional[dace.sdfg.nodes.EntryNode] = None) → dace.sdfg.scope.ScopeTree

Returns a scope tree that includes scopes from nested SDFGs. :param state: The state that contains the root of the scope tree. :param entry: A scope entry node to set as root, otherwise the state is

the root if None is given.
dace.transformation.helpers.simplify_state(state: dace.sdfg.state.SDFGState, remove_views: bool = False) → networkx.classes.multidigraph.MultiDiGraph

Returns a networkx MultiDiGraph object that contains all the access nodes and corresponding edges of an SDFG state. The removed code nodes and map scopes are replaced by edges that connect their ancestor and succesor access nodes. :param state: The input SDFG state. :return: The MultiDiGraph object.

dace.transformation.helpers.split_interstate_edges(sdfg: dace.sdfg.sdfg.SDFG) → None

Splits all inter-state edges into edges with conditions and edges with assignments. This procedure helps in nested loop detection. :param sdfg: The SDFG to split :note: Operates in-place on the SDFG.

dace.transformation.helpers.state_fission(sdfg: dace.sdfg.sdfg.SDFG, subgraph: dace.sdfg.graph.SubgraphView) → dace.sdfg.state.SDFGState

Given a subgraph, adds a new SDFG state before the state that contains it, removes the subgraph from the original state, and connects the two states. :param subgraph: the subgraph to remove. :return: the newly created SDFG state.

dace.transformation.helpers.tile(sdfg: dace.sdfg.sdfg.SDFG, map_entry: dace.sdfg.nodes.MapEntry, divides_evenly: bool, skew: bool, **tile_sizes)

Helper function that tiles a Map scope by the given sizes, in the given order. :param sdfg: The SDFG where the map resides. :param map_entry: The map entry node to tile. :param divides_evenly: If True, skips pre/postamble for cases

where the map dimension is not a multiplier of the tile size.
Parameters:
  • skew – If True, skews the tiled map to start from zero. Helps compilers improve performance in certain cases.
  • tile_sizes – An ordered dictionary of the map parameter names to tile and their respective tile size (which can be symbolic expressions).
dace.transformation.helpers.unsqueeze_memlet(internal_memlet: dace.memlet.Memlet, external_memlet: dace.memlet.Memlet, preserve_minima: bool = False, use_src_subset: bool = False, use_dst_subset: bool = False) → dace.memlet.Memlet

Unsqueezes and offsets a memlet, as per the semantics of nested SDFGs. :param internal_memlet: The internal memlet (inside nested SDFG)

before modification.
Parameters:
  • external_memlet – The external memlet before modification.
  • preserve_minima – Do not change the subset’s minimum elements.
  • use_src_subset – If both sides of the memlet refer to same array, prefer source subset.
  • use_dst_subset – If both sides of the memlet refer to same array, prefer destination subset.
Returns:

Offset Memlet to set on the resulting graph.

dace.transformation.pattern_matching module

Contains functions related to pattern matching in transformations.

dace.transformation.pattern_matching.collapse_multigraph_to_nx(graph: Union[dace.sdfg.graph.MultiDiGraph, dace.sdfg.graph.OrderedMultiDiGraph]) → networkx.classes.digraph.DiGraph

Collapses a directed multigraph into a networkx directed graph.

In the output directed graph, each node is a number, which contains itself as node_data[‘node’], while each edge contains a list of the data from the original edges as its attribute (edge_data[0…N]).

Parameters:graph – Directed multigraph object to be collapsed.
Returns:Collapsed directed graph object.
dace.transformation.pattern_matching.enumerate_matches(sdfg: dace.sdfg.sdfg.SDFG, pattern: dace.sdfg.graph.Graph, node_match=<function type_or_class_match>, edge_match=None) → Iterator[dace.sdfg.graph.SubgraphView]

Returns a generator of subgraphs that match the given subgraph pattern. :param sdfg: The SDFG to search in. :param pattern: A subgraph to look for. :param node_match: An optional function to use for matching nodes. :param node_match: An optional function to use for matching edges. :return: Yields SDFG subgraph view objects.

dace.transformation.pattern_matching.get_transformation_metadata(patterns: List[Type[dace.transformation.transformation.Transformation]], options: Optional[List[Dict[str, Any]]] = None) → Tuple[List[Tuple[Type[dace.transformation.transformation.Transformation], int, networkx.classes.digraph.DiGraph, Callable, Dict[str, Any]]], List[Tuple[Type[dace.transformation.transformation.Transformation], int, networkx.classes.digraph.DiGraph, Callable, Dict[str, Any]]]]

Collect all transformation expressions and metadata once, for use when applying transformations repeatedly. :param patterns: Transformation type (or list thereof) to compute. :param options: An optional list of transformation parameter dictionaries. :return: A tuple of inter-state and single-state pattern matching

transformations.
dace.transformation.pattern_matching.match_patterns(sdfg: dace.sdfg.sdfg.SDFG, patterns: Union[Type[dace.transformation.transformation.Transformation], List[Type[dace.transformation.transformation.Transformation]]], node_match: Callable[[Any, Any], bool] = <function type_match>, edge_match: Optional[Callable[[Any, Any], bool]] = None, strict: bool = False, metadata: Optional[Tuple[List[Tuple[Type[dace.transformation.transformation.Transformation], int, networkx.classes.digraph.DiGraph, Callable, Dict[str, Any]]], List[Tuple[Type[dace.transformation.transformation.Transformation], int, networkx.classes.digraph.DiGraph, Callable, Dict[str, Any]]]]] = None, states: Optional[List[dace.sdfg.state.SDFGState]] = None, options: Optional[List[Dict[str, Any]]] = None)

Returns a generator of Transformations that match the input SDFG. Ordered by SDFG ID. :param sdfg: The SDFG to match in. :param patterns: Transformation type (or list thereof) to match. :param node_match: Function for checking whether two nodes match. :param edge_match: Function for checking whether two edges match. :param strict: Only match transformation if strict (i.e., can only

improve the performance/reduce complexity of the SDFG).
Parameters:
  • metadata – Transformation metadata that can be reused.
  • states – If given, only tries to match single-state transformations on this list.
  • options – An optional iterable of transformation parameter dictionaries.
Returns:

A list of Transformation objects that match.

dace.transformation.pattern_matching.type_match(graph_node, pattern_node)

Checks whether the node types of the inputs match. :param graph_node: First node (in matched graph). :param pattern_node: Second node (in pattern subgraph). :return: True if the object types of the nodes match, False otherwise. :raise TypeError: When at least one of the inputs is not a dictionary

or does not have a ‘node’ attribute.
Raises:KeyError – When at least one of the inputs is a dictionary, but does not have a ‘node’ key.
dace.transformation.pattern_matching.type_or_class_match(node_a, node_b)

Checks whether node_a is an instance of the same type as node_b, or if either node_a/node_b is a type and the other is an instance of that type. This is used in subgraph matching to allow the subgraph pattern to be either a graph of instantiated nodes, or node types.

Parameters:
  • node_a – First node.
  • node_b – Second node.
Returns:

True if the object types of the nodes match according to the description, False otherwise.

Raises:
  • TypeError – When at least one of the inputs is not a dictionary or does not have a ‘node’ attribute.
  • KeyError – When at least one of the inputs is a dictionary, but does not have a ‘node’ key.
See:

enumerate_matches

dace.transformation.optimizer module

Contains classes and functions related to optimization of the stateful dataflow graph representation.

class dace.transformation.optimizer.Optimizer(sdfg, inplace=False)

Bases: object

Implements methods for optimizing a DaCe program stateful dataflow graph representation, by matching patterns and applying transformations on it.

get_pattern_matches(strict=False, states=None, patterns=None, sdfg=None, options=None) → Iterator[dace.transformation.transformation.Transformation]

Returns all possible transformations for the current SDFG. :param strict: Only consider strict transformations (i.e., ones

that surely increase performance or enhance readability)
Parameters:
  • states – An iterable of SDFG states to consider when pattern matching. If None, considers all.
  • patterns – An iterable of transformation classes to consider when matching. If None, considers all registered transformations in Transformation.
  • sdfg – If not None, searches for patterns on given SDFG.
  • options – An optional iterable of transformation parameters.
Returns:

List of matching Transformation objects.

See:

Transformation.

optimization_space()

Returns the optimization space of the current SDFG

optimize()
set_transformation_metadata(patterns: List[Type[dace.transformation.transformation.Transformation]], options: Optional[List[Dict[str, Any]]] = None)

Caches transformation metadata for a certain set of patterns to match.

class dace.transformation.optimizer.SDFGOptimizer(sdfg, inplace=False)

Bases: dace.transformation.optimizer.Optimizer

optimize()

A command-line UI for applying patterns on the SDFG. :return: An optimized SDFG object

dace.transformation.testing module

class dace.transformation.testing.TransformationTester(sdfg: dace.sdfg.sdfg.SDFG, depth=1, validate=True, generate_code=True, compile=False, print_exception=True, halt_on_exception=False)

Bases: dace.transformation.optimizer.Optimizer

An SDFG optimizer that consecutively applies available transformations up to a fixed depth.

optimize()

Module contents