This is an archive of the discontinued LLVM Phabricator instance.

[mlir] ODS-backed python binding generator for custom op classes
ClosedPublic

Authored by ftynse on Nov 6 2020, 10:38 AM.

Details

Summary

Introduce an ODS/Tablegen backend producing Op wrappers for Python bindings
based on the ODS operation definition. Usage:

mlir-tblgen -gen-python-op-bindings -Iinclude <path/to/Ops.td> \
            -bind-dialect=<dialect-name>

Diff Detail

Event Timeline

ftynse created this revision.Nov 6 2020, 10:38 AM
ftynse requested review of this revision.Nov 6 2020, 10:38 AM
ftynse updated this revision to Diff 303546.Nov 6 2020, 2:21 PM

support results

ftynse updated this revision to Diff 303887.Nov 9 2020, 8:29 AM

Ready for review

ftynse retitled this revision from [mlir] WIP: ODS-backed python binding generator for custom op classes to [mlir] ODS-backed python binding generator for custom op classes.
ftynse edited the summary of this revision. (Show Details)

Nice, could we have a Python test too to show the benefit?

ftynse updated this revision to Diff 303928.Nov 9 2020, 10:34 AM

Plumb the build system

LGTM overall.

Nice, could we have a Python test too to show the benefit?

I think that'd require a bit more CMake/build plumbing to get there.

mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
58

There is nothing in these that is dependent on the ODS content, can we have some Python helpers in mlir.ir and import them instead of regenerating these for every dialect?

ftynse updated this revision to Diff 303952.Nov 9 2020, 12:08 PM

Restructure cmake and move some common code to Python files

ftynse marked an inline comment as done.Nov 9 2020, 12:10 PM

Nice, could we have a Python test too to show the benefit?

Added a "some-check" test.

I think that'd require a bit more CMake/build plumbing to get there.

My changes actually crossed in-flight with your comment. I added build support for testing, but not yet for the installation. Let's check if this work for more dialects before enabling by default.

PTAL.

mehdi_amini accepted this revision.Nov 9 2020, 8:37 PM

Sweet!

This revision is now accepted and ready to land.Nov 9 2020, 8:37 PM

Nice, thanks

mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
308

Why is this returning bool?

This revision was landed with ongoing or failed builds.Nov 10 2020, 1:58 AM
This revision was automatically updated to reflect the committed changes.
ftynse added inline comments.Nov 10 2020, 1:58 AM
mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
308

Provisioned for error propagation. Removing this before commit.

mlir/lib/Bindings/Python/mlir/dialects/__init__.py