From 5828235f806c3e87a5b1eed34ef69ef317a110bd Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 4 Nov 2019 23:38:36 +0100 Subject: Extract streaming pattern into Mako definitions This should allow for plugging in e.g. a AA pattern implementation without without touching any file but `AA.$target.mako`. OpenCL and C++ target templates now look basically the same and could potentially be merged. However this would decrease flexibility should more differences appear in the future. Maintaining separate template files is an acceptable overhead to preserve flexibility. --- boltzgen/kernel/template/momenta_boundary.cpp.mako | 27 +++++----------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'boltzgen/kernel/template/momenta_boundary.cpp.mako') diff --git a/boltzgen/kernel/template/momenta_boundary.cpp.mako b/boltzgen/kernel/template/momenta_boundary.cpp.mako index ae78e9f..bea6cc1 100644 --- a/boltzgen/kernel/template/momenta_boundary.cpp.mako +++ b/boltzgen/kernel/template/momenta_boundary.cpp.mako @@ -1,23 +1,12 @@ +<%namespace name="pattern" file="${'/pattern/%s.cpp.mako' % context['streaming']}"/> <% import sympy - moments_subexpr, moments_assignment = model.moments() collision_subexpr, collision_assignment = model.collision(f_eq = model.equilibrium(resolve_moments = False)) %> -<%def name="momenta_boundary(name, param)"> -void ${name}_momenta_boundary( - ${float_type}* f_next, - const ${float_type}* f_prev, - std::size_t gid, ${param}) -{ - ${float_type}* preshifted_f_next = f_next + ${layout.cell_preshift('gid')}; - const ${float_type}* preshifted_f_prev = f_prev + ${layout.cell_preshift('gid')}; - -% for i, c_i in enumerate(descriptor.c): - const ${float_type} f_curr_${i} = preshifted_f_prev[${layout.pop_offset(i) + layout.neighbor_offset(-c_i)}]; -% endfor - +<%def name="momenta_boundary(name, params)"> +<%call expr="pattern.operator_ab('%s_momenta_boundary' % name, params)"> % for i, expr in enumerate(moments_subexpr): const ${float_type} ${expr[0]} = ${sympy.ccode(expr[1])}; % endfor @@ -31,21 +20,17 @@ void ${name}_momenta_boundary( % for i, expr in enumerate(collision_assignment): const ${float_type} ${sympy.ccode(expr)} % endfor - -% for i, expr in enumerate(collision_assignment): - preshifted_f_next[${layout.pop_offset(i)}] = f_next_${i}; -% endfor -} + -<%call expr="momenta_boundary('velocity', '%s velocity[%d]' % (float_type, descriptor.d))"> +<%call expr="momenta_boundary('velocity', [(float_type, 'velocity[%d]' % descriptor.d)])"> ${float_type} ${sympy.ccode(moments_assignment[0])} % for i, expr in enumerate(moments_assignment[1:]): ${float_type} ${expr.lhs} = velocity[${i}]; % endfor -<%call expr="momenta_boundary('density', '%s density' % float_type)"> +<%call expr="momenta_boundary('density', [(float_type, 'density')])"> ${float_type} ${moments_assignment[0].lhs} = density; % for i, expr in enumerate(moments_assignment[1:]): ${float_type} ${sympy.ccode(expr)} -- cgit v1.2.3