aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--boltzgen/kernel/template/collect_moments.cl.mako25
-rw-r--r--boltzgen/kernel/template/pattern/AA.cl.mako38
-rw-r--r--boltzgen/kernel/template/pattern/AB.cl.mako20
3 files changed, 83 insertions, 0 deletions
diff --git a/boltzgen/kernel/template/collect_moments.cl.mako b/boltzgen/kernel/template/collect_moments.cl.mako
index 67b2d68..63387b7 100644
--- a/boltzgen/kernel/template/collect_moments.cl.mako
+++ b/boltzgen/kernel/template/collect_moments.cl.mako
@@ -15,3 +15,28 @@ moments_subexpr, moments_assignment = model.moments()
preshifted_m[${i}] = ${sympy.ccode(expr.rhs)};
% endfor
</%call>
+
+% if 'opencl_gl_interop' in extras:
+<%call expr="pattern.functor_with_domain_dispatch('collect_moments_to_texture', [('__write_only %s' % {2: 'image2d_t', 3: 'image3d_t'}.get(descriptor.d), 'm')])">
+% for i, expr in enumerate(moments_subexpr):
+ const ${float_type} ${expr[0]} = ${sympy.ccode(expr[1])};
+% endfor
+
+ float4 data;
+% for i, expr in enumerate(moments_assignment):
+ data.${['x','y','z','w'][i]} = ${sympy.ccode(expr.rhs)};
+% endfor
+% if descriptor.d == 2:
+ data.w = sqrt(data.y*data.y + data.z*data.z);
+% endif
+
+<%
+def moments_cell():
+ return {
+ 2: '(int2)(get_global_id(0), get_global_id(1))',
+ 3: '(int4)(get_global_id(0), get_global_id(1), get_global_id(2), 0)'
+ }.get(descriptor.d)
+%>
+ write_imagef(m, ${moments_cell()}, data);
+</%call>
+% endif
diff --git a/boltzgen/kernel/template/pattern/AA.cl.mako b/boltzgen/kernel/template/pattern/AA.cl.mako
index f8a73cc..2a88755 100644
--- a/boltzgen/kernel/template/pattern/AA.cl.mako
+++ b/boltzgen/kernel/template/pattern/AA.cl.mako
@@ -165,3 +165,41 @@ __kernel void ${name}_cells_tock(
}
% endif
</%def>
+
+<%def name="functor_with_domain_dispatch(name, params = None)">
+__kernel void ${name}_tick(
+ __global ${float_type}* f
+% if params is not None:
+% for param_type, param_name in params:
+ , ${param_type} ${param_name}
+% endfor
+% endif
+) {
+ const unsigned int gid = ${index.gid('get_global_id(0)', 'get_global_id(1)', 'get_global_id(2)')};
+ __global ${float_type}* preshifted_f = f + ${layout.cell_preshift('gid')};
+
+% for i, c_i in enumerate(descriptor.c):
+ const ${float_type} f_curr_${i} = preshifted_f[${layout.pop_offset(descriptor.c.index(-c_i))}];
+% endfor
+
+ ${caller.body()}
+}
+
+__kernel void ${name}_tock(
+ __global ${float_type}* f
+% if params is not None:
+% for param_type, param_name in params:
+ , ${param_type} ${param_name}
+% endfor
+% endif
+) {
+ const unsigned int gid = ${index.gid('get_global_id(0)', 'get_global_id(1)', 'get_global_id(2)')};
+ __global ${float_type}* preshifted_f = f + ${layout.cell_preshift('gid')};
+
+% for i, c_i in enumerate(descriptor.c):
+ const ${float_type} f_curr_${i} = preshifted_f[${layout.pop_offset(i) + layout.neighbor_offset(c_i)}];
+% endfor
+
+ ${caller.body()}
+}
+</%def>
diff --git a/boltzgen/kernel/template/pattern/AB.cl.mako b/boltzgen/kernel/template/pattern/AB.cl.mako
index 33836ea..8e6421e 100644
--- a/boltzgen/kernel/template/pattern/AB.cl.mako
+++ b/boltzgen/kernel/template/pattern/AB.cl.mako
@@ -89,3 +89,23 @@ __kernel void ${name}_cells(
}
% endif
</%def>
+
+<%def name="functor_with_domain_dispatch(name, params = None)">
+__kernel void ${name}(
+ __global ${float_type}* f
+% if params is not None:
+% for param_type, param_name in params:
+ , ${param_type} ${param_name}
+% endfor
+% endif
+) {
+ const unsigned int gid = ${index.gid('get_global_id(0)', 'get_global_id(1)', 'get_global_id(2)')};
+ __global ${float_type}* preshifted_f = f + ${layout.cell_preshift('gid')};
+
+% for i in range(0,descriptor.q):
+ const ${float_type} f_curr_${i} = preshifted_f[${layout.pop_offset(i)}];
+% endfor
+
+ ${caller.body()}
+}
+</%def>