-
Notifications
You must be signed in to change notification settings - Fork 34
Generalise hoist_arguments_to_temporaries in NEMO utils to all arguments with array operations #3429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generalise hoist_arguments_to_temporaries in NEMO utils to all arguments with array operations #3429
Changes from all commits
97d4099
77b0823
9ada128
52e8df9
228d408
3de798f
8061ceb
d70c54b
483f51d
7fa1410
1a894b5
5cfcdeb
52e585b
bb5b2aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ | |
| Assignment, Loop, Directive, Node, Reference, CodeBlock, Call, | ||
| Routine, Schedule, IntrinsicCall, StructureReference, IfBlock, | ||
| Operation) | ||
| from psyclone.psyir.symbols import DataSymbol, ArrayType | ||
| from psyclone.psyir.symbols import DataSymbol, ArrayType, ScalarType | ||
| from psyclone.psyir.transformations import ( | ||
| ArrayAssignment2LoopsTrans, HoistLoopBoundExprTrans, HoistLocalArraysTrans, | ||
| HoistTrans, InlineTrans, Maxval2LoopTrans, Sum2LoopTrans, Minval2LoopTrans, | ||
|
|
@@ -205,10 +205,6 @@ def normalise_loops( | |
| :param hoist_argument_expressions: whether to hoist array expressions | ||
| out of the containing Call. | ||
| ''' | ||
| # TODO #3412: This is currently limited to iom_put, we want to expand it | ||
| # throughout the code | ||
| if hoist_argument_expressions: | ||
| iom_put_argument_to_temporary(schedule.walk(Call)) | ||
|
|
||
| if hoist_local_arrays and schedule.name not in CONTAINS_STMT_FUNCTIONS: | ||
| # Apply the HoistLocalArraysTrans when possible, it cannot be applied | ||
|
|
@@ -280,6 +276,20 @@ def normalise_loops( | |
| except TransformationError: | ||
| pass | ||
|
|
||
| if hoist_argument_expressions: | ||
| hoist_arguments_to_temporaries(schedule.walk(Call)) | ||
| normalise_loops( | ||
| schedule, | ||
| hoist_local_arrays=hoist_local_arrays, | ||
| convert_array_notation=convert_array_notation, | ||
| loopify_array_intrinsics=loopify_array_intrinsics, | ||
| convert_range_loops=convert_range_loops, | ||
| scalarise_loops=scalarise_loops, | ||
| increase_array_ranks=False, | ||
| hoist_expressions=hoist_expressions, | ||
| # Make sure we never repeat this step. | ||
| hoist_argument_expressions=False, | ||
| ) | ||
| # TODO #1928: In order to perform better on the GPU, nested loops with two | ||
| # sibling inner loops need to be fused or apply loop fission to the | ||
| # top level. This would allow the collapse clause to be applied. | ||
|
|
@@ -541,23 +551,30 @@ def _satisfies_minimum_region_rules(self, region: list[Node]) -> bool: | |
| MaximalProfilingOutsideDirectivesTrans().apply(children) | ||
|
|
||
|
|
||
| def iom_put_argument_to_temporary(calls: list[Call]): | ||
| '''Extracts the second argument of all iom_put calls and puts them | ||
| in a temporary if they are an Operation with an array datatype. | ||
| def hoist_arguments_to_temporaries(calls: list[Call]): | ||
| '''Extracts the arguments of all calls and puts them | ||
| in a temporary result if they are an Operation with an array datatype. | ||
|
|
||
| :param calls: The list of calls in a subroutine whose arguments | ||
| may be moved into temporary storage to allow additional potential | ||
| parallelisation. | ||
|
|
||
| ''' | ||
| for call in calls: | ||
| if call.symbol.name == "iom_put": | ||
| for arg in call.arguments: | ||
| dtype = arg.datatype | ||
| if (isinstance(dtype, ArrayType) and | ||
| (isinstance(arg, Operation) or | ||
| isinstance(arg, IntrinsicCall))): | ||
| try: | ||
| DataNodeToTempTrans().apply(arg, verbose=True) | ||
| except TransformationError: | ||
| pass | ||
| for arg in call.arguments: | ||
| dtype = arg.datatype | ||
| # Only extract expressions that can potentially be loopfied, | ||
| # i.e. operations over arrays. | ||
| if (isinstance(dtype, ArrayType) and | ||
| (isinstance(arg, Operation) or | ||
| isinstance(arg, IntrinsicCall))): | ||
| try: | ||
| # TODO #3443: Does the fixes in that PR fix this, or | ||
| # maybe the DataNodeToTempTrans has to skip characters | ||
| if (isinstance(dtype.elemental_type, ScalarType) | ||
| and dtype.elemental_type.intrinsic == | ||
| ScalarType.Intrinsic.CHARACTER): | ||
| continue | ||
|
Comment on lines
+574
to
+577
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an issue with the transformation? I am wondering if it should be inside the validation instead?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure - the transformation does it successfully but there was some error, I don't remember whether compiler or elsewhere in PSyclone. I can have a further look if you want, I just decided to skip it here for strings (not sure if there would be some other valid use case?)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found out in #3343 that node.datatype of a array_reference with a character string is special because those are not array with shapes but ScalarType with length. And therefore its datatype result is wrong. Could this be the same problem? (If this PR is ready before #3443 I can explore it, e.g. remove the condition, there) |
||
| DataNodeToTempTrans().apply(arg, verbose=True) | ||
| except TransformationError: | ||
| pass | ||
Uh oh!
There was an error while loading. Please reload this page.