diff --git a/python/dune/perftool/generation/__init__.py b/python/dune/perftool/generation/__init__.py index ae313551db63794fc6691aecc85b8fecc1d059ee..c7642cec3b4746248907d48f2b9606c0307fa4be 100644 --- a/python/dune/perftool/generation/__init__.py +++ b/python/dune/perftool/generation/__init__.py @@ -24,7 +24,6 @@ from dune.perftool.generation.loopy import (constantarg, globalarg, iname, instruction, - function_mangler, pymbolic_expr, temporary_variable, valuearg, diff --git a/python/dune/perftool/generation/loopy.py b/python/dune/perftool/generation/loopy.py index 1345af2486c6b1e7c77a4f5317ef7f6b1823ec83..506958e458107553745ada42bb475d4de0282139 100644 --- a/python/dune/perftool/generation/loopy.py +++ b/python/dune/perftool/generation/loopy.py @@ -11,7 +11,6 @@ import numpy iname = generator_factory(item_tags=("iname",)) pymbolic_expr = generator_factory(item_tags=("kernel", "pymbolic")) -function_mangler = generator_factory(item_tags=("kernel", "mangler")) @generator_factory(item_tags=("argument", "globalarg"), diff --git a/python/dune/perftool/loopy/functions.py b/python/dune/perftool/loopy/functions.py new file mode 100644 index 0000000000000000000000000000000000000000..4637c4ed191eeb1acaa001e7634e8285e7664de7 --- /dev/null +++ b/python/dune/perftool/loopy/functions.py @@ -0,0 +1,36 @@ +from loopy import CallMangleInfo +from loopy.symbolic import FunctionIdentifier +from loopy.types import NumpyType + +import numpy + + +class CoefficientAccess(FunctionIdentifier): + def __init__(self, restriction): + self.restriction = restriction + + def __getinitargs__(self): + return (self.restriction,) + + @property + def name(self): + from dune.perftool.pdelab.argument import name_coefficientcontainer + return name_coefficientcontainer(self.restriction) + + +def coefficient_mangler(target, func, dtypes): + if isinstance(func, CoefficientAccess): + return CallMangleInfo(func.name, (NumpyType(numpy.float64),), (NumpyType(str), NumpyType(numpy.int32))) + + +class PDELabAccumulationFunction(FunctionIdentifier): + def __init__(self, accumobj): + self.accumobj = accumobj + + def __getinitargs__(self): + return (self.accumobj,) + + +def accumulation_mangler(target, func, dtypes): + if isinstance(func, PDELabAccumulationFunction): + return CallMangleInfo('{}.accumulate'.format(func.accumobj), (), ()) diff --git a/python/dune/perftool/loopy/target.py b/python/dune/perftool/loopy/target.py index 3c717f2de5d87a3070fbec434cfb815c9676ab93..d31b54c76d3e418c2f89a1f1a216c1ca59bbfdec 100644 --- a/python/dune/perftool/loopy/target.py +++ b/python/dune/perftool/loopy/target.py @@ -23,13 +23,6 @@ class MyMapper(ExpressionToCMapper): ret = ret + '[{}]'.format(str(i)) return ret - def map_variable(self, expr, enclosing_prec, type_context): - from dune.perftool.pymbolic import VerbatimVariable - if isinstance(expr, VerbatimVariable): - return expr.name - else: - return super(MyMapper, self).map_variable(expr, enclosing_prec, type_context) - class DuneASTBuilder(CASTBuilder): def get_expression_to_code_mapper(self, codegen_state): diff --git a/python/dune/perftool/pdelab/argument.py b/python/dune/perftool/pdelab/argument.py index 720a46218ddf1aff087ea18cf979b4069f2d71fe..c96199fb2d8738918d9541359b78fbc6b22e9d82 100644 --- a/python/dune/perftool/pdelab/argument.py +++ b/python/dune/perftool/pdelab/argument.py @@ -1,6 +1,6 @@ """ Generator functions related to trial and test functions and the accumulation loop""" -from dune.perftool.generation import domain, iname, pymbolic_expr, symbol, globalarg, function_mangler, constantarg, get_global_context_value +from dune.perftool.generation import domain, iname, pymbolic_expr, symbol, globalarg, valuearg, get_global_context_value from dune.perftool.ufl.modified_terminals import ModifiedArgumentDescriptor from dune.perftool.pdelab import (name_index, restricted_name, @@ -15,6 +15,8 @@ from dune.perftool.pdelab.basis import (evaluate_trialfunction, from dune.perftool import Restriction from pymbolic.primitives import Call, Subscript, Variable +import loopy + @symbol def name_testfunction_gradient(element, restriction): @@ -68,28 +70,15 @@ def type_trialfunctionspace(): @symbol def name_coefficientcontainer(restriction): name = restricted_name("x", restriction) - from dune.perftool.pdelab.basis import name_lfs_bound, lfs_iname return name -@function_mangler -def create_function_mangler(container): - def _mangler(kernel, name, dtypes): - if name == container: - import loopy - return loopy.types.NumpyType("int"), container - - return _mangler - - @pymbolic_expr def pymbolic_coefficient(lfs, index, restriction): - container = name_coefficientcontainer(restriction) - create_function_mangler(container) - import loopy - constantarg(lfs, dtype=loopy.types.NumpyType("str")) - from dune.perftool.pymbolic import VerbatimVariable - return Call(VerbatimVariable(container), (VerbatimVariable(lfs), Variable(index),)) + # TODO introduce a proper type for local function spaces! + valuearg(lfs, dtype=loopy.types.NumpyType("str")) + from dune.perftool.loopy.functions import CoefficientAccess + return Call(CoefficientAccess(restriction), (Variable(lfs), Variable(index),)) @symbol diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py index 958e0974ddf24d2b3b7c8889d6ccfabd5207dd94..86f719037ebae1776d71e613af9ac1aac1497f33 100644 --- a/python/dune/perftool/pdelab/localoperator.py +++ b/python/dune/perftool/pdelab/localoperator.py @@ -180,7 +180,9 @@ def generate_kernel(integrals): instructions = [i for i in retrieve_cache_items("instruction")] temporaries = {i.name: i for i in retrieve_cache_items("temporary")} arguments = [i for i in retrieve_cache_items("argument")] - manglers = [i for i in retrieve_cache_items("mangler")] + + # Get the function manglers + from dune.perftool.loopy.functions import accumulation_mangler, coefficient_mangler # Create the kernel from loopy import make_kernel, preprocess_kernel @@ -188,7 +190,7 @@ def generate_kernel(integrals): instructions, arguments, temporary_variables=temporaries, - function_manglers=manglers, + function_manglers=[accumulation_mangler, coefficient_mangler], target=DuneTarget() ) diff --git a/python/dune/perftool/pymbolic/__init__.py b/python/dune/perftool/pymbolic/__init__.py index d4a85c13e666669948ac257142656a685dc8b24b..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/python/dune/perftool/pymbolic/__init__.py +++ b/python/dune/perftool/pymbolic/__init__.py @@ -1,5 +0,0 @@ -from pymbolic.primitives import Variable - - -class VerbatimVariable(Variable): - pass