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

[Optimizer] Greedy solution for join nodes in L1 Interleaved policy #1162

Merged
merged 4 commits into from
Dec 4, 2024

Conversation

fbajraktariTT
Copy link
Contributor

@fbajraktariTT fbajraktariTT commented Nov 5, 2024

This PR introduces new MemoryLayoutAnalysis policy as an alternative to the DFSharding policy with the goal of greedily solving join nodes. This means that if an op is a join node (node with multiple operands, e.g. Add, Matmul,...) we should consider placing multiple op's operands in the L1 memory and limit ourselves to only one operand being placed in L1 memory as is it the case with DFSharding. For all the combination of operands, we pick the one that maximizes L1 usage (by maximising L1 usage we try to have as few DRAM spills as possible) and minimizes required L1 usage (minimal amount of L1 memory neccesseary in order to reach desired memory configuration). Furthermore, it should be emphasized that this may not lead to globally optimal solution because we pick the optimal config at moment of analysing the op.

@nobradovictt
Copy link
Contributor

PR title does not correspond to changes made.

@fbajraktariTT fbajraktariTT force-pushed the v2_interleaved_policy branch 4 times, most recently from 5a24709 to daed82a Compare November 12, 2024 16:45
@fbajraktariTT fbajraktariTT force-pushed the v2_interleaved_policy branch 2 times, most recently from e6f54a9 to 4d1c249 Compare November 18, 2024 17:21
@fbajraktariTT fbajraktariTT linked an issue Nov 19, 2024 that may be closed by this pull request
@fbajraktariTT fbajraktariTT force-pushed the v2_interleaved_policy branch 3 times, most recently from 2036257 to 0cb6250 Compare November 25, 2024 15:28
@fbajraktariTT fbajraktariTT marked this pull request as ready for review November 25, 2024 15:29
@fbajraktariTT fbajraktariTT marked this pull request as draft November 25, 2024 15:32
Copy link
Contributor

@odjuricicTT odjuricicTT left a comment

Choose a reason for hiding this comment

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

As discussed offline, because it is a big change, let's make a few architectural adjustments first and then review the rest.

env/CMakeLists.txt Outdated Show resolved Hide resolved
include/ttmlir/Scheduler/PrecedenceScheduler.h Outdated Show resolved Hide resolved
@fbajraktariTT fbajraktariTT marked this pull request as ready for review November 26, 2024 16:09
Copy link
Contributor

@odjuricicTT odjuricicTT left a comment

Choose a reason for hiding this comment

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

Left a few comments, mostly about readability. As @nobradovic mentioned, the PR title should try to explain what the change is in a way so that people not familiar with the work can uderstand. Maybe something like: "[Optimizer] Solve join nodes in L1 interleaved policy"

}
l1ChainConfigs->back().build();
l1ChainConfigs->back().resolve();
std::unordered_set<Edge> memReconfigEdges;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we see a scenario in future where in L1Interleaved policy we will need reconfig edge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It depends on the op and there may be a scenario where we need reconfigEdges. For example, if we greedily decide that the output of an op's operand should be in DRAM and there is enough available L1 memory this operand then we can insert a ToLayout op on that edge so we can gain on the performance. I assume this may be true depending on the op.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but in this scenario it would not be coming from policy like for example in DFSharding, but only as an external override, because if policy found out that reconfigEdge is needed it could directly change OP output instead. Just thinking if it should be completely removed from L1Interleaved policy as it is currently only used as an empty dummy struct to satisfy API.

lib/Dialect/TTNN/Analysis/L1InterleavedPolicy.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/Analysis/L1InterleavedPolicy.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/Analysis/L1InterleavedPolicy.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/Analysis/L1InterleavedPolicy.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/Analysis/L1InterleavedPolicy.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/Analysis/L1InterleavedPolicy.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/Analysis/L1InterleavedPolicy.cpp Outdated Show resolved Hide resolved
@fbajraktariTT fbajraktariTT changed the title V2 interleaved policy for MemoryLayoutAnalysis [Optimizer] Greedy solution for join nodes in L1 Interleaved policy Nov 27, 2024
@nobradovictt
Copy link
Contributor

Change has no description.

@fbajraktariTT fbajraktariTT force-pushed the v2_interleaved_policy branch 3 times, most recently from 5eed6db to d559286 Compare November 28, 2024 12:17
Copy link
Contributor

@odjuricicTT odjuricicTT left a comment

Choose a reason for hiding this comment

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

Looks good! Please add a description for the PR with a few sentances describing the PR contains. Do this for all future PRs.

@fbajraktariTT fbajraktariTT merged commit f794b4c into main Dec 4, 2024
21 checks passed
@fbajraktariTT fbajraktariTT deleted the v2_interleaved_policy branch December 11, 2024 12:57
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.

Move MemoryLayoutAnalysisPolicyParams from TT to TTNN
3 participants