From aa509dd4ebbb9d1d8ad6ebfe05111228fd9ae7c0 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 12 Nov 2019 22:54:11 +0100 Subject: Match OpenCL and CUDA cell list dispatch templates --- boltzgen/kernel/template/pattern/AA.cl.mako | 118 +++++++++++++--------------- boltzgen/kernel/template/pattern/AB.cl.mako | 64 +++++++-------- 2 files changed, 83 insertions(+), 99 deletions(-) (limited to 'boltzgen/kernel/template/pattern') diff --git a/boltzgen/kernel/template/pattern/AA.cl.mako b/boltzgen/kernel/template/pattern/AA.cl.mako index 2a88755..74ad2fa 100644 --- a/boltzgen/kernel/template/pattern/AA.cl.mako +++ b/boltzgen/kernel/template/pattern/AA.cl.mako @@ -1,13 +1,20 @@ <%def name="operator(name, params = None)"> __kernel void ${name}_tick( __global ${float_type}* f +% if 'cell_list_dispatch' in extras: + , __global unsigned int* cells +% else: , unsigned int gid +% endif % if params is not None: % for param_type, param_name in params: , ${param_type} ${param_name} % endfor % endif ) { +% if 'cell_list_dispatch' in extras: + const unsigned int gid = cells[get_global_id(0)]; +% endif __global ${float_type}* preshifted_f = f + ${layout.cell_preshift('gid')}; % for i, c_i in enumerate(descriptor.c): @@ -23,13 +30,20 @@ __kernel void ${name}_tick( __kernel void ${name}_tock( __global ${float_type}* f +% if 'cell_list_dispatch' in extras: + , __global unsigned int* cells +% else: , unsigned int gid +% endif % if params is not None: % for param_type, param_name in params: , ${param_type} ${param_name} % endfor % endif ) { +% if 'cell_list_dispatch' in extras: + const unsigned int gid = cells[get_global_id(0)]; +% endif __global ${float_type}* preshifted_f = f + ${layout.cell_preshift('gid')}; % for i, c_i in enumerate(descriptor.c): @@ -42,60 +56,71 @@ __kernel void ${name}_tock( preshifted_f[${layout.pop_offset(i) + layout.neighbor_offset(c_i)}] = f_next_${i}; % endfor } + -% if 'cell_list_dispatch' in extras: -__kernel void ${name}_cells_tick( +<%def name="operator_with_domain_dispatch(name, params = None)"> +__kernel void ${name}_tick( __global ${float_type}* f - , __global unsigned int* cells % if params is not None: % for param_type, param_name in params: , ${param_type} ${param_name} % endfor % endif ) { - ${name}_tick( - f - , cells[get_global_id(0)] -% if params is not None: -% for param_type, param_name in params: - , ${param_name} + 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)}]; +% endfor + + ${caller.body()} + +% for i, c_i in enumerate(descriptor.c): + preshifted_f[${layout.pop_offset(i)}] = f_next_${descriptor.c.index(-c_i)}; % endfor -% endif - ); } -__kernel void ${name}_cells_tock( +__kernel void ${name}_tock( __global ${float_type}* f - , __global unsigned int* cells % if params is not None: % for param_type, param_name in params: , ${param_type} ${param_name} % endfor % endif ) { - ${name}_tock( - f - , cells[get_global_id(0)] -% if params is not None: -% for param_type, param_name in params: - , ${param_name} + 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_${descriptor.c.index(-c_i)} = preshifted_f[${layout.pop_offset(i) + layout.neighbor_offset(c_i)}]; +% endfor + + ${caller.body()} + +% for i, c_i in enumerate(descriptor.c): + preshifted_f[${layout.pop_offset(i) + layout.neighbor_offset(c_i)}] = f_next_${i}; % endfor -% endif - ); } -% endif <%def name="functor(name, params = None)"> __kernel void ${name}_tick( __global ${float_type}* f +% if 'cell_list_dispatch' in extras: + , __global unsigned int* cells +% else: , unsigned int gid +% endif % if params is not None: % for param_type, param_name in params: , ${param_type} ${param_name} % endfor % endif ) { +% if 'cell_list_dispatch' in extras: + const unsigned int gid = cells[get_global_id(0)]; +% endif __global ${float_type}* preshifted_f = f + ${layout.cell_preshift('gid')}; % for i, c_i in enumerate(descriptor.c): @@ -107,13 +132,20 @@ __kernel void ${name}_tick( __kernel void ${name}_tock( __global ${float_type}* f +% if 'cell_list_dispatch' in extras: + , __global unsigned int* cells +% else: , unsigned int gid +% endif % if params is not None: % for param_type, param_name in params: , ${param_type} ${param_name} % endfor % endif ) { +% if 'cell_list_dispatch' in extras: + const unsigned int gid = cells[get_global_id(0)]; +% endif __global ${float_type}* preshifted_f = f + ${layout.cell_preshift('gid')}; % for i, c_i in enumerate(descriptor.c): @@ -122,48 +154,6 @@ __kernel void ${name}_tock( ${caller.body()} } - -% if 'cell_list_dispatch' in extras: -__kernel void ${name}_cells_tick( - __global ${float_type}* f - , __global unsigned int* cells -% if params is not None: -% for param_type, param_name in params: - , ${param_type} ${param_name} -% endfor -% endif -) { - ${name}_tick( - f - , cells[get_global_id(0)] -% if params is not None: -% for param_type, param_name in params: - , ${param_name} -% endfor -% endif - ); -} - -__kernel void ${name}_cells_tock( - __global ${float_type}* f - , __global unsigned int* cells -% if params is not None: -% for param_type, param_name in params: - , ${param_type} ${param_name} -% endfor -% endif -) { - ${name}_tock( - f - , cells[get_global_id(0)] -% if params is not None: -% for param_type, param_name in params: - , ${param_name} -% endfor -% endif - ); -} -% endif <%def name="functor_with_domain_dispatch(name, params = None)"> diff --git a/boltzgen/kernel/template/pattern/AB.cl.mako b/boltzgen/kernel/template/pattern/AB.cl.mako index 8e6421e..8fa941b 100644 --- a/boltzgen/kernel/template/pattern/AB.cl.mako +++ b/boltzgen/kernel/template/pattern/AB.cl.mako @@ -2,13 +2,20 @@ __kernel void ${name}( __global ${float_type}* f_next , __global ${float_type}* f_prev +% if 'cell_list_dispatch' in extras: + , __global unsigned int* cells +% else: , unsigned int gid +% endif % if params is not None: % for param_type, param_name in params: , ${param_type} ${param_name} % endfor % endif ) { +% if 'cell_list_dispatch' in extras: + const unsigned int gid = cells[get_global_id(0)]; +% endif __global ${float_type}* preshifted_f_next = f_next + ${layout.cell_preshift('gid')}; __global ${float_type}* preshifted_f_prev = f_prev + ${layout.cell_preshift('gid')}; @@ -22,42 +29,51 @@ __kernel void ${name}( preshifted_f_next[${layout.pop_offset(i)}] = f_next_${i}; % endfor } + -% if 'cell_list_dispatch' in extras: -__kernel void ${name}_cells( +<%def name="operator_with_domain_dispatch(name, params = None)"> +__kernel void ${name}( __global ${float_type}* f_next , __global ${float_type}* f_prev - , __global unsigned int* cells % if params is not None: % for param_type, param_name in params: , ${param_type} ${param_name} % endfor % endif ) { - ${name}( - f_next - , f_prev - , cells[get_global_id(0)] -% if params is not None: -% for param_type, param_name in params: - , ${param_name} + const unsigned int gid = ${index.gid('get_global_id(0)', 'get_global_id(1)', 'get_global_id(2)')}; + __global ${float_type}* preshifted_f_next = f_next + ${layout.cell_preshift('gid')}; + __global ${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 + + ${caller.body()} + +% for i, _ in enumerate(descriptor.c): + preshifted_f_next[${layout.pop_offset(i)}] = f_next_${i}; % endfor -% endif - ); } -% endif <%def name="functor(name, params = None)"> __kernel void ${name}( __global ${float_type}* f +% if 'cell_list_dispatch' in extras: + , __global unsigned int* cells +% else: , unsigned int gid +% endif % if params is not None: % for param_type, param_name in params: , ${param_type} ${param_name} % endfor % endif ) { +% if 'cell_list_dispatch' in extras: + const unsigned int gid = cells[get_global_id(0)]; +% endif __global ${float_type}* preshifted_f = f + ${layout.cell_preshift('gid')}; % for i in range(0,descriptor.q): @@ -66,28 +82,6 @@ __kernel void ${name}( ${caller.body()} } - -% if 'cell_list_dispatch' in extras: -__kernel void ${name}_cells( - __global ${float_type}* f - , __global unsigned int* cells -% if params is not None: -% for param_type, param_name in params: - , ${param_type} ${param_name} -% endfor -% endif -) { - ${name}( - f - , cells[get_global_id(0)] -% if params is not None: -% for param_type, param_name in params: - , ${param_name} -% endfor -% endif - ); -} -% endif <%def name="functor_with_domain_dispatch(name, params = None)"> -- cgit v1.2.3