This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Add TensorFromElementsOp to Standard ops.
ClosedPublic

Authored by pifon2a on May 28 2020, 2:53 AM.

Details

Summary

Adds an operation that can create a 1D tensor from a list of values.

Diff Detail

Event Timeline

pifon2a created this revision.May 28 2020, 2:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 28 2020, 2:53 AM

Thanks for cleaning this up!

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
1532

Maybe use SameOperandsAndResultElementType?

1556

Would let assemblyFormat = "( $elements ) attr-dict : type($result)"; work?

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
1713

Remove extra '{' '}'.

pifon2a updated this revision to Diff 266813.May 28 2020, 4:37 AM
pifon2a marked 4 inline comments as done.

Address the comments.

herhut accepted this revision.May 28 2020, 6:10 AM

Thanks.

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
1556

Answer is, it does not because the operand types cannot be deduced with the given traits.

This revision is now accepted and ready to land.May 28 2020, 6:10 AM
pifon2a marked an inline comment as not done.May 28 2020, 6:25 AM
pifon2a added inline comments.
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
1532

Thanks, that's a new trait and a useful one. didn't know about it.

1556

no, it wouldn't. It would need to know the elements type to parse it. Can I use assemblyFormat for printing only and a custom parser?

This revision was automatically updated to reflect the committed changes.
pifon2a marked an inline comment as done.May 28 2020, 3:10 PM
pifon2a added inline comments.
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
1556

I might be doing smth wrong, but if i have the following op:

mlir
def TensorFromElementsOp : Std_Op<"tensor_from_elements",
    [NoSideEffect, SameOperandsAndResultElementType,
     TypesMatchWith<"value type matches element type of memref",
                    "result", "elements",
                    "$_self.cast<RankedTensorType>().getElementType()">
    ]> {

  let arguments = (ins Variadic<AnyType>:$elements);
  let results = (outs AnyTensor:$result);

  let assemblyFormat = "`(` $elements `)` attr-dict `:` type($result)";
}

then the operands will be resolved with a wrong resolveOperands overload. It should use

ParseResult resolveOperands(ArrayRef<OperandType> operands, Type type,
                            SmallVectorImpl<Value> &result)

instead of

ParseResult resolveOperands(ArrayRef<OperandType> operands,
                              ArrayRef<Type> types, llvm::SMLoc loc,
                              SmallVectorImpl<Value> &result)