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

[MemoryBanking] Support memory banking forGetGlobalOp #8047

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

jiahanxie353
Copy link
Contributor

This patch supports memory banking for multi-dimensional GetGlobalOps and restructure the data in their corresponding GlobalOps by the banking scheme (such as the banking factor and the dimension).

Copy link
Member

@cgyurgyik cgyurgyik left a comment

Choose a reason for hiding this comment

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

Nice job! Mostly style nits and a few smaller comments.

lib/Transforms/MemoryBanking.cpp Outdated Show resolved Hide resolved
@@ -88,6 +89,51 @@ MemRefType computeBankedMemRefType(MemRefType originalType,
return newMemRefType;
}

// Updates n-dimensional index array `ndIndex` in-place by decoding the flat
// index `linIndex` given the shape of the array. Assume row-major order.
void decodeIndex(int64_t linIndex, ArrayRef<int64_t> shape,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: just return a SmallVector<int64_t> instead of passing it as a reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good!

lib/Transforms/MemoryBanking.cpp Outdated Show resolved Hide resolved
lib/Transforms/MemoryBanking.cpp Outdated Show resolved Hide resolved
Comment on lines 185 to 186
auto globalOp =
dyn_cast_or_null<memref::GlobalOp>(SymbolTable::lookupSymbolIn(
Copy link
Member

Choose a reason for hiding this comment

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

If you're doing dyn_cast_or_null, we should have an assert here to make sure its not null. If you're absolutely sure it exists, then we should just use cast

lib/Transforms/MemoryBanking.cpp Outdated Show resolved Hide resolved
Comment on lines 199 to 206
for (size_t bankCnt = 0; bankCnt < bankingFactor; ++bankCnt) {
if (bankCnt == 0) {
// initialize globalOp and getGlobalOp's insertion points
builder.setInsertionPointAfter(globalOp);
globalOpsInsertPt = builder.saveInsertionPoint();
builder.setInsertionPointAfter(getGlobalOp);
getGlobalOpsInsertPt = builder.saveInsertionPoint();
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can we move this outside the loop, and if you want to avoid this when bankingFactor == 0, then just add an if statement as an early exit?

lib/Transforms/MemoryBanking.cpp Outdated Show resolved Hide resolved
@@ -1,4 +1,5 @@
// RUN: circt-opt %s -split-input-file -memory-banking="banking-factor=2 dimension=1" | FileCheck %s --check-prefix RANK2-BANKDIM1
// RUN: circt-opt %s -split-input-file -memory-banking="banking-factor=2" | FileCheck %s --check-prefix GETGLOBAL
Copy link
Member

Choose a reason for hiding this comment

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

You may have handled this in an earlier PR, but what about corner cases, e.g., banking-factor=0, dim_size % banking-factor != 0, etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in these cases, it will early signal failure:

if (bankingFactor == 0) {

or raise an assertion error:
assert(originalShape[bankingDimension] % bankingFactor == 0 &&

@@ -125,6 +171,76 @@ SmallVector<Value, 4> createBanks(Value originalMem, uint64_t bankingFactor,
banks.push_back(bankAllocaOp);
}
})
.Case<memref::GetGlobalOp>([&](memref::GetGlobalOp getGlobalOp) {
Copy link
Member

Choose a reason for hiding this comment

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

How difficult would it be to place all this code in a separate function and just call it here? It is quite large, but unsure if that would require too many arguments.

@jiahanxie353
Copy link
Contributor Author

Thanks @cgyurgyik for the review and suggestions! I've finished modifying the code based on the request. And it's ready for another round of review!

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