From fb607be28e4d67d94595a893ead6ae5003bc93e5 Mon Sep 17 00:00:00 2001 From: Dominik Thoennes <dominik.thoennes@fau.de> Date: Thu, 19 Mar 2020 15:31:00 +0100 Subject: [PATCH] add open merge requests from pystencils_walberla --- python/pystencils_walberla/jinja_filters.py | 31 +++++++++++-------- .../templates/Sweep.tmpl.h | 8 ++--- .../templates/SweepInnerOuter.tmpl.h | 14 ++++----- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/python/pystencils_walberla/jinja_filters.py b/python/pystencils_walberla/jinja_filters.py index eb209237b..003315448 100644 --- a/python/pystencils_walberla/jinja_filters.py +++ b/python/pystencils_walberla/jinja_filters.py @@ -14,16 +14,18 @@ temporary_fieldMemberTemplate = """ private: std::set< {type} *, field::SwapableCompare< {type} * > > cache_{original_field_name}_;""" temporary_fieldTemplate = """ -// Getting temporary field {tmp_field_name} -auto it = cache_{original_field_name}_.find( {original_field_name} ); -if( it != cache_{original_field_name}_.end() ) {{ - {tmp_field_name} = *it; -}} -else -{{ - {tmp_field_name} = {original_field_name}->cloneUninitialized(); - cache_{original_field_name}_.insert({tmp_field_name}); + // Getting temporary field {tmp_field_name} + auto it = cache_{original_field_name}_.find( {original_field_name} ); + if( it != cache_{original_field_name}_.end() ) + {{ + {tmp_field_name} = *it; + }} + else + {{ + {tmp_field_name} = {original_field_name}->cloneUninitialized(); + cache_{original_field_name}_.insert({tmp_field_name}); + }} }} """ @@ -42,7 +44,7 @@ def make_field_type(dtype, f_size, is_gpu): if is_gpu: return "cuda::GPUField<%s>" % (dtype,) else: - return "GhostLayerField<%s, %d>" % (dtype, f_size) + return "field::GhostLayerField<%s, %d>" % (dtype, f_size) def get_field_fsize(field): @@ -120,9 +122,9 @@ def field_extraction_code(field, is_temporary, declaration_only=False, else: prefix = "" if no_declaration else "auto " if update_member: - return "%s%s_ = block->uncheckedFastGetData< %s >(%sID);" % (prefix, field_name, field_type, field_name) + return "%s%s_ = block->getData< %s >(%sID);" % (prefix, field_name, field_type, field_name) else: - return "%s%s = block->uncheckedFastGetData< %s >(%sID);" % (prefix, field_name, field_type, field_name) + return "%s%s = block->getData< %s >(%sID);" % (prefix, field_name, field_type, field_name) else: assert field_name.endswith('_tmp') original_field_name = field_name[:-len('_tmp')] @@ -273,6 +275,9 @@ def generate_call(ctx, kernel_info, ghost_layers_to_include=0, cell_interval=Non else: spatial_shape_symbols = [TypedSymbol(s, SHAPE_DTYPE) for s in spatial_shape_symbols] + assert spatial_shape_symbols, "No shape parameters in kernel function arguments.\n"\ + "Please be only use kernels for generic field sizes!" + indexing_dict = ast.indexing.call_parameters(spatial_shape_symbols) sp_printer_c = CudaSympyPrinter() kernel_call_lines += [ @@ -312,7 +317,7 @@ def generate_constructor_initializer_list(kernel_info, parameters_to_ignore=None def generate_constructor_parameters(kernel_info, parameters_to_ignore=None): if parameters_to_ignore is None: parameters_to_ignore = [] - + varying_parameters = [] if hasattr(kernel_info, 'varying_parameters'): varying_parameters = kernel_info.varying_parameters diff --git a/python/pystencils_walberla/templates/Sweep.tmpl.h b/python/pystencils_walberla/templates/Sweep.tmpl.h index 9de4b96c2..b4db0f35b 100644 --- a/python/pystencils_walberla/templates/Sweep.tmpl.h +++ b/python/pystencils_walberla/templates/Sweep.tmpl.h @@ -57,10 +57,10 @@ public: {{ kernel| generate_destructor(class_name) |indent(4) }} - void operator() ( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %} ); + void operator() ( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream = nullptr{% 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 %}); + {%if target is equalto 'gpu'%} , cudaStream_t stream = nullptr{% endif %}); @@ -74,8 +74,8 @@ public: 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 %}); + return [kernel, blocks, globalCellInterval, ghostLayers] (IBlock * b{%if target is equalto 'gpu'%} , cudaStream_t stream = nullptr{% endif %}) { + kernel->runOnCellInterval(blocks, globalCellInterval, ghostLayers, b{%if target is equalto 'gpu'%}, stream {% endif %}); }; } diff --git a/python/pystencils_walberla/templates/SweepInnerOuter.tmpl.h b/python/pystencils_walberla/templates/SweepInnerOuter.tmpl.h index 466f51071..6f6094d0e 100644 --- a/python/pystencils_walberla/templates/SweepInnerOuter.tmpl.h +++ b/python/pystencils_walberla/templates/SweepInnerOuter.tmpl.h @@ -54,17 +54,17 @@ class {{class_name}} { public: {{class_name}}( {{kernel|generate_constructor_parameters}}, const Cell & outerWidth=Cell(1, 1, 1)) - : {{ kernel|generate_constructor_initializer_list }}, outerWidth_(outerWidth) + : {{ kernel|generate_constructor_initializer_list }}{% if kernel|generate_constructor_initializer_list|length %},{% endif %} outerWidth_(outerWidth) {}; {{ kernel| generate_destructor(class_name) |indent(4) }} - void operator() ( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream = 0{% endif %} ); + void operator() ( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream = nullptr{% 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 %}); + {%if target is equalto 'gpu'%} , cudaStream_t stream = nullptr{% endif %}); @@ -78,14 +78,14 @@ public: 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 %}); + return [kernel, blocks, globalCellInterval, ghostLayers] (IBlock * b{%if target is equalto 'gpu'%} , cudaStream_t stream = nullptr{% 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 %} ); + void inner( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream = nullptr{% endif %} ); + void outer( IBlock * block{%if target is equalto 'gpu'%} , cudaStream_t stream = nullptr{% endif %} ); void setOuterPriority(int priority ) { {%if target is equalto 'gpu'%} -- GitLab