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

L1 interleaved policy #1117

Merged
merged 10 commits into from
Nov 5, 2024
Merged

L1 interleaved policy #1117

merged 10 commits into from
Nov 5, 2024

Conversation

fbajraktariTT
Copy link
Contributor

@fbajraktariTT fbajraktariTT commented Oct 30, 2024

The goal of this PR is to add new MemoryLayoutAnalysis policy. Apart from DFShardingPolicy, the idea is to implement L1Interleaved policy that will try to build l1 interleaved chains instead of l1 sharding chains.

@fbajraktariTT fbajraktariTT force-pushed the l1_interleaved_policy branch 2 times, most recently from 5c18e7d to 608a531 Compare October 31, 2024 10:13
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, with a few comments.

include/ttmlir/Dialect/TTNN/Analysis/L1InterleavedPolicy.h Outdated Show resolved Hide resolved
include/ttmlir/Dialect/TTNN/Analysis/ShardingAnalysis.h Outdated Show resolved Hide resolved
lib/Dialect/TTNN/Analysis/L1InterleavedPolicy.cpp Outdated Show resolved Hide resolved
test/ttmlir/Dialect/TTNN/all_l1_interleaved_policy.mlir Outdated Show resolved Hide resolved
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.

LGTM

@nobradovictt Please take a quick look as well.

include/ttmlir/Dialect/TTNN/Analysis/L1InterleavedPolicy.h Outdated Show resolved Hide resolved

// Check if currentOp is valid l1 interleaved op.
//
if (legalLayouts.lookup(currentOp).size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't even check if adjacent OPs in chain are connected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is true, because we decided that is ok for V0 to put all ops with possible l1 interleaved layout into a single L1ChainConfig. Also, I added a comment that it will be fixed in V1.

// Resolve l1 chain configs.
//
for (auto &l1ChainConfig : *l1ChainConfigs) {
l1ChainConfig.build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't build happen when chain is fully populated. Using it here like this is pointless?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also here, for V0 we only have one L1ChainConfig and therefore build and resolve should happen at the same time. This for loop is only a placeholder for V1 and future versions of this policy.


// Check if currentOp is valid l1 interleaved op.
//
if (legalLayouts.lookup(currentOp).size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we don't have a valid l1 interleaved config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case, legalLayouts for that specific op will not be overridden by l1 interleaved layout and therefore keep the legalLayouts from LegalGridAnalysis.

lib/Dialect/TTNN/Analysis/L1InterleavedPolicy.cpp Outdated Show resolved Hide resolved
// This is V0 implementation of L1 interleaved policy. In the current
// implementation we have a single L1ChainCofig per FuncOp. This implies
// that in case of DRAM spil we will have a disconnected chain of L1 ops.
// This will be fixed in V1.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like this proposed staging, disconnected chain is not a chain and this policy is just random then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has already been fixed in V1 version of this policy (#1132).

@svuckovicTT
Copy link
Contributor

Hey @fbajraktariTT, can you please add a description on what the purpose of this PR is? Additionally, can you attach tracking issue? It's a little hidden, but after you create a PR, you can click on the development section (right-side bar) to attach issues.

@odjuricicTT
Copy link
Contributor

Looks good to me. Let's add two tests. One with a simple fork join and one with a huge tensor size that won't fit into L1.

Refactor sharding into mem layout analysis.

All l1 interleaved policy for mem layout analysis

Add mnist test

Add option in both optimizer pass and ttnn-ttir-backedn-pipeline to specify memory layout analysis policy type
@fbajraktariTT fbajraktariTT merged commit c038025 into main Nov 5, 2024
18 checks passed
@fbajraktariTT fbajraktariTT deleted the l1_interleaved_policy branch November 5, 2024 09:37
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.

Add new MemoryLayoutAnalysis Policy Testing of MemoryLayoutAnalysis policies
4 participants