Skip to content

Commit afc2c7e

Browse files
committed
clarity
1 parent 21fa4ae commit afc2c7e

1 file changed

Lines changed: 80 additions & 78 deletions

File tree

lib/Dialect/AIE/Transforms/AIEObjectFifoStatefulTransform.cpp

Lines changed: 80 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,11 +2488,15 @@ struct AIEObjectFifoStatefulTransformPass
24882488
if (state.objFifoLinks.find(*linkOp) != state.objFifoLinks.end())
24892489
target = state.objFifoLinks[*linkOp];
24902490

2491+
// The subview buffer references built at the end of this handler map
2492+
// each acquired access index to a physical buffer. For dynamic tiles
2493+
// they are only consumed for size-1 fifos: buffer addressing for
2494+
// size > 1 fifos is handled separately by the runtime index_switch in
2495+
// dynamicGlobalObjectFifos, which already replaced those accesses.
2496+
std::vector<int> acquiredIndices;
2497+
24912498
// For dynamic tiles, compute the number of locks to acquire at runtime
2492-
// as max(0, acqNumber - held), using the runtime "held" counter. Buffer
2493-
// addressing for size > 1 fifos is handled separately (via runtime
2494-
// index_switch in dynamicGlobalObjectFifos); the subview references
2495-
// built below are only used for size-1 fifos.
2499+
// as max(0, acqNumber - held), using the runtime "held" counter.
24962500
if (isDynamicCore && heldBuffer) {
24972501
builder.setInsertionPointAfter(acquireOp);
24982502
int acqNum = acquireOp.acqNumber();
@@ -2522,99 +2526,97 @@ struct AIEObjectFifoStatefulTransformPass
25222526
memref::StoreOp::create(builder, acquireOp.getLoc(), newHeld,
25232527
heldBuffer, ValueRange(ArrayRef({idx})));
25242528

2525-
// Build the subview buffer references (used by the subview.access
2526-
// replacement below for size-1 fifos).
2527-
std::vector<BufferOp *> subviewRefs;
2528-
subviewRefs.reserve(acqNum);
2529+
// Round-robin buffer index per acquired element (see note above).
25292530
for (int i = 0; i < acqNum; i++) {
2530-
subviewRefs.push_back(&state.buffersPerFifo[target][start]);
2531+
acquiredIndices.push_back(start);
25312532
start = (start + 1) % op.size();
25322533
}
2533-
subviews[acquireOp] = subviewRefs;
25342534
acqPerFifo[{op, portNum}] = start;
2535-
return WalkResult::advance();
2536-
}
2535+
} else {
25372536

2538-
// check how many elements have been released in between this AcquireOp
2539-
// and the previous one
2540-
// !!! operations may not be in the same block !!!
2541-
int numRel = 0;
2542-
for (std::vector<ObjectFifoReleaseOp>::iterator relOp =
2543-
releaseOps[{op, portNum}].begin();
2544-
relOp != releaseOps[{op, portNum}].end();) {
2545-
bool erased = false;
2546-
Operation *acqBlockDefOp = acquireOp.getOperation();
2547-
do {
2548-
Operation *relBlockDefOp = (*relOp).getOperation();
2537+
// check how many elements have been released in between this
2538+
// AcquireOp and the previous one
2539+
// !!! operations may not be in the same block !!!
2540+
int numRel = 0;
2541+
for (std::vector<ObjectFifoReleaseOp>::iterator relOp =
2542+
releaseOps[{op, portNum}].begin();
2543+
relOp != releaseOps[{op, portNum}].end();) {
2544+
bool erased = false;
2545+
Operation *acqBlockDefOp = acquireOp.getOperation();
25492546
do {
2550-
if (acqBlockDefOp->getBlock() == relBlockDefOp->getBlock()) {
2551-
if (relBlockDefOp->isBeforeInBlock(acqBlockDefOp)) {
2552-
numRel += (*relOp).relNumber();
2553-
relOp = releaseOps[{op, portNum}].erase(relOp);
2554-
// to ensure that we do not account
2555-
// the ReleaseOps again later,
2556-
// after the subview is created
2557-
erased = true;
2547+
Operation *relBlockDefOp = (*relOp).getOperation();
2548+
do {
2549+
if (acqBlockDefOp->getBlock() == relBlockDefOp->getBlock()) {
2550+
if (relBlockDefOp->isBeforeInBlock(acqBlockDefOp)) {
2551+
numRel += (*relOp).relNumber();
2552+
relOp = releaseOps[{op, portNum}].erase(relOp);
2553+
// to ensure that we do not account
2554+
// the ReleaseOps again later,
2555+
// after the subview is created
2556+
erased = true;
2557+
}
25582558
}
2559-
}
2560-
} while ((relBlockDefOp = relBlockDefOp->getParentOp()) &&
2561-
!isa<DeviceOp>(relBlockDefOp) && !erased);
2562-
} while ((acqBlockDefOp = acqBlockDefOp->getParentOp()) &&
2563-
!isa<DeviceOp>(acqBlockDefOp) && !erased);
2564-
if (!erased)
2565-
++relOp;
2566-
}
2559+
} while ((relBlockDefOp = relBlockDefOp->getParentOp()) &&
2560+
!isa<DeviceOp>(relBlockDefOp) && !erased);
2561+
} while ((acqBlockDefOp = acqBlockDefOp->getParentOp()) &&
2562+
!isa<DeviceOp>(acqBlockDefOp) && !erased);
2563+
if (!erased)
2564+
++relOp;
2565+
}
25672566

2568-
// track indices of elements to acquire
2569-
std::vector<int> acquiredIndices;
2570-
if (!acquiresPerFifo[{op, portNum}].empty()) {
2571-
// take into account what has already been acquired by previous
2572-
// AcquireOp in program order
2573-
acquiredIndices = acquiresPerFifo[{op, portNum}];
2574-
// take into account what has been released in-between
2575-
if (static_cast<size_t>(numRel) > acquiredIndices.size()) {
2576-
acquireOp->emitOpError("cannot release more elements than are "
2577-
"already acquired");
2578-
return WalkResult::interrupt();
2567+
// track indices of elements to acquire
2568+
if (!acquiresPerFifo[{op, portNum}].empty()) {
2569+
// take into account what has already been acquired by previous
2570+
// AcquireOp in program order
2571+
acquiredIndices = acquiresPerFifo[{op, portNum}];
2572+
// take into account what has been released in-between
2573+
if (static_cast<size_t>(numRel) > acquiredIndices.size()) {
2574+
acquireOp->emitOpError("cannot release more elements than are "
2575+
"already acquired");
2576+
return WalkResult::interrupt();
2577+
}
2578+
for (int i = 0; i < numRel; i++)
2579+
acquiredIndices.erase(acquiredIndices.begin());
25792580
}
2580-
for (int i = 0; i < numRel; i++)
2581-
acquiredIndices.erase(acquiredIndices.begin());
2582-
}
25832581

2584-
// acquire locks
2585-
int numLocks = acquireOp.acqNumber();
2586-
int alreadyAcq = acquiredIndices.size();
2587-
int numCreate;
2588-
if (numLocks > alreadyAcq)
2589-
numCreate = numLocks - alreadyAcq;
2590-
else
2591-
numCreate = 0;
2582+
// acquire locks
2583+
int numLocks = acquireOp.acqNumber();
2584+
int alreadyAcq = acquiredIndices.size();
2585+
int numCreate;
2586+
if (numLocks > alreadyAcq)
2587+
numCreate = numLocks - alreadyAcq;
2588+
else
2589+
numCreate = 0;
25922590

2593-
// account for repetition
2594-
if (op.getRepeatCount().has_value())
2595-
numCreate *= op.getRepeatCount().value();
2591+
// account for repetition
2592+
if (op.getRepeatCount().has_value())
2593+
numCreate *= op.getRepeatCount().value();
25962594

2597-
auto dev = op->getParentOfType<DeviceOp>();
2598-
if (auto &targetArch = dev.getTargetModel();
2599-
targetArch.getTargetArch() == AIEArch::AIE1)
2600-
createUseLocks(builder, op, port, acqPerFifo, numCreate,
2601-
LockAction::Acquire, state);
2602-
else
2603-
createUseLocks(builder, op, port, acqPerFifo, numCreate,
2604-
LockAction::AcquireGreaterEqual, state);
2595+
auto dev = op->getParentOfType<DeviceOp>();
2596+
if (auto &targetArch = dev.getTargetModel();
2597+
targetArch.getTargetArch() == AIEArch::AIE1)
2598+
createUseLocks(builder, op, port, acqPerFifo, numCreate,
2599+
LockAction::Acquire, state);
2600+
else
2601+
createUseLocks(builder, op, port, acqPerFifo, numCreate,
2602+
LockAction::AcquireGreaterEqual, state);
26052603

2606-
// create subview: buffers that were already acquired + new acquires
2607-
for (int i = 0; i < numCreate; i++) {
2608-
acquiredIndices.push_back(start);
2609-
start = (start + 1) % op.size();
2604+
// create subview: buffers that were already acquired + new acquires
2605+
for (int i = 0; i < numCreate; i++) {
2606+
acquiredIndices.push_back(start);
2607+
start = (start + 1) % op.size();
2608+
}
2609+
acquiresPerFifo[{op, portNum}] = acquiredIndices;
26102610
}
2611+
2612+
// Build the subview buffer references shared by both paths (see note
2613+
// above). For size > 1 dynamic fifos these are dead because the
2614+
// accesses were already rewired by dynamicGlobalObjectFifos.
26112615
std::vector<BufferOp *> subviewRefs;
26122616
subviewRefs.reserve(acquiredIndices.size());
26132617
for (auto index : acquiredIndices)
26142618
subviewRefs.push_back(&state.buffersPerFifo[target][index]);
2615-
26162619
subviews[acquireOp] = subviewRefs;
2617-
acquiresPerFifo[{op, portNum}] = acquiredIndices;
26182620

26192621
return WalkResult::advance();
26202622
});

0 commit comments

Comments
 (0)