Skip to content

Commit

Permalink
Faster (static) method to get unique id for creating global op (#1781)
Browse files Browse the repository at this point in the history
  • Loading branch information
erwei-xilinx authored Sep 19, 2024
1 parent 41fa0fc commit 51184e5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/Dialect/AIEX/Transforms/AIEDmaToNpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,13 @@ struct DmaWaitToSyncPattern : OpConversionPattern<NpuDmaWaitOp> {
struct WriteBdToBlockWritePattern : OpConversionPattern<NpuWriteBdOp> {
using OpConversionPattern::OpConversionPattern;

WriteBdToBlockWritePattern(MLIRContext *context, PatternBenefit benefit = 1)
: OpConversionPattern(context, benefit) {}
private:
int &cachedId;

public:
WriteBdToBlockWritePattern(MLIRContext *context, int &cachedId,
PatternBenefit benefit = 1)
: OpConversionPattern(context, benefit), cachedId(cachedId) {}

LogicalResult
matchAndRewrite(NpuWriteBdOp op, OpAdaptor adaptor,
Expand Down Expand Up @@ -634,10 +639,11 @@ struct WriteBdToBlockWritePattern : OpConversionPattern<NpuWriteBdOp> {
std::string name = "blockwrite_data_";
rewriter.setInsertionPoint(
op->getParentOfType<AIEX::RuntimeSequenceOp>());
int id = 0;
int id = cachedId;
while (dev.lookupSymbol(name + std::to_string(id)))
id++;
name += std::to_string(id);
cachedId = id;
global = rewriter.create<memref::GlobalOp>(
op->getLoc(), name, rewriter.getStringAttr("private"), memrefType,
DenseElementsAttr::get<uint32_t>(tensorType, words), true, nullptr);
Expand Down Expand Up @@ -689,7 +695,8 @@ struct AIEDmaToNpuPass : AIEDmaToNpuBase<AIEDmaToNpuPass> {
patterns.insert<PushQueuetoWrite32Pattern>(&getContext());
patterns.insert<RtpToWrite32Pattern>(&getContext());
patterns.insert<Write32SymToAddr>(&getContext());
patterns.insert<WriteBdToBlockWritePattern>(&getContext());
int cachedId = 0;
patterns.insert<WriteBdToBlockWritePattern>(&getContext(), cachedId);

if (failed(applyPartialConversion(device, target, std::move(patterns))))
signalPassFailure();
Expand Down

0 comments on commit 51184e5

Please sign in to comment.