From 7373aa5550551cf6b0b95891388b18c7a4450a71 Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Thu, 4 Apr 2019 15:04:38 +0200 Subject: [PATCH] pystencils_walberla: same interface for overlap & non-overlap sweeps --- .../templates/SweepInnerOuter.tmpl.cpp | 18 +++++++++++++ .../templates/SweepInnerOuter.tmpl.h | 25 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/pystencils_walberla/templates/SweepInnerOuter.tmpl.cpp b/pystencils_walberla/templates/SweepInnerOuter.tmpl.cpp index 0bb5110..3cf5069 100644 --- a/pystencils_walberla/templates/SweepInnerOuter.tmpl.cpp +++ b/pystencils_walberla/templates/SweepInnerOuter.tmpl.cpp @@ -53,6 +53,24 @@ void {{class_name}}::operator() ( IBlock * block{%if target is equalto 'gpu'%} , } +void {{class_name}}::runOnCellInterval( const shared_ptr<StructuredBlockStorage> & blocks, + const CellInterval & globalCellInterval, + cell_idx_t ghostLayers, + IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream{% endif %} ) +{ + CellInterval ci = globalCellInterval; + CellInterval blockBB = blocks->getBlockCellBB( *block); + blockBB.expand( ghostLayers ); + ci.intersect( blockBB ); + blocks->transformGlobalToBlockLocalCellInterval( ci, *block ); + if( ci.empty() ) + return; + + {{kernel|generate_block_data_to_field_extraction|indent(4)}} + {{kernel|generate_call(stream='stream', cell_interval='ci')|indent(4)}} + {{kernel|generate_swaps|indent(4)}} +} + void {{class_name}}::inner( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream{% endif %} ) { diff --git a/pystencils_walberla/templates/SweepInnerOuter.tmpl.h b/pystencils_walberla/templates/SweepInnerOuter.tmpl.h index 141df47..733083a 100644 --- a/pystencils_walberla/templates/SweepInnerOuter.tmpl.h +++ b/pystencils_walberla/templates/SweepInnerOuter.tmpl.h @@ -17,6 +17,7 @@ //! \\author pystencils //====================================================================================================================== +#pragma once #include "core/DataTypes.h" {% if target is equalto 'cpu' -%} @@ -28,7 +29,7 @@ #include "field/SwapableCompare.h" #include "domain_decomposition/BlockDataID.h" #include "domain_decomposition/IBlock.h" - +#include "domain_decomposition/StructuredBlockStorage.h" #include <set> #ifdef __GNUC__ @@ -60,6 +61,28 @@ public: 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 + {%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %}); + + + + static std::function<void (IBlock*)> getSweep(const shared_ptr<{{class_name}}> & kernel) { + return [kernel](IBlock * b) { (*kernel)(b); }; + } + + 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{%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %}) { + kernel->runOnCellInterval(blocks, globalCellInterval, ghostLayers, b{%if target is equalto 'gpu'%},stream {% endif %}); + }; + } + + void inner( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %} ); void outer( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %} ); -- GitLab