Skip to content

Commit 4cc4704

Browse files
authored
[IR] Add keep_pkt_header attribute to amdaie.flow (#1338)
It was previously existing in aie.flow only.
1 parent 1447eb5 commit 4cc4704

File tree

7 files changed

+61
-5
lines changed

7 files changed

+61
-5
lines changed

compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,13 @@ LogicalResult FlowOp::verify() {
563563
return emitOpError()
564564
<< "multiple source and multiple targets is unsupported";
565565
}
566+
567+
if (!getIsPacketFlow() && getPacketId().has_value())
568+
return emitOpError() << "packet ID can only be set for packet flows";
569+
570+
if (!getIsPacketFlow() && getKeepPktHeader().value_or(false))
571+
return emitOpError() << "keep_pkt_header can only be set for packet flows";
572+
566573
return success();
567574
}
568575

compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/AMDAIEOps.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,16 @@ def AMDAIE_FlowOp: AMDAIE_Op<"flow", [AttrSizedOperandSegments]>,
132132
%channel_1 = amdaie.channel(%tile_0_1, 0, port_type = DMA)
133133
%channel_2 = amdaie.channel(%tile_1_1, 0, port_type = DMA)
134134
%0 = amdaie.flow({%channel} -> {%channel_1, %channel_2})
135-
{is_packet_flow = true, packet_id = 0 : ui8}
135+
{is_packet_flow = true, keep_pkt_header = true, packet_id = 0 : ui8}
136136
```
137137
}];
138138

139139
let arguments = (
140140
ins Variadic<Index>:$sources,
141141
Variadic<Index>:$targets,
142142
BoolAttr:$is_packet_flow,
143-
OptionalAttr<UI8Attr>:$packet_id
143+
OptionalAttr<UI8Attr>:$packet_id,
144+
OptionalAttr<BoolAttr>:$keep_pkt_header
144145
);
145146

146147
let assemblyFormat = [{ `(` `{` $sources `}` `->` `{` $targets `}` `)` attr-dict }];

compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/test/invalid.mlir

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,50 @@ func.func @dma_cpy_nd_negative_source_stride(%arg0: !amdaie.logicalobjectfifo<me
320320

321321
// -----
322322

323+
func.func @flow_multi_sources_and_targets() {
324+
%c0 = arith.constant 0 : index
325+
%c1 = arith.constant 1 : index
326+
%tile_0_0 = amdaie.tile(%c0, %c0)
327+
%tile_0_1 = amdaie.tile(%c0, %c1)
328+
%channel = amdaie.channel(%tile_0_0, 0, port_type = DMA, direction = MM2S)
329+
%channel_1 = amdaie.channel(%tile_0_0, 1, port_type = DMA, direction = MM2S)
330+
%channel_2 = amdaie.channel(%tile_0_1, 0, port_type = DMA, direction = S2MM)
331+
%channel_3 = amdaie.channel(%tile_0_1, 1, port_type = DMA, direction = S2MM)
332+
// expected-error @+1 {{multiple source and multiple targets is unsupported}}
333+
%0 = amdaie.flow({%channel, %channel_1} -> {%channel_2, %channel_3}) {is_packet_flow = true}
334+
return
335+
}
336+
337+
// -----
338+
339+
func.func @flow_invalid_packet_id() {
340+
%c0 = arith.constant 0 : index
341+
%c1 = arith.constant 1 : index
342+
%tile_0_0 = amdaie.tile(%c0, %c0)
343+
%tile_0_1 = amdaie.tile(%c0, %c1)
344+
%channel = amdaie.channel(%tile_0_0, 0, port_type = DMA, direction = MM2S)
345+
%channel_1 = amdaie.channel(%tile_0_1, 0, port_type = DMA, direction = S2MM)
346+
// expected-error @+1 {{packet ID can only be set for packet flows}}
347+
%0 = amdaie.flow({%channel} -> {%channel_1}) {is_packet_flow = false, packet_id = 0 : ui8}
348+
return
349+
}
350+
351+
// -----
352+
353+
func.func @flow_invalid_keep_pkt_header() {
354+
%c0 = arith.constant 0 : index
355+
%c1 = arith.constant 1 : index
356+
%tile_0_0 = amdaie.tile(%c0, %c0)
357+
%tile_0_1 = amdaie.tile(%c0, %c1)
358+
%channel = amdaie.channel(%tile_0_0, 0, port_type = DMA, direction = MM2S)
359+
%channel_1 = amdaie.channel(%tile_0_1, 0, port_type = DMA, direction = S2MM)
360+
// expected-error @+1 {{keep_pkt_header can only be set for packet flows}}
361+
%0 = amdaie.flow({%channel} -> {%channel_1}) {is_packet_flow = false, keep_pkt_header = true}
362+
return
363+
}
364+
365+
// -----
366+
323367
func.func @npu_dma_cpy_nd_invalid_src_offsets() {
324368
%c0 = arith.constant 0 : index
325369
%c1 = arith.constant 1 : index

compiler/plugins/target/AMD-AIE/iree-amd-aie/IR/test/roundtrip.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func.func @dma_cpy_nd_mixed(%arg0: !amdaie.logicalobjectfifo<memref<1x1x8x16xi32
158158
// CHECK: %[[CHANNEL_1:.*]] = amdaie.channel(%[[TILE_0_1]], 0, port_type = DMA, direction = S2MM)
159159
// CHECK: amdaie.flow({%[[CHANNEL]]} -> {%[[CHANNEL_1]]}) {is_packet_flow = false}
160160
// CHECK: amdaie.flow({%[[CHANNEL]]} -> {%[[CHANNEL_1]]}) {is_packet_flow = true, packet_id = 1 : ui8}
161+
// CHECK: amdaie.flow({%[[CHANNEL]]} -> {%[[CHANNEL_1]]}) {is_packet_flow = true, keep_pkt_header = true, packet_id = 2 : ui8}
161162
func.func @flow() {
162163
%c0 = arith.constant 0 : index
163164
%c1 = arith.constant 1 : index
@@ -167,6 +168,7 @@ func.func @flow() {
167168
%channel_1 = amdaie.channel(%tile_0_1, 0, port_type = DMA, direction = S2MM)
168169
%0 = amdaie.flow({%channel} -> {%channel_1}) {is_packet_flow = false}
169170
%1 = amdaie.flow({%channel} -> {%channel_1}) {is_packet_flow = true, packet_id = 1 : ui8}
171+
%2 = amdaie.flow({%channel} -> {%channel_1}) {is_packet_flow = true, keep_pkt_header = true, packet_id = 2 : ui8}
170172
return
171173
}
172174

compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/AMDAIEAssignPacketIds.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void AMDAIEAssignPacketIdsPass::runOnOperation() {
8383
rewriter.setInsertionPoint(flowOp);
8484
rewriter.replaceOpWithNewOp<AMDAIE::FlowOp>(
8585
flowOp, flowOp.getSources(), flowOp.getTargets(),
86-
flowOp.getIsPacketFlow(), pktIdAttr);
86+
flowOp.getIsPacketFlow(), pktIdAttr, /*keepPktHeader=*/nullptr);
8787
channelToPktFlowIndex[sourceChannelOp]++;
8888
}
8989
}

compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/AMDAIEConnectionToFlow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void AMDAIEConnectionToFlowPass::runOnOperation() {
3737
AMDAIE::ConnectionType::Packet;
3838
auto flowOp = rewriter.create<AMDAIE::FlowOp>(
3939
rewriter.getUnknownLoc(), connectionOp.getSourceChannels(),
40-
connectionOp.getTargetChannels(), isPacketFlow, /*packetId*/ nullptr);
40+
connectionOp.getTargetChannels(), isPacketFlow, /*packetId=*/nullptr,
41+
/*keepPktHeader=*/nullptr);
4142
rewriter.replaceOpWithNewOp<AMDAIE::ConnectionOp>(
4243
connectionOp, connectionOp.getTarget(),
4344
connectionOp.getTargetChannels(), connectionOp.getSource(),

compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/AMDAIELowerToAIE.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ SmallVector<Operation *> AIEDeviceBuilder::createFlowOps(
206206
if (pktId) {
207207
OpBuilder::InsertionGuard gg(rewriter);
208208
AIE::PacketFlowOp pktFlow = rewriter.create<AIE::PacketFlowOp>(
209-
rewriter.getUnknownLoc(), pktId.value(), nullptr, nullptr);
209+
rewriter.getUnknownLoc(), pktId.value(),
210+
flowOp.getKeepPktHeaderAttr(), /*priority_route=*/nullptr);
210211
Region &r_pktFlow = pktFlow.getPorts();
211212
Block *b_pktFlow = rewriter.createBlock(&r_pktFlow);
212213
rewriter.setInsertionPointToStart(b_pktFlow);

0 commit comments

Comments
 (0)