Skip to content

Commit

Permalink
Bump mlir-aie to f85a4a974fd59c82c878656d2b1536b4c2e74453 (Xilinx#789)
Browse files Browse the repository at this point in the history
* Bump mlir-aie

* Switch to using hasProperty() method on AIE target devices

* Switch to using hasProperty() method on AIE target devices
  • Loading branch information
erwei-xilinx authored Nov 22, 2024
1 parent 8ed48b9 commit 3e46233
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
6 changes: 4 additions & 2 deletions mlir/lib/Conversion/AIRRtToNpuPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,12 +1557,14 @@ struct AIRRtToNpuPass : public impl::AIRRtToNpuBase<AIRRtToNpuPass> {
/*enable_packet*/ 1, /*out_of_order_id*/ 0,
/*packet_id*/ flowID, pkt_type,
/* d0_size */ 0, /* d0_stride */ 0, /* d1_size */ 0,
/* d1_stride */ 0, /* d2_stride */ 0,
/* d1_stride */ 0, /* d2_size */ 0, /* d2_stride */ 0,
/* iteration_current */ 0, /* iteration_size */ 0,
/* iteration_stride */ 0, /* next_bd */ 0, dstRowIndex,
/* use_next_bd */ 0,
/* valid_bd */ 1, /* lock_rel_val */ 0, /* lock_rel_id */ 0,
/* lock_acq_enable */ 0, /* lock_acq_val */ 0, /* lock_acq_id */ 0);
/* lock_acq_enable */ 0, /* lock_acq_val */ 0, /* lock_acq_id */ 0,
/* d0_zero_before*/ 0, /* d1_zero_before*/ 0, /* d2_zero_before*/ 0,
/* d0_zero_after*/ 0, /* d1_zero_after*/ 0, /* d2_zero_after*/ 0);
uint32_t addr = (dstColIndex << target_model.getColumnShift()) |
(0x1D004 + bdID * 0x20);
builder.create<AIEX::NpuAddressPatchOp>(builder.getUnknownLoc(), addr,
Expand Down
39 changes: 22 additions & 17 deletions mlir/lib/Conversion/AIRToAIEPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2583,7 +2583,8 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
std::unordered_set<Operation *> &allocs_to_remap,
const AIE::AIETargetModel &targetModel,
TileDMAAllocator &tileDmaAlloc, int x, int y) {
bool isAIE2 = isa<AIE::AIE2TargetModel>(targetModel);
bool UsesSemaphoreLocks =
targetModel.hasProperty(AIE::AIETargetModel::UsesSemaphoreLocks);
AIE::DMAChannel tile_channel =
tileDmaAlloc.lookupDMAAllocation(x, y, memcpyOpIf).dma_channel;
AIE::BufferOp bufferOp = tileDmaAlloc.getBuffer(BufferId, x, y, memcpyOpIf);
Expand All @@ -2596,12 +2597,12 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
Value alloc = nullptr;
auto tileInbound = isTileInbound(memcpyOpIf, (int)air::MemorySpace::L1);
if (tileInbound) {
lockAqValue = isAIE2 ? 1 : 1;
lockRelValue = isAIE2 ? 1 : 0;
lockAqValue = UsesSemaphoreLocks ? 1 : 1;
lockRelValue = UsesSemaphoreLocks ? 1 : 0;
alloc = memcpyOpIf.getDstMemref();
} else {
lockAqValue = isAIE2 ? 1 : 0;
lockRelValue = isAIE2 ? 1 : 1;
lockAqValue = UsesSemaphoreLocks ? 1 : 0;
lockRelValue = UsesSemaphoreLocks ? 1 : 1;
alloc = memcpyOpIf.getSrcMemref();
}

Expand All @@ -2619,8 +2620,9 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
builder.setInsertionPoint(memcpyOpIf);

builder.create<AIE::UseLockOp>(memcpyOpIf->getLoc(), acqLockOp,
isAIE2 ? AIE::LockAction::AcquireGreaterEqual
: AIE::LockAction::Acquire,
UsesSemaphoreLocks
? AIE::LockAction::AcquireGreaterEqual
: AIE::LockAction::Acquire,
lockAqValue);
// try to find a place to put the unlock. If there are deallocs,
// replace them with unlock. Otherwise, put them at the end.
Expand Down Expand Up @@ -2715,7 +2717,8 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
const AIE::AIETargetModel &targetModel, Block *bd,
air::MemcpyInterface memcpyOp, bufferOpTy bufferOp,
int chan) {
bool isAIE2 = isa<AIE::AIE2TargetModel>(targetModel);
bool UsesSemaphoreLocks =
targetModel.hasProperty(AIE::AIETargetModel::UsesSemaphoreLocks);
bool isMM2S = (dir == AIE::DMAChannelDir::MM2S);

auto b = OpBuilder::atBlockEnd(bd);
Expand All @@ -2726,11 +2729,11 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
int64_t lockRelValue = -1;
auto aie2LockVal = getLockValuePair(targetModel, bufferOp->getResult(0));
if (!isMM2S) {
lockAqValue = isAIE2 ? aie2LockVal.first : 0;
lockRelValue = isAIE2 ? aie2LockVal.first : 1;
lockAqValue = UsesSemaphoreLocks ? aie2LockVal.first : 0;
lockRelValue = UsesSemaphoreLocks ? aie2LockVal.first : 1;
} else {
lockAqValue = isAIE2 ? aie2LockVal.second : 1;
lockRelValue = isAIE2 ? aie2LockVal.second : 0;
lockAqValue = UsesSemaphoreLocks ? aie2LockVal.second : 1;
lockRelValue = UsesSemaphoreLocks ? aie2LockVal.second : 0;
}
auto ndcpy = cast<air::MemcpyInterface>(memcpyOp);

Expand Down Expand Up @@ -2763,8 +2766,9 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
Value length =
b.create<arith::ConstantIndexOp>(memcpyOp.getLoc(), len)->getResult(0);
b.create<AIE::UseLockOp>(loc, acqLockOp,
isAIE2 ? AIE::LockAction::AcquireGreaterEqual
: AIE::LockAction::Acquire,
UsesSemaphoreLocks
? AIE::LockAction::AcquireGreaterEqual
: AIE::LockAction::Acquire,
lockAqValue);

// Packet flow routing: get packet flow id.
Expand All @@ -2783,7 +2787,8 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
auto wraps_and_strides =
AIE::BDDimLayoutArrayAttr::get(ndcpy->getContext(), ArrayRef(dims));
bool useDefaultDataAccessPattern =
isAIE2 ? isDefaultDataAccessPattern(sizes, strides, memref) : true;
UsesSemaphoreLocks ? isDefaultDataAccessPattern(sizes, strides, memref)
: true;
AIE::DMABDOp aieDmaBdOp = nullptr;
if (wraps_and_strides.getValue().empty() || useDefaultDataAccessPattern)
aieDmaBdOp = b.create<AIE::DMABDOp>(
Expand Down Expand Up @@ -3318,7 +3323,7 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {

for (auto herd : herds) {
std::vector<Attribute> dma_allocations;
if (!device.getTargetModel().isNPU()) {
if (!device.getTargetModel().hasProperty(AIE::AIETargetModel::IsNPU)) {
// AIE1 dma metadata format
getDmaAllocationMetadata(builder, ctx, herd, shimDmaAlloc.s2mm_allocs,
AIE::DMAChannelDir::S2MM,
Expand Down Expand Up @@ -3354,7 +3359,7 @@ class AIRToAIEPass : public air::impl::AIRToAIEBase<AIRToAIEPass> {
}
for (auto seg : segs) {
std::vector<Attribute> dma_allocations;
if (!device.getTargetModel().isNPU()) {
if (!device.getTargetModel().hasProperty(AIE::AIETargetModel::IsNPU)) {
// AIE1 memtile dma metadata format
getDmaAllocationMetadata(builder, ctx, seg, shimDmaAlloc.mm2s_allocs,
AIE::DMAChannelDir::MM2S,
Expand Down
35 changes: 17 additions & 18 deletions mlir/lib/Conversion/AIRToAIESchedulingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ air::getWrapsAndStrides(SmallVector<Value> memcpy_sizes,
std::pair<int64_t, int64_t>
air::getLockValuePair(const AIE::AIETargetModel &targetModel,
Value buffer_memref) {
if (isa<AIE::AIE1TargetModel>(targetModel))
if (!targetModel.hasProperty(AIE::AIETargetModel::UsesSemaphoreLocks))
return std::make_pair(0, 0);

// Infer semaphore lock values using buffer op
Expand Down Expand Up @@ -264,7 +264,7 @@ air::getLockValuePair(const AIE::AIETargetModel &targetModel,
std::pair<int64_t, int64_t>
air::getLockValuePair(const AIE::AIETargetModel &targetModel,
Value buffer_memref, air::ChannelOp air_chan) {
if (isa<AIE::AIE1TargetModel>(targetModel))
if (!targetModel.hasProperty(AIE::AIETargetModel::UsesSemaphoreLocks))
return std::make_pair(0, 0);

if (!llvm::isa<MemRefType>(buffer_memref.getType()))
Expand Down Expand Up @@ -418,21 +418,10 @@ DMAAllocator::getLockForDMA(air::MemcpyInterface &memcpyOp, int col, int row,
air_chan = getChannelDeclarationThroughSymbol(air_chan_op);
}
const auto &target_model = device.getTargetModel();
bool isAIE2 = isa<AIE::AIE2TargetModel>(target_model);
bool isAIE1 = isa<AIE::AIE1TargetModel>(target_model);
bool UsesSemaphoreLocks =
target_model.hasProperty(AIE::AIETargetModel::UsesSemaphoreLocks);

if (isAIE1) {
for (size_t i = 0; i < lock_allocation_list.size(); i++) {
// If multiple bds reference the same buffer and DMA channel
if ((std::get<0>(lock_allocation_list[i]) == bufferOp) &&
(std::get<2>(lock_allocation_list[i]) == channel)) {
return {std::get<3>(lock_allocation_list[i]),
std::get<4>(lock_allocation_list[i])};
}
}
}

else if (isAIE2) {
if (UsesSemaphoreLocks) {
if (air_chan) {
// AIE2's semaphore locks may share by air.channels
for (size_t i = 0; i < lock_allocation_list.size(); i++) {
Expand Down Expand Up @@ -471,6 +460,15 @@ DMAAllocator::getLockForDMA(air::MemcpyInterface &memcpyOp, int col, int row,
}
}
}
} else {
for (size_t i = 0; i < lock_allocation_list.size(); i++) {
// If multiple bds reference the same buffer and DMA channel
if ((std::get<0>(lock_allocation_list[i]) == bufferOp) &&
(std::get<2>(lock_allocation_list[i]) == channel)) {
return {std::get<3>(lock_allocation_list[i]),
std::get<4>(lock_allocation_list[i])};
}
}
}
if (!bufferOp) {
memcpyOp->emitOpError(
Expand All @@ -487,7 +485,7 @@ DMAAllocator::getLockForDMA(air::MemcpyInterface &memcpyOp, int col, int row,

OpBuilder builder(bufferOp);
auto rlock = allocateLockOp(device, tile, 0);
auto wlock = isAIE2 ? allocateLockOp(device, tile, init) : rlock;
auto wlock = UsesSemaphoreLocks ? allocateLockOp(device, tile, init) : rlock;
lock_allocation_list.push_back({bufferOp, air_chan, channel, rlock, wlock});
return {rlock, wlock};
}
Expand Down Expand Up @@ -1042,7 +1040,8 @@ void air::simpleDMAChannelAllocation(
}

// If found item in vector, return index; else return -1.
template <typename T> int air::foundInVector(T item, std::vector<T> vec) {
template <typename T>
int air::foundInVector(T item, std::vector<T> vec) {
auto it = std::find(vec.begin(), vec.end(), item);
int index = it - vec.begin();
return index;
Expand Down
2 changes: 1 addition & 1 deletion utils/clone-mlir-aie.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
##===----------------------------------------------------------------------===##

export HASH=779bbd147cd4c934aa0728afa52b1bda076e28f6
export HASH=f85a4a974fd59c82c878656d2b1536b4c2e74453
target_dir=mlir-aie

if [[ ! -d $target_dir ]]; then
Expand Down

0 comments on commit 3e46233

Please sign in to comment.