Repository navigation
[MLIR] Make printing Value to a stream thread-safe - #185762
Conversation
Adjust Value's operator<< and dump() function so that it can be safely used with multithreading enabled.
|
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Jacenty Andruszkiewicz (Jacenty-And-Intel) ChangesAdjust Similar to 2 Files Affected:
diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h
index af58778a0a13e..e72ace0920eb1 100644
--- a/mlir/include/mlir/IR/Value.h
+++ b/mlir/include/mlir/IR/Value.h
@@ -243,10 +243,7 @@ class Value {
detail::ValueImpl *impl;
};
-inline raw_ostream &operator<<(raw_ostream &os, Value value) {
- value.print(os);
- return os;
-}
+raw_ostream &operator<<(raw_ostream &os, Value value);
//===----------------------------------------------------------------------===//
// OpOperand
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index b3242f838fc1d..5e9f6e87dfe08 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -4142,8 +4142,13 @@ void Value::print(raw_ostream &os, AsmState &state) const {
<< "' at index: " << arg.getArgNumber();
}
+raw_ostream &mlir::operator<<(raw_ostream &os, Value value) {
+ value.print(os, OpPrintingFlags().useLocalScope());
+ return os;
+}
+
void Value::dump() const {
- print(llvm::errs());
+ print(llvm::errs(), OpPrintingFlags().useLocalScope());
llvm::errs() << "\n";
}
|
| void Value::dump() const { | ||
| print(llvm::errs()); | ||
| print(llvm::errs(), OpPrintingFlags().useLocalScope()); |
There was a problem hiding this comment.
I would think we want dump() to print just the same as the default output.
When is dump() useful in a threaded context?
There was a problem hiding this comment.
When is dump() useful in a threaded context?
In manual debug of concurrently ran OperationPasses could be useful.
I've updated the description with more context, please take a look. @joker-eph
There was a problem hiding this comment.
In manual debug of concurrently ran OperationPasses could be useful.
I'm not so sure: the output would be completely mangled from the concurrent writes to stderr
There was a problem hiding this comment.
Without any mutex or logger adjusted to concurrent passes sure, but it wouldn't fail the compilation as it could now
There was a problem hiding this comment.
I agree that crashing is bad.
My concern is that dump() is what we call from the debugger, and it is useful to do op->dump() and then op->getParentOp()->dump() and finding your op in the larger output, which is hard with the local scope...
That said since Operation::dump() has this problem, aligning Value should be fine.
There was a problem hiding this comment.
Could you please hit the merge button then? Thanks!
Adjust `mlir::Value`'s `operator<<` and `dump()` function so that it can be safely used with multithreading enabled. Similar to `mlir::Operation` which uses `OpPrintingFlags` with `localScope` enabled in printing methods. Using `Value::print(raw_ostream &os)` creates default `OpPrintingFlags` and with these flags print method is called on `getDefiningOp()`. With `localScope` disabled by default, `findParent()` could go all the way up to the `ModuleOp` which can be outside of the pass scope. We had an instance of it in our project when multiple OperationPasses were ran concurrently. Trying to print or dump `mlir::Value` in one of the passes resulted in crash due to failed verifiers that got triggered on parent op before the print.
* [mlir][RFC] Allow to skip operands type specification in ASM form * Add FlatSymbolRefAttr and ArrayAttr for memory space representation (llvm#44/llvm#45) * [mlir] Relax ASM parser requirements about operands Type presence * [mlir] Remove LIT tests affected by ASM simplification * Add method getInlineBlockAndPoint for DialectInlinerInterface * Initialize pass options using pipeline options * Fix compilation issue with MSVC * Port Ubunu-24 warning fixes to npu/release/18.x (llvm#45) * Extend Quant dialect with Quantile Quantization type (llvm#53) * Extending QuantileQuantizedType with quantileType mlir::Type member (llvm#60) * Relax negative scales conditions in Quant Dialect (llvm#61) * Adding missing check in QuantileQuantizedPerAxisType::verify (llvm#66) * Adding new quantileType types to mlir test (llvm#85) * Add Value back to SideEffectInterfaces * EISW-130780: remove all wd flag to enable warnings when LLVM_ENABLE_WARNINGS is ON (llvm#99) * EISW-176770 Fix argument parsing issue in mlir-src-sharder after command-line parser reset * Enable quantization for FP4 type * [MLIR] Make printing Value to a stream thread-safe (llvm#185762) * [MLIR] Fix mlir-doc build failures by adding -dialect to add_mlir_doc calls * [MLIR] Add getter for the action handler of MLIR context (llvm#197230) * Silence deprecation warning for OpBuilder::create * [MLIR] make One-Shot and SCF bufferization TensorLikeType-aware (llvm#189073) * [NFC][mlir][bufferization] Remove getMemRefType() helper (llvm#199034) * [mlir][bufferization] Drop TensorLikeType::getBufferType() (llvm#201350) --------- Signed-off-by: Gladilov, Gleb <[email protected]> Signed-off-by: Zhu, Shaojie <[email protected]> Signed-off-by: Dmitrii Makarenko <[email protected]> Co-authored-by: Vladislav Vinogradov <[email protected]> Co-authored-by: Nikita Kudriavtsev <[email protected]> Co-authored-by: Schondube, Jorn <[email protected]> Co-authored-by: Daria Mityagina <[email protected]> Co-authored-by: Luca Sarti <[email protected]> Co-authored-by: Zoran Zomborat <[email protected]> Co-authored-by: Ngun, Raymond <[email protected]> Co-authored-by: Shaojie Zhu <[email protected]> Co-authored-by: Surendar Rama Sitaraman <[email protected]> Co-authored-by: Andruszkiewicz, Jacenty <[email protected]> Co-authored-by: Mehdi Amini <[email protected]> Co-authored-by: Kigyosi Alexandru <[email protected]> Co-authored-by: Dmitrii Makarenko <[email protected]> Co-authored-by: Andrei Golubev <[email protected]>
Adjust `mlir::Value`'s `operator<<` and `dump()` function so that it can be safely used with multithreading enabled. Similar to `mlir::Operation` which uses `OpPrintingFlags` with `localScope` enabled in printing methods. Using `Value::print(raw_ostream &os)` creates default `OpPrintingFlags` and with these flags print method is called on `getDefiningOp()`. With `localScope` disabled by default, `findParent()` could go all the way up to the `ModuleOp` which can be outside of the pass scope. We had an instance of it in our project when multiple OperationPasses were ran concurrently. Trying to print or dump `mlir::Value` in one of the passes resulted in crash due to failed verifiers that got triggered on parent op before the print.
Adjust
mlir::Value'soperator<<anddump()function so that it can be safely used with multithreading enabled.Similar to
mlir::Operationwhich usesOpPrintingFlagswithlocalScopeenabled in printing methods.Using
Value::print(raw_ostream &os)creates defaultOpPrintingFlagsand with these flags print method is called ongetDefiningOp(). WithlocalScopedisabled by default,findParent()could go all the way up to theModuleOpwhich can be outside of the pass scope.We had an instance of it in our project when multiple OperationPasses were ran concurrently. Trying to print or dump
mlir::Valuein one of the passes resulted in crash due to failed verifiers that got triggered on parent op before the print.