This is an archive of the discontinued LLVM Phabricator instance.

Adds MLIR C-API for marshaling Python capsules.
ClosedPublic

Authored by stellaraccident on Sep 28 2020, 9:11 AM.

Details

Summary
  • Providing stable, C-accessible definitions for bridging MLIR Python<->C APIs, we eliminate inter-extension dependencies (i.e. they can all share a diamond dependency on the MLIR C-API).
  • Just provides accessors for context and module right now.
  • Needed in NPComp in ~a week or so for high level Torch APIs.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2020, 9:11 AM
stellaraccident requested review of this revision.Sep 28 2020, 9:11 AM
mehdi_amini accepted this revision.Sep 28 2020, 1:00 PM
mehdi_amini added inline comments.
mlir/include/mlir-c/PythonDefs.h
69

Isn't the isError redundant with returning a null context ?

94

Why isn't this file in the Python binding directory?

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

What about zero initializing explicitly? Reading such code is always suggesting me to read the implementation of the callee to make sure there isn't a path where it won't set the error flag.

mlir/lib/Bindings/Python/IRModules.h
210

Is this useful right now on the Module?

This revision is now accepted and ready to land.Sep 28 2020, 1:00 PM

Address comments.

Thanks!

mlir/include/mlir-c/PythonDefs.h
69

Ah, we were missing an mlirContextIsNull and I just wasn't thinking (Alex still wants these structs to be mostly opaque from user's perspectives). Added it and removed the arg.

94

My mistake: I was considering the right place high order bit to put it in to be mlir-c but then neglected to create the sub-directory. Moved to mlir-c/Bindings/Python/Interop.h.

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

I think how this is now side-steps the concern, but let me know if not? (not quite following what you want to zero-initialize here)

mlir/lib/Bindings/Python/IRModules.h
210

I have a use for it in npcomp and am working around it not existing (basically, want to allocate a Python-visible Module and also interop with it at the MLIR-C API level).

This revision was landed with ongoing or failed builds.Sep 29 2020, 10:49 AM
This revision was automatically updated to reflect the committed changes.
Harbormaster completed remote builds in B73371: Diff 295046.
mehdi_amini added inline comments.Sep 29 2020, 11:29 AM
mlir/lib/Bindings/Python/IRModules.cpp
462

Yes LG, it was the output parameter isError that is removed now.