[all-commits] [llvm/llvm-project] ace1d0: [mlir][python] Normalize asm-printing IR behavior.
Stella Laurenzo via All-commits
all-commits at lists.llvm.org
Sun Nov 28 18:03:33 PST 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: ace1d0ad3dc43e28715cbe2f3e0a5a76578bda9f
https://github.com/llvm/llvm-project/commit/ace1d0ad3dc43e28715cbe2f3e0a5a76578bda9f
Author: Stella Laurenzo <stellaraccident at gmail.com>
Date: 2021-11-28 (Sun, 28 Nov 2021)
Changed paths:
M mlir/lib/Bindings/Python/IRCore.cpp
M mlir/lib/Bindings/Python/IRModule.h
M mlir/test/python/dialects/builtin.py
M mlir/test/python/dialects/linalg/opdsl/emit_structured_generic.py
M mlir/test/python/dialects/linalg/ops.py
M mlir/test/python/dialects/shape.py
M mlir/test/python/dialects/std.py
M mlir/test/python/ir/module.py
M mlir/test/python/ir/operation.py
Log Message:
-----------
[mlir][python] Normalize asm-printing IR behavior.
While working on an integration, I found a lot of inconsistencies on IR printing and verification. It turns out that we were:
* Only doing "soft fail" verification on IR printing of Operation, not of a Module.
* Failed verification was interacting badly with binary=True IR printing (causing a TypeError trying to pass an `str` to a `bytes` based handle).
* For systematic integrations, it is often desirable to control verification yourself so that you can explicitly handle errors.
This patch:
* Trues up the "soft fail" semantics by having `Module.__str__` delegate to `Operation.__str__` vs having a shortcut implementation.
* Fixes soft fail in the presence of binary=True (and adds an additional happy path test case to make sure the binary functionality works).
* Adds an `assume_verified` boolean flag to the `print`/`get_asm` methods which disables internal verification, presupposing that the caller has taken care of it.
It turns out that we had a number of tests which were generating illegal IR but it wasn't being caught because they were doing a print on the `Module` vs operation. All except two were trivially fixed:
* linalg/ops.py : Had two tests for direct constructing a Matmul incorrectly. Fixing them made them just like the next two tests so just deleted (no need to test the verifier only at this level).
* linalg/opdsl/emit_structured_generic.py : Hand coded conv and pooling tests appear to be using illegal shaped inputs/outputs, causing a verification failure. I just used the `assume_verified=` flag to restore the original behavior and left a TODO. Will get someone who owns that to fix it properly in a followup (would also be nice to break this file up into multiple test modules as it is hard to tell exactly what is failing).
Notes to downstreams:
* If, like some of our tests, you get verification failures after this patch, it is likely that your IR was always invalid and you will need to fix the root cause. To temporarily revert to prior (broken) behavior, replace calls like `print(module)` with `print(module.operation.get_asm(assume_verified=True))`.
Differential Revision: https://reviews.llvm.org/D114680
More information about the All-commits
mailing list