| 28 | namespace tensorflow { |
| 29 | |
| 30 | std::string ImportGraphDef(const std::string &proto, |
| 31 | const std::string &pass_pipeline, |
| 32 | TF_Status *status) { |
| 33 | GraphDef graphdef; |
| 34 | auto s = tensorflow::LoadProtoFromBuffer(proto, &graphdef); |
| 35 | if (!s.ok()) { |
| 36 | Set_TF_Status_from_Status(status, s); |
| 37 | return "// error"; |
| 38 | } |
| 39 | GraphDebugInfo debug_info; |
| 40 | GraphImportConfig specs; |
| 41 | mlir::MLIRContext context; |
| 42 | auto module = ConvertGraphdefToMlir(graphdef, debug_info, specs, &context); |
| 43 | if (!module.ok()) { |
| 44 | Set_TF_Status_from_Status(status, module.status()); |
| 45 | return "// error"; |
| 46 | } |
| 47 | |
| 48 | // Run the pass_pipeline on the module if not empty. |
| 49 | if (!pass_pipeline.empty()) { |
| 50 | mlir::PassManager pm(&context); |
| 51 | std::string error; |
| 52 | llvm::raw_string_ostream error_stream(error); |
| 53 | if (failed(mlir::parsePassPipeline(pass_pipeline, pm, error_stream))) { |
| 54 | TF_SetStatus(status, TF_INVALID_ARGUMENT, |
| 55 | ("Invalid pass_pipeline: " + error_stream.str()).c_str()); |
| 56 | return "// error"; |
| 57 | } |
| 58 | |
| 59 | mlir::StatusScopedDiagnosticHandler statusHandler(&context); |
| 60 | if (failed(pm.run(*module.ValueOrDie()))) { |
| 61 | Set_TF_Status_from_Status(status, statusHandler.ConsumeStatus()); |
| 62 | return "// error"; |
| 63 | } |
| 64 | } |
| 65 | return MlirModuleToString(*module.ConsumeValueOrDie()); |
| 66 | } |
| 67 | |
| 68 | std::string ExperimentalConvertSavedModelToMlir( |
| 69 | const std::string &saved_model_path, const std::string &exported_names_str, |
no test coverage detected