Skip to content

Commit

Permalink
Renamed experimental_cfg_blocks to explicit_control_flow
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Dec 11, 2024
1 parent a8546ab commit c9d6b51
Show file tree
Hide file tree
Showing 56 changed files with 159 additions and 167 deletions.
2 changes: 1 addition & 1 deletion dace/codegen/control_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ def structured_control_flow_tree(sdfg: SDFG, dispatch_state: Callable[[SDFGState
:param sdfg: The SDFG to iterate over.
:return: Control-flow block representing the entire SDFG.
"""
if sdfg.root_sdfg.using_experimental_blocks:
if sdfg.root_sdfg.using_explicit_control_flow:
return structured_control_flow_tree_with_regions(sdfg, dispatch_state)

# Avoid import loops
Expand Down
2 changes: 1 addition & 1 deletion dace/codegen/targets/framecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def dispatch_state(state: SDFGState) -> str:
states_generated.add(state) # For sanity check
return stream.getvalue()

if sdfg.root_sdfg.recheck_using_experimental_blocks():
if sdfg.root_sdfg.recheck_using_explicit_control_flow():
# Use control flow blocks embedded in the SDFG to generate control flow.
cft = cflow.structured_control_flow_tree_with_regions(sdfg, dispatch_state)
elif config.Config.get_bool('optimizer', 'detect_control_flow'):
Expand Down
18 changes: 9 additions & 9 deletions dace/frontend/fortran/fortran_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AST_translator:
"""
This class is responsible for translating the internal AST into a SDFG.
"""
def __init__(self, ast: ast_components.InternalFortranAst, source: str, use_experimental_cfg_blocks: bool = False):
def __init__(self, ast: ast_components.InternalFortranAst, source: str, use_explicit_cf: bool = False):
"""
:ast: The internal fortran AST to be used for translation
:source: The source file name from which the AST was generated
Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(self, ast: ast_components.InternalFortranAst, source: str, use_expe
ast_internal_classes.Allocate_Stmt_Node: self.allocate2sdfg,
ast_internal_classes.Break_Node: self.break2sdfg,
}
self.use_experimental_cfg_blocks = use_experimental_cfg_blocks
self.use_explicit_cf = use_explicit_cf

def get_dace_type(self, type):
"""
Expand Down Expand Up @@ -271,7 +271,7 @@ def forstmt2sdfg(self, node: ast_internal_classes.For_Stmt_Node, sdfg: SDFG, cfg
:param sdfg: The SDFG to which the node should be translated
"""

if not self.use_experimental_cfg_blocks:
if not self.use_explicit_cf:
declloop = False
name = "FOR_l_" + str(node.line_number[0]) + "_c_" + str(node.line_number[1])
begin_state = ast_utils.add_simple_state_to_sdfg(self, cfg, "Begin" + name)
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def create_sdfg_from_string(
source_string: str,
sdfg_name: str,
normalize_offsets: bool = False,
use_experimental_cfg_blocks: bool = False
use_explicit_cf: bool = False
):
"""
Creates an SDFG from a fortran file in a string
Expand Down Expand Up @@ -1133,7 +1133,7 @@ def create_sdfg_from_string(

program = ast_transforms.ForDeclarer().visit(program)
program = ast_transforms.IndexExtractor(program, normalize_offsets).visit(program)
ast2sdfg = AST_translator(own_ast, __file__, use_experimental_cfg_blocks)
ast2sdfg = AST_translator(own_ast, __file__, use_explicit_cf)
sdfg = SDFG(sdfg_name)
ast2sdfg.top_level = program
ast2sdfg.globalsdfg = sdfg
Expand All @@ -1148,11 +1148,11 @@ def create_sdfg_from_string(
sdfg.parent_sdfg = None
sdfg.parent_nsdfg_node = None
sdfg.reset_cfg_list()
sdfg.using_experimental_blocks = use_experimental_cfg_blocks
sdfg.using_explicit_control_flow = use_explicit_cf
return sdfg


def create_sdfg_from_fortran_file(source_string: str, use_experimental_cfg_blocks: bool = False):
def create_sdfg_from_fortran_file(source_string: str, use_explicit_cf: bool = False):
"""
Creates an SDFG from a fortran file
:param source_string: The fortran file name
Expand Down Expand Up @@ -1180,11 +1180,11 @@ def create_sdfg_from_fortran_file(source_string: str, use_experimental_cfg_block

program = ast_transforms.ForDeclarer().visit(program)
program = ast_transforms.IndexExtractor(program).visit(program)
ast2sdfg = AST_translator(own_ast, __file__, use_experimental_cfg_blocks)
ast2sdfg = AST_translator(own_ast, __file__, use_explicit_cf)
sdfg = SDFG(source_string)
ast2sdfg.top_level = program
ast2sdfg.globalsdfg = sdfg
ast2sdfg.translate(program, sdfg)

sdfg.using_experimental_blocks = use_experimental_cfg_blocks
sdfg.using_explicit_control_flow = use_explicit_cf
return sdfg
7 changes: 3 additions & 4 deletions dace/frontend/python/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def program(f: F,
recompile: bool = True,
distributed_compilation: bool = False,
constant_functions=False,
use_experimental_cfg_blocks=True,
use_explicit_cf=True,
**kwargs) -> Callable[..., parser.DaceProgram]:
"""
Entry point to a data-centric program. For methods and ``classmethod``s, use
Expand All @@ -69,8 +69,7 @@ def program(f: F,
not depend on internal variables are constant.
This will hardcode their return values into the
resulting program.
:param use_experimental_cfg_blocks: If True, makes use of experimental CFG blocks susch as loop and conditional
regions.
:param use_explicit_cfl: If True, makes use of explicit control flow constructs.
:note: If arguments are defined with type hints, the program can be compiled
ahead-of-time with ``.compile()``.
"""
Expand All @@ -87,7 +86,7 @@ def program(f: F,
regenerate_code=regenerate_code,
recompile=recompile,
distributed_compilation=distributed_compilation,
use_experimental_cfg_blocks=use_experimental_cfg_blocks)
use_explicit_cf=use_explicit_cf)


function = program
Expand Down
8 changes: 4 additions & 4 deletions dace/frontend/python/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(self,
recompile: bool = True,
distributed_compilation: bool = False,
method: bool = False,
use_experimental_cfg_blocks: bool = True):
use_explicit_cf: bool = True):
from dace.codegen import compiled_sdfg # Avoid import loops

self.f = f
Expand All @@ -176,7 +176,7 @@ def __init__(self,
self.recreate_sdfg = recreate_sdfg
self.regenerate_code = regenerate_code
self.recompile = recompile
self.use_experimental_cfg_blocks = use_experimental_cfg_blocks
self.use_explicit_cf = use_explicit_cf
self.distributed_compilation = distributed_compilation

self.global_vars = _get_locals_and_globals(f)
Expand Down Expand Up @@ -494,10 +494,10 @@ def _parse(self, args, kwargs, simplify=None, save=False, validate=False) -> SDF
# Obtain DaCe program as SDFG
sdfg, cached = self._generate_pdp(args, kwargs, simplify=simplify)

if not self.use_experimental_cfg_blocks:
if not self.use_explicit_cf:
for nsdfg in sdfg.all_sdfgs_recursive():
sdutils.inline_control_flow_regions(nsdfg)
sdfg.using_experimental_blocks = self.use_experimental_cfg_blocks
sdfg.using_explicit_control_flow = self.use_explicit_cf

sdfg.reset_cfg_list()

Expand Down
2 changes: 1 addition & 1 deletion dace/sdfg/analysis/schedule_tree/sdfg_to_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def as_schedule_tree(sdfg: SDFG, in_place: bool = False, toplevel: bool = True)
#############################

# Create initial tree from CFG
if sdfg.using_experimental_blocks:
if sdfg.using_explicit_control_flow:
cfg: cf.ControlFlow = cf.structured_control_flow_tree_with_regions(sdfg, lambda _: '')
else:
cfg: cf.ControlFlow = cf.structured_control_flow_tree(sdfg, lambda _: '')
Expand Down
2 changes: 1 addition & 1 deletion dace/sdfg/analysis/writeset_underapproximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ class UnderapproximateWritesDict:
Tuple[SDFGState, SDFGState, List[SDFGState], str, subsets.Range]] = field(default_factory=dict)


@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class UnderapproximateWrites(ppl.Pass):

# Dictionary mapping each edge to a copy of the memlet of that edge with its write set underapproximated.
Expand Down
2 changes: 1 addition & 1 deletion dace/sdfg/propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def propagate_states(sdfg: 'SDFG', concretize_dynamic_unbounded: bool = False) -
:note: This operates on the SDFG in-place.
"""

if sdfg.using_experimental_blocks:
if sdfg.using_explicit_control_flow:
# Avoid cyclic imports
from dace.transformation.pass_pipeline import Pipeline
from dace.transformation.passes.analysis import StatePropagation
Expand Down
16 changes: 8 additions & 8 deletions dace/sdfg/sdfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ class SDFG(ControlFlowRegion):
desc='Mapping between callback name and its original callback '
'(for when the same callback is used with a different signature)')

using_experimental_blocks = Property(dtype=bool, default=False,
desc="Whether the SDFG contains experimental control flow blocks")
using_explicit_control_flow = Property(dtype=bool, default=False,
desc="Whether the SDFG contains explicit control flow constructs")

def __init__(self,
name: str,
Expand Down Expand Up @@ -2844,14 +2844,14 @@ def make_array_memlet(self, array: str):
"""
return dace.Memlet.from_array(array, self.data(array))

def recheck_using_experimental_blocks(self) -> bool:
found_experimental_block = False
def recheck_using_explicit_control_flow(self) -> bool:
found_explicit_cf_block = False
for node, graph in self.root_sdfg.all_nodes_recursive():
if isinstance(graph, ControlFlowRegion) and not isinstance(graph, SDFG):
found_experimental_block = True
found_explicit_cf_block = True
break
if isinstance(node, ControlFlowBlock) and not isinstance(node, SDFGState):
found_experimental_block = True
found_explicit_cf_block = True
break
self.root_sdfg.using_experimental_blocks = found_experimental_block
return found_experimental_block
self.root_sdfg.using_explicit_control_flow = found_explicit_cf_block
return found_explicit_cf_block
2 changes: 1 addition & 1 deletion dace/transformation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .transformation import (PatternNode, PatternTransformation, SingleStateTransformation,
MultiStateTransformation, SubgraphTransformation, ExpandTransformation,
experimental_cfg_block_compatible, single_level_sdfg_only)
explicit_cf_compatible, single_level_sdfg_only)
from .pass_pipeline import Pass, Pipeline, FixedPointPipeline
2 changes: 1 addition & 1 deletion dace/transformation/dataflow/map_fission.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import List, Optional, Tuple


@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class MapFission(transformation.SingleStateTransformation):
""" Implements the MapFission transformation.
Map fission refers to subsuming a map scope into its internal subgraph,
Expand Down
2 changes: 1 addition & 1 deletion dace/transformation/dataflow/map_for_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ def replace_param(param):

sdfg.reset_cfg_list()
# Ensure the SDFG is marked as containing CFG regions
sdfg.root_sdfg.using_experimental_blocks = True
sdfg.root_sdfg.using_explicit_control_flow = True

return node, nstate
2 changes: 1 addition & 1 deletion dace/transformation/interstate/block_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dace.transformation import transformation


@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class BlockFusion(transformation.MultiStateTransformation):
""" Implements the block-fusion transformation.
Expand Down
2 changes: 1 addition & 1 deletion dace/transformation/interstate/fpga_transform_sdfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@properties.make_properties
@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class FPGATransformSDFG(transformation.MultiStateTransformation):
""" Implements the FPGATransformSDFG transformation, which takes an entire
SDFG and transforms it into an FPGA-capable SDFG. """
Expand Down
2 changes: 1 addition & 1 deletion dace/transformation/interstate/fpga_transform_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def fpga_update(sdfg: SDFG, state: SDFGState, depth: int):
fpga_update(node.sdfg, s, depth + 1)


@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class FPGATransformState(transformation.MultiStateTransformation):
""" Implements the FPGATransformState transformation. """

Expand Down
2 changes: 1 addition & 1 deletion dace/transformation/interstate/gpu_transform_sdfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _recursive_in_check(node, state, gpu_scalars):


@make_properties
@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class GPUTransformSDFG(transformation.MultiStateTransformation):
""" Implements the GPUTransformSDFG transformation.
Expand Down
2 changes: 1 addition & 1 deletion dace/transformation/interstate/loop_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


# NOTE: This class extends PatternTransformation directly in order to not show up in the matches
@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class DetectLoop(transformation.PatternTransformation):
""" Detects a for-loop construct from an SDFG. """

Expand Down
4 changes: 2 additions & 2 deletions dace/transformation/interstate/loop_lifting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@properties.make_properties
@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class LoopLifting(DetectLoop, transformation.MultiStateTransformation):

def can_be_applied(self, graph: transformation.ControlFlowRegion, expr_index: int, sdfg: transformation.SDFG,
Expand Down Expand Up @@ -95,5 +95,5 @@ def apply(self, graph: ControlFlowRegion, sdfg: SDFG):
for n in full_body:
graph.remove_node(n)

sdfg.root_sdfg.using_experimental_blocks = True
sdfg.root_sdfg.using_explicit_control_flow = True
sdfg.reset_cfg_list()
4 changes: 2 additions & 2 deletions dace/transformation/interstate/loop_peeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
from dace.symbolic import pystr_to_symbolic
from dace.transformation.interstate.loop_unroll import LoopUnroll
from dace.transformation.passes.analysis import loop_analysis
from dace.transformation.transformation import experimental_cfg_block_compatible
from dace.transformation.transformation import explicit_cf_compatible


@make_properties
@experimental_cfg_block_compatible
@explicit_cf_compatible
class LoopPeeling(LoopUnroll):
"""
Splits the first `count` iterations of loop into multiple, separate control flow regions (one per iteration).
Expand Down
2 changes: 1 addition & 1 deletion dace/transformation/interstate/loop_to_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _sanitize_by_index(indices: Set[int], subset: subsets.Subset) -> subsets.Ran


@properties.make_properties
@xf.experimental_cfg_block_compatible
@xf.explicit_cf_compatible
class LoopToMap(xf.MultiStateTransformation):
"""
Convert a control flow loop into a dataflow map. Currently only supports the simple case where there is no overlap
Expand Down
2 changes: 1 addition & 1 deletion dace/transformation/interstate/loop_unroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from dace.transformation.passes.analysis import loop_analysis

@make_properties
@xf.experimental_cfg_block_compatible
@xf.explicit_cf_compatible
class LoopUnroll(xf.MultiStateTransformation):
""" Unrolls a for-loop into multiple individual control flow regions """

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from dace.transformation import transformation


@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class MoveAssignmentOutsideIf(transformation.MultiStateTransformation):

conditional = transformation.PatternNode(ConditionalBlock)
Expand Down
2 changes: 1 addition & 1 deletion dace/transformation/interstate/move_loop_into_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def offset(memlet_subset_ranges, value):
return (memlet_subset_ranges[0] + value, memlet_subset_ranges[1] + value, memlet_subset_ranges[2])


@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class MoveLoopIntoMap(transformation.MultiStateTransformation):
"""
Moves a loop around a map into the map
Expand Down
11 changes: 2 additions & 9 deletions dace/transformation/interstate/multistate_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


@make_properties
@transformation.experimental_cfg_block_compatible
@transformation.explicit_cf_compatible
class InlineMultistateSDFG(transformation.SingleStateTransformation):
"""
Inlines a multi-state nested SDFG into a top-level SDFG. This only happens
Expand Down Expand Up @@ -141,14 +141,7 @@ def apply(self, outer_state: SDFGState, sdfg: SDFG):
if isinstance(blk, ReturnBlock):
has_return = True
if has_return:
# Avoid cyclic imports
from dace.transformation.passes.fusion_inline import InlineControlFlowRegions
from dace.transformation.passes.simplification.control_flow_raising import ControlFlowRaising

sdutil.inline_control_flow_regions(nsdfg)
# After inlining, try to lift out control flow again, essentially preserving all control flow that can be
# preserved while removing the return blocks.
ControlFlowRaising().apply_pass(nsdfg, {})
sdutil.inline_control_flow_regions(nsdfg, lower_returns=True)

if nsdfg_node.schedule != dtypes.ScheduleType.Default:
infer_types.set_default_schedule_and_storage_types(nsdfg, [nsdfg_node.schedule])
Expand Down
Loading

0 comments on commit c9d6b51

Please sign in to comment.