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

Add support for manual common subexpression elimination #35

Open
charleskawczynski opened this issue Sep 6, 2024 · 1 comment
Open
Labels

Comments

@charleskawczynski
Copy link
Member

charleskawczynski commented Sep 6, 2024

It seems that MultiBroadcastFusion is not fusing reads/writes in ClimaCore. Perhaps the compiler is unable to perform the optimization (these are pretty complicated expressions afterall). If the compiler is unable to fuse the reads and writes in a multi-broadcast fusion object, then we could try to write a function that manually does this by transforming the object.

Some important examples might include:

(Pair(x, Broadcasted(+, x, 1)),
Pair(x, Broadcasted(-, x, 2)),
Pair(x, Broadcasted(*, x, 3)),
Pair(x, Broadcasted(/, x, 4)))

would be transformed to

(Pair(x, Broadcasted(/, Broadcasted(*, Broadcasted(-, Broadcasted(+, x, 1), 2), 3), 4)),)

and

(Pair(z, Broadcasted(+, a, b)),
Pair(x, Broadcasted(-, z, a)),
Pair(y, Broadcasted(*, z, b)))

transformed to

?

Hm, I'm not sure how to hoist here without things inlined.. All of the reads/writes exist inside a single getindex call, but if hoisted reads/writes depend on all the reads to exist inside a single _broadcast_getindex call, then we'll need to transform the MBF object into a custom broadcasted object and have it return a tuple, like @dennisYatunin suggested.

Either way, this sort of transformation should guarantee avoiding duplicate reads/writes in the first case, and (hopefully) lead to fused reads/writes in the latter case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant