Skip to content
Merged
21 changes: 14 additions & 7 deletions examples/nemo/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
from psyclone.psyir.symbols import DataSymbol
from psyclone.psyir.transformations import (
ArrayAssignment2LoopsTrans, HoistLoopBoundExprTrans, HoistLocalArraysTrans,
HoistTrans, InlineTrans, Maxval2LoopTrans, ProfileTrans,
OMPMinimiseSyncTrans, Reference2ArrayRangeTrans,
ScalarisationTrans, IncreaseRankLoopArraysTrans, MaximalRegionTrans)
HoistTrans, InlineTrans, Maxval2LoopTrans, Sum2LoopTrans, Minval2LoopTrans,
Product2LoopTrans, ProfileTrans, OMPMinimiseSyncTrans,
Reference2ArrayRangeTrans, ScalarisationTrans, IncreaseRankLoopArraysTrans,
MaximalRegionTrans)
from psyclone.transformations import TransformationError

# USE statements to chase to gather additional symbol information.
Expand Down Expand Up @@ -219,11 +220,17 @@ def normalise_loops(

if loopify_array_intrinsics:
for intr in schedule.walk(IntrinsicCall):
if intr.intrinsic.name == "MAXVAL":
try:
try:
if intr.intrinsic.name == "MAXVAL":
Maxval2LoopTrans().apply(intr, verbose=True)
except TransformationError as err:
print(err.value)
elif intr.intrinsic.name == "SUM":
Sum2LoopTrans().apply(intr, verbose=True)
elif intr.intrinsic.name == "MINVAL":
Minval2LoopTrans().apply(intr, verbose=True)
elif intr.intrinsic.name == "PRODUCT":
Product2LoopTrans().apply(intr, verbose=True)
except TransformationError as err:
print(err.value)

if convert_range_loops:
# Convert all array implicit loops to explicit loops
Expand Down
21 changes: 10 additions & 11 deletions src/psyclone/psyir/nodes/intrinsic_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,26 +241,27 @@ def _type_of_named_arg_with_optional_kind_and_dim(

def _type_with_specified_precision_and_optional_dim(
node: IntrinsicCall, argument_name: str,
intrinsic: ScalarType.Intrinsic = ScalarType.Intrinsic.BOOLEAN
) -> DataType:
) -> DataType:
Comment thread
LonelyCat124 marked this conversation as resolved.
"""Helper function for the common IntrinsicCall case where the
return type is a Scalar with the precision of a named argument,
unless an optional argument named 'dim' exists, in which case an array
with rank one less than the input node is given instead.

:param node: The IntrinsicCall whose return type to compute.
:param argument_name: The name of the argument whose precision to be used.
:param intrinsic: The type of the intrinsic of the resulting datatype.
Default is ScalarType.Intrinsic.BOOLEAN

:returns: the computed datatype for the IntrinsicCall.
"""
dtype = ScalarType(
intrinsic, node.argument_by_name(argument_name).datatype.precision
)
# If dim is not present, or the rank of the
# array argument is 1 then this returns a scalar.
arg = node.argument_by_name(argument_name)
arg_dt = arg.datatype
if (
not isinstance(arg_dt, ArrayType) or
not isinstance(arg_dt.elemental_type, ScalarType) or
not isinstance(arg_dt.elemental_type.intrinsic, ScalarType.Intrinsic)
):
return UnresolvedType()
dtype = arg_dt.elemental_type
# If dim is not present, return the same datatype
if "dim" not in node.argument_names:
return dtype

Expand Down Expand Up @@ -3885,7 +3886,6 @@ class Intrinsic(IAttr, Enum):
lambda node:
_type_with_specified_precision_and_optional_dim(
node, "array",
node.argument_by_name("array").datatype.intrinsic
)
),
reference_accesses=lambda node: (
Expand Down Expand Up @@ -4542,7 +4542,6 @@ class Intrinsic(IAttr, Enum):
lambda node:
_type_with_specified_precision_and_optional_dim(
node, "array",
node.argument_by_name("array").datatype.intrinsic
)
),
reference_accesses=lambda node: (
Expand Down
4 changes: 3 additions & 1 deletion src/psyclone/psyir/tools/dependency_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,9 @@ def can_loop_be_parallelised(self, loop,
except AttributeError:
# If its a node without a symbol, look it up
var_name = signature.var_name
symbol = symbol_table.lookup(var_name)
symbol = symbol_table.lookup(var_name, otherwise=None)
if symbol is None:
return False

# TODO #1270 - the is_array_access function might be moved
Comment thread
LonelyCat124 marked this conversation as resolved.
Outdated
is_array = symbol.is_array_access(access_info=var_info)
Expand Down
11 changes: 9 additions & 2 deletions src/psyclone/tests/psyir/nodes/intrinsic_call_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,30 +1068,37 @@ def test_type_with_specified_precision_and_optional_dim(fortran_reader):
"""Test the _type_with_specified_precision_and_optional_dim
helper function."""
code = """subroutine test
use other
integer, dimension(100, 100) :: x
integer :: y
y = PRODUCT(x)
y = PRODUCT(x, dim=2)
y = PRODUCT(z, dim=2)
end subroutine test"""
psyir = fortran_reader.psyir_from_source(code)
intrinsics = psyir.walk(IntrinsicCall)

dtype = _type_with_specified_precision_and_optional_dim(
intrinsics[0], "array", ScalarType.Intrinsic.INTEGER,
intrinsics[0], "array"
)
assert isinstance(dtype, ScalarType)
assert dtype.intrinsic == ScalarType.Intrinsic.INTEGER
assert dtype.precision == ScalarType.Precision.UNDEFINED

dtype = _type_with_specified_precision_and_optional_dim(
intrinsics[1], "array", ScalarType.Intrinsic.INTEGER,
intrinsics[1], "array"
)
assert isinstance(dtype, ArrayType)
assert len(dtype.shape) == 1
assert dtype.shape[0] == ArrayType.Extent.DEFERRED
assert dtype.intrinsic == ScalarType.Intrinsic.INTEGER
assert dtype.precision == ScalarType.Precision.UNDEFINED

dtype = _type_with_specified_precision_and_optional_dim(
intrinsics[2], "array"
)
assert isinstance(dtype, UnresolvedType)


def test_type_of_intrinsic_with_precision_of_named_arg(fortran_reader):
"""Test the _type_of_intrinsic_with_precision_of_named_arg helper
Expand Down
Loading