This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Vector] Support 0-D vectors in `ConstantMaskOp`
ClosedPublic

Authored by michalt on Dec 2 2021, 10:29 PM.

Details

Summary

To support creating both a mask with just a single true and false values,
I had to relax the restriction in the verifier that the rank is always equal to
the length of the attribute array, in other words, we now allow:

  • vector.constant_mask [0] : vector<i1> which gets lowered to arith.constant dense<false> : vector<i1>
  • vector.constant_mask [1] : vector<i1> which gets lowered to arith.constant dense<true> : vector<i1>

(the attribute list for the 0-D case must be a singleton containing
either 0 or 1)

Diff Detail

Event Timeline

michalt created this revision.Dec 2 2021, 10:29 PM
michalt requested review of this revision.Dec 2 2021, 10:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2021, 10:29 PM
nicolasvasilache accepted this revision.Dec 2 2021, 11:44 PM

LGTM, modulo the extension of BuiltinTypes that I would just drop unless @rriddle wants it in.
Accepting conditioned on that being dropped or River weighing in positively, whichever comes first.

mlir/include/mlir/IR/Builders.h
124 ↗(On Diff #391549)

I think this is too confusing to put in Builders.h and I would just avoid it.
It is also inconsistent, al APIs would have to be updated.

At the very minimum I'd spell it getZeroDimBoolVectorAttr(bool value) but I think @rriddle wouldn't buy it, never hurts to ask though.

Spelling it explicitly at use the corner-case use sites is better IMO.

mlir/lib/Dialect/Vector/VectorTransforms.cpp
970

Would this work ?

bool value = ... ;
 rewriter.replaceOpWithNewOp<arith::ConstantOp>(
op, dstType, VectorType::get(ArrayRef<int64_t>{}, rewriter.getI1Type()), value));

(not sure whether bool -> ArrayRef<bool> is automatic, you may need ArrayRef<bool>{value})

This revision is now accepted and ready to land.Dec 2 2021, 11:44 PM
michalt updated this revision to Diff 391889.Dec 4 2021, 10:44 PM
michalt marked 2 inline comments as done.

Address review comments

mlir/include/mlir/IR/Builders.h
124 ↗(On Diff #391549)

Yeah, I agree: creating it at the use site looks better. Thanks! :)

mlir/lib/Dialect/Vector/VectorTransforms.cpp
970

That looks way better too :D
(but I did need the ArrayRef<bool> to make it work)

nicolasvasilache accepted this revision.Dec 5 2021, 11:57 PM

Thanks for your contribution @michalt !

This revision was automatically updated to reflect the committed changes.