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

Simple bank-aware malloc scheme #1143

Merged
merged 111 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
2a13bc3
Add new attr to ObjectFifoCreateOp to note another objfifo to avoid w…
abisca Mar 18, 2024
7fe8b2a
Matrix multiply works!
abisca Mar 21, 2024
2f3d5ac
Cleanup passes and rename objFifo_name to objFifo_to_avoid_at_alloc
abisca Mar 21, 2024
1b92ef3
Fix merge conflicts
abisca Mar 21, 2024
88071a9
Update lib/Dialect/AIE/Transforms/AIEObjectFifoStatefulTransform.cpp
AndraBisca Mar 21, 2024
7659ce1
Update lib/Dialect/AIE/IR/AIEDialect.cpp
AndraBisca Mar 21, 2024
26deab7
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
0ed53ca
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
78c67c7
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
f96b29f
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
fb8532b
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
f901f24
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
931168e
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
6c99058
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
ecdc85a
Update reference_designs/ipu-xrt/matrix_multiplication/aie2.py
AndraBisca Mar 21, 2024
250750c
Update reference_designs/ipu-xrt/matrix_multiplication/aie2.py
AndraBisca Mar 21, 2024
8b0a5a8
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
efc2e8f
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
37902a7
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
84c4269
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
ec1161b
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
a19dcd8
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
ed6bf0f
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
cba1466
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
2f4fdc2
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 21, 2024
c423327
Merge branch 'main' of https://github.com/Xilinx/mlir-aie into objfif…
abisca Mar 21, 2024
c3441f0
Update tests
abisca Mar 21, 2024
ae09f80
Merge branch 'main' of https://github.com/Xilinx/mlir-aie into objfif…
abisca Mar 22, 2024
105ab31
Fix failing tests
abisca Mar 22, 2024
7554731
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 22, 2024
24003d0
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 22, 2024
4c61125
Function cleanup. Added function descriptions.
abisca Mar 22, 2024
f6b31bb
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 22, 2024
26fd992
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Mar 22, 2024
b88f83f
Fix unit tests
abisca Mar 22, 2024
0003102
Merge branch 'main' of https://github.com/Xilinx/mlir-aie into objfif…
abisca Mar 26, 2024
314215b
Fix merge conflicts
abisca Apr 16, 2024
59306ce
Remove objfifo attr.
abisca Apr 17, 2024
713a3de
Fix errors
abisca Apr 17, 2024
2a35c0c
Update lib/Dialect/AIE/Transforms/AIEObjectFifoStatefulTransform.cpp
AndraBisca Apr 17, 2024
0737cec
Tets flag
abisca Apr 18, 2024
1c5307f
Merge branch 'main' of https://github.com/Xilinx/mlir-aie into objfif…
abisca Apr 22, 2024
24604a3
Create different classes for allocation schemes
abisca Apr 22, 2024
7e3c127
Started cleanup alloc schemes
abisca Apr 22, 2024
6be0d66
Merge branch 'main' of https://github.com/Xilinx/mlir-aie into objfif…
abisca Apr 23, 2024
d8cdb54
Restructure pass with OpConversionPatterns
abisca Apr 23, 2024
a715799
Add missing return failure()
abisca Apr 24, 2024
da83f63
Add tests for both alloc schemes
abisca Apr 24, 2024
2b6ec63
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
e02fd2e
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
9a2289d
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
e72977c
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
fe4aca8
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
8a16dea
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
590f2c7
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
2f47719
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
54682da
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
075dcf5
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
fd20082
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
4abbb80
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
9132f59
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
7481632
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
1bcd415
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
fc8e063
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
f637184
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
80cc5d5
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
bbfb4fc
Update
abisca Apr 24, 2024
fef685a
Final version of the alloc schemes
abisca Apr 24, 2024
8688b68
Clang format
abisca Apr 24, 2024
81cfcb6
Remove missed merge conflict
abisca Apr 24, 2024
f3f7d5f
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
8d41218
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
8e768a7
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
5d3d8ef
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
72ff475
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
2624f0b
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
5e7a38d
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
d3e1f78
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
71465fe
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
d0a3234
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
13093b2
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
3f6a0e8
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
4331c02
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
d7139f9
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
32040aa
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
2524e13
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
92bdd3b
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
9250651
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 24, 2024
cff06b0
Merge branch 'main' of https://github.com/Xilinx/mlir-aie into objfif…
abisca Apr 24, 2024
50a8e4a
Merge branch 'objfifo-alloc' of https://github.com/Xilinx/mlir-aie in…
abisca Apr 24, 2024
28c0de4
Fixed modulesXilinx
abisca Apr 24, 2024
9fd6b84
Add aiecc flag for basic_alloc_scheme
abisca Apr 24, 2024
9926ca1
Merge branch 'main' of https://github.com/Xilinx/mlir-aie into objfif…
abisca Apr 24, 2024
e88bd2b
Update python/compiler/aiecc/main.py
AndraBisca Apr 24, 2024
cca86ff
Merge branch 'objfifo-alloc' of https://github.com/Xilinx/mlir-aie in…
abisca Apr 24, 2024
11a4adc
Add flag where needed
abisca Apr 24, 2024
c2039db
Add flag to test
abisca Apr 24, 2024
b699c42
Attemp to fix tests
abisca Apr 24, 2024
25bc685
Attempt 2
abisca Apr 24, 2024
1efb1ae
Rooting out error
abisca Apr 24, 2024
7912328
Still looking for root cause of errors
abisca Apr 25, 2024
6a880fb
Still looking for root cause of errors
abisca Apr 25, 2024
c60cb3f
Test
abisca Apr 25, 2024
59ac15f
Replace getOps with device.walk to pick up all buffers in device
abisca Apr 25, 2024
c147498
Update lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
AndraBisca Apr 25, 2024
845b178
Remove flag when not necessary
abisca Apr 25, 2024
155c5a1
Merge branch 'objfifo-alloc' of https://github.com/Xilinx/mlir-aie in…
abisca Apr 25, 2024
3bff413
Merge branch 'main' of https://github.com/Xilinx/mlir-aie into objfif…
abisca Apr 25, 2024
f7eeef5
Fix tests
abisca Apr 25, 2024
fdf18aa
Fix copyrights
abisca Apr 25, 2024
b688633
Merge branch 'main' of https://github.com/Xilinx/mlir-aie into objfif…
abisca Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/aie/Dialect/AIE/IR/AIEOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,8 @@ def AIE_BufferOp: AIE_Op<"buffer", [
ins Index:$tile,
OptionalAttr<StrAttr>:$sym_name,
OptionalAttr<AIEI32Attr>:$address,
OptionalAttr<ElementsAttr>:$initial_value
OptionalAttr<ElementsAttr>:$initial_value,
OptionalAttr<AIEI32Attr>:$mem_bank
);

