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

Support for memRef of L1 Interleaved tensors (#1292) #1607

Merged
merged 7 commits into from
Dec 19, 2024

Conversation

fbajraktariTT
Copy link
Contributor

@fbajraktariTT fbajraktariTT commented Dec 16, 2024

This PR fixes the issue of incorrect memRef for L1 Interleaved layouts.

In the previous implementation of TTNNLayoutAttr we were modelling memRef as its memory layout is BlockSharded. By modelling everything as BlockSharded we hit the error of incorrect memory usage for tensors with the given layout.

For example, if we wanted to create a L1 Interleaved TTNNLayout of tensor<1x1024xbf16>, we would get a memref<1x4x!tt.tile<32x32, bf16>, #l1_>. This was incorrect since the whole tensor can be tiled into 32 tiles and if grid shape is 8x8 we could assign only one tile per grid unit. There is no need for 4 tiles to be placed in one grid unit.

This PR adds workaround for this issue by using different logic for calculating logical shard shape for L1 Interleaved layouts. This workaround creates a memref<1x1x!tt.tile<32x32, bf16>, #l1_> for tensor<1x1024xbf16>.

Closes issue: #1292

@fbajraktariTT fbajraktariTT linked an issue Dec 17, 2024 that may be closed by this pull request
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.

Great work! Let's open this up as ready for review!

lib/Dialect/TTNN/IR/TTNNOpsAttrs.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/IR/TTNNOpsAttrs.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/IR/TTNNOpsAttrs.cpp Outdated Show resolved Hide resolved
std::accumulate(logicalTiledShape.begin(), logicalTiledShape.end(), 1,
std::multiplies<std::int64_t>());
uint64_t numOfGridUnits =
std::accumulate(grid.getShape().begin(), grid.getShape().end(), 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe leave an assert here that grid is equal to device max grid? Or at least a comment. I'm not sure that l1 interleaved is supported for non max grid configurations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to check this, but I suspect that l1 is supported for non max grid configuration.

Comment on lines 107 to 125
shardShape.push_back(1);
shardShape.push_back((numOfTiles + numOfGridUnits - 1) / numOfGridUnits);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is always 2D. Is there a case when it needs more dimensions? Maybe just leave an assert that this is the desired number of dims, so when we introduce 3D this fails in a friendly manner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of asserting, we can add n-1 ones at the beginning of merRef so its dimension corresponds to the grid dimension.

lib/Dialect/TTNN/Analysis/LegalLayoutAnalysis.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/IR/TTNNOpsAttrs.cpp Show resolved Hide resolved
lib/Dialect/TTNN/IR/TTNNOpsAttrs.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/IR/TTNNOpsAttrs.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/IR/TTNNOpsAttrs.cpp Outdated Show resolved Hide resolved
lib/Dialect/TTNN/IR/TTNNOpsAttrs.cpp Outdated Show resolved Hide resolved
@mtopalovicTT
Copy link
Contributor

Will continue tmrw.

@fbajraktariTT fbajraktariTT merged commit 293d226 into main Dec 19, 2024
21 checks passed
@fbajraktariTT fbajraktariTT deleted the fix_L1_interleaved_mlir branch December 19, 2024 07:59
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.

Representation of L1 Interleaved layout
3 participants