Skip to content

Commit 12e87fc

Browse files
James Molloycopybara-github
authored andcommitted
[xls][mlir] Support FifoConfig and FlopKinds on top-level Sprocs/Eprocs
Modifies the boundary_channel_names attribute from an array of strings to an array of #xls.boundary_channel, which contains the name but also FifoConfig and FlopKind. PiperOrigin-RevId: 812789063
1 parent 58a5340 commit 12e87fc

File tree

6 files changed

+49
-23
lines changed

6 files changed

+49
-23
lines changed

xls/contrib/mlir/IR/xls_ops.td

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,24 @@ def Xls_FifoConfig : Xls_Attr<"FifoConfig"> {
203203
let assemblyFormat = "`<` struct(params) `>`";
204204
}
205205

206+
def Xls_BoundaryChannelAttr : Xls_Attr<"BoundaryChannelAttr"> {
207+
let summary = "Boundary channel attribute";
208+
let description = [{
209+
Contains attributes associated with boundary channels for SprocOps.
210+
}];
211+
let parameters = (ins
212+
"::mlir::StringAttr":$name,
213+
OptionalParameter<"FifoConfig", "">:$fifo_config,
214+
OptionalParameter<"FlopKindAttr", "">:$input_flop_kind,
215+
OptionalParameter<"FlopKindAttr", "">:$output_flop_kind
216+
);
217+
let mnemonic = "boundary_channel";
218+
let assemblyFormat = "`<` struct(params) `>`";
219+
}
220+
221+
def Xls_BoundaryChannelArrayAttr :
222+
TypedArrayAttrBase<Xls_BoundaryChannelAttr, "array of boundary_channel">;
223+
206224
class GetShapeSplat<string name> :
207225
StrFunc<"getShapeSplat($" # name # ".getType())">;
208226

@@ -1874,9 +1892,8 @@ def Xls_SprocOp : Xls_Op<"sproc", [
18741892
region contains Schan declarations and "spawns" of other Sprocs. The only way
18751893
to create an Sproc is to spawn another Sproc.
18761894

1877-
Sprocs may be marked as "top" if they EITHER:
1878-
a) Have no channels.
1879-
b) Have the optional `boundary_channel_names` attribute set.
1895+
Sprocs may be marked as "top" if they populate the `boundary_channels`
1896+
list per argument.
18801897