let results = (outs AnyMemRef:$buffer);
Expand Down Expand Up @@ -1607,7 +1608,8 @@ def AIE_ObjectFifoCreateOp: AIE_Op<"objectfifo", [HasParent<"DeviceOp">, Symbol]
AIE_ObjectFifo_Depth:$elemNumber,
TypeAttrOf<AIE_ObjectFifoType>:$elemType,
BDDimLayoutArrayAttr:$dimensionsToStream,
BDDimLayoutArrayArrayAttr:$dimensionsFromStreamPerConsumer
BDDimLayoutArrayArrayAttr:$dimensionsFromStreamPerConsumer,
OptionalAttr<FlatSymbolRefAttr>:$objFifo_to_avoid_at_alloc
);

let assemblyFormat = [{
Expand Down Expand Up @@ -1640,6 +1642,7 @@ def AIE_ObjectFifoCreateOp: AIE_Op<"objectfifo", [HasParent<"DeviceOp">, Symbol]
return getOperation()->getAttrOfType<mlir::StringAttr>(
mlir::SymbolTable::getSymbolAttrName());
}
ObjectFifoCreateOp getObjectFifoToAvoidAtAlloc();
}];

let builders = [
Expand Down
13 changes: 13 additions & 0 deletions lib/Dialect/AIE/IR/AIEDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,19 @@ void printObjectFifoConsumerTiles(OpAsmPrinter &printer, Operation *op,
}
}

ObjectFifoCreateOp ObjectFifoCreateOp::getObjectFifoToAvoidAtAlloc() {
Operation *parent = getOperation();
while ((parent = parent->getParentOp())) {
if (parent->hasTrait<OpTrait::SymbolTable>()) {
if (auto *st = SymbolTable::lookupSymbolIn(
parent, getObjFifoToAvoidAtAlloc().value());
isa_and_nonnull<ObjectFifoCreateOp>(st))
return dyn_cast<ObjectFifoCreateOp>(st);
}
}
return {};
}

} // namespace xilinx::AIE

//===----------------------------------------------------------------------===//
Expand Down
216 changes: 181 additions & 35 deletions lib/Dialect/AIE/Transforms/AIEAssignBuffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,104 @@ using namespace xilinx::AIE;

struct AIEAssignBufferAddressesPass
: AIEAssignBufferAddressesBase<AIEAssignBufferAddressesPass> {

typedef struct BankLimits {
int64_t startAddr;
int64_t endAddr;
} BankLimits;

std::map<TileOp, std::vector<int64_t>>
nextAddrInBanks; // each entry is the next address available for use for
// that bank (e.g. nextAddrInBanks[1] = next available
// address in bank 1)
std::map<TileOp, std::vector<BankLimits>> bankLimits;

void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<func::FuncDialect>();
registry.insert<AIEDialect>();
}

