Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFG analysis does not handle properly SDFGs with structurally inaccessible states #1625

Open
kotsaloscv opened this issue Jul 31, 2024 · 0 comments

Comments

@kotsaloscv
Copy link
Collaborator

kotsaloscv commented Jul 31, 2024

There are some changes from DaCe v0.16 to v0.16.1 especially in the CFG analysis that appear to be incompatible with SDFGs that have structurally inaccessible states. There is a workaround involving calling DeadStateElimination first to remove those states so that they don't cause issues in subsequent passes.

The error I get is the following:

_external_src/gt4py/src/gt4py/next/program_processors/runners/dace_iterator/__init__.py:302: in build_sdfg_from_itir
    sdfg.simplify()
_external_src/dace/dace/sdfg/sdfg.py:2384: in simplify
    return SimplifyPass(validate=validate, validate_all=validate_all, verbose=verbose).apply_pass(self, {})
_external_src/dace/dace/transformation/passes/simplify.py:113: in apply_pass
    result = super().apply_pass(sdfg, pipeline_results)
_external_src/dace/dace/transformation/pass_pipeline.py:547: in apply_pass
    newret = super().apply_pass(sdfg, state)
_external_src/dace/dace/transformation/pass_pipeline.py:502: in apply_pass
    r = self.apply_subpass(sdfg, p, state)
_external_src/dace/dace/transformation/passes/simplify.py:90: in apply_subpass
    ret = p.apply_pass(sdfg, state)
_external_src/dace/dace/transformation/passes/constant_propagation.py:141: in apply_pass
    internal = self.apply_pass(node.sdfg, _, const_syms)
_external_src/dace/dace/transformation/passes/constant_propagation.py:141: in apply_pass
    internal = self.apply_pass(node.sdfg, _, const_syms)
_external_src/dace/dace/transformation/passes/constant_propagation.py:72: in apply_pass
    per_state_constants: Dict[SDFGState, Dict[str, Any]] = self.collect_constants(sdfg, initial_symbols)
_external_src/dace/dace/transformation/passes/constant_propagation.py:196: in collect_constants
    for state in optional_progressbar(cfg.stateorder_topological_sort(sdfg), 'Collecting constants',
_external_src/dace/dace/cli/progress.py:55: in optional_progressbar
    for counter, elem in enumerate(iter):
_external_src/dace/dace/sdfg/analysis/cfg.py:296: in stateorder_topological_sort
    ptree = state_parent_tree(sdfg, loopexits)
_external_src/dace/dace/sdfg/analysis/cfg.py:87: in state_parent_tree
    for be in back_edges(sdfg, idom, alldoms):
_external_src/dace/dace/sdfg/analysis/cfg.py:67: in back_edges
    return [e for e in sdfg.edges() if e.dst in alldoms[e.src]]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <list_iterator object at 0x32fc44a30>

>   return [e for e in sdfg.edges() if e.dst in alldoms[e.src]]
E   KeyError: SDFGState (join)

_external_src/dace/dace/sdfg/analysis/cfg.py:67: KeyError

Workaround code (thanks to @alexnick83), before applying simplify to the corresponding SDFG:

import dace
from dace.transformation.pass_pipeline import Pipeline
from dace.transformation.passes import DeadStateElimination

sdfg = dace.SDFG.from_file('sdfg_before_simplify.sdfg')
my_pipeline = Pipeline([DeadStateElimination()])
for sd in sdfg.all_sdfgs_recursive():
    my_pipeline.apply_pass(sd, {})

I have attached the SDFG that causes this issue. While for DaCe v0.16 everything works as expected, for DaCe v0.16.1 I get the error above.

sdfg_v0.16_after_simplify.json
sdfg_v0.16_before_simplify.json
sdfg_v0.16.1_before_simplify.json

cc: @alexnick83

kotsaloscv added a commit to kotsaloscv/gt4py that referenced this issue Jul 31, 2024
edopao added a commit to GridTools/gt4py that referenced this issue Aug 2, 2024
…#1599)

Addresses the issue reported in spcl/dace#1625

GT4Py was generating a wrong SDFG for icon4py stencil
`calculate_enhanced_diffusion_coefficients_for_grid_point_cold_pools`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant