-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[MLIR][Python] remove liveOperations
#155114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
9af755c
809f0dc
fd8a12a
8eb4d75
8c72271
70d6b56
685fbb5
57ad5a1
d319108
8ee9d2c
7cc8a50
e5e345b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,13 +216,26 @@ added to an attached operation, they need to be re-parented to the containing | |
| module). | ||
|
|
||
| Due to the validity and parenting accounting needs, `PyOperation` is the owner | ||
| for regions and blocks and needs to be a top-level type that we can count on not | ||
| aliasing. This let's us do things like selectively invalidating instances when | ||
| mutations occur without worrying that there is some alias to the same operation | ||
| in the hierarchy. Operations are also the only entity that are allowed to be in | ||
| a detached state, and they are interned at the context level so that there is | ||
| never more than one Python `mlir.ir.Operation` object for a unique | ||
| `MlirOperation`, regardless of how it is obtained. | ||
| for regions and blocks. Operations are also the only entities which are allowed to be in | ||
| a detached state. | ||
|
|
||
| **Note**: Multiple `PyOperation` objects (i.e., the Python objects themselves) can alias a single `mlir::Operation`. | ||
| This means, for example, if you have `py_op1` and `py_op2` which wrap the same `mlir::Operation op` | ||
| and you somehow transform `op` (e.g., you run a pass on `op`) then walking the MLIR AST via either/or `py_op1`, `py_op2` | ||
| will reflect the same MLIR AST. This is perfectly safe and supported. What is not supported is invalidating any | ||
| operation while there exist multiple Python objects wrapping that operation **and then manipulating those wrappers**. | ||
| For example if `py_op1` and `py_op2` wrap the same operation under a root `py_op3` and then `py_op3` is | ||
| transformed such that the operation referenced (by `py_op1`, `py_op2`) is erased. Then `py_op1`, `py_op2` | ||
| become "undefined" in a sense; manipulating them in any way is "formally forbidden". Note, this also applies to | ||
| `SymbolTable` mutation, which is considered a transformation of the root `SymbolTable`-supporting operation for the | ||
| purposes of the discussion here. Metaphorically, one can think of this similarly to how STL container iterators are invalidated once the container itself is changed. The "best practices" recommendation is to structure your code such that | ||
|
|
||
| 1. First, query/manipulate various Python wrapper objects `py_op1`, `py_op2`, `py_op3`, etc.; | ||
| 2. Second, Transform the AST/erase operations/etc. via a single root object; | ||
|
||
| 3. End. | ||
|
||
|
|
||
| Ideally this should be done in a function body so that "End" corresponds to the end of the function and there are no | ||
| risks of Python wrapper objects leaking/living longer than necessary. | ||
|
|
||
| The C/C++ API allows for Region/Block to also be detached, but it simplifies the | ||
| ownership model a lot to eliminate that possibility in this API, allowing the | ||
|
|
@@ -238,11 +251,6 @@ blocks. We may end up needing an op-local one at some point TBD, depending on | |
| how hard it is to guarantee how mutations interact with their Python peer | ||
| objects. We can cross that bridge easily when we get there. | ||
|
|
||
| Module, when used purely from the Python API, can't alias anyway, so we can use | ||
| it as a top-level ref type without a live-list for interning. If the API ever | ||
| changes such that this cannot be guaranteed (i.e. by letting you marshal a | ||
| native-defined Module in), then there would need to be a live table for it too. | ||
|
||
|
|
||
| ## User-level API | ||
|
|
||
| ### Context Management | ||
|
|
@@ -1229,4 +1237,4 @@ The exceptions to the free-threading compatibility: | |
| - Usage of `Location.emit_error` is unsafe (due to thread-unsafe `llvm::raw_ostream`). | ||
| - Usage of `Module.dump` is unsafe (due to thread-unsafe `llvm::raw_ostream`). | ||
| - Usage of `mlir.dialects.transform.interpreter` is unsafe. | ||
| - Usage of `mlir.dialects.gpu` and `gpu-module-to-binary` is unsafe. | ||
| - Usage of `mlir.dialects.gpu` and `gpu-module-to-binary` is unsafe. | ||
Uh oh!
There was an error while loading. Please reload this page.