aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-10-21 22:23:41 +0200
committerAdrian Kummerlaender2019-10-21 22:24:51 +0200
commit8f88aea2c963ebe63db83480fc9a4b48451220af (patch)
tree0213cb1a46fc38e3fcf6dc2d3d6337beb06e3818
parent82a44e0d64afb8818ea98d68dc08108885d503c2 (diff)
downloadboltzgen-8f88aea2c963ebe63db83480fc9a4b48451220af.tar
boltzgen-8f88aea2c963ebe63db83480fc9a4b48451220af.tar.gz
boltzgen-8f88aea2c963ebe63db83480fc9a4b48451220af.tar.bz2
boltzgen-8f88aea2c963ebe63db83480fc9a4b48451220af.tar.lz
boltzgen-8f88aea2c963ebe63db83480fc9a4b48451220af.tar.xz
boltzgen-8f88aea2c963ebe63db83480fc9a4b48451220af.tar.zst
boltzgen-8f88aea2c963ebe63db83480fc9a4b48451220af.zip
Pull in C++ template from symlbm_playground's standalone branch
-rw-r--r--boltzgen/kernel/generator.py4
-rw-r--r--boltzgen/kernel/template/basic.cpp.mako66
-rw-r--r--boltzgen/kernel/template/basic.opencl.mako (renamed from boltzgen/kernel/template/kernel.mako)0
-rw-r--r--test.py1
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
diff --git a/test.py b/test.py
index b5831aa..0eec050 100644
--- a/test.py
+++ b/test.py
@@ -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),