def make_efunc(name, iet, dynamic_parameters=None, retval='void', prefix='static'): """ Create an ElementalFunction from (a sequence of) perfectly nested Iterations. """ # Arrays are by definition (vector) temporaries, so if they are written # within `iet`, they can also be declared and allocated within the `efunc` items = FindSymbols().visit(iet) local = [ i.write for i in FindNodes(Expression).visit(iet) if i.write.is_Array ] external = [i for i in items if i.is_Tensor and i not in local] # Insert array casts casts = [ArrayCast(i) for i in external] iet = List(body=casts + [iet]) # Insert declarations iet = iet_insert_C_decls(iet, external) # The Callable parameters params = [i for i in derive_parameters(iet) if i not in local] return ElementalFunction(name, iet, retval, params, prefix, dynamic_parameters)
def make_efunc(name, iet, dynamic_parameters=None, retval='void', prefix='static'): """ Shortcut to create an ElementalFunction. """ return ElementalFunction(name, iet, retval, derive_parameters(iet), prefix, dynamic_parameters)
def make_efunc(name, iet, dynamic_parameters=None, retval='void', prefix='static'): """ Create an ElementalFunction from (a sequence of) perfectly nested Iterations. """ # Arrays are by definition (vector) temporaries, so if they are written-only # within `iet`, they can also be declared and allocated within the `efunc` exprs = FindNodes(Expression).visit(iet) write_arrays = {i.write for i in exprs if i.write.is_Array} rw_arrays = write_arrays.intersection(set().union(*[i.reads for i in exprs])) # The Callable parameters parameters = [i for i in derive_parameters(iet) if i not in rw_arrays] return ElementalFunction(name, iet, retval, parameters, prefix, dynamic_parameters)
def make_efunc(name, iet, dynamic_parameters=None, retval='void', prefix='static'): """ Create an ElementalFunction from (a sequence of) perfectly nested Iterations. """ # Arrays are by definition (vector) temporaries, so if they are written-only # within `iet`, they can also be declared and allocated within the `efunc` exprs = FindNodes(Expression).visit(iet) write_arrays = {i.write for i in exprs if i.write.is_Array} rw_arrays = write_arrays.intersection( set().union(*[i.reads for i in exprs])) # The Callable parameters parameters = [i for i in derive_parameters(iet) if i not in rw_arrays] return ElementalFunction(name, iet, retval, parameters, prefix, dynamic_parameters)