This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][python bindings] TypeCasters for Attributes
ClosedPublic

Authored by makslevental on May 31 2023, 1:52 PM.

Details

Summary

This diff adds casting for Attributes similar to that of Types.

Diff Detail

Event Timeline

makslevental created this revision.May 31 2023, 1:52 PM
Herald added a project: Restricted Project. · View Herald Transcript

add DenseArray and DenseIntOrFPElements support

remove .operator std::string()

makslevental published this revision for review.Jun 5 2023, 2:42 PM
makslevental edited the summary of this revision. (Show Details)Jun 5 2023, 2:43 PM
makslevental added a reviewer: rkayaith.

remove cruft

add BoolAttr

restore static_typeid on IntegerAttr

increase use-case coverage and add support for mlir_attribute_subclass

update tests

clean up and repr for mlir_attribute_subclass

a few more tests

mlir/lib/Bindings/Python/IRAttributes.cpp
417

maybe a comment here explaining why getTypeIdFunction isn't used?

mlir/lib/Bindings/Python/IRCore.cpp
3195–3198

can this ever happen? below it's just an assert

mlir/test/python/ir/builtin_types.py
404–408 ↗(On Diff #528682)

returning None here might be a better API? I don't have any strong opinion, but it'd be more consistent with PyRankedTensorType.encoding as well

makslevental marked 2 inline comments as done.

update comments

mlir/lib/Bindings/Python/IRCore.cpp
3195–3198

if you get to the caster then you definitely have a typeid (otherwise there wouldn't have been a match for a/some key in the typecaster densemap) but here you might be able to call typeid on some strange attribute.

makslevental added inline comments.Jun 6 2023, 8:13 PM
mlir/include/mlir/Bindings/Python/PybindAdaptors.h
418–419

just wanted to point out how descriptive this comment string is 😂

rkayaith accepted this revision.Jun 7 2023, 8:47 AM
rkayaith added inline comments.
mlir/lib/Bindings/Python/IRCore.cpp
3195–3198

here you might be able to call typeid on some strange attribute.

Only case I can think of is if you called mlirAttributeGetTypeID on a null attribute, but in that case it looks like the call would crash instead of returning a null TypeID

This revision is now accepted and ready to land.Jun 7 2023, 8:47 AM

change exception to assert

makslevental marked 2 inline comments as done.Jun 7 2023, 9:19 AM
makslevental added inline comments.
mlir/lib/Bindings/Python/IRCore.cpp
3195–3198

i double checked and right you are - it segfaults. so i did as you imply and changed to an assert.

This revision was automatically updated to reflect the committed changes.
makslevental marked an inline comment as done.