void fillBankLimits(TileOp tile, int numBanks, int bankSize) {
for (int i = 0; i < numBanks; i++) {
auto startAddr = bankSize * i;
auto endAddr = bankSize * (i + 1);
if (bankLimits.find(tile) == bankLimits.end()) {
std::vector<BankLimits> limits;
bankLimits[tile] = limits;
}
bankLimits[tile].push_back({startAddr, endAddr});
}
}

void setAndUpdateAddressInBank(TileOp tile, BufferOp buffer,
int64_t start, int64_t end) {
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
// Fixme: alignment
buffer.setAddress(start);
nextAddrInBanks[tile][buffer.getMemBank().value()] = end;
}

bool checkAndAddBufferWithAddress(TileOp tile, BufferOp buffer, int numBanks, int bankSize) {
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
if (auto addrAttr = buffer->getAttrOfType<IntegerAttr>("address")) {
int addr = addrAttr.getInt();
for (int i = 0; i < numBanks; i++) {
if (bankLimits[tile][i].startAddr <= addr && addr < bankLimits[tile][i].endAddr) {
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
if (addr >= nextAddrInBanks[tile][i]) {
nextAddrInBanks[tile][i] = addr + buffer.getAllocationSize();
buffer.setMemBank(i);
} else {
buffer->emitWarning("Overriding existing address");
return false;
}
}
}
return true;
}
return false;
}

bool checkAndAddBufferWithMemBank(TileOp tile, BufferOp buffer, int numBanks, int bankSize) {
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
if (auto memBankAttr = buffer->getAttrOfType<IntegerAttr>("mem_bank")) {
int mem_bank = memBankAttr.getInt();
int64_t startAddr = nextAddrInBanks[tile][mem_bank];
int64_t endAddr = startAddr + buffer.getAllocationSize();
if (endAddr <= bankLimits[tile][mem_bank].endAddr) {
setAndUpdateAddressInBank(tile, buffer, startAddr, endAddr);
} else {
buffer->emitWarning("Overriding existing mem_bank");
int bankIndex = mem_bank;
for (int i = 0; i < numBanks; i++) {
bankIndex++;
bankIndex %= numBanks;
startAddr = nextAddrInBanks[tile][bankIndex];
endAddr = startAddr + buffer.getAllocationSize();
if (endAddr <= bankLimits[tile][bankIndex].endAddr || i == numBanks - 1) {
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
buffer.setMemBank(bankIndex);
setAndUpdateAddressInBank(tile, buffer, startAddr, endAddr);
}
}
}
return true;
}
return false;
}

int setBufferAddress(TileOp tile, BufferOp buffer, int numBanks, int bankSize, int startBankIndex) {
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
int bankIndex = startBankIndex;
for (int i = 0; i < numBanks; i++) {
bankIndex %= numBanks;
int64_t startAddr = nextAddrInBanks[tile][bankIndex];
int64_t endAddr = startAddr + buffer.getAllocationSize();
if (endAddr <= bankLimits[tile][bankIndex].endAddr || i == numBanks - 1) {
buffer.setMemBank(bankIndex);
setAndUpdateAddressInBank(tile, buffer, startAddr, endAddr);
bankIndex++;
break;
}
bankIndex++;
}
return bankIndex;
}

