LLVM Discussion Forums

How to get mlir-opt to parse tf_executor dialect in mlir file?

I used tf-mlir-translate to translate a tensorflow graphdef into mlir file - which contains tf graph embedded in tf_executor dialect as shown below:

module attributes {tf.versions = {bad_consumers = [], min_consumer = 0 : i32, producer = 0 : i32}} {
  func @main() {
    tf_executor.graph {
       ...

How can I tell mlir-opt to interpret it using tf_executor and tf dialects ?

I am trying to write a simple pass by extending a module pass to walk over all functions and Operations to process each Operation. I use mlir-opt --<my_registered_pass> to test my code. But I am hitting a parse error

error: custom op 'tf_executor.graph' is unknown
    tf_executor.graph {
    ^

here’s the call stack

(anonymous namespace)::ModuleParser::parseModule((anonymous namespace)::ModuleParser * const this, mlir::ModuleOp module) (<path>//llvm-project/mlir/lib/Parser/Parser.cpp:4655)
mlir::parseSourceFile(const llvm::SourceMgr & sourceMgr, mlir::MLIRContext * context) (<path>/llvm-project/mlir/lib/Parser/Parser.cpp:4720)
performActions(llvm::raw_ostream & os, bool verifyDiagnostics, bool verifyPasses, llvm::SourceMgr & sourceMgr, mlir::MLIRContext * context, const mlir::PassPipelineCLParser & passPipeline) (<path>/llvm-project/mlir/lib/Support/MlirOptMain.cpp:44)
processBuffer(llvm::raw_ostream & os, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> > ownedBuffer, bool verifyDiagnostics, bool verifyPasses, const mlir::PassPipelineCLParser & passPipeline) (<path>/llvm-project/mlir/lib/Support/MlirOptMain.cpp:83)
mlir::MlirOptMain(llvm::raw_ostream & os, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> > buffer, const mlir::PassPipelineCLParser & passPipeline, bool splitInputFile, bool verifyDiagnostics, bool verifyPasses) (<path>/llvm-project/mlir/lib/Support/MlirOptMain.cpp:116)
main(int argc, char ** argv) (<path>/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:74)

The TensorFlow dialect does not come with MLIR, it lives in the TensorFlow directory. There you can use tf-opt (just the same way you got tf-mlir-translate) that provides a superset of mlir-opt and includes the TensorFlow specific bits needed to process TensorFlow MLIR files.

Thanks for quick response. I will try it out with tf-opt.