This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add Float Attribute, Integer Attribute and Bool Attribute subclasses to python bindings.
ClosedPublic

Authored by zhanghb97 on Sep 29 2020, 11:23 PM.

Details

Summary

Based on PyAttribute and PyConcreteAttribute classes, this patch implements the bindings of Float Attribute, Integer Attribute and Bool Attribute subclasses.
This patch also defines the mlirFloatAttrDoubleGetChecked C API which is bound with the FloatAttr.get python method.

Diff Detail

Event Timeline

zhanghb97 created this revision.Sep 29 2020, 11:23 PM
zhanghb97 requested review of this revision.Sep 29 2020, 11:23 PM
stellaraccident accepted this revision.Sep 30 2020, 8:04 AM

Thanks!

mlir/include/mlir-c/StandardAttributes.h
97

Can you change this to something like: "if the type is not valid for a construction of a FloatAttr, returns a null MlirAttribute."

mlir/lib/Bindings/Python/IRModules.cpp
753

It is common enough that I feel we would benefit from a get_f32 and get_f64 that do not take a type and do not fail.

754

Maybe drop the _typed suffix?

789

Ditto on just get

815

Change the c++ type to bool. (Aside from being more correct, that will trigger important conversion rules on the python side for "truthy" value).

mlir/test/Bindings/Python/ir_attributes.py
143

Test with True, not 1

This revision is now accepted and ready to land.Sep 30 2020, 8:04 AM
zhanghb97 added inline comments.Oct 1 2020, 1:51 AM
mlir/lib/Bindings/Python/IRModules.cpp
753

I'd like to confirm that if we give the get_f32 and get_f64 methods, then what about the f16 and bf16 float type, and do we still need to give the default get method (It seems that get_f32, get_f64, get_f16, get_bf16 can cover all the usage)?

zhanghb97 updated this revision to Diff 295757.Oct 2 2020, 1:47 AM
zhanghb97 marked 6 inline comments as done.
zhanghb97 edited the summary of this revision. (Show Details)
  • Modify the comment for mlirFloatAttrDoubleGetChecked.
  • Drop the _typed suffix for FloatAttr and IntegerAttr get methods.
  • Change the parameter type of BoolAttr.get method to bool.
  • Add get_f32 and get_f64 methods to FloatAttr.
This revision was landed with ongoing or failed builds.Oct 2 2020, 9:34 AM
This revision was automatically updated to reflect the committed changes.