From 286e243a171c8bcdfc91b5b6dcdd937ac95b0b7b Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 9 Nov 2019 16:19:40 +0100 Subject: Add optional OpenGL interop helper function for OpenCL target --- boltzgen/kernel/template/collect_moments.cl.mako | 25 ++++++++++++++++ boltzgen/kernel/template/pattern/AA.cl.mako | 38 ++++++++++++++++++++++++ boltzgen/kernel/template/pattern/AB.cl.mako | 20 +++++++++++++ 3 files changed, 83 insertions(+) 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 + +% 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); + +% 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 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()} +} + 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 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()} +} + -- cgit v1.2.3