(Closes #1957) Added an Intrinsic2CodeTrans metatransformation - #3577
(Closes #1957) Added an Intrinsic2CodeTrans metatransformation#3577LonelyCat124 wants to merge 4 commits into
Conversation
|
Should be ready now for a first look from @arporter or @sergisiso . I had a name conflict which I changed, so this transformation does have |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3577 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 399 400 +1
Lines 56173 56196 +23
=========================================
+ Hits 56173 56196 +23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
arporter
left a comment
There was a problem hiding this comment.
Thanks Aidan, I think this is a good simplification to the user interface. If @hiker and @sergisiso agree with my naming suggestion, it may be best to do that first as a separate PR as files and test files will need renaming/moving.
A few strange files have appeared in examples/nemo/scripts and probably shouldn't be there?
Finally, please update the UG section on transformations to include this functionality.
| @@ -0,0 +1,33 @@ | |||
| module stringop | |||
There was a problem hiding this comment.
Is this file supposed to be included? Similarly there a out with just whitespace changes?
There was a problem hiding this comment.
Oops, I think I did git add . as I would for the src dir and ended up with bonus files, I'll make sure to remove them.
| @@ -0,0 +1,33 @@ | |||
| MODULE stringop | |||
There was a problem hiding this comment.
I don't think we should have a .f90 file in the nemo/scripts directory?
| Minval2LoopTrans().apply(intr, verbose=True) | ||
| elif intr.intrinsic.name == "PRODUCT": | ||
| Product2LoopTrans().apply(intr, verbose=True) | ||
| Intrinsic2CodeMetaTrans().apply(intr, verbose=True) |
|
|
||
|
|
||
| @transformation_documentation_wrapper | ||
| class Intrinsic2CodeMetaTrans(Transformation): |
There was a problem hiding this comment.
Regarding naming, if @sergisiso and @hiker agree, I would suggest re-naming the existing Intrinsic2CodeTrans to Intrinsic2CodeBaseTrans (or SingleIntrinsic2CodeTrans or similar) and then having this one as Intrinsic2CodeTrans as it's the one we'd expect people to use.
There was a problem hiding this comment.
I agree with this suggestion, but another alternative is to use something like: AllArrayIntrinsics2Code or something that make more clear that this transformation is aiming to loopify intrinsics that apply to all items of the array.
|
|
||
| # Create a map of intrinsic names to the appropriate Intrinsic2Code | ||
| # transformation. | ||
| intrinsic_to_trans = {"MAXVAL": Maxval2LoopTrans, |
There was a problem hiding this comment.
Rather than use strings, can we use members of the IntrinsicCall.Intrinsic enum instead?
There was a problem hiding this comment.
Also, we have a few more: abs2code, matmul2code, ... is it a problem for NEMO is we add them all here?
There was a problem hiding this comment.
I'm not sure - I just mirrored the behaviour in the NEMO scripts, I think it would be better to do a separate performance analysis to check?
There was a problem hiding this comment.
I guess these intrinsics are all array -> scalar result intrinsics, I could do a base one (this one) and nanother ArrayToScalarIntrinsics2Code or similar that just does these 4? I think we can in theory only subclass by overriding intrinsic_to_trans, but there may be some funny doc/options that appear in the docstring or are accepted but would be ignored.
|
|
||
| # If the intrinsic is one of the supported intrinsics then | ||
| # apply the relevant transformation. | ||
| if node.intrinsic.name in Intrinsic2CodeMetaTrans.intrinsic_to_trans: |
There was a problem hiding this comment.
If we can use the members of the IntrinsicCall.Intrinsic enum as keys, we can remove the various .name here.
| # apply the relevant transformation. | ||
| if node.intrinsic.name in Intrinsic2CodeMetaTrans.intrinsic_to_trans: | ||
| Intrinsic2CodeMetaTrans.intrinsic_to_trans[node.intrinsic.name]().\ | ||
| apply(node, **kwargs_dict[node.intrinsic.name]) |
There was a problem hiding this comment.
We could add some logging here. I'm never sure what an appropriate level of detail would be but I'm thinking that, for debugging purposes, it might be good if a user could discover that a given intrinsic has not been transformed because this transformation doesn't support it?
| "OMPCriticalTrans", | ||
| "MaximalOMPParallelRegionTrans", | ||
| "OMPParallelTrans", | ||
| "Intrinsic2CodeMetaTrans", |
There was a problem hiding this comment.
I think that having this __all__ list in this __init__.py file results in the annoying situation where the AutoAPI docs will create an empty page for e.g. Intrinsic2CodeMetaTrans (and all the others here). If you could put an __all__ at the end of the appropriate source file instead the that seems to work better.
| "but received 'int'." in str(err.value)) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("code, expected", [ |
There was a problem hiding this comment.
I think all we need to test here is that the appropriate apply method is being called - the unit tests for each individual transformation obviously cover their functionality. You might be able to do that by monkeypatching the apply method on the class so that it raises an exception and then checking for that.
There was a problem hiding this comment.
(You'd need to monkeypatch the instance of the individual transfomration classes that are stored within the meta class.)
There was a problem hiding this comment.
@arporter I'm not sure I quite understand, does this not test that anyway? Or I guess the point is if we change the functionality/output from the other tests we break this test as an unintended side-effect and we shouldn't care about the actual result in the tests for the MetaTransformation as they're an implementation detail of the sub transformations?
| del first_dict[key] | ||
| # Sometimes we may have the same option in multiple | ||
| # subtransformations, so we only delete the key | ||
| # from the first_dict if its still present. |
Simple additional metatransformation to cleanup the nemo script.