coneoproject / COFFEE

COFFEE - A COmpiler For Fast Expression Evaluation
Other
9 stars 6 forks source link

Loop merger embarrassed by empty loops #98

Closed miklos1 closed 7 years ago

miklos1 commented 8 years ago

Testing with the finat branch of Firedrake, firedrakeproject/tsfc@4589cf2 and master FInAT, I get the following failure:

$ py.test tests/extrusion/test_helmholtz_scalar.py::test_scalar_convergence[testcase2-3.9-False]
...
../PyOP2/pyop2/host.py:60: in _ast_to_c
    ast_handler.plan_cpu(self._opts)
../COFFEE/coffee/plan.py:120: in plan_cpu
    loop_opt.rewrite(rewrite)
../COFFEE/coffee/optimizer.py:145: in rewrite
    merged_loops = SSALoopMerger(self.expr_graph).merge(self.header)
../COFFEE/coffee/scheduler.py:183: in merge
    merged, l_dims, m_dims = self._merge_loops(parent, l, merging_in)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <coffee.scheduler.SSALoopMerger object at 0x7f8e602b2dd0>
root = <coffee.base.Block object at 0x7f8e5ab0c510>
loop_a = <coffee.base.For object at 0x7f8e5abb6490>
loop_b = <coffee.base.Block object at 0x7f8e5abdb290>

    def _merge_loops(self, root, loop_a, loop_b):
        """Merge the body of ``loop_a`` in ``loop_b`` and eliminate ``loop_a``
            from the tree rooted in ``root``. Return a reference to the block
            containing the merged loop as well as the iteration variables used
            in the respective iteration spaces."""
        # Find the first statement in the perfect loop nest loop_b
        dims_a, dims_b = [], []
>       while isinstance(loop_b.children[0], (Block, For)):
E       IndexError: list index out of range

../COFFEE/coffee/scheduler.py:76: IndexError

Here is the unoptimised C code. It seems that the loop merger doesn't expect spurious empty loops.

miklos1 commented 8 years ago

Note that firedrakeproject/tsfc@509cb75 avoids triggering this code path, but then leads to #99.

FabioLuporini commented 8 years ago

OK, this is another easy fix