diff --git a/python/dune/codegen/blockstructured/accumulation.py b/python/dune/codegen/blockstructured/accumulation.py index 9af9759d5e3426df12a10db39f94048e48006867..1f26d3cad33771c8a8872898bbd854beeccd9d57 100644 --- a/python/dune/codegen/blockstructured/accumulation.py +++ b/python/dune/codegen/blockstructured/accumulation.py @@ -1,5 +1,5 @@ from dune.codegen.blockstructured.tools import sub_element_inames -from dune.codegen.generation import accumulation_mixin, instruction +from dune.codegen.generation import accumulation_mixin, instruction, preamble from dune.codegen.loopy.target import dtype_floatingpoint from dune.codegen.options import get_form_option from dune.codegen.pdelab.geometry import world_dimension, name_intersection_geometry_wrapper @@ -28,16 +28,13 @@ def name_accumulation_alias(container, accumspace): k = get_form_option("number_of_blocks") p = accumspace.element.degree() + @preamble def _add_alias_insn(name): dim = world_dimension() element_stride = tuple(p * (p * k + 1)**i for i in range(0, dim)) index_stride = tuple((p * k + 1)**i for i in range(0, dim)) globalarg(name, shape=(k,) * dim + (p + 1,) * dim, strides=element_stride + index_stride, managed=True) - code = "auto {} = &{}.container()({},0);".format(name, container, accumspace.lfs.name) - instruction(within_inames=frozenset(), - code=code, - read_variables=frozenset({container}), - assignees=frozenset({name})) + return "auto {} = &{}.container()({},0);".format(name, container, accumspace.lfs.name) _add_alias_insn(name) _add_alias_insn(name_tail) diff --git a/python/dune/codegen/blockstructured/argument.py b/python/dune/codegen/blockstructured/argument.py index 420773e85bea93ee55cb310255da7fa60d55d9de..0cc7bd175d116b9d47c25b844fc590bbc0f958f2 100644 --- a/python/dune/codegen/blockstructured/argument.py +++ b/python/dune/codegen/blockstructured/argument.py @@ -1,5 +1,5 @@ from dune.codegen.generation import (kernel_cached, - valuearg, instruction, globalarg) + valuearg, globalarg, preamble) from dune.codegen.options import get_form_option from dune.codegen.pdelab.argument import CoefficientAccess from dune.codegen.blockstructured.tools import micro_index_to_macro_index, sub_element_inames @@ -10,17 +10,18 @@ import pymbolic.primitives as prim def name_alias(container, lfs, element): name = container + "_" + lfs.name + "_alias" - k = get_form_option("number_of_blocks") - p = element.degree() - dim = world_dimension() - element_stride = tuple(p * (p * k + 1)**i for i in range(0, dim)) - index_stride = tuple((p * k + 1)**i for i in range(0, dim)) - globalarg(name, shape=(k,) * dim + (p + 1,) * dim, strides=element_stride + index_stride, managed=True) - code = "const auto {} = &{}({},0);".format(name, container, lfs.name) - instruction(within_inames=frozenset(), - code=code, - read_variables=frozenset({container}), - assignees=frozenset({name})) + + @preamble + def _add_alias_insn(name): + k = get_form_option("number_of_blocks") + p = element.degree() + dim = world_dimension() + element_stride = tuple(p * (p * k + 1)**i for i in range(0, dim)) + index_stride = tuple((p * k + 1)**i for i in range(0, dim)) + globalarg(name, shape=(k,) * dim + (p + 1,) * dim, strides=element_stride + index_stride, managed=True) + return "const auto {} = &{}({},0);".format(name, container, lfs.name) + + _add_alias_insn(name) return name