Commit 3358d690 authored by Diego Caballero's avatar Diego Caballero

[MLIR] Improve MLIR dump

It refactor MLIR dump code in MLIRCompiler and adds missing dumps for
some steps of the lowering. It also removes some redundant dump for
affine dialect.
parent 62e52be8
...@@ -141,10 +141,9 @@ void MLIRCompiler::build_ng_dialect_module() ...@@ -141,10 +141,9 @@ void MLIRCompiler::build_ng_dialect_module()
{ {
NGRAPH_FAIL() << "Invalid module after lowering to NG dialect"; NGRAPH_FAIL() << "Invalid module after lowering to NG dialect";
} }
if (std::getenv("NGRAPH_MLIR_DUMP_ALL") != nullptr)
{ dump_mlir_module("nGraph Dialect Dump:");
m_module->dump();
}
} }
// Converts an nGraph Tensor into an MLIR tensor type, including the conversion of the Tensor's // Converts an nGraph Tensor into an MLIR tensor type, including the conversion of the Tensor's
...@@ -215,10 +214,8 @@ void MLIRCompiler::lower_ng_dialect() ...@@ -215,10 +214,8 @@ void MLIRCompiler::lower_ng_dialect()
{ {
NGRAPH_FAIL() << "Incorrect module after dialect lowering"; NGRAPH_FAIL() << "Incorrect module after dialect lowering";
} }
if (std::getenv("NGRAPH_MLIR_DUMP_ALL") != nullptr)
{ dump_mlir_module("Affine Dialect Dump:");
m_module->dump();
}
} }
// Receives affine dialect as input and applies affine and standard dialect based optimizations. // Receives affine dialect as input and applies affine and standard dialect based optimizations.
...@@ -231,6 +228,8 @@ void MLIRCompiler::optimize() ...@@ -231,6 +228,8 @@ void MLIRCompiler::optimize()
pm.addPass(mlir::createLowerAffinePass()); pm.addPass(mlir::createLowerAffinePass());
auto rr = pm.run(m_module.get()); auto rr = pm.run(m_module.get());
NGRAPH_ASSERT(succeeded(rr)) << "Affine loop lowering failed"; NGRAPH_ASSERT(succeeded(rr)) << "Affine loop lowering failed";
dump_mlir_module("Standard Dialect Dump:");
} }
// MLIR builders // MLIR builders
...@@ -346,6 +345,8 @@ void MLIRCompiler::execute() ...@@ -346,6 +345,8 @@ void MLIRCompiler::execute()
(void)r; (void)r;
NGRAPH_ASSERT(succeeded(r)) << "second conversion failed"; NGRAPH_ASSERT(succeeded(r)) << "second conversion failed";
dump_mlir_module("LLVM-IR Dialect Dump:");
// Initialize LLVM targets. // Initialize LLVM targets.
llvm::InitializeNativeTarget(); llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter(); llvm::InitializeNativeTargetAsmPrinter();
...@@ -411,3 +412,13 @@ mlir::StaticFloatMemRef* MLIRCompiler::allocate_memref_descriptor(mlir::Type typ ...@@ -411,3 +412,13 @@ mlir::StaticFloatMemRef* MLIRCompiler::allocate_memref_descriptor(mlir::Type typ
descriptor->data = nullptr; descriptor->data = nullptr;
return descriptor; return descriptor;
} }
void MLIRCompiler::dump_mlir_module(const std::string msg)
{
if (std::getenv("NGRAPH_MLIR_DUMP_ALL") != nullptr)
{
llvm::dbgs() << "*** " << msg << " ***\n";
m_module->dump();
llvm::dbgs() << "\n\n";
}
}
...@@ -115,6 +115,9 @@ namespace ngraph ...@@ -115,6 +115,9 @@ namespace ngraph
/// Helper to allocate a mem ref object. Handles static shapes only for now. /// Helper to allocate a mem ref object. Handles static shapes only for now.
mlir::StaticFloatMemRef* allocate_memref_descriptor(mlir::Type type); mlir::StaticFloatMemRef* allocate_memref_descriptor(mlir::Type type);
/// Helper to dump MLIR module into llvm::dbgs prepended by the message \p msg.
void dump_mlir_module(const std::string msg);
private: private:
// Sub-graph to be compiled and executed with MLIR. // Sub-graph to be compiled and executed with MLIR.
const ngraph::op::CompiledKernel* m_compiled_kernel; const ngraph::op::CompiledKernel* m_compiled_kernel;
......
...@@ -112,15 +112,8 @@ namespace ...@@ -112,15 +112,8 @@ namespace
"Error lowering dialect\n"); "Error lowering dialect\n");
signalPassFailure(); signalPassFailure();
} }
if (std::getenv("NGRAPH_MLIR_DUMP_ALL") != nullptr)
{
getModule().dump();
}
processFakeInstrs(); processFakeInstrs();
if (std::getenv("NGRAPH_MLIR_DUMP_ALL") != nullptr)
{
getModule().dump();
}
} }
void DialectLoweringPass::findOutputValues() void DialectLoweringPass::findOutputValues()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment