-
Notifications
You must be signed in to change notification settings - Fork 13
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
introduce 'flatten_arrays()' (to overcome pointer hack) #199
Conversation
Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/199/index.html |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #199 +/- ##
==========================================
- Coverage 92.23% 92.23% -0.01%
==========================================
Files 95 95
Lines 16972 17009 +37
==========================================
+ Hits 15654 15688 +34
- Misses 1318 1321 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much, this is a great addition and clean solution to the original pointer hack. I think there's no need to retain the original pointer variant.
I have left a few remarks throughout, minor things mostly. The testing could benefit from a sanity check on the IR level directly, and I've proposed a potential solution for range-based shapes.
assert order in ['F', 'C'] | ||
if order == 'C': | ||
array_map = { | ||
var: var.clone(dimensions=new_dims(list(var.dimensions)[::-1], list(var.shape)[::-1])) | ||
for var in FindVariables().visit(routine.body) | ||
if isinstance(var, sym.Array) and var.shape and len(var.shape) | ||
} | ||
elif order == 'F': | ||
array_map = { | ||
var: var.clone(dimensions=new_dims(list(var.dimensions), list(var.shape))) | ||
for var in FindVariables().visit(routine.body) | ||
if isinstance(var, sym.Array) and var.shape and len(var.shape) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve our error reporting, I'd suggest not to use assert
here but instead throw an exception in an else branch:
assert order in ['F', 'C'] | |
if order == 'C': | |
array_map = { | |
var: var.clone(dimensions=new_dims(list(var.dimensions)[::-1], list(var.shape)[::-1])) | |
for var in FindVariables().visit(routine.body) | |
if isinstance(var, sym.Array) and var.shape and len(var.shape) | |
} | |
elif order == 'F': | |
array_map = { | |
var: var.clone(dimensions=new_dims(list(var.dimensions), list(var.shape))) | |
for var in FindVariables().visit(routine.body) | |
if isinstance(var, sym.Array) and var.shape and len(var.shape) | |
} | |
if order == 'C': | |
array_map = { | |
var: var.clone(dimensions=new_dims(list(var.dimensions)[::-1], list(var.shape)[::-1])) | |
for var in FindVariables().visit(routine.body) | |
if isinstance(var, sym.Array) and var.shape and len(var.shape) | |
} | |
elif order == 'F': | |
array_map = { | |
var: var.clone(dimensions=new_dims(list(var.dimensions), list(var.shape))) | |
for var in FindVariables().visit(routine.body) | |
if isinstance(var, sym.Array) and var.shape and len(var.shape) | |
} | |
else: | |
raise ValueError(f'Unsupported array order "{order}") |
array_map = { | ||
var: var.clone(dimensions=new_dims(list(var.dimensions)[::-1], list(var.shape)[::-1])) | ||
for var in FindVariables().visit(routine.body) | ||
if isinstance(var, sym.Array) and var.shape and len(var.shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ratehr unconventional to increase indentation here since you are not entering a new block/scope
} | ||
elif order == 'F': | ||
array_map = { | ||
var: var.clone(dimensions=new_dims(list(var.dimensions), list(var.shape))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid the conversion to list
here and the other uses. Instead, use a tuple for _dim and replace the call to extend
in new_dims
by new_dim += _dim
which allows you to work directly with the tuples.
0e33dab
to
5709ae8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thanks for this! I've left a few housekeeping remarks but otherwise this looks very promising.
Note that you may have to rebase over main again to avoid the regression tests from failing.
…rays' to allow for arrays start counting not with '1'
ff67104
to
f70cc6e
Compare
f70cc6e
to
b2fef9b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, everything looks fantastic now.
@mlange05 do you want to confirm this is fine in offline regression tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only had a brief look at code changes, but played with CLODUSC regression test. All seems good, so GTG from me.
|
This suggests to me that we see one of the recurring vectorization-related issues. Does this occur in the kernel itself or the validation routine? |
Yes ... must be kernel itself, as the rest (including validation) is still (the original) Fortran?! |
Usable and tested as drop in replacement for the CLOUDSC Loki C transpilation
Convert e.g.,
to:
However:
currently not handled are arrays like
This complicates things a lot and the question is how to handle this especially regarding the f2c transpilation... thus, whether this utility should handle that or whether another utility/transformation before flattening the arrays is more appropriate.