diff --git a/mindspore/ccsrc/backend/session/infer_session.cc b/mindspore/ccsrc/backend/session/infer_session.cc index 5e897f8606..d653423f89 100644 --- a/mindspore/ccsrc/backend/session/infer_session.cc +++ b/mindspore/ccsrc/backend/session/infer_session.cc @@ -60,7 +60,7 @@ MSInferSession::~MSInferSession() = default; Status MSInferSession::LoadModelFromFile(const std::string &file_name, uint32_t &model_id) { Py_Initialize(); - auto graph = RunLoadMindIR(file_name); + auto graph = mindspore::LoadMindIR(file_name); if (graph == nullptr) { MS_LOG(ERROR) << "Load graph model failed, file name is " << file_name.c_str(); return FAILED; diff --git a/mindspore/ccsrc/pipeline/jit/init.cc b/mindspore/ccsrc/pipeline/jit/init.cc index fd93c32a67..a6b677a50a 100644 --- a/mindspore/ccsrc/pipeline/jit/init.cc +++ b/mindspore/ccsrc/pipeline/jit/init.cc @@ -74,8 +74,6 @@ PYBIND11_MODULE(_c_expression, m) { .def("get_func_graph", &ExecutorPy::GetFuncGraph, py::arg("phase") = py::str(""), "Get graph pointer.") .def("get_func_graph_proto", &ExecutorPy::GetFuncGraphProto, py::arg("phase") = py::str(""), py::arg("type") = py::str("onnx_ir"), "Get graph proto string by specifying ir type.") - .def("convert_funcgraph_to_mindir", &ExecutorPy::ConvertFuncGraphToMindIR, py::arg("graph"), - "Convert FuncGraph to MindIR proto.") .def("compile", &ExecutorPy::Compile, py::arg("obj"), py::arg("args"), py::arg("phase") = py::str(""), py::arg("use_vm") = py::bool_(false), "Compile obj by executor.") .def("updata_param_node_default_input", &ExecutorPy::UpdataParamNodeDefaultInput, py::arg("phase"), @@ -110,7 +108,6 @@ PYBIND11_MODULE(_c_expression, m) { (void)m.def("init_backend", &mindspore::pipeline::InitBackend, "Init Backend."); (void)m.def("export_graph", &mindspore::pipeline::ExportGraph, "Export Graph."); - (py::object) m.def("load_mindir", &mindspore::pipeline::LoadMindIR, py::arg("file_name"), "Load MindIR as Graph."); (void)py::class_>(m, "MpiConfig") .def_static("get_instance", &mindspore::MpiConfig::GetInstance, "Get mpi config instance.") diff --git a/mindspore/ccsrc/pipeline/jit/pipeline.cc b/mindspore/ccsrc/pipeline/jit/pipeline.cc index 1843c441a4..0e85d79fdb 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline.cc +++ b/mindspore/ccsrc/pipeline/jit/pipeline.cc @@ -45,7 +45,6 @@ #include "debug/draw.h" #include "pipeline/pynative/pynative_execute.h" #include "frontend/optimizer/py_pass_manager.h" -#include "load_mindir/load_model.h" #include "pybind_api/pybind_patch.h" #include "utils/shape_utils.h" #include "utils/info.h" @@ -104,16 +103,6 @@ void CheckArgIsTensor(const ValuePtr &arg, std::size_t idx) { } } // namespace -py::bytes ExecutorPy::ConvertFuncGraphToMindIR(const FuncGraphPtr &fg_ptr) { - std::string proto_str = GetBinaryProtoString(fg_ptr); - if (proto_str.empty()) { - MS_LOG(EXCEPTION) << "Graph proto is empty."; - } - return proto_str; -} - -FuncGraphPtr LoadMindIR(const std::string &file_name) { return mindspore::RunLoadMindIR(file_name); } - py::tuple GenerateKey(const std::string &name, const std::unordered_map &defaults) { MS_LOG(DEBUG) << "GenerateKey args size:" << defaults.size(); abstract::AbstractBasePtrList args_spec; diff --git a/mindspore/ccsrc/pipeline/jit/pipeline.h b/mindspore/ccsrc/pipeline/jit/pipeline.h index ff14b47725..2e7502ec90 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline.h +++ b/mindspore/ccsrc/pipeline/jit/pipeline.h @@ -82,7 +82,6 @@ class ExecutorPy : public std::enable_shared_from_this { ResourcePtr GetResource(const std::string &phase); FuncGraphPtr GetFuncGraph(const std::string &phase); py::bytes GetFuncGraphProto(const std::string &phase, const std::string &type); - py::bytes ConvertFuncGraphToMindIR(const FuncGraphPtr &fg_ptr); compile::VmEvalFuncPtr GetVmEvalFunc(const std::string &phase); bool HasCompiled(const std::string &phase) const; @@ -139,7 +138,6 @@ void ClearResAtexit(); void ReleaseGeTsd(); void ExportGraph(const std::string &file_name, const std::string &, const std::string &phase); -FuncGraphPtr LoadMindIR(const std::string &file_name); // init and exec dataset sub graph bool InitExecDataset(const std::string &queue_name, int64_t iter_num, int64_t batch_size, diff --git a/mindspore/core/c_ops/add.cc b/mindspore/core/c_ops/add.cc index c2c2e50e84..66aa7b86f3 100644 --- a/mindspore/core/c_ops/add.cc +++ b/mindspore/core/c_ops/add.cc @@ -50,5 +50,5 @@ AbstractBasePtr TensorAddInfer(const abstract::AnalysisEnginePtr &, const Primit InferShape(primitive, input_args)->shape()); } REGISTER_PRIMITIVE_EVAL_IMPL(TensorAdd, prim::kPrimTensorAdd, TensorAddInfer); -REGISTER_PRIMITIVE_C(TensorAdd); +REGISTER_PRIMITIVE_C(kNameTensorAdd, TensorAdd); } // namespace mindspore diff --git a/mindspore/core/c_ops/avg_pool.cc b/mindspore/core/c_ops/avg_pool.cc index 323c4ddc61..a13aca7773 100644 --- a/mindspore/core/c_ops/avg_pool.cc +++ b/mindspore/core/c_ops/avg_pool.cc @@ -102,5 +102,5 @@ AbstractBasePtr AvgPoolInfer(const abstract::AnalysisEnginePtr &, const Primitiv InferShape(primitive, input_args)->shape()); } REGISTER_PRIMITIVE_EVAL_IMPL(AvgPool, prim::kPrimAvgPool, AvgPoolInfer); -REGISTER_PRIMITIVE_C(AvgPool); +REGISTER_PRIMITIVE_C(kNameAvgPool, AvgPool); } // namespace mindspore diff --git a/mindspore/core/c_ops/conv2d.cc b/mindspore/core/c_ops/conv2d.cc index 76f637ffe8..993d28a777 100644 --- a/mindspore/core/c_ops/conv2d.cc +++ b/mindspore/core/c_ops/conv2d.cc @@ -107,7 +107,7 @@ TypePtr Conv2dInferType(const PrimitivePtr &prim, const std::vector &kernel_size, int64_t mode, const std::string &pad_mode, const std::vector &pad, const std::vector &stride, @@ -193,5 +193,5 @@ AbstractBasePtr Conv2dInfer(const abstract::AnalysisEnginePtr &, const Primitive Conv2dInferShape(primitive, input_args)->shape()); } REGISTER_PRIMITIVE_EVAL_IMPL(Conv2D, prim::kPrimConv2D, Conv2dInfer); -REGISTER_PRIMITIVE_C(Conv2D); +REGISTER_PRIMITIVE_C(kNameConv2D, Conv2D); } // namespace mindspore diff --git a/mindspore/core/c_ops/conv2d.h b/mindspore/core/c_ops/conv2d.h index 62c2b75f93..786a8dbd17 100644 --- a/mindspore/core/c_ops/conv2d.h +++ b/mindspore/core/c_ops/conv2d.h @@ -26,7 +26,7 @@ #include "abstract/abstract_value.h" #include "utils/check_convert_utils.h" namespace mindspore { -constexpr auto kConv2DName = "Conv2D"; +constexpr auto kNameConv2D = "Conv2D"; class Conv2D : public PrimitiveC { public: Conv2D(); diff --git a/mindspore/core/c_ops/depthwise_conv2d.cc b/mindspore/core/c_ops/depthwise_conv2d.cc index c88749c042..b03e8df710 100644 --- a/mindspore/core/c_ops/depthwise_conv2d.cc +++ b/mindspore/core/c_ops/depthwise_conv2d.cc @@ -206,4 +206,5 @@ AbstractBasePtr DepthWiseConv2DInfer(const abstract::AnalysisEnginePtr &, const return std::make_shared(InferType(primitive, input_args), InferShape(primitive, input_args)->shape()); } +REGISTER_PRIMITIVE_C(kNameDepthWiseConv2D, DepthWiseConv2D); } // namespace mindspore diff --git a/mindspore/core/c_ops/primitive_c.cc b/mindspore/core/c_ops/primitive_c.cc index 690ebd121f..68a9efcebe 100644 --- a/mindspore/core/c_ops/primitive_c.cc +++ b/mindspore/core/c_ops/primitive_c.cc @@ -38,6 +38,6 @@ OpPrimCRegister &OpPrimCRegister::GetInstance() { } std::map OpPrimCRegister::GetPrimCMap() { return op_primc_fns_; } -void OpPrimCRegister::SetPrimCMap(const std::string &name, const OpPrimCDefineFunc &fn) { op_primc_fns_[name] = fn; } +void OpPrimCRegister::SetPrimCMap(const std::string &kname, const OpPrimCDefineFunc &fn) { op_primc_fns_[kname] = fn; } } // namespace mindspore diff --git a/mindspore/core/c_ops/primitive_c.h b/mindspore/core/c_ops/primitive_c.h index 662fddd007..aded5848e4 100644 --- a/mindspore/core/c_ops/primitive_c.h +++ b/mindspore/core/c_ops/primitive_c.h @@ -41,7 +41,7 @@ class OpPrimCRegister { ~OpPrimCRegister() {} static OpPrimCRegister &GetInstance(); std::map GetPrimCMap(); - void SetPrimCMap(const std::string &name, const OpPrimCDefineFunc &fn); + void SetPrimCMap(const std::string &kname, const OpPrimCDefineFunc &fn); private: OpPrimCRegister() {} @@ -50,17 +50,17 @@ class OpPrimCRegister { class OpPrimCRegisterHelper { public: - OpPrimCRegisterHelper(const std::string &name, const OpPrimCDefineFunc &fn) { - OpPrimCRegister::GetInstance().SetPrimCMap(name, fn); + OpPrimCRegisterHelper(const std::string &kname, const OpPrimCDefineFunc &fn) { + OpPrimCRegister::GetInstance().SetPrimCMap(kname, fn); } ~OpPrimCRegisterHelper() = default; }; -#define REGISTER_PRIMITIVE_C(name) \ - std::shared_ptr GetDefaultPrimC##name() { \ - auto out = std::make_shared(); \ - return out; \ - } \ - OpPrimCRegisterHelper primc_gen_##name(#name, GetDefaultPrimC##name); +#define REGISTER_PRIMITIVE_C(kname, primc) \ + std::shared_ptr GetDefaultPrimC##primc() { \ + auto out = std::make_shared(); \ + return out; \ + } \ + OpPrimCRegisterHelper primc_gen_##kname(kname, GetDefaultPrimC##primc); } // namespace mindspore #endif // MINDSPORE_CORE_C_OPS_PRIMITIVE_C_H_ diff --git a/mindspore/core/c_ops/relu6.cc b/mindspore/core/c_ops/relu6.cc index 1d962cd258..93fda4209d 100644 --- a/mindspore/core/c_ops/relu6.cc +++ b/mindspore/core/c_ops/relu6.cc @@ -49,5 +49,5 @@ AbstractBasePtr Relu6Infer(const abstract::AnalysisEnginePtr &, const PrimitiveP Relu6InferShape(primitive, input_args)->shape()); } REGISTER_PRIMITIVE_EVAL_IMPL(Relu6, prim::kPrimRelu6, Relu6Infer); -REGISTER_PRIMITIVE_C(Relu6); +REGISTER_PRIMITIVE_C(kNameRelu6, Relu6); } // namespace mindspore diff --git a/mindspore/core/c_ops/reshape.cc b/mindspore/core/c_ops/reshape.cc index 43028366b7..308d047387 100644 --- a/mindspore/core/c_ops/reshape.cc +++ b/mindspore/core/c_ops/reshape.cc @@ -41,5 +41,5 @@ AbstractBasePtr ReshapeInfer(const abstract::AnalysisEnginePtr &, const Primitiv } REGISTER_PRIMITIVE_EVAL_IMPL(Reshape, prim::kPrimReshape, ReshapeInfer); -REGISTER_PRIMITIVE_C(Reshape); +REGISTER_PRIMITIVE_C(kNameReshape, Reshape); } // namespace mindspore diff --git a/mindspore/core/c_ops/softmax.cc b/mindspore/core/c_ops/softmax.cc index 8482d07cbb..b30e23110b 100644 --- a/mindspore/core/c_ops/softmax.cc +++ b/mindspore/core/c_ops/softmax.cc @@ -75,5 +75,5 @@ AbstractBasePtr SoftmaxInfer(const abstract::AnalysisEnginePtr &, const Primitiv } REGISTER_PRIMITIVE_EVAL_IMPL(Softmax, prim::kPrimSoftmax, SoftmaxInfer); -REGISTER_PRIMITIVE_C(Softmax); +REGISTER_PRIMITIVE_C(kNameSoftmax, Softmax); } // namespace mindspore diff --git a/mindspore/core/c_ops/squeeze.cc b/mindspore/core/c_ops/squeeze.cc index dfd31b00a7..02732b6073 100644 --- a/mindspore/core/c_ops/squeeze.cc +++ b/mindspore/core/c_ops/squeeze.cc @@ -76,5 +76,5 @@ AbstractBasePtr SqueezeInfer(const abstract::AnalysisEnginePtr &, const Primitiv } REGISTER_PRIMITIVE_EVAL_IMPL(Squeeze, prim::kPrimSqueeze, SqueezeInfer); -REGISTER_PRIMITIVE_C(Squeeze); +REGISTER_PRIMITIVE_C(kNameSqueeze, Squeeze); } // namespace mindspore diff --git a/mindspore/core/load_mindir/load_model.cc b/mindspore/core/load_mindir/load_model.cc index 4e5cfc5446..92122f7782 100644 --- a/mindspore/core/load_mindir/load_model.cc +++ b/mindspore/core/load_mindir/load_model.cc @@ -71,7 +71,7 @@ std::shared_ptr> ReadProtoFile(const std::string &file) { return buf; } -std::shared_ptr RunLoadMindIR(const std::string &file_name) { +std::shared_ptr LoadMindIR(const std::string &file_name) { auto graphBuf = ReadProtoFile(file_name); if (graphBuf == nullptr) { MS_LOG(ERROR) << "Read Mind IR failed, file name is " << file_name.c_str(); diff --git a/mindspore/core/load_mindir/load_model.h b/mindspore/core/load_mindir/load_model.h index f7681a5d49..afe739cb3b 100644 --- a/mindspore/core/load_mindir/load_model.h +++ b/mindspore/core/load_mindir/load_model.h @@ -24,7 +24,7 @@ #include "ir/func_graph.h" namespace mindspore { -std::shared_ptr RunLoadMindIR(const std::string &file_name); +std::shared_ptr LoadMindIR(const std::string &file_name); std::shared_ptr> ReadProtoFile(const std::string &file); std::shared_ptr ConvertStreamToFuncGraph(const char *buf, const size_t buf_size); } // namespace mindspore