Skip to content

Commit

Permalink
Add option for turning scalar fix on and off
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfhm committed Oct 30, 2023
1 parent 32f9cdf commit 94c89c6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
13 changes: 9 additions & 4 deletions cmake/loki_transform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ include( loki_transform_helpers )
# [CPP]
# [FRONTEND <frontend>]
# [INLINE_MEMBERS]
# [FIX_SCALAR_SYNTAX]
# [BUILDDIR <build-path>]
# [SOURCES <source1> [<source2> ...]]
# [HEADERS <header1> [<header2> ...]]
Expand All @@ -46,7 +47,7 @@ function( loki_transform )

set( options
CPP DATA_OFFLOAD REMOVE_OPENMP ASSUME_DEVICEPTR TRIM_VECTOR_SECTIONS GLOBAL_VAR_OFFLOAD
REMOVE_DERIVED_ARGS INLINE_MEMBERS DERIVE_ARGUMENT_ARRAY_SHAPE
REMOVE_DERIVED_ARGS INLINE_MEMBERS FIX_SCALAR_SYNTAX DERIVE_ARGUMENT_ARRAY_SHAPE
)
set( oneValueArgs
COMMAND MODE DIRECTIVE FRONTEND CONFIG BUILDDIR
Expand Down Expand Up @@ -193,7 +194,7 @@ endfunction()
# [DIRECTIVE <openacc|openmp|...>]
# [SOURCES <source1> [<source2> ...]]
# [HEADERS <header1> [<header2> ...]]
# [NO_PLAN_SOURCEDIR COPY_UNMODIFIED INLINE_MEMBERS]
# [NO_PLAN_SOURCEDIR COPY_UNMODIFIED INLINE_MEMBERS FIX_SCALAR_SYNTAX]
# )
#
# Applies a Loki bulk transformation to the source files belonging to a particular
Expand Down Expand Up @@ -222,7 +223,7 @@ endfunction()

function( loki_transform_target )

set( options NO_PLAN_SOURCEDIR COPY_UNMODIFIED CPP CPP_PLAN INLINE_MEMBERS )
set( options NO_PLAN_SOURCEDIR COPY_UNMODIFIED CPP CPP_PLAN INLINE_MEMBERS FIX_SCALAR_SYNTAX )
set( single_value_args TARGET COMMAND MODE DIRECTIVE FRONTEND CONFIG PLAN )
set( multi_value_args SOURCES HEADERS )

Expand Down Expand Up @@ -291,6 +292,10 @@ function( loki_transform_target )
list( APPEND _TRANSFORM_OPTIONS INLINE_MEMBERS )
endif()

if( _PAR_FIX_SCALAR_SYNTAX )
list( APPEND _TRANSFORM_OPTIONS FIX_SCALAR_SYNTAX )
endif()

loki_transform(
COMMAND ${_PAR_COMMAND}
OUTPUT ${LOKI_SOURCES_TO_APPEND}
Expand Down Expand Up @@ -384,7 +389,7 @@ or

set( options
CPP DATA_OFFLOAD REMOVE_OPENMP ASSUME_DEVICEPTR GLOBAL_VAR_OFFLOAD
TRIM_VECTOR_SECTIONS REMOVE_DERIVED_ARGS INLINE_MEMBERS
TRIM_VECTOR_SECTIONS REMOVE_DERIVED_ARGS INLINE_MEMBERS FIX_SCALAR_SYNTAX
)
set( oneValueArgs
MODE DIRECTIVE FRONTEND CONFIG PATH OUTPATH
Expand Down
4 changes: 4 additions & 0 deletions cmake/loki_transform_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ macro( _loki_transform_parse_options )
list( APPEND _ARGS --inline-members )
endif()

if( _PAR_FIX_SCALAR_SYNTAX )
list( APPEND _ARGS --fix-scalar-syntax )
endif()

if( _PAR_DERIVE_ARGUMENT_ARRAY_SHAPE )
list( APPEND _ARGS --derive-argument-array-shape )
endif()
Expand Down
8 changes: 6 additions & 2 deletions scripts/loki_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ def cli(debug):
help="Remove derived-type arguments and replace with canonical arguments")
@click.option('--inline-members/--no-inline-members', default=False,
help='Inline member functions for SCC-class transformations.')
@click.option('--fix-scalar-syntax/--no-fix-scalar-syntax', default=False,
help='Replace array arguments passed as scalars with arrays.')
@click.option('--derive-argument-array-shape/--no-derive-argument-array-shape', default=False,
help="Recursively derive explicit shape dimension for argument arrays")
def convert(
mode, config, build, source, header, cpp, directive, include, define, omni_include, xmod,
data_offload, remove_openmp, assume_deviceptr, frontend, trim_vector_sections,
global_var_offload, remove_derived_args, inline_members, derive_argument_array_shape
global_var_offload, remove_derived_args, inline_members, fix_scalar_syntax,
derive_argument_array_shape
):
"""
Batch-processing mode for Fortran-to-Fortran transformations that
Expand Down Expand Up @@ -207,7 +210,8 @@ def convert(
if mode in ['scc', 'scc-hoist', 'scc-stack']:
# Apply the basic SCC transformation set
scheduler.process( SCCBaseTransformation(
horizontal=horizontal, directive=directive, inline_members=inline_members
horizontal=horizontal, directive=directive,
inline_members=inline_members, fix_scalar_syntax=fix_scalar_syntax
))
scheduler.process( SCCDevectorTransformation(
horizontal=horizontal, trim_vector_sections=trim_vector_sections
Expand Down
7 changes: 5 additions & 2 deletions transformations/transformations/single_column_coalesced.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ class methods can be called directly.
Enable full source-inlining of member subroutines; default: False.
"""

def __init__(self, horizontal, directive=None, inline_members=False):
def __init__(self, horizontal, directive=None, inline_members=False, fix_scalar_syntax=False):
self.horizontal = horizontal

assert directive in [None, 'openacc']
self.directive = directive

self.fix_scalar_syntax = fix_scalar_syntax
self.inline_members = inline_members

@classmethod
Expand Down Expand Up @@ -291,7 +292,9 @@ def process_kernel(self, routine):
# Find the iteration index variable for the specified horizontal
v_index = self.get_integer_variable(routine, name=self.horizontal.index)

fix_scalar_syntax(routine)
# Transform arrays passed with scalar syntax to array syntax
if self.fix_scalar_syntax:
fix_scalar_syntax(routine)

# Perform full source-inlining for member subroutines if so requested
if self.inline_members:
Expand Down

0 comments on commit 94c89c6

Please sign in to comment.