MLIR  17.0.0git
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
mlir::python::PyMlirContext Class Reference

#include "Bindings/Python/IRModule.h"

Classes

struct  ErrorCapture
 RAII object that captures any error diagnostics emitted to the provided context. More...
 

Public Member Functions

 PyMlirContext ()=delete
 
 PyMlirContext (const PyMlirContext &)=delete
 
 PyMlirContext (PyMlirContext &&)=delete
 
 ~PyMlirContext ()
 
MlirContext get ()
 Accesses the underlying MlirContext. More...
 
PyMlirContextRef getRef ()
 Gets a strong reference to this context, which will ensure it is kept alive for the life of the reference. More...
 
pybind11::object getCapsule ()
 Gets a capsule wrapping the void* within the MlirContext. More...
 
size_t getLiveOperationCount ()
 Gets the count of live operations associated with this context. More...
 
size_t clearLiveOperations ()
 Clears the live operations map, returning the number of entries which were invalidated. More...
 
size_t getLiveModuleCount ()
 Gets the count of live modules associated with this context. More...
 
pybind11::object contextEnter ()
 Enter and exit the context manager. More...
 
void contextExit (const pybind11::object &excType, const pybind11::object &excVal, const pybind11::object &excTb)
 
pybind11::object attachDiagnosticHandler (pybind11::object callback)
 Attaches a Python callback as a diagnostic handler, returning a registration object (internally a PyDiagnosticHandler). More...
 
void setEmitErrorDiagnostics (bool value)
 Controls whether error diagnostics should be propagated to diagnostic handlers, instead of being captured by ErrorCapture. More...
 

Static Public Member Functions

static PyMlirContextcreateNewContextForInit ()
 For the case of a python init (py::init) method, pybind11 is quite strict about needing to return a pointer that is not yet associated to an py::object. More...
 
static PyMlirContextRef forContext (MlirContext context)
 Returns a context reference for the singleton PyMlirContext wrapper for the given context. More...
 
static pybind11::object createFromCapsule (pybind11::object capsule)
 Creates a PyMlirContext from the MlirContext wrapped by a capsule. More...
 
static size_t getLiveCount ()
 Gets the count of live context objects. Used for testing. More...
 

Friends

class PyModule
 
class PyOperation
 

Detailed Description

Definition at line 160 of file IRModule.h.

Constructor & Destructor Documentation

◆ PyMlirContext() [1/3]

mlir::python::PyMlirContext::PyMlirContext ( )
delete

◆ PyMlirContext() [2/3]

mlir::python::PyMlirContext::PyMlirContext ( const PyMlirContext )
delete

◆ PyMlirContext() [3/3]

mlir::python::PyMlirContext::PyMlirContext ( PyMlirContext &&  )
delete

◆ ~PyMlirContext()

PyMlirContext::~PyMlirContext ( )

Definition at line 566 of file IRCore.cpp.

References mlirContextDestroy().

Member Function Documentation

◆ attachDiagnosticHandler()

py::object PyMlirContext::attachDiagnosticHandler ( pybind11::object  callback)

Attaches a Python callback as a diagnostic handler, returning a registration object (internally a PyDiagnosticHandler).

Definition at line 637 of file IRCore.cpp.

References get(), mlir::python::PyDiagnostic::invalidate(), mlirContextAttachDiagnosticHandler(), mlirLogicalResultFailure(), and mlirLogicalResultSuccess().

◆ clearLiveOperations()

size_t PyMlirContext::clearLiveOperations ( )

Clears the live operations map, returning the number of entries which were invalidated.

To be used as a safety mechanism so that API end-users can't corrupt by holding references they shouldn't have accessed in the first place.

Definition at line 617 of file IRCore.cpp.

◆ contextEnter()

pybind11::object PyMlirContext::contextEnter ( )

Enter and exit the context manager.

Definition at line 627 of file IRCore.cpp.

References mlir::python::PyThreadContextEntry::pushContext().

◆ contextExit()

void PyMlirContext::contextExit ( const pybind11::object &  excType,
const pybind11::object &  excVal,
const pybind11::object &  excTb 
)

Definition at line 631 of file IRCore.cpp.

References mlir::python::PyThreadContextEntry::popContext().

◆ createFromCapsule()

py::object PyMlirContext::createFromCapsule ( pybind11::object  capsule)
static

Creates a PyMlirContext from the MlirContext wrapped by a capsule.

Note that PyMlirContext instances are uniqued, so the returned object may be a pre-existing object. Ownership of the underlying MlirContext is taken by calling this function.

Definition at line 579 of file IRCore.cpp.

References forContext(), mlirContextIsNull(), mlirPythonCapsuleToContext(), and mlir::python::PyObjectRef< T >::releaseObject().

◆ createNewContextForInit()

PyMlirContext * PyMlirContext::createNewContextForInit ( )
static

For the case of a python init (py::init) method, pybind11 is quite strict about needing to return a pointer that is not yet associated to an py::object.

Since the forContext() method acts like a pool, possibly returning a recycled context, it does not satisfy this need. The usual way in python to accomplish such a thing is to override new, but that is also not supported by pybind11. Instead, we use this entry point which always constructs a fresh context (which cannot alias an existing one because it is fresh).

Definition at line 586 of file IRCore.cpp.

References mlirContextCreate(), and PyMlirContext().

◆ forContext()

PyMlirContextRef PyMlirContext::forContext ( MlirContext  context)
static

◆ get()

MlirContext mlir::python::PyMlirContext::get ( )
inline

◆ getCapsule()

py::object PyMlirContext::getCapsule ( )

Gets a capsule wrapping the void* within the MlirContext.

Definition at line 575 of file IRCore.cpp.

References get(), and mlirPythonContextToCapsule().

◆ getLiveCount()

size_t PyMlirContext::getLiveCount ( )
static

Gets the count of live context objects. Used for testing.

Definition at line 613 of file IRCore.cpp.

◆ getLiveModuleCount()

size_t PyMlirContext::getLiveModuleCount ( )

Gets the count of live modules associated with this context.

Used for testing.

Definition at line 625 of file IRCore.cpp.

◆ getLiveOperationCount()

size_t PyMlirContext::getLiveOperationCount ( )

Gets the count of live operations associated with this context.

Used for testing.

Definition at line 615 of file IRCore.cpp.

◆ getRef()

PyMlirContextRef mlir::python::PyMlirContext::getRef ( )
inline

Gets a strong reference to this context, which will ensure it is kept alive for the life of the reference.

Definition at line 186 of file IRModule.h.

◆ setEmitErrorDiagnostics()

void mlir::python::PyMlirContext::setEmitErrorDiagnostics ( bool  value)
inline

Controls whether error diagnostics should be propagated to diagnostic handlers, instead of being captured by ErrorCapture.

Definition at line 228 of file IRModule.h.

Friends And Related Function Documentation

◆ PyModule

friend class PyModule
friend

Definition at line 261 of file IRModule.h.

◆ PyOperation

friend class PyOperation
friend

Definition at line 262 of file IRModule.h.


The documentation for this class was generated from the following files: