diff options
-rw-r--r-- | boltzgen/kernel/generator.py | 4 | ||||
-rw-r--r-- | boltzgen/kernel/template/basic.cpp.mako | 66 | ||||
-rw-r--r-- | boltzgen/kernel/template/basic.opencl.mako (renamed from boltzgen/kernel/template/kernel.mako) | 0 | ||||
-rw-r--r-- | test.py | 1 |
4 files changed, 69 insertions, 2 deletions
diff --git a/boltzgen/kernel/generator.py b/boltzgen/kernel/generator.py index bd1bb86..59654e2 100644 --- a/boltzgen/kernel/generator.py +++ b/boltzgen/kernel/generator.py @@ -3,8 +3,8 @@ import sympy from mako.template import Template from pathlib import Path -def source(descriptor, moments, collide, boundary_src, float_type, geometry): - return Template(filename = str(Path(__file__).parent/'template/kernel.mako')).render( +def source(target, descriptor, moments, collide, boundary_src, float_type, geometry): + return Template(filename = str(Path(__file__).parent/('template/basic.' + target + '.mako'))).render( descriptor = descriptor, geometry = geometry, diff --git a/boltzgen/kernel/template/basic.cpp.mako b/boltzgen/kernel/template/basic.cpp.mako new file mode 100644 index 0000000..1879c35 --- /dev/null +++ b/boltzgen/kernel/template/basic.cpp.mako @@ -0,0 +1,66 @@ +<% +def pop_offset(i): + return i * geometry.volume +%> + +void equilibrilize(${float_type}* f_next, + ${float_type}* f_prev, + const std::size_t gid) +{ + ${float_type}* preshifted_f_next = f_next + gid; + ${float_type}* preshifted_f_prev = f_prev + gid; + +% for i, w_i in enumerate(descriptor.w): + preshifted_f_next[${pop_offset(i)}] = ${w_i.evalf()}; + preshifted_f_prev[${pop_offset(i)}] = ${w_i.evalf()}; +% endfor +} + +<% +def neighbor_offset(c_i): + return { + 2: lambda: c_i[1]*geometry.size_x + c_i[0], + 3: lambda: c_i[2]*geometry.size_x*geometry.size_y + c_i[1]*geometry.size_x + c_i[0] + }.get(descriptor.d)() + +def padding(): + return { + 2: lambda: 1*geometry.size_x + 1, + 3: lambda: 1*geometry.size_x*geometry.size_y + 1*geometry.size_x + 1 + }.get(descriptor.d)() +%> + +void collide_and_stream( ${float_type}* f_next, + const ${float_type}* f_prev, + const int* material, + const std::size_t gid) +{ + const int m = material[gid]; + + ${float_type}* preshifted_f_next = f_next + gid; + const ${float_type}* preshifted_f_prev = f_prev + gid; + +% for i, c_i in enumerate(descriptor.c): + const ${float_type} f_curr_${i} = preshifted_f_prev[${pop_offset(i) + neighbor_offset(-c_i)}]; +% endfor + +% for i, expr in enumerate(moments_subexpr): + const ${float_type} ${expr[0]} = ${ccode(expr[1])}; +% endfor + +% for i, expr in enumerate(moments_assignment): + ${float_type} ${ccode(expr)} +% endfor + +% for i, expr in enumerate(collide_subexpr): + const ${float_type} ${expr[0]} = ${ccode(expr[1])}; +% endfor + +% for i, expr in enumerate(collide_assignment): + const ${float_type} ${ccode(expr)} +% endfor + +% for i, expr in enumerate(collide_assignment): + preshifted_f_next[${pop_offset(i)}] = m*f_next_${i} + (1.0-m)*${descriptor.w[i].evalf()}; +% endfor +} diff --git a/boltzgen/kernel/template/kernel.mako b/boltzgen/kernel/template/basic.opencl.mako index 5ddf64c..5ddf64c 100644 --- a/boltzgen/kernel/template/kernel.mako +++ b/boltzgen/kernel/template/basic.opencl.mako @@ -4,6 +4,7 @@ lbm = LBM(D2Q9) geometry = Geometry(32,32) src = source( + 'opencl', D2Q9, lbm.moments(), lbm.bgk(f_eq = lbm.equilibrium(), tau = 0.6), |