18811898
In the latter case, boundary channels (used by XLS for tests etc) are
18821899
created with the given names.
@@ -1926,7 +1943,7 @@ def Xls_SprocOp : Xls_Op<"sproc", [
19261943
let arguments = (ins
19271944
SymbolNameAttr:$sym_name,
19281945
BoolAttr:$is_top,
1929-
OptionalAttr<ArrayAttr>:$boundary_channel_names,
1946+
OptionalAttr<Xls_BoundaryChannelArrayAttr>:$boundary_channels,
19301947
DefaultValuedAttr<I64Attr, "1">:$min_pipeline_stages
19311948
);
19321949
let regions = (region

xls/contrib/mlir/testdata/extract_as_top_level_module.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module attributes {test.name = "sproc"} {
8080
// CHECK-NOT: func @nope
8181
// CHECK: xls.sproc @leaf
8282
// CHECK-NOT: xls.sproc @unrelated
83-
// CHECK: xls.sproc @sproc(%arg0: !xls.schan<i32, in>) top attributes {boundary_channel_names = ["arg0"]}
83+
// CHECK: xls.sproc @sproc(%arg0: !xls.schan<i32, in>) top attributes {boundary_channels = [#xls.boundary_channel<name = "arg0">]}
8484
func.func @nope(%arg0: !xls.token, %arg1: i32, %arg2: i1) ->i32 {
8585
%0 = arith.constant 1 : i32
8686
return %0 : i32

xls/contrib/mlir/testdata/ops.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func.func @not(%arg0: tensor<32xi8>) -> tensor<32xi8> {
1313
%0 = xls.not %arg0 : tensor<32xi8>
1414
return %0 : tensor<32xi8>
1515
}
16-
16+
1717
// CHECK-LABEL: func @and
1818
func.func @and(%arg0: tensor<32xi8>, %arg1: tensor<32xi8>) -> tensor<32xi8> {
1919
// CHECK: xls.and %arg0, %arg1

xls/contrib/mlir/testdata/proc_elaboration.mlir

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
// CHECK-NEXT: xls.chan @fetch_arg0 : i32
3939
// CHECK-NEXT: xls.chan @fetch_arg1 : i32
4040
// CHECK-NEXT: xls.instantiate_eproc @fetch (@fetch_arg0 as @req, @fetch_arg1 as @resp)
41-
// CHECK-NEXT: xls.chan @boundary1 {send_supported = false} : i32
41+
// CHECK-NEXT: xls.chan @boundary1 {fifo_config = #xls.fifo_config<fifo_depth = 1, bypass = true, register_push_outputs = true, register_pop_outputs = false>, input_flop_kind = #xls<flop_kind skid>, send_supported = false} : i32
4242
// CHECK-NEXT: xls.chan @boundary2 {recv_supported = false} : i32
4343
// CHECK-NEXT: xls.instantiate_eproc @rom (@rom_arg0 as @boundary1, @rom_arg1 as @boundary2)
4444

@@ -77,7 +77,10 @@ xls.sproc @proxy(%req: !xls.schan<i32, in>, %resp: !xls.schan<i32, out>) attribu
7777
}
7878
}
7979

80-
xls.sproc @rom(%req: !xls.schan<i32, in>, %resp: !xls.schan<i32, out>) top attributes {boundary_channel_names = ["boundary1", "boundary2"]} {
80+
xls.sproc @rom(%req: !xls.schan<i32, in>, %resp: !xls.schan<i32, out>) top attributes {boundary_channels = [
81+
#xls.boundary_channel<name = "boundary1", fifo_config = #xls.fifo_config<fifo_depth = 1, bypass = true, register_push_outputs = true, register_pop_outputs = false>, input_flop_kind = #xls<flop_kind skid>>,
82+
#xls.boundary_channel<name = "boundary2">
83+
]} {
8184
spawns {
8285
xls.yield %req, %resp : !xls.schan<i32, in>, !xls.schan<i32, out>
8386
}
@@ -144,7 +147,9 @@ module {
144147
xls.yield %0 : index
145148
}
146149
}
147-
xls.sproc @some_wrapped_machine(%arg0: !xls.schan<tensor<i32>, in>, %arg1: !xls.schan<tensor<i32>, out>, %arg2: !xls.schan<tensor<i32>, out>) top attributes {boundary_channel_names = ["x['y']", "x['y']1", "x['y']2"]} {
150+
xls.sproc @some_wrapped_machine(%arg0: !xls.schan<tensor<i32>, in>, %arg1: !xls.schan<tensor<i32>, out>, %arg2: !xls.schan<tensor<i32>, out>) top attributes {
151+
boundary_channels = [#xls.boundary_channel<name = "x['y']">, #xls.boundary_channel<name = "x['y']1">, #xls.boundary_channel<name = "x['y']2">]
152+
} {
148153
spawns {
149154
%out, %in = xls.schan<tensor<i32>>("x['y']")
150155
%out_0, %in_1 = xls.schan<tensor<i32>>("x['y']")

xls/contrib/mlir/transforms/proc_elaboration.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,19 @@ void ProcElaborationPass::runOnOperation() {
323323

324324
OpBuilder builder(sproc);
325325
SmallVector<ChanOp> boundaryChannels;
326-
if (sproc.getBoundaryChannelNames().has_value()) {
327-
for (auto [arg, name] : llvm::zip(sproc.getChannelArguments(),
328-
*sproc.getBoundaryChannelNames())) {
326+
if (sproc.getBoundaryChannels().has_value()) {
327+
for (auto [arg, boundaryChannelAttr] : llvm::zip(
328+
sproc.getChannelArguments(), *sproc.getBoundaryChannels())) {
329329
SchanType schan = cast<SchanType>(arg.getType());
330-
auto nameAttr = cast<StringAttr>(name);
330+
auto boundaryChannel = cast<BoundaryChannelAttr>(boundaryChannelAttr);
331+
auto nameAttr = boundaryChannel.getName();
331332
// TODO(jpienaar): Remove unnecessary default args once they are
332333
// generated automatically.
333-
auto echan = ChanOp::create(builder, sproc.getLoc(), nameAttr.str(),
334-
schan.getElementType(),
335-
/*fifo_config=*/nullptr,
336-
/*input_flop_kind=*/nullptr,
337-
/*output_flop_kind=*/nullptr);
334+
auto echan = ChanOp::create(
335+
builder, sproc.getLoc(), boundaryChannel.getName(),
336+
schan.getElementType(), boundaryChannel.getFifoConfig(),
337+
boundaryChannel.getInputFlopKind(),
338+
boundaryChannel.getOutputFlopKind());
338339
// We insert the channel in the symbol table, since there might be
339340
// a clash with an *eproc* name later, so we need to know. Alternatively
340341
// we could have done something similar in the constructor of the

xls/contrib/mlir/util/extraction_utils.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,19 @@ void addBoundaryChannelNames(
137137
};
138138
}
139139

140-
if (op.getBoundaryChannelNames().has_value()) {
140+
if (op.getBoundaryChannels().has_value()) {
141141
return;
142142
}
143143
::mlir::OpBuilder builder(op.getOperation());
144-
::mlir::SmallVector<::mlir::Attribute> boundaryChannelNames;
144+
::mlir::SmallVector<::mlir::Attribute> boundaryChannels;
145145
for (Value value : op.getChannelArguments()) {
146-
boundaryChannelNames.push_back(
147-
builder.getStringAttr(boundaryChannelName(cast<BlockArgument>(value))));
146+
BoundaryChannelAttr boundaryChannel = BoundaryChannelAttr::get(
147+
builder.getContext(),
148+
builder.getStringAttr(boundaryChannelName(cast<BlockArgument>(value))),
149+
FifoConfig(), FlopKindAttr(), FlopKindAttr());
150+
boundaryChannels.push_back(boundaryChannel);
148151
}
149-
op.setBoundaryChannelNamesAttr(builder.getArrayAttr(boundaryChannelNames));
152+
op.setBoundaryChannelsAttr(builder.getArrayAttr(boundaryChannels));
150153
}
151154
} // namespace
152155

0 commit comments

Comments
 (0)