Skip to content

Commit

Permalink
Merge pull request #98 from Xilinx/corentin.kernel_unnamed_str_params
Browse files Browse the repository at this point in the history
[FXML-5060] Kernel op: Amend instantiation args parser to support unnamed strings
  • Loading branch information
cferry-AMD authored Oct 7, 2024
2 parents 8f42383 + 94d1a00 commit 780aeae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/Dialect/XTenNN/IR/XTenNNOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ static ParseResult parseKernelInstantiationArgs(OpAsmParser &p,
if (failed(p.parseCommaSeparatedList([&p, &names, &values]() {
std::string name;
if (succeeded(p.parseOptionalString(&name))) {
if (failed(p.parseOptionalEqual())) {
// This is an unnamed string parameter (e.g. class name).
values.push_back(StringAttr::get(p.getContext(), name));
return success();
}
names.push_back(StringAttr::get(p.getContext(), name));
if (failed(p.parseEqual()))
return failure();
}
Attribute attr;
auto res = p.parseOptionalAttribute(attr);
Expand Down
4 changes: 4 additions & 0 deletions test/Dialect/XTenNN/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func.func @kernel(%arg0: tensor<2xi64>, %arg1 : tensor<4xi64>) {
// CHECK: xten_nn.kernel "matmul" (%arg0 : tensor<2xi64>) instantiation_args [42 : i32, 56 : index] {attr = 4 : i32} -> tensor<2xi64>
%g = xten_nn.kernel "matmul" (%arg0 : tensor<2xi64>) instantiation_args [42, 56, 1.0] {attr = 4 : i32} -> tensor<2xi64>
// CHECK: xten_nn.kernel "matmul" (%arg0 : tensor<2xi64>) instantiation_args [42 : i64, 56 : i64, 1.000000e+00 : f64] {attr = 4 : i32} -> tensor<2xi64>
%h = xten_nn.kernel "readInput" (%arg0 : tensor<2xi64>) instantiation_args ["type" = "double", "length" = 42 : i64] {attr = 4 : i32} -> tensor<2xi64>
// CHECK: xten_nn.kernel "readInput" (%arg0 : tensor<2xi64>) instantiation_args ["type" = "double", "length" = 42 : i64] {attr = 4 : i32} -> tensor<2xi64>
%i = xten_nn.kernel "readInput" (%arg0 : tensor<2xi64>) instantiation_args ["double", 42 : i64] {attr = 4 : i32} -> tensor<2xi64>
// CHECK: xten_nn.kernel "readInput" (%arg0 : tensor<2xi64>) instantiation_args ["double", 42 : i64] {attr = 4 : i32} -> tensor<2xi64>
return
}

Expand Down

0 comments on commit 780aeae

Please sign in to comment.