From 3c6dd047f164ea4cb513c9a973e429ee70379cc7 Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Fri, 22 Feb 2019 16:20:13 +0100 Subject: [PATCH] pystencils_walberla: stream passed at call instead of constructor --- templates/Sweep.tmpl.cpp | 9 ++++----- templates/Sweep.tmpl.h | 26 ++++++++++++-------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/templates/Sweep.tmpl.cpp b/templates/Sweep.tmpl.cpp index 4eb4a35..75e7d41 100644 --- a/templates/Sweep.tmpl.cpp +++ b/templates/Sweep.tmpl.cpp @@ -50,11 +50,10 @@ namespace {{namespace}} { {{kernel|generate_definition(target)}} - -void {{class_name}}::operator()( IBlock * block ) +void {{class_name}}::operator()( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream{% endif %} ) { {{kernel|generate_block_data_to_field_extraction|indent(4)}} - {{kernel|generate_call(stream='stream_')|indent(4)}} + {{kernel|generate_call(stream='stream')|indent(4)}} {{kernel|generate_swaps|indent(4)}} } @@ -62,7 +61,7 @@ void {{class_name}}::operator()( IBlock * block ) void {{class_name}}::runOnCellInterval( const shared_ptr<StructuredBlockStorage> & blocks, const CellInterval & globalCellInterval, cell_idx_t ghostLayers, - IBlock * block ) + IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream{% endif %} ) { CellInterval ci = globalCellInterval; CellInterval blockBB = blocks->getBlockCellBB( *block); @@ -73,7 +72,7 @@ void {{class_name}}::runOnCellInterval( const shared_ptr<StructuredBlockStorage> return; {{kernel|generate_block_data_to_field_extraction|indent(4)}} - {{kernel|generate_call(stream='stream_', cell_interval='ci')|indent(4)}} + {{kernel|generate_call(stream='stream', cell_interval='ci')|indent(4)}} {{kernel|generate_swaps|indent(4)}} } diff --git a/templates/Sweep.tmpl.h b/templates/Sweep.tmpl.h index e6d24cf..9de4b96 100644 --- a/templates/Sweep.tmpl.h +++ b/templates/Sweep.tmpl.h @@ -51,15 +51,16 @@ namespace {{namespace}} { class {{class_name}} { public: - {{class_name}}( {{kernel|generate_constructor_parameters}}{%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %}) - : {{ kernel|generate_constructor_initializer_list }}{%if target is equalto 'gpu'%}, stream_(stream) {%endif %} + {{class_name}}( {{kernel|generate_constructor_parameters}}) + : {{ kernel|generate_constructor_initializer_list }} {}; {{ kernel| generate_destructor(class_name) |indent(4) }} - void operator()(IBlock * b); + void operator() ( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %} ); void runOnCellInterval(const shared_ptr<StructuredBlockStorage> & blocks, - const CellInterval & globalCellInterval, cell_idx_t ghostLayers, IBlock * block); + const CellInterval & globalCellInterval, cell_idx_t ghostLayers, IBlock * block + {%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %}); @@ -67,22 +68,19 @@ public: return [kernel](IBlock * b) { (*kernel)(b); }; } - static std::function<void (IBlock*)> getSweepOnCellInterval(const shared_ptr<{{class_name}}> & kernel, - const shared_ptr<StructuredBlockStorage> & blocks, - const CellInterval & globalCellInterval, - cell_idx_t ghostLayers=1 ) + static std::function<void (IBlock*{%if target is equalto 'gpu'%} , cudaStream_t {% endif %})> + getSweepOnCellInterval(const shared_ptr<{{class_name}}> & kernel, + const shared_ptr<StructuredBlockStorage> & blocks, + const CellInterval & globalCellInterval, + cell_idx_t ghostLayers=1 ) { - return [kernel, blocks, globalCellInterval, ghostLayers] (IBlock * b) { - kernel->runOnCellInterval(blocks, globalCellInterval, ghostLayers, b); + return [kernel, blocks, globalCellInterval, ghostLayers] (IBlock * b{%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %}) { + kernel->runOnCellInterval(blocks, globalCellInterval, ghostLayers, b{%if target is equalto 'gpu'%},stream {% endif %}); }; } {{ kernel|generate_members|indent(4) }} -private: - {%if target is equalto 'gpu'%} - cudaStream_t stream_; - {% endif %} }; -- GitLab