void runOnOperation() override {
DeviceOp device = getOperation();
OpBuilder builder = OpBuilder::atBlockEnd(device.getBody());
Expand All @@ -49,54 +143,106 @@ struct AIEAssignBufferAddressesPass
maxDataMemorySize = targetModel.getMemTileSize();
else
maxDataMemorySize = targetModel.getLocalMemorySize();
SmallVector<BufferOp, 4> buffers;
// Collect all the buffers for this tile.
device.walk<WalkOrder::PreOrder>([&](BufferOp buffer) {
if (buffer.getTileOp() == tile)
buffers.push_back(buffer);
});
// Sort by allocation size.
std::sort(buffers.begin(), buffers.end(), [](BufferOp a, BufferOp b) {
return a.getAllocationSize() > b.getAllocationSize();
});

// Address range owned by the MemTile is 0x80000.
// Address range owned by the tile is 0x8000,
// but we need room at the bottom for stack.
// Address range owned by the tile is 0x8000 in
// AIE1 and 0x10000 in AIE2, but we need room at
// the bottom for stack.
// TODO: add function in TargetModel that returns num banks per arch
int numBanks = 0;
if (tile.isMemTile())
numBanks = 1;
else
numBanks = 4;
int bankSize = maxDataMemorySize / numBanks;
int stacksize = 0;
int address = 0;
if (nextAddrInBanks.find(tile) == nextAddrInBanks.end()) {
std::vector<int64_t> nextAddresses;
nextAddrInBanks[tile] = nextAddresses;
}
for (int i = 0; i < numBanks; i++)
nextAddrInBanks[tile].push_back(bankSize * i);
if (auto core = tile.getCoreOp()) {
stacksize = core.getStackSize();
address += stacksize;
nextAddrInBanks[tile][0] += stacksize;
}
fillBankLimits(tile, numBanks, bankSize);

for (auto buffer : buffers) {
if (buffer.getAddress())
buffer->emitWarning("Overriding existing address");
buffer.setAddress(address);
address += buffer.getAllocationSize();
SmallVector<BufferOp, 4> buffers;
SmallVector<BufferOp, 4> allBuffers;
// Collect all the buffers for this tile.
// If possible, the buffers with an already specified address will not be
// overwritten (the available address range of the bank the buffers
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
// are in will start AFTER the specified adress + buffer size).
// Buffers with a specified mem_bank will be assigned first, after
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
// the above.
for (auto buffer : device.getOps<BufferOp>()) {
if (buffer.getTileOp() == tile) {
bool has_addr = checkAndAddBufferWithAddress(tile, buffer, numBanks, bankSize);
bool has_bank = checkAndAddBufferWithMemBank(tile, buffer, numBanks, bankSize);
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
if (!has_addr && !has_bank)
buffers.push_back(buffer);
allBuffers.push_back(buffer);
}
}

if (address > maxDataMemorySize) {
// Sort by largest allocation size.
std::sort(buffers.begin(), buffers.end(), [](BufferOp a, BufferOp b) {
assert(buffer.getAddress().has_value() &&
"buffer must have address assigned");
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
return a.getAllocationSize() > b.getAllocationSize();
});

// Set addresses for remaining buffers.
int bankIndex = 0;
for (auto buffer : buffers)
bankIndex = setBufferAddress(tile, buffer, numBanks, bankSize, bankIndex);
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved

// Sort by smallest address.
std::sort(allBuffers.begin(), allBuffers.end(), [](BufferOp a, BufferOp b) {
return a.getAddress().value() < b.getAddress().value();
});
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved

// Check if memory was exceeded on any bank and print debug info.
bool foundOverflow = false;
std::vector<int> overflow_banks;
for (int i = 0; i < numBanks; i++) {
if (nextAddrInBanks[tile][i] > bankLimits[tile][i].endAddr) {
foundOverflow = true;
overflow_banks.push_back(i);
}
}
if (foundOverflow) {
InFlightDiagnostic error =
tile.emitOpError("allocated buffers exceeded available memory\n");
auto &note = error.attachNote() << "MemoryMap:\n";
auto &note = error.attachNote() << "Error in bank(s) : ";
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
for (auto bank : overflow_banks)
note << bank << " ";
note << "\n";
note << "MemoryMap:\n";
auto printbuffer = [&](StringRef name, int address, int size) {
note << "\t" << name << " \t"
<< ": 0x" << llvm::utohexstr(address) << "-0x"
<< llvm::utohexstr(address + size - 1) << " \t(" << size
<< " bytes)\n";
note << "\t" << "\t" << name << " \t"
<< ": 0x" << llvm::utohexstr(address) << "-0x"
<< llvm::utohexstr(address + size - 1) << " \t(" << size
<< " bytes)\n";
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
};
if (stacksize > 0)
printbuffer("(stack)", 0, stacksize);
else
error << "(no stack allocated)\n";

for (auto buffer : buffers) {
assert(buffer.getAddress().has_value() &&
"buffer must have address assigned");
printbuffer(buffer.name(), buffer.getAddress().value(),
buffer.getAllocationSize());
for (int i = 0; i < numBanks; i++) {
note << "\t" << "bank : " << i << "\t"
<< "0x" << llvm::utohexstr(bankLimits[tile][i].startAddr)
<< "-0x" << llvm::utohexstr(bankLimits[tile][i].endAddr - 1)
<< "\n";
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
if (i == 0) {
if (stacksize > 0)
printbuffer("(stack)", 0, stacksize);
else
error << "(no stack allocated)\n";
}
for (auto buffer : allBuffers) {
auto addr = buffer.getAddress().value();
auto mem_bank = buffer.getMemBank().value();
if (mem_bank == i)
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
AndraBisca marked this conversation as resolved.
Show resolved Hide resolved
printbuffer(buffer.name(), addr, buffer.getAllocationSize());
}
}
return signalPassFailure();
}
Expand Down
Loading
Loading