dace.sdfg package¶
Submodules¶
dace.sdfg.propagation module¶
Functionality relating to Memlet propagation (deducing external memlets from internal memory accesses and scope ranges).
-
class
dace.sdfg.propagation.
AffineSMemlet
¶ Bases:
dace.sdfg.propagation.SeparableMemletPattern
Separable memlet pattern that matches affine expressions, i.e., of the form a * {index} + b.
-
can_be_applied
(dim_exprs, variable_context, node_range, orig_edges, dim_index, total_dims)¶
-
propagate
(array, dim_exprs, node_range)¶
-
-
class
dace.sdfg.propagation.
ConstantRangeMemlet
¶ Bases:
dace.sdfg.propagation.MemletPattern
Memlet pattern that matches arbitrary expressions with constant range.
-
can_be_applied
(expressions, variable_context, node_range, orig_edges)¶
-
propagate
(array, expressions, node_range)¶
-
-
class
dace.sdfg.propagation.
ConstantSMemlet
¶ Bases:
dace.sdfg.propagation.SeparableMemletPattern
Separable memlet pattern that matches constant (i.e., unrelated to current scope) expressions.
-
can_be_applied
(dim_exprs, variable_context, node_range, orig_edges, dim_index, total_dims)¶
-
propagate
(array, dim_exprs, node_range)¶
-
-
class
dace.sdfg.propagation.
GenericSMemlet
¶ Bases:
dace.sdfg.propagation.SeparableMemletPattern
Separable memlet pattern that detects any expression, and propagates interval bounds. Used as a last resort.
-
can_be_applied
(dim_exprs, variable_context, node_range, orig_edges, dim_index, total_dims)¶
-
propagate
(array, dim_exprs, node_range)¶
-
-
class
dace.sdfg.propagation.
MemletPattern
¶ Bases:
object
A pattern match on a memlet subset that can be used for propagation.
-
can_be_applied
(expressions, variable_context, node_range, orig_edges)¶
-
extensions
()¶
-
propagate
(array, expressions, node_range)¶
-
register
(**kwargs)¶
-
unregister
()¶
-
-
class
dace.sdfg.propagation.
ModuloSMemlet
¶ Bases:
dace.sdfg.propagation.SeparableMemletPattern
Separable memlet pattern that matches modulo expressions, i.e., of the form f(x) % N.
Acts as a meta-pattern: Finds the underlying pattern for f(x).
-
can_be_applied
(dim_exprs, variable_context, node_range, orig_edges, dim_index, total_dims)¶
-
propagate
(array, dim_exprs, node_range)¶
-
-
class
dace.sdfg.propagation.
SeparableMemlet
¶ Bases:
dace.sdfg.propagation.MemletPattern
Meta-memlet pattern that applies all separable memlet patterns.
-
can_be_applied
(expressions, variable_context, node_range, orig_edges)¶
-
propagate
(array, expressions, node_range)¶
-
-
class
dace.sdfg.propagation.
SeparableMemletPattern
¶ Bases:
object
Memlet pattern that can be applied to each of the dimensions separately.
-
can_be_applied
(dim_exprs, variable_context, node_range, orig_edges, dim_index, total_dims)¶
-
extensions
()¶
-
propagate
(array, dim_exprs, node_range)¶
-
register
(**kwargs)¶
-
unregister
()¶
-
-
dace.sdfg.propagation.
propagate_memlet
(dfg_state, memlet: dace.memlet.Memlet, scope_node: dace.sdfg.nodes.EntryNode, union_inner_edges: bool, arr=None, connector=None)¶ Tries to propagate a memlet through a scope (computes the image of the memlet function applied on an integer set of, e.g., a map range) and returns a new memlet object. :param dfg_state: An SDFGState object representing the graph. :param memlet: The memlet adjacent to the scope node from the inside. :param scope_node: A scope entry or exit node. :param union_inner_edges: True if the propagation should take other
neighboring internal memlets within the same scope into account.
-
dace.sdfg.propagation.
propagate_memlets_nested_sdfg
(parent_sdfg, parent_state, nsdfg_node)¶ Propagate memlets out of a nested sdfg.
Parameters: - parent_sdfg – The parent SDFG this nested SDFG is in.
- parent_state – The state containing this nested SDFG.
- nsdfg_node – The NSDFG node containing this nested SDFG.
Note: This operates in-place on the parent SDFG.
-
dace.sdfg.propagation.
propagate_memlets_scope
(sdfg, state, scopes)¶ Propagate memlets from the given scopes outwards. :param sdfg: The SDFG in which the scopes reside. :param state: The SDFG state in which the scopes reside. :param scopes: The ScopeTree object or a list thereof to start from. :note: This operation is performed in-place on the given SDFG.
-
dace.sdfg.propagation.
propagate_memlets_sdfg
(sdfg)¶ Propagates memlets throughout an entire given SDFG. :note: This is an in-place operation on the SDFG.
-
dace.sdfg.propagation.
propagate_memlets_state
(sdfg, state)¶ Propagates memlets throughout one SDFG state. :param sdfg: The SDFG in which the state is situated. :param state: The state to propagate in. :note: This is an in-place operation on the SDFG state.
-
dace.sdfg.propagation.
propagate_states
(sdfg) → None¶ Annotate the states of an SDFG with the number of executions.
Algorithm: 1. Clean up the state machine by splitting condition and assignment edges
into separate edes with a dummy state in between.Detect and annotate any for-loop constructs with their corresponding loop variable ranges.
Start traversing the state machine from the start state (start state gets executed once by default). At every state, check the following:
- The state was already visited -> in this case it can either be the guard of a loop we’re returning to - in which case the number of executions is additively combined - or it is a state that can be reached through multiple paths (e.g. if/else branches), in which case the number of executions is equal to the maximum number of executions for each incoming path (in case this fully merges a previously branched out tree again, the number of executions isn’t dynamic anymore). In both cases we override the calculated number of executions if we’re propagating dynamic unbounded. This DFS traversal is complete and we continue with the next unvisited state.
- We’re propagating dynamic unbounded -> this overrides every calculated number of executions, so this gets unconditionally propagated to all child states.
- None of the above, the next regular traversal step is executed:
- 3.1: If there is no further outgoing edge, this DFS traversal is
- done and we continue with the next unvisited state.
- 3.2: If there is one outgoing edge, we continue propagating the
- same number of executions to the child state. If the transition to the child state is conditional, the current state might be an implicit exit state, in which case we mark the next state as dynamic to signal that it’s an upper bound.
- 3.3: If there is more than one outgoing edge we:
- 3.3.1: Check if it’s an annotated loop guard with a range. If
- so, we calculate the number of executions for the loop and propagate this down the loop.
- 3.3.2: Check if it’s a loop that hasn’t been unannotated, which
- means it’s unbounded. In this case we propagate dynamic unbounded down the loop.
- 3.3.3: Otherwise this must be a conditional branch, so this
- state’s number of executions is given to all child states as an upper bound.
The traversal ends when all reachable states have been visited at least once.
Parameters: sdfg – The SDFG to annotate. Note: This operates on the SDFG in-place.
-
dace.sdfg.propagation.
propagate_subset
(memlets: List[dace.memlet.Memlet], arr: dace.data.Data, params: List[str], rng: dace.subsets.Subset, defined_variables: Set[Union[sympy.core.basic.Basic, dace.symbolic.SymExpr]] = None, use_dst: bool = False) → dace.memlet.Memlet¶ Tries to propagate a list of memlets through a range (computes the image of the memlet function applied on an integer set of, e.g., a map range) and returns a new memlet object. :param memlets: The memlets to propagate. :param arr: Array descriptor for memlet (used for obtaining extents). :param params: A list of variable names. :param rng: A subset with dimensionality len(params) that contains the
range to propagate with.Parameters: - defined_variables – A set of symbols defined that will remain the same throughout propagation. If None, assumes that all symbols outside of params have been defined.
- use_dst – Whether to propagate the memlets’ dst subset or use the src instead, depending on propagation direction.
Returns: Memlet with propagated subset and volume.
-
dace.sdfg.propagation.
reset_state_annotations
(sdfg)¶ Resets the state (loop-related) annotations of an SDFG. :note: This operation is shallow (does not go into nested SDFGs).
dace.sdfg.scope module¶
-
class
dace.sdfg.scope.
ScopeSubgraphView
(graph, subgraph_nodes, entry_node)¶ Bases:
dace.sdfg.state.StateSubgraphView
An extension to SubgraphView that enables the creation of scope dictionaries in subgraphs and free symbols.
-
parent
¶
-
top_level_transients
()¶ Iterate over top-level transients of this subgraph.
-
-
class
dace.sdfg.scope.
ScopeTree
(entrynode: dace.sdfg.nodes.EntryNode, exitnode: dace.sdfg.nodes.ExitNode)¶ Bases:
object
A class defining a scope, its parent and children scopes, and scope entry/exit nodes.
-
dace.sdfg.scope.
common_parent_scope
(sdict: Dict[dace.sdfg.nodes.Node, List[dace.sdfg.nodes.Node]], scope_a: dace.sdfg.nodes.Node, scope_b: dace.sdfg.nodes.Node) → dace.sdfg.nodes.Node¶ Finds a common parent scope for both input scopes, or None if the scopes are in different connected components. :param sdict: Scope parent dictionary. :param scope_a: First scope. :param scope_b: Second scope. :return: Scope node or None for top-level scope.
-
dace.sdfg.scope.
devicelevel_block_size
(sdfg: dace.sdfg.SDFG, state: dace.sdfg.SDFGState, node: dace.sdfg.nodes.Node) → Tuple[dace.symbolic.SymExpr]¶ Returns the current thread-block size if the given node is enclosed in a GPU kernel, or None otherwise. :param sdfg: The SDFG in which the node resides. :param state: The SDFG state in which the node resides. :param node: The node in question :return: A tuple of sizes or None if the node is not in device-level
code.
-
dace.sdfg.scope.
is_devicelevel_fpga
(sdfg: dace.sdfg.SDFG, state: dace.sdfg.SDFGState, node: dace.sdfg.nodes.Node) → bool¶ Tests whether a node in an SDFG is contained within FPGA device-level code. :param sdfg: The SDFG in which the node resides. :param state: The SDFG state in which the node resides. :param node: The node in question :return: True if node is in device-level code, False otherwise.
-
dace.sdfg.scope.
is_devicelevel_gpu
(sdfg: dace.sdfg.SDFG, state: dace.sdfg.SDFGState, node: dace.sdfg.nodes.Node, with_gpu_default: bool = False) → bool¶ Tests whether a node in an SDFG is contained within GPU device-level code. :param sdfg: The SDFG in which the node resides. :param state: The SDFG state in which the node resides. :param node: The node in question :return: True if node is in device-level code, False otherwise.
-
dace.sdfg.scope.
is_in_scope
(sdfg: dace.sdfg.SDFG, state: dace.sdfg.SDFGState, node: dace.sdfg.nodes.Node, schedules: List[dace.dtypes.ScheduleType]) → bool¶ Tests whether a node in an SDFG is contained within a certain set of scope schedules. :param sdfg: The SDFG in which the node resides. :param state: The SDFG state in which the node resides. :param node: The node in question :return: True if node is in device-level code, False otherwise.
-
dace.sdfg.scope.
scope_contains_scope
(sdict: Dict[dace.sdfg.nodes.Node, List[dace.sdfg.nodes.Node]], node: dace.sdfg.nodes.Node, other_node: dace.sdfg.nodes.Node) → bool¶ Returns true iff scope of node contains the scope of other_node.
dace.sdfg.sdfg module¶
-
class
dace.sdfg.sdfg.
InterstateEdge
(*args, **kwargs)¶ Bases:
object
An SDFG state machine edge. These edges can contain a condition (which may include data accesses for data-dependent decisions) and zero or more assignments of values to inter-state variables (e.g., loop iterates).
-
assignments
¶ Assignments to perform upon transition (e.g., ‘x=x+1; y = 0’)
-
condition
¶ Transition condition
-
condition_sympy
()¶
-
free_symbols
¶ Returns a set of symbols used in this edge’s properties.
-
static
from_json
(json_obj, context=None)¶
-
is_unconditional
()¶ Returns True if the state transition is unconditional.
-
label
¶
-
new_symbols
(sdfg, symbols) → Dict[str, dace.dtypes.typeclass]¶ Returns a mapping between symbols defined by this edge (i.e., assignments) to their type.
-
properties
()¶
-
replace
(name: str, new_name: str, replace_keys=True) → None¶ Replaces all occurrences of
name
withnew_name
. :param name: The source name. :param new_name: The replacement name. :param replace_keys: If False, skips replacing assignment keys.
-
replace_dict
(repl: Dict[str, str], replace_keys=True) → None¶ Replaces all given keys with their corresponding values. :param repl: Replacement dictionary. :param replace_keys: If False, skips replacing assignment keys.
-
to_json
(parent=None)¶
-
-
class
dace.sdfg.sdfg.
LogicalGroup
(*args, **kwargs)¶ Bases:
object
Logical element groupings on a per-SDFG level.
-
color
¶ Color for the group, given as a hexadecimal string
-
static
from_json
(json_obj, context=None)¶
-
name
¶ Logical group name
-
nodes
¶ Nodes in this group given by [State, Node] id tuples
-
properties
()¶
-
states
¶ States in this group given by their ids
-
to_json
()¶
-
-
class
dace.sdfg.sdfg.
SDFG
(*args, **kwargs)¶ Bases:
dace.sdfg.graph.OrderedDiGraph
The main intermediate representation of code in DaCe.
A Stateful DataFlow multiGraph (SDFG) is a directed graph of directed acyclic multigraphs (i.e., where two nodes can be connected by more than one edge). The top-level directed graph represents a state machine, where edges can contain state transition conditions and assignments (see the InterstateEdge class documentation). The nested acyclic multigraphs represent dataflow, where nodes may represent data regions in memory, tasklets, or parametric graph scopes (see dace.sdfg.nodes for a full list of available node types); edges in the multigraph represent data movement using memlets, as described in the Memlet class documentation.
-
add_array
(name: str, shape, dtype, storage=<StorageType.Default: 1>, location=None, transient=False, strides=None, offset=None, lifetime=<AllocationLifetime.Scope: 1>, debuginfo=None, allow_conflicts=False, total_size=None, find_new_name=False, alignment=0, may_alias=False) → Tuple[str, dace.data.Array]¶ Adds an array to the SDFG data descriptor store.
-
add_constant
(name: str, value: Any, dtype: dace.data.Data = None)¶ Adds/updates a new compile-time constant to this SDFG. A constant may either be a scalar or a numpy ndarray thereof. :param name: The name of the constant. :param value: The constant value. :param dtype: Optional data type of the symbol, or None to deduce
automatically.
-
add_datadesc
(name: str, datadesc: dace.data.Data, find_new_name=False) → str¶ Adds an existing data descriptor to the SDFG array store. :param name: Name to use. :param datadesc: Data descriptor to add. :param find_new_name: If True and data descriptor with this name
exists, finds a new name to add.Returns: Name of the new data descriptor
-
add_edge
(u, v, edge)¶ Adds a new edge to the SDFG. Must be an InterstateEdge or a subclass thereof. :param u: Source node. :param v: Destination node. :param edge: The edge to add.
-
add_loop
(before_state, loop_state, after_state, loop_var: str, initialize_expr: str, condition_expr: str, increment_expr: str, loop_end_state=None)¶ Helper function that adds a looping state machine around a given state (or sequence of states). :param before_state: The state after which the loop should
begin, or None if the loop is the first state (creates an empty state).Parameters: - loop_state – The state that begins the loop. See also loop_end_state if the loop is multi-state.
- after_state – The state that should be invoked after the loop ends, or None if the program should terminate (creates an empty state).
- loop_var – A name of an inter-state variable to use for the loop. If None, initialize_expr and increment_expr must be None.
- initialize_expr – A string expression that is assigned to loop_var before the loop begins. If None, does not define an expression.
- condition_expr – A string condition that occurs every loop iteration. If None, loops forever (undefined behavior).
- increment_expr –
A string expression that is assigned to loop_var after every loop iteration.
If None, does not define an expression. - loop_end_state – If the loop wraps multiple states, the state where the loop iteration ends. If None, sets the end state to loop_state as well.
Returns: A 3-tuple of (before_state, generated loop guard state, after_state).
-
add_node
(node, is_start_state=False)¶ Adds a new node to the SDFG. Must be an SDFGState or a subclass thereof. :param node: The node to add. :param is_start_state: If True, sets this node as the starting
state.
-
add_pgrid
(shape: Sequence[Union[numbers.Integral, str, dace.symbolic.symbol, dace.symbolic.SymExpr, sympy.core.basic.Basic]] = None, parent_grid: str = None, color: Sequence[Union[numbers.Integral, bool]] = None, exact_grid: Union[numbers.Integral, str, dace.symbolic.symbol, dace.symbolic.SymExpr, sympy.core.basic.Basic] = None, root: Union[numbers.Integral, str, dace.symbolic.symbol, dace.symbolic.SymExpr, sympy.core.basic.Basic] = 0)¶ Adds a process-grid to the process-grid descriptor store. For more details on process-grids, please read the documentation of the ProcessGrid class. :param shape: Shape of the process-grid (see dims parameter of [MPI_Cart_create](https://www.mpich.org/static/docs/latest/www3/MPI_Cart_create.html)), e.g., [2, 3, 3]. :param parent_grid: Parent process-grid (similar to the comm parameter of [MPI_Cart_sub](https://www.mpich.org/static/docs/v3.2/www3/MPI_Cart_sub.html)). :param color: The i-th entry specifies whether the i-th dimension is kept in the sub-grid or is dropped (see remain_dims input of [MPI_Cart_sub](https://www.mpich.org/static/docs/v3.2/www3/MPI_Cart_sub.html)). :param exact_grid: If set then, out of all the sub-grids created, only the one that contains the rank with id exact_grid will be utilized for collective communication. :param root: Root rank (used for collective communication). :return: Name of the new process-grid descriptor.
-
add_rdistrarray
(array_a: str, array_b: str)¶ Adds a sub-array redistribution to the sub-array redistribution descriptor store. For more details on redistributions, please read the documentation of the RedistrArray class. :param array_a: Input sub-array descriptor. :param array_b: Output sub-array descriptor. :return: Name of the new redistribution descriptor.
-
add_reference
(name: str, shape, dtype, storage=<StorageType.Default: 1>, strides=None, offset=None, debuginfo=None, allow_conflicts=False, total_size=None, find_new_name=False, alignment=0, may_alias=False) → Tuple[str, dace.data.Reference]¶ Adds a reference to the SDFG data descriptor store.
-
add_scalar
(name: str, dtype, storage=<StorageType.Default: 1>, transient=False, lifetime=<AllocationLifetime.Scope: 1>, debuginfo=None, find_new_name=False) → Tuple[str, dace.data.Scalar]¶ Adds a scalar to the SDFG data descriptor store.
-
add_state
(label=None, is_start_state=False) → dace.sdfg.state.SDFGState¶ Adds a new SDFG state to this graph and returns it. :param label: State label. :param is_start_state: If True, resets SDFG starting state to this
state.Returns: A new SDFGState object.
-
add_state_after
(state: dace.sdfg.state.SDFGState, label=None, is_start_state=False) → dace.sdfg.state.SDFGState¶ Adds a new SDFG state after an existing state, reconnecting it to the successors instead. :param state: The state to append the new state after. :param label: State label. :param is_start_state: If True, resets SDFG starting state to this
state.Returns: A new SDFGState object.
-
add_state_before
(state: dace.sdfg.state.SDFGState, label=None, is_start_state=False) → dace.sdfg.state.SDFGState¶ Adds a new SDFG state before an existing state, reconnecting predecessors to it instead. :param state: The state to prepend the new state before. :param label: State label. :param is_start_state: If True, resets SDFG starting state to this
state.Returns: A new SDFGState object.
-
add_stream
(name: str, dtype, buffer_size=1, shape=(1, ), storage=<StorageType.Default: 1>, transient=False, offset=None, lifetime=<AllocationLifetime.Scope: 1>, debuginfo=None, find_new_name=False) → Tuple[str, dace.data.Stream]¶ Adds a stream to the SDFG data descriptor store.
-
add_subarray
(dtype: dace.dtypes.typeclass, shape: Sequence[Union[numbers.Integral, str, dace.symbolic.symbol, dace.symbolic.SymExpr, sympy.core.basic.Basic]], subshape: Sequence[Union[numbers.Integral, str, dace.symbolic.symbol, dace.symbolic.SymExpr, sympy.core.basic.Basic]], pgrid: str = None, correspondence: Sequence[numbers.Integral] = None)¶ Adds a sub-array to the sub-array descriptor store. For more details on sub-arrays, please read the documentation of the SubArray class. :param dtype: Datatype of the array (see oldtype parameter of [MPI_Type_create_subarray](https://www.mpich.org/static/docs/v3.2/www3/MPI_Type_create_subarray.html)). :param shape: Shape of the sub-array (see array_of_sizes parameter of [MPI_Type_create_subarray](https://www.mpich.org/static/docs/v3.2/www3/MPI_Type_create_subarray.html)). :param subshape: Sub-shape of the sub-array (see array_of_subsizes parameter of [MPI_Type_create_subarray](https://www.mpich.org/static/docs/v3.2/www3/MPI_Type_create_subarray.html)). :param pgrid: Process-grid used for collective scatter/gather operations. :param correspondence: Matching among array dimensions and process-grid dimensions. :return: Name of the new sub-array descriptor.
-
add_symbol
(name, stype)¶ Adds a symbol to the SDFG. :param name: Symbol name. :param stype: Symbol type.
-
add_temp_transient
(shape, dtype, storage=<StorageType.Default: 1>, location=None, strides=None, offset=None, lifetime=<AllocationLifetime.Scope: 1>, debuginfo=None, allow_conflicts=False, total_size=None, alignment=0, may_alias=False)¶ Convenience function to add a transient array with a temporary name to the data descriptor store.
-
add_temp_transient_like
(desc: Union[dace.data.Array, dace.data.Scalar], dtype=None, debuginfo=None)¶ Convenience function to add a transient array with a temporary name to the data descriptor store.
-
add_transient
(name, shape, dtype, storage=<StorageType.Default: 1>, location=None, strides=None, offset=None, lifetime=<AllocationLifetime.Scope: 1>, debuginfo=None, allow_conflicts=False, total_size=None, find_new_name=False, alignment=0, may_alias=False) → Tuple[str, dace.data.Array]¶ Convenience function to add a transient array to the data descriptor store.
-
add_view
(name: str, shape, dtype, storage=<StorageType.Default: 1>, strides=None, offset=None, debuginfo=None, allow_conflicts=False, total_size=None, find_new_name=False, alignment=0, may_alias=False) → Tuple[str, dace.data.View]¶ Adds a view to the SDFG data descriptor store.
-
all_edges_recursive
()¶ Iterate over all edges in this SDFG, including state edges, inter-state edges, and recursively edges within nested SDFGs, returning tuples on the form (edge, parent), where the parent is either the SDFG (for states) or a DFG (nodes).
-
all_nodes_recursive
() → Iterator[Tuple[dace.sdfg.nodes.Node, Union[dace.sdfg.sdfg.SDFG, dace.sdfg.state.SDFGState]]]¶ Iterate over all nodes in this SDFG, including states, nodes in states, and recursive states and nodes within nested SDFGs, returning tuples on the form (node, parent), where the parent is either the SDFG (for states) or a DFG (nodes).
-
all_sdfgs_recursive
()¶ Iterate over this and all nested SDFGs.
-
append_exit_code
(cpp_code: str, location: str = 'frame')¶ Appends C++ code that will be generated in the __dace_exit_* functions on one of the generated code files. :param cpp_code: The code to append. :param location: The file/backend in which to generate the code.
Options are None (all files), “frame”, “openmp”, “cuda”, “xilinx”, “intel_fpga”, or any code generator name.
-
append_global_code
(cpp_code: str, location: str = 'frame')¶ Appends C++ code that will be generated in a global scope on one of the generated code files. :param cpp_code: The code to set. :param location: The file/backend in which to generate the code.
Options are None (all files), “frame”, “openmp”, “cuda”, “xilinx”, “intel_fpga”, or any code generator name.
-
append_init_code
(cpp_code: str, location: str = 'frame')¶ Appends C++ code that will be generated in the __dace_init_* functions on one of the generated code files. :param cpp_code: The code to append. :param location: The file/backend in which to generate the code.
Options are None (all files), “frame”, “openmp”, “cuda”, “xilinx”, “intel_fpga”, or any code generator name.
-
append_transformation
(transformation)¶ Appends a transformation to the treansformation history of this SDFG. If this is the first transformation being applied, it also saves the initial state of the SDFG to return to and play back the history. :param transformation: The transformation to append.
-
apply_fpga_transformations
(states=None, validate=True, validate_all=False, permissive=False)¶ Applies a series of transformations on the SDFG for it to generate FPGA code.
Note: This is an in-place operation on the SDFG.
-
apply_gpu_transformations
(states=None, validate=True, validate_all=False, permissive=False, sequential_innermaps=True, register_transients=True)¶ Applies a series of transformations on the SDFG for it to generate GPU code. :param sequential_innermaps: Make all internal maps Sequential. :param register_transients: Make all transients inside GPU maps registers. :note: It is recommended to apply redundant array removal transformation after this transformation. Alternatively, you can simplify() after this transformation. :note: This is an in-place operation on the SDFG.
-
apply_strict_transformations
(validate=True, validate_all=False)¶ This method is DEPRECATED in favor of
simplify
. Applies safe transformations (that will surely increase the performance) on the SDFG. For example, this fuses redundant states (safely) and removes redundant arrays.B{Note:} This is an in-place operation on the SDFG.
-
apply_transformations
(xforms: Union[Type[CT_co], List[Type[CT_co]]], options: Union[Dict[str, Any], List[Dict[str, Any]], None] = None, validate: bool = True, validate_all: bool = False, permissive: bool = False, states: Optional[List[Any]] = None, print_report: Optional[bool] = None) → int¶ This function applies a transformation or a sequence thereof consecutively. Operates in-place.
Parameters: - xforms – A PatternTransformation class or a sequence.
- options – An optional dictionary (or sequence of dictionaries) to modify transformation parameters.
- validate – If True, validates after all transformations.
- validate_all – If True, validates after every transformation.
- permissive – If True, operates in permissive mode.
- states – If not None, specifies a subset of states to apply transformations on.
- print_report – Whether to show debug prints or not (None if the DaCe config option ‘debugprint’ should apply)
Returns: Number of transformations applied.
Examples:
# Applies MapTiling, then MapFusion, followed by # GPUTransformSDFG, specifying parameters only for the # first transformation. sdfg.apply_transformations( [MapTiling, MapFusion, GPUTransformSDFG], options=[{'tile_size': 16}, {}, {}])
-
apply_transformations_once_everywhere
(xforms: Union[Type[CT_co], List[Type[CT_co]]], options: Union[Dict[str, Any], List[Dict[str, Any]], None] = None, validate: bool = True, validate_all: bool = False, permissive: bool = False, states: Optional[List[Any]] = None, print_report: Optional[bool] = None, order_by_transformation: bool = True, progress: Optional[bool] = None) → int¶ This function applies a transformation or a set of (unique) transformations until throughout the entire SDFG once. Operates in-place.
param xforms: A PatternTransformation class or a set thereof. param options: An optional dictionary (or sequence of dictionaries) to modify transformation parameters. param validate: If True, validates after all transformations. param validate_all: If True, validates after every transformation. param permissive: If True, operates in permissive mode. param states: If not None, specifies a subset of states to apply transformations on. param print_report: Whether to show debug prints or not (None if the DaCe config option ‘debugprint’ should apply). param order_by_transformation: Try to apply transformations ordered by class rather than SDFG. param progress: If True, prints every intermediate transformation applied. If False, never prints anything. If None (default), prints only after 5 seconds of transformations. return: Number of transformations applied. Examples:
# Tiles all maps once sdfg.apply_transformations_once_everywhere(MapTiling, options=dict(tile_size=16))
-
apply_transformations_repeated
(xforms: Union[Type[CT_co], List[Type[CT_co]]], options: Union[Dict[str, Any], List[Dict[str, Any]], None] = None, validate: bool = True, validate_all: bool = False, permissive: bool = False, states: Optional[List[Any]] = None, print_report: Optional[bool] = None, order_by_transformation: bool = True, progress: Optional[bool] = None) → int¶ This function repeatedly applies a transformation or a set of (unique) transformations until none can be found. Operates in-place.
Parameters: - xforms – A PatternTransformation class or a set thereof.
- options – An optional dictionary (or sequence of dictionaries) to modify transformation parameters.
- validate – If True, validates after all transformations.
- validate_all – If True, validates after every transformation.
- permissive – If True, operates in permissive mode.
- states – If not None, specifies a subset of states to apply transformations on.
- print_report – Whether to show debug prints or not (None if the DaCe config option ‘debugprint’ should apply).
- order_by_transformation – Try to apply transformations ordered by class rather than SDFG.
- progress – If True, prints every intermediate transformation applied. If False, never prints anything. If None (default), prints only after 5 seconds of transformations.
Returns: Number of transformations applied.
Examples:
# Applies InlineSDFG until no more subgraphs can be inlined sdfg.apply_transformations_repeated(InlineSDFG)
-
arg_names
¶ Ordered argument names (used for calling conventions).
-
arglist
(scalars_only=False, free_symbols=None) → Dict[str, dace.data.Data]¶ Returns an ordered dictionary of arguments (names and types) required to invoke this SDFG.
The arguments follow the following order: <sorted data arguments>, <sorted scalar arguments>. Data arguments are all the non-transient data containers in the SDFG; and scalar arguments are all the non-transient scalar data containers and free symbols (see
SDFG.free_symbols
). This structure will create a sorted list of pointers followed by a sorted list of PoDs and structs.Returns: An ordered dictionary of (name, data descriptor type) of all the arguments, sorted as defined here.
-
argument_typecheck
(args, kwargs, types_only=False)¶ Checks if arguments and keyword arguments match the SDFG types. Raises RuntimeError otherwise.
Raises: - RuntimeError – Argument count mismatch.
- TypeError – Argument type mismatch.
- NotImplementedError – Unsupported argument type.
-
arrays
¶ Returns a dictionary of data descriptors (Data objects) used in this SDFG, with an extra None entry for empty memlets.
-
arrays_recursive
()¶ Iterate over all arrays in this SDFG, including arrays within nested SDFGs. Yields 3-tuples of (sdfg, array name, array).
-
available_data_reports
() → List[str]¶ Returns a list of available instrumented data reports for this SDFG.
-
build_folder
¶ Returns a relative path to the build cache folder for this SDFG.
-
call_with_instrumented_data
(dreport: dace.codegen.instrumentation.data.data_report.InstrumentedDataReport, *args, **kwargs)¶ Invokes an SDFG with an instrumented data report, generating and compiling code if necessary. Arguments given as
args
andkwargs
will be overriden by the data containers defined in the report. :param dreport: The instrumented data report to use upon calling. :param args: Arguments to call SDFG with. :param kwargs: Keyword arguments to call SDFG with. :return: The return value(s) of this SDFG.
-
callback_mapping
¶ Mapping between callback name and its original callback (for when the same callback is used with a different signature)
-
clear_data_reports
()¶ Clears the instrumented data report folders of this SDFG.
-
clear_instrumentation_reports
()¶ Clears the instrumentation report folder of this SDFG.
-
compile
(output_file=None, validate=True) → dace.codegen.compiler.CompiledSDFG¶ Compiles a runnable binary from this SDFG. :param output_file: If not None, copies the output library file to
the specified path.Parameters: validate – If True, validates the SDFG prior to generating code. Returns: A callable CompiledSDFG object.
-
constants
¶ A dictionary of compile-time constants defined in this SDFG.
-
constants_prop
¶ Compile-time constants
-
data
(dataname: str)¶ Looks up a data descriptor from its name, which can be an array, stream, or scalar symbol.
-
debuginfo
¶ Object property of type DebugInfo
-
exit_code
¶ Code generated in the __dace_exit function.
-
expand_library_nodes
(recursive=True)¶ Recursively expand all unexpanded library nodes in the SDFG, resulting in a “pure” SDFG that the code generator can handle. :param recursive: If True, expands all library nodes recursively,
including library nodes that expand to library nodes.
-
fill_scope_connectors
()¶ Fills missing scope connectors (i.e., “IN_#”/”OUT_#” on entry/exit nodes) according to data on the memlets.
-
find_new_constant
(name: str)¶ Tries to find a new constant name by adding an underscore and a number.
-
find_new_symbol
(name: str)¶ Tries to find a new symbol name by adding an underscore and a number.
-
find_state
(state_id_or_label)¶ Finds a state according to its ID (if integer is provided) or label (if string is provided).
Parameters: state_id_or_label – State ID (if int) or label (if str). Returns: An SDFGState object.
-
free_symbols
¶ Returns a set of symbol names that are used by the SDFG, but not defined within it. This property is used to determine the symbolic parameters of the SDFG and verify that
SDFG.symbols
is complete. :note: Assumes that the graph is valid (i.e., without undefined oroverlapping symbols).
-
static
from_file
(filename: str) → dace.sdfg.sdfg.SDFG¶ Constructs an SDFG from a file. :param filename: File name to load SDFG from. :return: An SDFG.
-
classmethod
from_json
(json_obj, context_info=None)¶
-
generate_code
()¶ Generates code from this SDFG and returns it. :return: A list of CodeObject objects containing the generated
code of different files and languages.
-
get_instrumentation_reports
() → List[dace.codegen.instrumentation.report.InstrumentationReport]¶ Returns a list of instrumentation reports from previous runs of this SDFG. :return: A List of timestamped InstrumentationReport objects.
-
get_instrumented_data
(timestamp: Optional[int] = None) → Optional[dace.codegen.instrumentation.data.data_report.InstrumentedDataReport]¶ Returns an instrumented data report from the latest run of this SDFG, with a given timestamp, or None if no reports exist. :param timestamp: An optional timestamp to use for the report. :return: An InstrumentedDataReport object, or None if one does not exist.
-
get_latest_report
() → Optional[dace.codegen.instrumentation.report.InstrumentationReport]¶ Returns an instrumentation report from the latest run of this SDFG, or None if the file does not exist. :return: A timestamped InstrumentationReport object, or None if does
not exist.
-
global_code
¶ Code generated in a global scope on the output files.
-
hash_sdfg
(jsondict: Optional[Dict[str, Any]] = None) → str¶ Returns a hash of the current SDFG, without considering IDs and attribute names. :param jsondict: If not None, uses given JSON dictionary as input. :return: The hash (in SHA-256 format).
-
init_code
¶ Code generated in the __dace_init function.
-
init_signature
(for_call=False, free_symbols=None) → str¶ Returns a C/C++ signature of this SDFG, used when generating the initalization code. It only contains symbols.
Parameters: for_call – If True, returns arguments that can be used when calling the SDFG.
-
input_arrays
()¶ Returns a list of input arrays that need to be fed into the SDFG.
-
instrument
¶ Measure execution statistics with given method
-
is_instrumented
() → bool¶ Returns True if the SDFG has performance instrumentation enabled on it or any of its elements.
-
is_loaded
() → bool¶ Returns True if the SDFG binary is already loaded in the current process.
-
is_valid
() → bool¶ Returns True if the SDFG is verified correctly (using validate).
-
label
¶ The name of this SDFG.
-
logical_groups
¶ Logical groupings of nodes and edges
-
make_array_memlet
(array: str)¶ Convenience method to generate a Memlet that transfers a full array.
Parameters: array – the name of the array Returns: a Memlet that fully transfers array
-
name
¶ The name of this SDFG.
-
openmp_sections
¶ Whether to generate OpenMP sections in code
-
optimize
(optimizer=None) → dace.sdfg.sdfg.SDFG¶ Optimize an SDFG using the CLI or external hooks. :param optimizer: If defines a valid class name, it will be called
during compilation to transform the SDFG as necessary. If None, uses configuration setting.Returns: An SDFG (returns self if optimizer is in place)
-
orig_sdfg
¶ Object property of type OptionalSDFGReferenceProperty
-
output_arrays
()¶ Returns a list of output arrays that need to be returned from the SDFG.
-
parent
¶ Returns the parent SDFG state of this SDFG, if exists.
-
parent_nsdfg_node
¶ Returns the parent NestedSDFG node of this SDFG, if exists.
-
parent_sdfg
¶ Returns the parent SDFG of this SDFG, if exists.
-
predecessor_state_transitions
(state)¶ Yields paths (lists of edges) that the SDFG can pass through before computing the given state.
-
predecessor_states
(state)¶ Returns a list of unique states that the SDFG can pass through before computing the given state.
-
prepend_exit_code
(cpp_code: str, location: str = 'frame')¶ Prepends C++ code that will be generated in the __dace_exit_* functions on one of the generated code files. :param cpp_code: The code to prepend. :param location: The file/backend in which to generate the code.
Options are None (all files), “frame”, “openmp”, “cuda”, “xilinx”, “intel_fpga”, or any code generator name.
-
process_grids
¶ Returns a dictionary of process-grid descriptors (ProcessGrid objects) used in this SDFG.
-
propagate
¶
-
properties
()¶
-
rdistrarrays
¶ Returns a dictionary of sub-array redistribution descriptors (RedistrArray objects) used in this SDFG.
-
read_and_write_sets
() → Tuple[Set[AnyStr], Set[AnyStr]]¶ Determines what data containers are read and written in this SDFG. Does not include reads to subsets of containers that have previously been written within the same state. :return: A two-tuple of sets of things denoting
({data read}, {data written}).
-
remove_data
(name, validate=True)¶ Removes a data descriptor from the SDFG. :param name: The name of the data descriptor to remove. :param validate: If True, verifies that there are no access
nodes that are using this data descriptor prior to removing it.
-
remove_node
(node: dace.sdfg.state.SDFGState)¶ Removes the specified node.
-
remove_symbol
(name)¶ Removes a symbol from the SDFG. :param name: Symbol name.
-
replace
(name: str, new_name: str)¶ Finds and replaces all occurrences of a symbol or array name in SDFG. :param name: Name to find. :param new_name: Name to replace. :raise FileExistsError: If name and new_name already exist as data descriptors or symbols.
-
replace_dict
(repldict: Dict[str, str], symrepl: Optional[Dict[Union[sympy.core.basic.Basic, dace.symbolic.SymExpr], Union[sympy.core.basic.Basic, dace.symbolic.SymExpr]]] = None, replace_in_graph: bool = True, replace_keys: bool = True) → None¶ Replaces all occurrences of keys in the given dictionary with the mapped values. :param repldict: The replacement dictionary. :param replace_keys: If False, skips replacing assignment keys. :param symrepl: A symbolic expression replacement dictionary (for performance reasons). :param replace_in_graph: Whether to replace in SDFG nodes / edges. :param replace_keys: If True, replaces in SDFG property names (e.g., array, symbol, and constant names).
-
reset_sdfg_list
()¶
-
save
(filename: str, use_pickle=False, hash=None, exception=None, compress=False) → Optional[str]¶ Save this SDFG to a file. :param filename: File name to save to. :param use_pickle: Use Python pickle as the SDFG format (default:
JSON).Parameters: - hash – By default, saves the hash if SDFG is JSON-serialized. Otherwise, if True, saves the hash along with the SDFG.
- exception – If not None, stores error information along with SDFG.
- compress – If True, uses gzip to compress the file upon saving.
Returns: The hash of the SDFG, or None if failed/not requested.
-
sdfg_id
¶ Returns the unique index of the current SDFG within the current tree of SDFGs (top-level SDFG is 0, nested SDFGs are greater).
-
sdfg_list
¶
-
set_exit_code
(cpp_code: str, location: str = 'frame')¶ Sets C++ code that will be generated in the __dace_exit_* functions on one of the generated code files. :param cpp_code: The code to set. :param location: The file/backend in which to generate the code.
Options are None (all files), “frame”, “openmp”, “cuda”, “xilinx”, “intel_fpga”, or any code generator name.
-
set_global_code
(cpp_code: str, location: str = 'frame')¶ Sets C++ code that will be generated in a global scope on one of the generated code files. :param cpp_code: The code to set. :param location: The file/backend in which to generate the code.
Options are None (all files), “frame”, “openmp”, “cuda”, “xilinx”, “intel_fpga”, or any code generator name.
-
set_init_code
(cpp_code: str, location: str = 'frame')¶ Sets C++ code that will be generated in the __dace_init_* functions on one of the generated code files. :param cpp_code: The code to set. :param location: The file/backend in which to generate the code.
Options are None (all files), “frame”, “openmp”, “cuda”, “xilinx”, “intel_fpga”, or any code generator name.
-
set_sourcecode
(code: str, lang=None)¶ Set the source code of this SDFG (for IDE purposes). :param code: A string of source code. :param lang: A string representing the language of the source code,
for syntax highlighting and completion.
Returns a list of transient data that appears in more than one state.
-
signature
(with_types=True, for_call=False, with_arrays=True, arglist=None) → str¶ Returns a C/C++ signature of this SDFG, used when generating code. :param with_types: If True, includes argument types (can be used
for a function prototype). If False, only include argument names (can be used for function calls).Parameters: - for_call – If True, returns arguments that can be used when calling the SDFG.
- with_arrays – If True, includes arrays, otherwise, only symbols and scalars are included.
- arglist – An optional cached argument list.
-
signature_arglist
(with_types=True, for_call=False, with_arrays=True, arglist=None) → List[str]¶ Returns a list of arguments necessary to call this SDFG, formatted as a list of C definitions. :param with_types: If True, includes argument types in the result. :param for_call: If True, returns arguments that can be used when
calling the SDFG.Parameters: - with_arrays – If True, includes arrays, otherwise, only symbols and scalars are included.
- arglist – An optional cached argument list.
Returns: A list of strings. For example: [‘float *A’, ‘int b’].
-
simplify
(validate=True, validate_all=False)¶ Applies safe transformations (that will surely increase the performance) on the SDFG. For example, this fuses redundant states (safely) and removes redundant arrays.
B{Note:} This is an in-place operation on the SDFG.
-
specialize
(symbols: Dict[str, Any])¶ Sets symbolic values in this SDFG to constants. :param symbols: Values to specialize.
-
start_state
¶ Returns the starting state of this SDFG.
-
states
()¶ Alias that returns the nodes (states) in this SDFG.
-
subarrays
¶ Returns a dictionary of sub-array descriptors (SubArray objects) used in this SDFG.
-
symbols
¶ Global symbols for this SDFG
-
temp_data_name
()¶ Returns a temporary data descriptor name that can be used in this SDFG.
-
to_json
(hash=False)¶ Serializes this object to JSON format. :return: A string representing the JSON-serialized SDFG.
-
transformation_hist
¶ Object property of type list
-
transients
()¶ Returns a dictionary mapping transient data descriptors to their parent scope entry node, or None if top-level (i.e., exists in multiple scopes).
-
update_sdfg_list
(sdfg_list)¶
-
validate
() → None¶
-
view
(filename=None)¶ View this sdfg in the system’s HTML viewer :param filename: the filename to write the HTML to. If None, a temporary file will be created.
-
dace.sdfg.utils module¶
Various utility functions to create, traverse, and modify SDFGs.
-
exception
dace.sdfg.utils.
StopTraversal
¶ Bases:
Exception
Special exception that stops DFS conditional traversal beyond the current node.
See: dfs_conditional
-
dace.sdfg.utils.
change_edge_dest
(graph: dace.sdfg.graph.OrderedDiGraph, node_a: Union[dace.sdfg.nodes.Node, dace.sdfg.graph.OrderedMultiDiConnectorGraph], node_b: Union[dace.sdfg.nodes.Node, dace.sdfg.graph.OrderedMultiDiConnectorGraph])¶ Changes the destination of edges from node A to node B.
The function finds all edges in the graph that have node A as their destination. It then creates a new edge for each one found, using the same source nodes and data, but node B as the destination. Afterwards, it deletes the edges found and inserts the new ones into the graph.
Parameters: - graph – The graph upon which the edge transformations will be applied.
- node_a – The original destination of the edges.
- node_b – The new destination of the edges to be transformed.
-
dace.sdfg.utils.
change_edge_src
(graph: dace.sdfg.graph.OrderedDiGraph, node_a: Union[dace.sdfg.nodes.Node, dace.sdfg.graph.OrderedMultiDiConnectorGraph], node_b: Union[dace.sdfg.nodes.Node, dace.sdfg.graph.OrderedMultiDiConnectorGraph])¶ Changes the sources of edges from node A to node B.
The function finds all edges in the graph that have node A as their source. It then creates a new edge for each one found, using the same destination nodes and data, but node B as the source. Afterwards, it deletes the edges found and inserts the new ones into the graph.
Parameters: - graph – The graph upon which the edge transformations will be applied.
- node_a – The original source of the edges to be transformed.
- node_b – The new source of the edges to be transformed.
-
dace.sdfg.utils.
concurrent_subgraphs
(graph)¶ Finds subgraphs of an SDFGState or ScopeSubgraphView that can run concurrently.
-
dace.sdfg.utils.
consolidate_edges
(sdfg: dace.sdfg.sdfg.SDFG, starting_scope=None) → int¶ Union scope-entering memlets relating to the same data node in all states. This effectively reduces the number of connectors and allows more transformations to be performed, at the cost of losing the individual per-tasklet memlets. :param sdfg: The SDFG to consolidate. :return: Number of edges removed.
-
dace.sdfg.utils.
consolidate_edges_scope
(state: dace.sdfg.state.SDFGState, scope_node: Union[dace.sdfg.nodes.EntryNode, dace.sdfg.nodes.ExitNode]) → int¶ Union scope-entering memlets relating to the same data node in a 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. :param state: The SDFG state in which the scope to consolidate resides. :param scope_node: The scope node whose edges will be consolidated. :return: Number of edges removed.
-
dace.sdfg.utils.
depth_limited_dfs_iter
(source, depth)¶ Produce nodes in a Depth-Limited DFS.
-
dace.sdfg.utils.
depth_limited_search
(source, depth)¶ Return best node and its value using a limited-depth Search (depth- limited DFS).
-
dace.sdfg.utils.
dfs_conditional
(G, sources=None, condition=None, reverse=False, yield_parent=False)¶ Produce nodes in a depth-first ordering with an optional condition to stop traversal. If
StopTraversal
is raised during iteration, the outgoing edges of the current node will not be traversed.Parameters: - G – An input DiGraph (assumed acyclic).
- sources – (optional) node or list of nodes that specify starting point(s) for depth-first search and return edges in the component reachable from source. If None, traverses from every node in the graph.
- condition – (optional) a callback that receives the traversed parent and child. Called before each child node is traversed. If it returns True, traversal proceeds normally. If False, the child and reachable nodes are not traversed.
- reverse – If True, traverses the graph backwards from the sources.
- yield_parent – If True, yields a 2-tuple of (parent, child)
Returns: A generator of edges in the lastvisit depth-first-search.
Note: by D. Eppstein, July 2004.
Note: If a source is not specified then a source is chosen arbitrarily and repeatedly until all components in the graph are searched.
-
dace.sdfg.utils.
dfs_topological_sort
(G, sources=None, condition=None, reverse=False)¶ Produce nodes in a depth-first topological ordering.
The function produces nodes in a depth-first topological ordering (DFS to make sure maps are visited properly), with the condition that each node visited had all its predecessors visited. Applies for DAGs only, but works on any directed graph.
Parameters: - G – An input DiGraph (assumed acyclic).
- sources – (optional) node or list of nodes that specify starting point(s) for depth-first search and return edges in the component reachable from source.
- reverse – If True, traverses the graph backwards from the sources.
Returns: A generator of nodes in the lastvisit depth-first-search.
Note: by D. Eppstein, July 2004.
Note: If a source is not specified then a source is chosen arbitrarily and repeatedly until all components in the graph are searched.
-
dace.sdfg.utils.
distributed_compile
(sdfg: dace.sdfg.sdfg.SDFG, comm: Intracomm) → dace.codegen.compiled_sdfg.CompiledSDFG¶ Compiles an SDFG in rank 0 of MPI communicator comm. Then, the compiled SDFG is loaded in all other ranks. NOTE: This method can be used only if the module mpi4py is installed. :param sdfg: SDFG to be compiled. :param comm: MPI communicator. “Intracomm” is the base mpi4py communicator class. :return: Compiled SDFG.
-
dace.sdfg.utils.
dynamic_map_inputs
(state: dace.sdfg.state.SDFGState, map_entry: dace.sdfg.nodes.MapEntry) → List[dace.sdfg.graph.MultiConnectorEdge]¶ For a given map entry node, returns a list of dynamic-range input edges. :param state: The state in which the map entry node resides. :param map_entry: The given node. :return: A list of edges in state whose destination is map entry and denote
dynamic-range input memlets.
-
dace.sdfg.utils.
find_input_arraynode
(graph, edge)¶
-
dace.sdfg.utils.
find_output_arraynode
(graph, edge)¶
-
dace.sdfg.utils.
fuse_states
(sdfg: dace.sdfg.sdfg.SDFG, permissive: bool = False, progress: bool = None) → int¶ Fuses all possible states of an SDFG (and all sub-SDFGs) using an optimized routine that uses the structure of the StateFusion transformation. :param sdfg: The SDFG to transform. :param permissive: If True, operates in permissive mode, which ignores some
race condition checks.Parameters: progress – If True, prints out a progress bar of fusion (may be inaccurate, requires tqdm
). If None, prints out progress if over 5 seconds have passed. If False, never shows progress bar.Returns: The total number of states fused.
-
dace.sdfg.utils.
get_last_view_node
(state: dace.sdfg.state.SDFGState, view: dace.sdfg.nodes.AccessNode) → dace.sdfg.nodes.AccessNode¶ Given a view access node, returns the last viewed access node if existent, else None
-
dace.sdfg.utils.
get_next_nonempty_states
(sdfg: dace.sdfg.sdfg.SDFG, state: dace.sdfg.state.SDFGState) → Set[dace.sdfg.state.SDFGState]¶ From the given state, return the next set of states that are reachable in the SDFG, skipping empty states. Traversal stops at the non-empty state. This function is used to determine whether synchronization should happen at the end of a GPU state. :param sdfg: The SDFG that contains the state. :param state: The state to start from. :return: A set of reachable non-empty states.
-
dace.sdfg.utils.
get_view_edge
(state: dace.sdfg.state.SDFGState, view: dace.sdfg.nodes.AccessNode) → dace.sdfg.graph.MultiConnectorEdge[dace.memlet.Memlet][dace.memlet.Memlet]¶ Given a view access node, returns the incoming/outgoing edge which points to the viewed access node. See the ruleset in the documentation of
dace.data.View
.Parameters: - state – The state in which the view resides.
- view – The view access node.
Returns: An edge pointing to the viewed data or None if view is invalid.
See: dace.data.View
-
dace.sdfg.utils.
get_view_node
(state: dace.sdfg.state.SDFGState, view: dace.sdfg.nodes.AccessNode) → dace.sdfg.nodes.AccessNode¶ Given a view access node, returns the viewed access node if existent, else None
-
dace.sdfg.utils.
has_dynamic_map_inputs
(state: dace.sdfg.state.SDFGState, map_entry: dace.sdfg.nodes.MapEntry) → bool¶ Returns True if a map entry node has dynamic-range inputs. :param state: The state in which the map entry node resides. :param map_entry: The given node. :return: True if there are dynamic-range input memlets, False otherwise.
-
dace.sdfg.utils.
inline_sdfgs
(sdfg: dace.sdfg.sdfg.SDFG, permissive: bool = False, progress: bool = None, multistate: bool = True) → int¶ Inlines all possible nested SDFGs (or sub-SDFGs) using an optimized routine that uses the structure of the SDFG hierarchy. :param sdfg: The SDFG to transform. :param permissive: If True, operates in permissive mode, which ignores some
checks.Parameters: - progress – If True, prints out a progress bar of inlining (may be
inaccurate, requires
tqdm
). If None, prints out progress if over 5 seconds have passed. If False, never shows progress bar. - multistate – Include
Returns: The total number of SDFGs inlined.
- progress – If True, prints out a progress bar of inlining (may be
inaccurate, requires
-
dace.sdfg.utils.
is_array_stream_view
(sdfg: dace.sdfg.sdfg.SDFG, dfg: dace.sdfg.state.SDFGState, node: dace.sdfg.nodes.AccessNode)¶ Test whether a stream is directly connected to an array.
-
dace.sdfg.utils.
is_fpga_kernel
(sdfg, state)¶ Returns whether the given state is an FPGA kernel and should be dispatched to the FPGA code generator. :return: True if this is an FPGA kernel, False otherwise.
-
dace.sdfg.utils.
is_nonfree_sym_dependent
(node: dace.sdfg.nodes.AccessNode, desc: dace.data.Data, state: dace.sdfg.state.SDFGState, fsymbols: Set[str]) → bool¶ Checks whether the Array or View descriptor is non-free symbol dependent. An Array is non-free symbol dependent when its attributes (e.g., shape) depend on non-free symbols. A View is non-free symbol dependent when either its adjacent edges or its viewed node depend on non-free symbols. :param node: the access node to check :param desc: the data descriptor to check :param state: the state that contains the node :param fsymbols: the free symbols to check against
-
dace.sdfg.utils.
is_parallel
(state: dace.sdfg.state.SDFGState, node: Optional[dace.sdfg.nodes.Node] = None) → bool¶ Returns True if a node or state are contained within a parallel section. :param state: The state to test. :param node: An optional node in the state to test. If None, only checks
state.Returns: True if the state or node are located within a map scope that is scheduled to run in parallel, False otherwise.
-
dace.sdfg.utils.
load_precompiled_sdfg
(folder: str)¶ Loads a pre-compiled SDFG from an output folder (e.g. “.dacecache/program”). Folder must contain a file called “program.sdfg” and a subfolder called “build” with the shared object.
Parameters: folder – Path to SDFG output folder. Returns: A callable CompiledSDFG object.
-
dace.sdfg.utils.
local_transients
(sdfg, dfg, entry_node, include_nested=False)¶ Returns transients local to the scope defined by the specified entry node in the dataflow graph. :param entry_node: The entry node that opens the scope. If None, the
top-level scope is used.Parameters: include_nested – Include transients defined in nested scopes.
-
dace.sdfg.utils.
merge_maps
(graph: dace.sdfg.state.SDFGState, outer_map_entry: dace.sdfg.nodes.MapEntry, outer_map_exit: dace.sdfg.nodes.MapExit, inner_map_entry: dace.sdfg.nodes.MapEntry, inner_map_exit: dace.sdfg.nodes.MapExit, param_merge: Callable[[List[dace.symbolic.symbol], List[dace.symbolic.symbol]], List[dace.symbolic.symbol]] = <function <lambda>>, range_merge: Callable[[List[dace.subsets.Subset], List[dace.subsets.Subset]], List[dace.subsets.Subset]] = <function <lambda>>) -> (<class 'dace.sdfg.nodes.MapEntry'>, <class 'dace.sdfg.nodes.MapExit'>)¶ Merges two maps (their entries and exits). It is assumed that the operation is valid.
-
dace.sdfg.utils.
node_path_graph
(*args)¶ Generates a path graph passing through the input nodes.
The function generates a graph using as nodes the input arguments. Subsequently, it creates a path passing through all the nodes, in the same order as they were given in the function input.
Parameters: *args – Variable number of nodes or a list of nodes.
Returns: A directed graph based on the input arguments. @rtype: gr.OrderedDiGraph
-
dace.sdfg.utils.
nodes_in_all_simple_paths
(G, source, target, condition: Callable[[Any], bool] = None) → Set[Any]¶ Returns a set of nodes that appear in any of the paths from
source
totargets
. Optionally, a condition can be given to control traversal.Parameters: - G – The graph to traverse.
- source – Source node.
- targets –
This algorithm uses a modified depth-first search, adapted from networkx.all_simple_paths.
The algorithm is written for directed _graphs_. For multigraphs, use networkx.all_simple_paths!
[1] R. Sedgewick, “Algorithms in C, Part 5: Graph Algorithms”, Addison Wesley Professional, 3rd ed., 2001.
-
dace.sdfg.utils.
remove_edge_and_dangling_path
(state: dace.sdfg.state.SDFGState, edge: dace.sdfg.graph.MultiConnectorEdge)¶ Removes an edge and all of its parent edges in a memlet path, cleaning dangling connectors and isolated nodes resulting from the removal. :param state: The state in which the edge exists. :param edge: The edge to remove.
-
dace.sdfg.utils.
separate_maps
(state, dfg, schedule)¶ Separates the given ScopeSubgraphView into subgraphs with and without maps of the given schedule type. The function assumes that the given ScopeSubgraph view does not contain any concurrent segments (i.e. pass it through concurrent_subgraphs first). Only top level maps will be accounted for, if the desired schedule occurs in another (undesired) map, it will be ignored.
Returns a list with the subgraph views in order of the original DFG. ScopeSubgraphViews for the parts with maps, StateSubgraphViews for the parts without maps.
-
dace.sdfg.utils.
trace_nested_access
(node: dace.sdfg.nodes.AccessNode, state: dace.sdfg.state.SDFGState, sdfg: dace.sdfg.sdfg.SDFG) → List[Tuple[dace.sdfg.nodes.AccessNode, dace.sdfg.state.SDFGState, dace.sdfg.sdfg.SDFG]]¶ Given an AccessNode in a nested SDFG, trace the accessed memory back to the outermost scope in which it is defined.
Parameters: - node – An access node.
- state – State in which the access node is located.
- sdfg – SDFG in which the access node is located.
Returns: A list of scopes ((input_node, output_node), (memlet_read, memlet_write), state, sdfg) in which the given data is accessed, from outermost scope to innermost scope.
-
dace.sdfg.utils.
traverse_sdfg_with_defined_symbols
(sdfg: dace.sdfg.sdfg.SDFG, recursive: bool = False) → Generator[Tuple[dace.sdfg.state.SDFGState, dace.sdfg.nodes.Node, Dict[str, dace.dtypes.typeclass]], None, None]¶ Traverses the SDFG, its states and nodes, yielding the defined symbols and their types at each node. :return: A generator that yields tuples of (state, node in state, currently-defined symbols)
-
dace.sdfg.utils.
unique_node_repr
(graph: Union[dace.sdfg.state.SDFGState, dace.sdfg.scope.ScopeSubgraphView], node: dace.sdfg.nodes.Node) → str¶ Returns unique string representation of the given node, considering its placement into the SDFG graph. Useful for hashing, or building node-based dictionaries. :param graph: the state/subgraph that contains the node :param node: node to represent :return: the unique representation
-
dace.sdfg.utils.
weakly_connected_component
(dfg, node_in_component: dace.sdfg.nodes.Node) → dace.sdfg.state.StateSubgraphView¶ Returns a subgraph of all nodes that form the weakly connected component in dfg that contains node_in_component.
dace.sdfg.validation module¶
Exception classes and methods for validation of SDFGs.
-
exception
dace.sdfg.validation.
InvalidSDFGEdgeError
(message: str, sdfg, state_id, edge_id)¶ Bases:
dace.sdfg.validation.InvalidSDFGError
Exceptions of invalid edges in an SDFG state.
-
to_json
()¶
-
-
exception
dace.sdfg.validation.
InvalidSDFGError
(message: str, sdfg, state_id)¶ Bases:
Exception
A class of exceptions thrown when SDFG validation fails.
-
to_json
()¶
-
-
exception
dace.sdfg.validation.
InvalidSDFGInterstateEdgeError
(message: str, sdfg, edge_id)¶ Bases:
dace.sdfg.validation.InvalidSDFGError
Exceptions of invalid inter-state edges in an SDFG.
-
to_json
()¶
-
-
exception
dace.sdfg.validation.
InvalidSDFGNodeError
(message: str, sdfg, state_id, node_id)¶ Bases:
dace.sdfg.validation.InvalidSDFGError
Exceptions of invalid nodes in an SDFG state.
-
to_json
()¶
-
-
exception
dace.sdfg.validation.
NodeNotExpandedError
(sdfg: dace.sdfg.SDFG, state_id: int, node_id: int)¶ Bases:
dace.sdfg.validation.InvalidSDFGNodeError
Exception that is raised whenever a library node was not expanded before code generation.
-
dace.sdfg.validation.
validate
(graph: dace.sdfg.graph.SubgraphView)¶
-
dace.sdfg.validation.
validate_sdfg
(sdfg: dace.sdfg.SDFG, references: Set[int] = None)¶ Verifies the correctness of an SDFG by applying multiple tests. :param sdfg: The SDFG to verify. :param references: An optional set keeping seen IDs for object
miscopy validation.Raises an InvalidSDFGError with the erroneous node/edge on failure.
-
dace.sdfg.validation.
validate_state
(state: dace.sdfg.SDFGState, state_id: int = None, sdfg: dace.sdfg.SDFG = None, symbols: Dict[str, dace.dtypes.typeclass] = None, initialized_transients: Set[str] = None, references: Set[int] = None)¶ Verifies the correctness of an SDFG state by applying multiple tests. Raises an InvalidSDFGError with the erroneous node on failure.