Example #1
0
    def __new__(cls, expressions, **kwargs):
        if expressions is None:
            # Return a dummy Callable. This is exploited by unpickling. Users
            # can't do anything useful with it
            return super(Operator, cls).__new__(cls, **kwargs)

        # Parse input arguments
        kwargs = parse_kwargs(**kwargs)

        # The Operator type for the given target
        cls = operator_selector(**kwargs)

        # Normalize input arguments for the selected Operator
        kwargs = cls._normalize_kwargs(**kwargs)

        # Create a symbol registry
        kwargs['sregistry'] = SymbolRegistry()

        # Lower to a JIT-compilable object
        with timed_region('op-compile') as r:
            op = cls._build(expressions, **kwargs)
        op._profiler.py_timers.update(r.timings)

        # Emit info about how long it took to perform the lowering
        op._emit_build_profiling()

        return op
Example #2
0
    def __new__(cls, expressions, **kwargs):
        if expressions is None:
            # Return a dummy Callable. This is exploited by unpickling. Users
            # can't do anything useful with it
            return super(Operator, cls).__new__(cls, **kwargs)

        with timed_region('op-compile') as r:
            op = cls._build(expressions, **kwargs)
        op._profiler.py_timers.update(r.timings)

        op._emit_build_profiling()

        return op
Example #3
0
    def test_lower_func_as_ind(self):
        grid = Grid((11, 11))
        x, y = grid.dimensions
        t = grid.stepping_dim
        h = DefaultDimension("h", default_value=10)

        u = TimeFunction(name='u', grid=grid, time_order=2, space_order=2)
        oh = Function(name="ou", dimensions=(h, ), shape=(10, ), dtype=int)

        eq = [Eq(u.forward, u._subs(x, x + oh))]
        lowered = LoweredEq(
            Eq(u[t + 1, x + 2, y + 2], u[t, x + oh[h] + 2, y + 2]))

        with timed_region('x'):
            leq = Operator._lower_exprs(eq)

        assert leq[0] == lowered
Example #4
0
    def test_expr_collection(self):
        """
        Test that expressions with different time dimensions are not collected.
        """
        grid = Grid((10,))
        f = TimeFunction(name="f", grid=grid, save=10)
        f2 = TimeFunction(name="f2", grid=grid, save=10)
        g = TimeFunction(name="g", grid=grid)
        g2 = TimeFunction(name="g2", grid=grid)

        w = Function(name="w", grid=grid)
        eq = Eq(w, f.dt*g + f2.dt*g2)

        with timed_region('x'):
            # Since all Function are time dependent, there should be no collection
            # and produce the same result as with the pre evaluated expression
            expr = Operator._lower_exprs([eq])[0]
            expr2 = Operator._lower_exprs([eq.evaluate])[0]

        assert expr == expr2
Example #5
0
    def test_subdomain_dim(self):
        """
        Test that all dimensions including ones used as an expression
        are replaced by the subdimension dimensions.
        """
        class sd0(SubDomain):
            name = 'd0'

            def define(self, dimensions):
                x, y = dimensions
                return {x: ('middle', 1, 6), y: ('middle', 1, 1)}
        s_d0 = sd0()
        grid = Grid(shape=(10, 10), subdomains=(s_d0,))
        x, y = grid.dimensions
        x1, y1 = s_d0.dimensions
        f = Function(name='f', grid=grid, dtype=np.int32)

        eq0 = Eq(f, x*f+y, subdomain=grid.subdomains['d0'])
        with timed_region('x'):
            expr = Operator._lower_exprs([eq0])[0]
        assert expr.rhs == x1 * f[x1 + 1, y1 + 1] + y1