-
Notifications
You must be signed in to change notification settings - Fork 32
(Towards #3060) intrinsic return types #3119
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
base: master
Are you sure you want to change the base?
Conversation
|
One other coding style question - are we happy with statements like: Or would you prefer to pull out the if statement? (This was required when this was a lambda, but its turning into a function as its getting a lot of reuse so I'm happy to rewrite it if it is preferred). |
|
Also one thing to note is PSyclone appears to support more Also a question for @sergisiso - can you always refer to arguments with their names? I see for example |
|
I would also say - there are some cases of reusing precision througout this code. I'm not sure if this is a good idea with the new "precision can be DataNodes" - if not then the review might need to request me to fix that by copying if they're a |
5911f97 to
9f0799f
Compare
|
I applied the black formatter to these files as well - I couldn't work out how to make formatting happy myself for a couple of the lambdas so I had to make black do it for me. |
I think I'd prefer a separate if for this - it's quite hard to parse :-) |
I'm a bit confused by the check on whether it is |
|
Thanks Aidan, I think it's looking mostly as I'd expect although, as commented above, I was anticipating always having a Callable - whether a lambda or a separate routine if it's complicated enough. EDIT: scrub that - I was getting confused between the definition of an IntrinsicCall and an Intrinsic. I think what you're suggesting is fine actually. |
I could always have a lambda - it just felt overkill for cases where the return type is just an |
|
I will say I semi-lost the will to carry on for specifically I'll clean up the remaining test suite issues before I have "finished" return_type and probably it would be good to have a closer look before I move on to implementing reference_accesses. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3119 +/- ##
==========================================
- Coverage 99.95% 99.95% -0.01%
==========================================
Files 376 377 +1
Lines 53485 53642 +157
==========================================
+ Hits 53463 53619 +156
- Misses 22 23 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I fixed the remaining failing test and added the keywords for |
|
Fixed up the remaining coverage I can do with |
|
@arporter @sergisiso ready for a look now - Andy suggested doing reference accesses as its own PR separately. There is coverage missing, but PSyclone/fparser doesn't support the inputs that could result in those - I want to leave the correct results in the code for when we do, but I'll leave it to the reviewer to decide. Edit: Note that this PR incorporates the kind stuff from #3110 - so ignore anything that looks like it comes from changes to kinds. Edit2: The other thing I'm unsure about for both this PR and the following PR is if we have optional arguments declared on an IntrinsicCall do they HAVE to be named in Fortran? I.e. is only |
|
Also one note - I think TEAM_IMAGE is a typo/made up intrinsic we have? I think it should be |
|
One note - this probably needs a todo w.r.t #2302 - I am rewriting the reference_accesses code to handle that, but this does not handle unexpected naming of arguments (that would cause IntrinsicCall.create to fail). |
arporter
left a comment
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 realised that it's a bit early to review this as it's branched off the PR that makes precision a DataNode. Therefore, I've only done a limited look, mainly focused on intrinsic_call.py (once I realised about the branching).
I like the way it's going and thanks for adding the keywords to the arguments to the many IAttr constructors. Mainly it's the usual request for comments plus it would be really helpful to write down the rules that are implemented by the various help methods - if you could do that for all of them (in their docstrings) then that would be great. I think there's also some scope to reduce duplication.
src/psyclone/domain/common/transformations/kernel_module_inline_trans.py
Outdated
Show resolved
Hide resolved
src/psyclone/tests/domain/common/transformations/kernel_module_inline_trans_test.py
Outdated
Show resolved
Hide resolved
|
@arporter Should ready for another look now. |
arporter
left a comment
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.
Nice. Thanks Aidan. Very close now. Just a bit more tidying and comments and I think there's some dead code that can be removed.
I'll fire off the integration tests.
| ScalarType.Intrinsic.INTEGER, | ||
| ScalarType.Intrinsic.REAL): | ||
| try: | ||
| return compute_scalar_type(argtypes) |
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.
Now that you've added this new method (compute_scalar_type) I think you could probably just inline the content of this method (get_result_scalar_type) at the one location (L452) where it is called.
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.
In doing this, you'll also need to tighten-up the code a little as it's currently possible (at least theoretically) for it to return None (if none of the argument types are INTEGER or REAL).
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.
Its not currently possible for it to return None since compute_scalar_type always falls through to raise a TypeError if it fails.
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.
Not inlining - discussed on teams.
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.
There is still the issue of the return value - pylint can't tell that it's not possible for it to return None and complains:
psyir/nodes/operation.py:323:4: R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
Is it possible to re-write the code so that it first finds the unsupported type and then raises the error:
actual_types = set(atype.intrinsic for atype in argtypes)
actual_types -= set(ScalarType.Intrinsic.INTEGER, ScalarType.Intrinsic.REAL)
raise ...list(actual_types)[0]...
src/psyclone/tests/psyir/transformations/intrinsics/sign2code_trans_test.py
Show resolved
Hide resolved
|
@arporter Hopefully I got everything, should be back to you now. |
…3060_intrinsic_types
|
@arporter I think I got the missing parts now. |
arporter
left a comment
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 Aidan - very, very close now.
There's one bit of outstanding refactoring to reduce duplication (return type is array of rank one less than input or a scalar if that's a rank-1 array). If you dig into all previous comments you should find where I point these cases out (although there may be others I don't point out.)
There's a little bit of refactoring to make pylint happy.
There's also one line that CodeCov is saying isn't covered.
Happily the ITs were all green so I won't run them this time around.
| # at compile time. It will have one fewer dimension than the | ||
| # input. | ||
| arg = node.argument_by_name(array_arg_name) | ||
| shape = arg.datatype.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 think this is worth doing. Perhaps:
def _type_of_arg_with_rank_minus_one(arg, scalar_type) -> Union[ScalarType, ArrayType]:
'''
TODO
'''
shape = arg.shape
if len(shape) == 1:
return scalar_type
new_shape = [ArrayType.Extent.DEFERRED] * (len(shape) - 1)
return ArrayType(scalar_type, new_shape)| # at compile time. It will have one fewer dimension than the | ||
| # input. | ||
| arg = node.argument_by_name(array_arg_name) | ||
| shape = arg.datatype.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.
This one is still outstanding?
| ztmp1 = 0.0 | ||
| ! Can't handle because we don't know the type of MAX or ABS | ||
| ztmp1 = SIGN( MAX(ABS(ztmp1),1.E-6_wp), ztmp1 ) | ||
| ! Can't handle because MAXVAL returns an array. |
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 think you have it working? MAXVAL returns a scalar here?
| ScalarType.Intrinsic.INTEGER, | ||
| ScalarType.Intrinsic.REAL): | ||
| try: | ||
| return compute_scalar_type(argtypes) |
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.
There is still the issue of the return value - pylint can't tell that it's not possible for it to return None and complains:
psyir/nodes/operation.py:323:4: R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
Is it possible to re-write the code so that it first finds the unsupported type and then raises the error:
actual_types = set(atype.intrinsic for atype in argtypes)
actual_types -= set(ScalarType.Intrinsic.INTEGER, ScalarType.Intrinsic.REAL)
raise ...list(actual_types)[0]...
I'm putting this up early so if anyone has time to have a quick look at the implementation before I go too far down the rabbit hole with how I'm implementing the return type and tests.
I have added two more members to the
IAttrnamedtuple,return_typeandreference_accesses, which can either be aCallableor specific value (depending on whats required).To get the return_type of an
IntrinsicCall, my plan is to do something like:The return type implementations are started - there are 3 helper functions at the moment (for cases I expect to be used a lot), e.g.
_get_first_argument_type, wheras other's have their own lambda (for example seeAINT).I'm unsure how much to avoid code duplication here, for example AINT and ANINT have the same lambda for their return_type, so I'm not sure whether its worth moving this out (and whether the result should be a lambda or function) every time I have any 2 intrinsic calls with the same return type? Feedback on this specific question would be appreciated as early as possible (probably one for @arporter to answer perhaps).
To test the return types, my plan was to have standalone test for every "helper" function (or even helper lambda later).
I was then planning to create a parametrize test for all other intrinsics who have their own specific lambda. My one concern is this parametrize would become very large - again feedback/thoughts on this approach would be helpful. You can see an initial versoin of how this parametrize might look at
intrinsic_call_test::650.NB. This is dependent on #3110 and I think I will rebase onto that branch for now so I can have passing tests.