Skip to content
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

Slate: Transpose(Tensor(form)) -> Tensor(adjoint(form)) #2272

Merged
merged 1 commit into from
Nov 10, 2021

Conversation

sv2518
Copy link
Contributor

@sv2518 sv2518 commented Nov 8, 2021

This PR addresses #2262. It's a small codegen improvement which inlines transposes into the local assembly kernels generated by TSFC. I have done this on the highest level (in Slate) via def __new__.

@wence-
Copy link
Contributor

wence- commented Nov 8, 2021

Looks like there's an actual failure in the hybridisation notebook?

firedrake/slate/slate.py Outdated Show resolved Hide resolved
Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the actual test failure in the build, I think this is good.

tests/slate/test_linear_algebra.py Outdated Show resolved Hide resolved
@sv2518
Copy link
Contributor Author

sv2518 commented Nov 9, 2021

Ok I think some tests were failing, because I took the ufl adjoint and not the one from firedrake.ufl_expr.

@wence-
Copy link
Contributor

wence- commented Nov 9, 2021

Now it looks like we have many fails because adjoint(linear_form) isn't defined, whereas Tensor(linear_form).T does work, I think?

@sv2518
Copy link
Contributor Author

sv2518 commented Nov 9, 2021

Mhh, maybe this is not the right way to do it after all. Maybe I need to do it at a lower level. The leftover issues we have are that a) M.T.arguments() != M.T.arguments[::-1] because M.T generates a new Tensor with new arguments and b) e.g. that M.T.T != M.

@wence-
Copy link
Contributor

wence- commented Nov 9, 2021

Mhh, maybe this is not the right way to do it after all. Maybe I need to do it at a lower level. The leftover issues we have are that a) M.T.arguments() != M.T.arguments[::-1] because M.T generates a new Tensor with new arguments

I think the difference is that:

adjoint(a)

Turns the argument with count 0 into the one with count 1, and vice versa

whereas

Tensor(a).arguments()[::-1]

just reverses the argument list.

b) e.g. that M.T.T != M.

This one should be the case, unless I misunderstand?

@sv2518
Copy link
Contributor Author

sv2518 commented Nov 9, 2021

Sorry I think I explained b) wrong actually. In the Slate optimiser we drop double transposes so that M.T.T is just M. If we introduce the change on Slate level we won't know when we have double transposes on terminal tensors anymore, so we can't do that optimisation. But in fact actually we don't need this optimisation on terminal tensors anymore if we go over the adjoint, I think, because we just do Tensor(adjoint(adjoint(form)) so that no extra operations in the Slate kernel are needed.
I guess I could work around a) by specifying reordered_arguments [EDIT: ok that does not help because I still need to switch the count argument].

wence-
wence- previously approved these changes Nov 10, 2021
Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to squash everything nicely, or shall I just do it in the merge commit? Thanks!

…spose(Tensor(form) -> Tensor(adjoint(form)). This optimisation is introduced at the Slate optimiser level but essentially results in inlining transposes on tensors into the local assembly kernels generated by TSFC
@sv2518 sv2518 force-pushed the sv/inline-transpose-into-localassembly branch from 3dc3e7d to ab71183 Compare November 10, 2021 17:55
@sv2518
Copy link
Contributor Author

sv2518 commented Nov 10, 2021

Sorry I had to force-push twice because I screwed up the squashing the first way round. If you give me an approving review, I will merge tomorrow myself as soon as the tests are passing. :)
Thanks for feedback!

Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@wence-
Copy link
Contributor

wence- commented Nov 10, 2021

I will merge tomorrow myself as soon as the tests are passing.

I turned on auto-merge, so it might be done by the time you get up!

@wence- wence- merged commit e70fa3b into master Nov 10, 2021
@wence- wence- deleted the sv/inline-transpose-into-localassembly branch November 10, 2021 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants