Beispiel #1
0
    def _extract_time_invariants(self,
                                 cluster,
                                 template,
                                 with_cse=True,
                                 costmodel=None,
                                 **kwargs):
        """
        Extract time-invariant subexpressions, and assign them to temporaries.
        """
        make = lambda: Scalar(name=template(), dtype=cluster.dtype).indexify()
        rule = iq_timeinvariant(cluster.trace)
        costmodel = costmodel or (lambda e: estimate_cost(e) > 0)
        processed, found = xreplace_constrained(cluster.exprs, make, rule,
                                                costmodel)

        if with_cse:
            leaves = [i for i in processed if i not in found]

            # Search for common sub-expressions amongst them (and only them)
            found = common_subexprs_elimination(found, make)

            # Some temporaries may be droppable at this point
            processed = compact_temporaries(found, leaves)

        return cluster.rebuild(processed)
Beispiel #2
0
    def _eliminate_intra_stencil_redundancies(self, cluster, template, **kwargs):
        """
        Perform common subexpression elimination, bypassing the tensor expressions
        extracted in previous passes.
        """
        make = lambda: Scalar(name=template(), dtype=cluster.dtype).indexify()
        processed = common_subexprs_elimination(cluster.exprs, make)

        return cluster.rebuild(processed)
Beispiel #3
0
    def _eliminate_intra_stencil_redundancies(self, cluster, template, **kwargs):
        """
        Perform common subexpression elimination, bypassing the tensor expressions
        extracted in previous passes.
        """

        skip = [e for e in cluster.exprs if e.lhs.base.function.is_TensorFunction]
        candidates = [e for e in cluster.exprs if e not in skip]

        make = lambda i: ScalarFunction(name=template(i)).indexify()

        processed = common_subexprs_elimination(candidates, make)

        return cluster.reschedule(skip + processed)
Beispiel #4
0
    def _eliminate_intra_stencil_redundancies(self, cluster, template, **kwargs):
        """
        Perform common subexpression elimination, bypassing the tensor expressions
        extracted in previous passes.
        """

        skip = [e for e in cluster.exprs if e.lhs.base.function.is_Array]
        candidates = [e for e in cluster.exprs if e not in skip]

        make = lambda: Scalar(name=template(), dtype=cluster.dtype).indexify()

        processed = common_subexprs_elimination(candidates, make)

        return cluster.rebuild(skip + processed)
Beispiel #5
0
    def _eliminate_intra_stencil_redundancies(self, cluster, **kwargs):
        """
        Perform common subexpression elimination, bypassing the scalar expressions
        extracted in previous passes.
        """

        skip = [
            e for e in cluster.exprs if e.lhs.base.function.is_SymbolicFunction
        ]
        candidates = [e for e in cluster.exprs if e not in skip]

        template = self.conventions['temporary'] + "%d"
        make = lambda i: ScalarFunction(name=template % i).indexify()

        processed = common_subexprs_elimination(candidates, make)

        return cluster.rebuild(skip + processed)
Beispiel #6
0
    def _extract_time_invariants(self, cluster, template, with_cse=True, **kwargs):
        """
        Extract time-invariant subexpressions, and assign them to temporaries.
        """
        make = lambda: Scalar(name=template(), dtype=cluster.dtype).indexify()
        rule = iq_timeinvariant(cluster.trace)
        costmodel = lambda e: estimate_cost(e) > 0
        processed, found = xreplace_constrained(cluster.exprs, make, rule, costmodel)

        if with_cse:
            leaves = [i for i in processed if i not in found]

            # Search for common sub-expressions amongst them (and only them)
            found = common_subexprs_elimination(found, make)

            # Some temporaries may be droppable at this point
            processed = compact_temporaries(found, leaves)

        return cluster.rebuild(processed)
Beispiel #7
0
    def _extract_time_invariants(self, cluster, **kwargs):
        """
        Extract time-invariant subexpressions, and assign them to temporaries.
        """

        # Extract time invariants
        template = self.conventions['time-invariant'] + "%d"
        make = lambda i: ScalarFunction(name=template % i).indexify()

        rule = iq_timeinvariant(cluster.trace)

        cm = lambda e: estimate_cost(e) > 0

        processed, found = xreplace_constrained(cluster.exprs, make, rule, cm)
        leaves = [i for i in processed if i not in found]

        # Search for common sub-expressions amongst them (and only them)
        template = "%s%s%s" % (self.conventions['redundancy'],
                               self.conventions['time-invariant'], '%d')
        make = lambda i: ScalarFunction(name=template % i).indexify()

        found = common_subexprs_elimination(found, make)

        return cluster.rebuild(found + leaves)