diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index ecfd29ce0de..4339ec8288b 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -503,8 +503,6 @@ else() COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h") install(FILES ${UTILS_HEADER} DESTINATION ${CONVERTER_ROOT_DIR}/include/core/utils COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/mindspore/lite/tools/converter/ops/ops_def.h - DESTINATION ${CONVERTER_ROOT_DIR}/include COMPONENT ${RUNTIME_COMPONENT_NAME}) install(DIRECTORY ${TOP_DIR}/mindspore/lite/build/schema/ DESTINATION ${CONVERTER_ROOT_DIR}/include/schema COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "schema_generated.h" EXCLUDE) install(DIRECTORY ${flatbuffers_INC}/ DESTINATION ${CONVERTER_ROOT_DIR}/include/third_party diff --git a/include/api/dual_abi_helper.h b/include/api/dual_abi_helper.h index 862830edc6f..bd3e9a783e3 100644 --- a/include/api/dual_abi_helper.h +++ b/include/api/dual_abi_helper.h @@ -103,6 +103,26 @@ inline std::unordered_map UnorderedMapCharToString( return ret; } +inline std::map, std::vector> MapStringToVectorChar( + const std::map &s) { + std::map, std::vector> ret; + std::transform(s.begin(), s.end(), std::inserter(ret, ret.begin()), [](auto str) { + return std::pair, std::vector>(std::vector(str.first.begin(), str.first.end()), + std::vector(str.second.begin(), str.second.end())); + }); + return ret; +} + +inline std::map MapVectorCharToString( + const std::map, std::vector> &c) { + std::map ret; + std::transform(c.begin(), c.end(), std::inserter(ret, ret.begin()), [](auto ch) { + return std::pair(std::string(ch.first.begin(), ch.first.end()), + std::string(ch.second.begin(), ch.second.end())); + }); + return ret; +} + inline std::vector, std::vector>> ClassIndexStringToChar( const std::vector>> &s) { std::vector, std::vector>> ret; diff --git a/mindspore/core/ops/make_tuple.cc b/mindspore/core/ops/make_tuple.cc new file mode 100644 index 00000000000..e82324cc095 --- /dev/null +++ b/mindspore/core/ops/make_tuple.cc @@ -0,0 +1,23 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ops/make_tuple.h" + +namespace mindspore { +namespace ops { +REGISTER_PRIMITIVE_C(kNameMakeTuple, MakeTuple); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/make_tuple.h b/mindspore/core/ops/make_tuple.h new file mode 100644 index 00000000000..0b560cc574b --- /dev/null +++ b/mindspore/core/ops/make_tuple.h @@ -0,0 +1,38 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_CORE_OPS_MAKE_TUPLE_H_ +#define MINDSPORE_CORE_OPS_MAKE_TUPLE_H_ +#include "ops/primitive_c.h" + +namespace mindspore { +namespace ops { +constexpr auto kNameMakeTuple = "MakeTuple"; +/// \brief MakeTuple op is used to pack multiple nodes into a whole, which is only used in FuncGraph. +class MS_CORE_API MakeTuple : public PrimitiveC { + public: + /// \brief Constructor. + MakeTuple() : PrimitiveC(kNameMakeTuple) {} + + /// \brief Destructor. + ~MakeTuple() = default; + + MS_DECLARE_PARENT(MakeTuple, PrimitiveC); +}; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_MAKE_TUPLE_H_ diff --git a/mindspore/core/ops/return.cc b/mindspore/core/ops/return.cc new file mode 100644 index 00000000000..2a32e4d5f96 --- /dev/null +++ b/mindspore/core/ops/return.cc @@ -0,0 +1,23 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ops/return.h" + +namespace mindspore { +namespace ops { +REGISTER_PRIMITIVE_C(kNameReturn, Return); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/return.h b/mindspore/core/ops/return.h new file mode 100644 index 00000000000..c472d6d70f4 --- /dev/null +++ b/mindspore/core/ops/return.h @@ -0,0 +1,38 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_CORE_OPS_RETURN_H_ +#define MINDSPORE_CORE_OPS_RETURN_H_ +#include "ops/primitive_c.h" + +namespace mindspore { +namespace ops { +constexpr auto kNameReturn = "Return"; +/// \brief Return op is the output node, which is only used in FuncGraph. +class MS_CORE_API Return : public PrimitiveC { + public: + /// \brief Constructor. + Return() : PrimitiveC(kNameReturn) {} + + /// \brief Destructor. + ~Return() = default; + + MS_DECLARE_PARENT(Return, PrimitiveC); +}; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_RETURN_H_ diff --git a/mindspore/core/ops/tuple_get_item.cc b/mindspore/core/ops/tuple_get_item.cc new file mode 100644 index 00000000000..6eda4f4c3ae --- /dev/null +++ b/mindspore/core/ops/tuple_get_item.cc @@ -0,0 +1,23 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ops/tuple_get_item.h" + +namespace mindspore { +namespace ops { +REGISTER_PRIMITIVE_C(kNameTupleGetItem, TupleGetItem); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/tuple_get_item.h b/mindspore/core/ops/tuple_get_item.h new file mode 100644 index 00000000000..9c947827eb0 --- /dev/null +++ b/mindspore/core/ops/tuple_get_item.h @@ -0,0 +1,39 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_CORE_OPS_TUPLE_GET_ITEM_H_ +#define MINDSPORE_CORE_OPS_TUPLE_GET_ITEM_H_ +#include "ops/primitive_c.h" + +namespace mindspore { +namespace ops { +constexpr auto kNameTupleGetItem = "TupleGetItem"; +/// \brief TupleGetItem op is added to the multi-output node to describe which output of the node, which is only used +/// in FuncGraph. +class MS_CORE_API TupleGetItem : public PrimitiveC { + public: + /// \brief Constructor. + TupleGetItem() : PrimitiveC(kNameTupleGetItem) {} + + /// \brief Destructor. + ~TupleGetItem() = default; + + MS_DECLARE_PARENT(TupleGetItem, PrimitiveC); +}; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_TUPLE_GET_ITEM_H_ diff --git a/mindspore/lite/build_lite.sh b/mindspore/lite/build_lite.sh index d1c8609d9a5..3af9087b95c 100755 --- a/mindspore/lite/build_lite.sh +++ b/mindspore/lite/build_lite.sh @@ -151,7 +151,7 @@ build_lite() { CMAKE_TOOLCHAIN_FILE=${BASEPATH}/cmake/lite_ios.cmake fi - BRANCH_NAME=nnie_3516_master + BRANCH_NAME=nnie_3516_master_2 if [[ ("${MSLITE_REGISTRY_DEVICE}" == "Hi3516D" || "${TOOLCHAIN_NAME}" == "himix200") && "${local_lite_platform}" == "arm32" ]]; then TOOLCHAIN_NAME="himix200" MSLITE_REGISTRY_DEVICE=Hi3516D diff --git a/mindspore/lite/include/registry/converter_context.h b/mindspore/lite/include/registry/converter_context.h index 1206edf4459..fc2383af3fe 100644 --- a/mindspore/lite/include/registry/converter_context.h +++ b/mindspore/lite/include/registry/converter_context.h @@ -21,6 +21,7 @@ #include #include #include "include/lite_utils.h" +#include "include/api/dual_abi_helper.h" namespace mindspore { namespace converter { @@ -53,12 +54,30 @@ class MS_API ConverterContext { /// \brief Static method to set exported model's output name as needed by users. /// /// \param[in] output_names Define model's output name, the order of which is consistent with the original model. - static void SetGraphOutputTensorNames(const std::vector &output_names); + static void SetGraphOutputTensorNames(const std::vector &output_names) { + SetGraphOutputTensorNames(VectorStringToChar(output_names)); + } /// \brief Static method to obtain the outputs' name. /// /// \return the outputs' name. - static std::vector GetGraphOutputTensorNames(); + static std::vector GetGraphOutputTensorNames() { + return VectorCharToString(GetGraphOutputTensorNamesInChar()); + } + + /// \brief Static method to get configure information which is used only by external extension. + /// + /// \param[in] section Define config section name. + /// + /// \return config key-value map. + static std::map GetConfigInfo(const std::string §ion) { + return MapVectorCharToString(GetConfigInfo(StringToChar(section))); + } + + private: + static void SetGraphOutputTensorNames(const std::vector> &&output_names); + static std::vector> GetGraphOutputTensorNamesInChar(); + static std::map, std::vector> GetConfigInfo(const std::vector &§ion); }; } // namespace converter } // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/optimizer/fusion/fusion_inout_test/fusion_inout_test.cc b/mindspore/lite/test/ut/tools/optimizer/fusion/fusion_inout_test/fusion_inout_test.cc index ed6196758e1..5fa4d7144cc 100644 --- a/mindspore/lite/test/ut/tools/optimizer/fusion/fusion_inout_test/fusion_inout_test.cc +++ b/mindspore/lite/test/ut/tools/optimizer/fusion/fusion_inout_test/fusion_inout_test.cc @@ -18,7 +18,8 @@ #include #include "src/common/log_adapter.h" #include "tools/common/tensor_util.h" -#include "tools/converter/ops/ops_def.h" +#include "ops/make_tuple.h" +#include "ops/return.h" #include "ir/func_graph.h" #include "ops/fusion/conv2d_fusion.h" #include "backend/kernel_compiler/cpu/nnacl/op_base.h" @@ -93,7 +94,7 @@ CNodePtr FusionInoutTest::AddReturn(const FuncGraphPtr &graph, const std::vector if (return_inputs.size() == 1) { return_input = return_inputs.front(); } else { - auto make_tuple_prim_ptr = std::make_shared(); + auto make_tuple_prim_ptr = std::make_shared(); if (make_tuple_prim_ptr == nullptr) { MS_LOG(ERROR) << "new MakeTuple failed"; return nullptr; @@ -107,7 +108,7 @@ CNodePtr FusionInoutTest::AddReturn(const FuncGraphPtr &graph, const std::vector return_input = return_input_cnode; } - auto return_prim = std::make_shared(); + auto return_prim = std::make_shared(); MS_CHECK_TRUE_MSG(return_prim != nullptr, nullptr, "create return primitivec failed"); auto return_cnode = graph->NewCNode(return_prim, {return_input}); MS_CHECK_TRUE_MSG(return_cnode != nullptr, nullptr, "create Return failed"); diff --git a/mindspore/lite/tools/anf_exporter/anf_exporter.cc b/mindspore/lite/tools/anf_exporter/anf_exporter.cc index 0cdf30b458b..dd695bd8adc 100644 --- a/mindspore/lite/tools/anf_exporter/anf_exporter.cc +++ b/mindspore/lite/tools/anf_exporter/anf_exporter.cc @@ -29,8 +29,10 @@ #include "ops/call.h" #include "ops/control_depend.h" #include "ops/depend.h" -#include "tools/converter/ops/ops_def.h" #include "ops/quant_dtype_cast.h" +#include "ops/make_tuple.h" +#include "ops/return.h" +#include "ops/tuple_get_item.h" #include "tools/converter/quant_param_holder.h" #include "tools/optimizer/common/gllo_utils.h" #include "tools/converter/quantizer/bitpacking.h" @@ -428,8 +430,8 @@ int AnfExporter::SetTailCallForNonOutput() { } bool AnfExporter::CaseToContinue(const string &prim_name) { - return prim_name == mindspore::ops::kNameDepend || prim_name == mindspore::lite::kNameTupleGetItem || - prim_name == mindspore::lite::kNameMakeTuple || prim_name == "make_tuple"; + return prim_name == mindspore::ops::kNameDepend || prim_name == mindspore::ops::kNameTupleGetItem || + prim_name == mindspore::ops::kNameMakeTuple || prim_name == "make_tuple"; } int AnfExporter::Anf2Fb(const FuncGraphPtr &func_graph, const std::unique_ptr &meta_graphT, @@ -464,7 +466,7 @@ int AnfExporter::Anf2Fb(const FuncGraphPtr &func_graph, const std::unique_ptrname = mindspore::lite::kNameReturn; + node->name = mindspore::ops::kNameReturn; ret = SetSubGraphOutputIndex(cnode, subgraph_index, meta_graphT, node.get()); if (ret != RET_OK) { MS_LOG(ERROR) << "SetOpOutputN failed"; diff --git a/mindspore/lite/tools/common/graph_util.cc b/mindspore/lite/tools/common/graph_util.cc index 20e431388e6..363c18911ff 100644 --- a/mindspore/lite/tools/common/graph_util.cc +++ b/mindspore/lite/tools/common/graph_util.cc @@ -27,8 +27,8 @@ #include "tools/common/node_util.h" #include "src/common/log_adapter.h" #include "src/common/utils.h" -#include "tools/converter/ops/ops_def.h" #include "nnacl/op_base.h" +#include "ops/make_tuple.h" namespace mindspore { namespace lite { @@ -45,7 +45,7 @@ int SetFuncGraphOutput(const FuncGraphPtr &graph, const std::vector graph->set_output(outputs.front(), false); return RET_OK; } - auto make_tuple_prim_ptr = std::make_shared(); + auto make_tuple_prim_ptr = std::make_shared(); if (make_tuple_prim_ptr == nullptr) { MS_LOG(DEBUG) << "new MakeTuple failed"; return lite::RET_NULL_PTR; diff --git a/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.cc b/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.cc index 80df5aa21df..f2fc9b527e2 100644 --- a/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.cc +++ b/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.cc @@ -17,7 +17,6 @@ #include "tools/converter/adapter/acl/acl_pass_impl.h" #include #include -#include "tools/converter/ops/ops_def.h" #include "tools/common/graph_util.h" #include "tools/common/tensor_util.h" #include "tools/converter/adapter/acl/mapper/primitive_mapper_register.h" @@ -28,6 +27,7 @@ #include "include/registry/pass_registry.h" #include "common/utils.h" #include "ops/custom.h" +#include "ops/tuple_get_item.h" #include "base/core_ops.h" #include "cxx_api/model/acl/model_converter.h" #include "backend/kernel_compiler/cpu/nnacl/op_base.h" @@ -570,7 +570,7 @@ STATUS AclPassImpl::ModifyGraphByCustomNode(const FuncGraphPtr &func_graph, cons } } else { for (size_t j = 0; j < graph_outputs_.size(); ++j) { - auto tuple_get_item_prim_ptr = std::make_shared(); + auto tuple_get_item_prim_ptr = std::make_shared(); if (tuple_get_item_prim_ptr == nullptr) { MS_LOG(ERROR) << "New TupleGetItem failed for output " << j; return lite::RET_ERROR; diff --git a/mindspore/lite/tools/converter/adapter/acl/mapper/spatial_node_adapter.cc b/mindspore/lite/tools/converter/adapter/acl/mapper/spatial_node_adapter.cc index fc4d4ee7ea0..0e6eb0347f8 100644 --- a/mindspore/lite/tools/converter/adapter/acl/mapper/spatial_node_adapter.cc +++ b/mindspore/lite/tools/converter/adapter/acl/mapper/spatial_node_adapter.cc @@ -20,7 +20,6 @@ #include #include #include "tools/converter/adapter/acl/common/utils.h" -#include "tools/converter/ops/ops_def.h" #include "tools/converter/adapter/acl/mapper/tbe_op_def.h" #include "tools/common/tensor_util.h" #include "include/errorcode.h" @@ -30,6 +29,7 @@ #include "ops/batch_norm.h" #include "ops/fused_batch_norm.h" #include "ops/stack.h" +#include "ops/tuple_get_item.h" namespace mindspore { namespace lite { @@ -44,7 +44,7 @@ const std::set kCNodeWithDynamicInput = {kNamewiEltwise, ops::kName CNodePtr CreateTupleGetItemNode(const FuncGraphPtr &func_graph, const CNodePtr &input_cnode) { CNodePtr get_item_cnode = nullptr; - auto tuple_get_item_prim_ptr = std::make_shared(); + auto tuple_get_item_prim_ptr = std::make_shared(); if (tuple_get_item_prim_ptr == nullptr) { MS_LOG(ERROR) << "New TupleGetItem failed"; return nullptr; diff --git a/mindspore/lite/tools/converter/config_parser/config_file_parser.cc b/mindspore/lite/tools/converter/config_parser/config_file_parser.cc index 3b55c323a8d..fd65c2c1430 100644 --- a/mindspore/lite/tools/converter/config_parser/config_file_parser.cc +++ b/mindspore/lite/tools/converter/config_parser/config_file_parser.cc @@ -18,6 +18,7 @@ #include "tools/common/parse_config_utils.h" #include "include/errorcode.h" #include "src/common/log_adapter.h" +#include "tools/converter/converter_context.h" namespace mindspore { namespace lite { @@ -37,35 +38,44 @@ int ConfigFileParser::ParseConfigFile(const std::string &config_file_path) { return ret; } ret = ParseDataPreProcessString(maps); + (void)maps.erase(kDataPreprocessParam); if (ret != RET_OK) { MS_LOG(ERROR) << "ParseDataPreProcessString failed."; return ret; } ret = ParseCommonQuantString(maps); + (void)maps.erase(kCommonQuantParam); if (ret != RET_OK) { MS_LOG(ERROR) << "ParseCommonQuantString failed."; return ret; } ret = ParseMixedBitQuantString(maps); + (void)maps.erase(kMixedBitWeightQuantParam); if (ret != RET_OK) { MS_LOG(ERROR) << "ParseMixedBitQuantString failed."; return ret; } ret = ParseFullQuantString(maps); + (void)maps.erase(kFullQuantParam); if (ret != RET_OK) { MS_LOG(ERROR) << "ParseFullQuantString failed."; return ret; } ret = ParseRegistryInfoString(maps); + (void)maps.erase(kRegistry); if (ret != RET_OK) { MS_LOG(ERROR) << "ParseExtendedintegrationString failed."; return ret; } ret = ParseAclOptionCfgString(maps); + (void)maps.erase(kAclOptionParam); if (ret != RET_OK) { MS_LOG(ERROR) << "ParseAclOptionCfgString failed."; return ret; } + for (const auto &config_info : maps) { + ConverterInnerContext::GetInstance()->SetExternalUsedConfigInfos(config_info.first, config_info.second); + } return RET_OK; } diff --git a/mindspore/lite/tools/converter/converter_context.cc b/mindspore/lite/tools/converter/converter_context.cc index 12e23063116..e310e8ed4a5 100644 --- a/mindspore/lite/tools/converter/converter_context.cc +++ b/mindspore/lite/tools/converter/converter_context.cc @@ -15,22 +15,41 @@ */ #include "tools/converter/converter_context.h" -#include #include #include "include/registry/converter_context.h" namespace mindspore { namespace converter { -void ConverterContext::SetGraphOutputTensorNames(const std::vector &output_names) { +void ConverterContext::SetGraphOutputTensorNames(const std::vector> &&output_names) { auto converter_context = lite::ConverterInnerContext::GetInstance(); - MS_ASSERT(converter_context != nullptr); - converter_context->SetGraphOutputTensorNames(output_names); + if (converter_context == nullptr) { + MS_LOG(ERROR) << "Set graph output's names failed."; + return; + } + converter_context->SetGraphOutputTensorNames(VectorCharToString(output_names)); } -std::vector ConverterContext::GetGraphOutputTensorNames() { +std::vector> ConverterContext::GetGraphOutputTensorNamesInChar() { auto converter_context = lite::ConverterInnerContext::GetInstance(); - MS_ASSERT(converter_context != nullptr); - return converter_context->GetGraphOutputTensorNames(); + if (converter_context == nullptr) { + MS_LOG(ERROR) << "Get graph output's names failed."; + return {}; + } + return VectorStringToChar(converter_context->GetGraphOutputTensorNames()); +} + +std::map, std::vector> ConverterContext::GetConfigInfo(const std::vector &§ion) { + auto converter_context = lite::ConverterInnerContext::GetInstance(); + if (converter_context == nullptr) { + MS_LOG(ERROR) << "Get config information only used by external extension failed."; + return {}; + } + auto &external_used_config_infos = converter_context->GetExternalUsedConfigInfos(); + if (external_used_config_infos.find(CharToString(section)) == external_used_config_infos.end()) { + MS_LOG(ERROR) << "This section " << section << " config info is not existed."; + return {}; + } + return MapStringToVectorChar(external_used_config_infos.at(CharToString(section))); } } // namespace converter } // namespace mindspore diff --git a/mindspore/lite/tools/converter/converter_context.h b/mindspore/lite/tools/converter/converter_context.h index b8b07bbe00a..5183f72a70c 100644 --- a/mindspore/lite/tools/converter/converter_context.h +++ b/mindspore/lite/tools/converter/converter_context.h @@ -112,6 +112,18 @@ class ConverterInnerContext { const std::vector GetGraphOutputTensorNames() const { return graph_output_tensor_names_; } + void SetExternalUsedConfigInfos(const std::string §ion, + const std::map &external_infos) { + if (external_used_config_infos_.find(section) != external_used_config_infos_.end()) { + MS_LOG(WARNING) << "This section " << section << " has been saved. Now, the content will be overwrite."; + } + external_used_config_infos_.emplace(section, external_infos); + } + + const std::map> &GetExternalUsedConfigInfos() { + return external_used_config_infos_; + } + private: ConverterInnerContext() = default; virtual ~ConverterInnerContext() = default; @@ -119,6 +131,7 @@ class ConverterInnerContext { std::map graph_output_data_type_map_; std::map> graph_input_tensor_shape_map_; std::vector graph_output_tensor_names_; + std::map> external_used_config_infos_; }; } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/import/mindir_control_flow_adjust.cc b/mindspore/lite/tools/converter/import/mindir_control_flow_adjust.cc index 3b33bbc3991..0197c398fb2 100644 --- a/mindspore/lite/tools/converter/import/mindir_control_flow_adjust.cc +++ b/mindspore/lite/tools/converter/import/mindir_control_flow_adjust.cc @@ -18,7 +18,8 @@ #include #include #include -#include "tools/converter/ops/ops_def.h" +#include "ops/make_tuple.h" +#include "ops/return.h" #include "tools/converter/converter_context.h" #include "tools/converter/quant_param_holder.h" #include "src/common/log_adapter.h" @@ -130,7 +131,7 @@ FuncGraphPtr MindIRControlFlowAdjust::AddAfterFuncGraph(const FuncGraphPtr &fg, if (after_fg->get_inputs().size() > 1) { std::vector make_tuple_inputs = after_fg->get_inputs(); - auto make_tuple_prim_ptr = std::make_shared(); + auto make_tuple_prim_ptr = std::make_shared(); if (make_tuple_prim_ptr == nullptr) { MS_LOG(ERROR) << "new MakeTuple failed"; return nullptr; @@ -141,7 +142,7 @@ FuncGraphPtr MindIRControlFlowAdjust::AddAfterFuncGraph(const FuncGraphPtr &fg, auto make_tuple_cnode = after_fg->NewCNode(make_tuple_inputs); MS_CHECK_TRUE_MSG(make_tuple_cnode != nullptr, nullptr, "Failed to create C node."); make_tuple_cnode->set_fullname_with_scope("return tuple"); - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); if (return_prim_ptr == nullptr) { MS_LOG(ERROR) << "new Return failed"; return nullptr; @@ -154,7 +155,7 @@ FuncGraphPtr MindIRControlFlowAdjust::AddAfterFuncGraph(const FuncGraphPtr &fg, cnode->set_fullname_with_scope("Return"); after_fg->set_return(cnode); } else { - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); if (return_prim_ptr == nullptr) { MS_LOG(ERROR) << "new Return failed"; return nullptr; diff --git a/mindspore/lite/tools/converter/ops/ops_def.h b/mindspore/lite/tools/converter/ops/ops_def.h index 18e54d60392..787ae495332 100644 --- a/mindspore/lite/tools/converter/ops/ops_def.h +++ b/mindspore/lite/tools/converter/ops/ops_def.h @@ -16,7 +16,6 @@ #ifndef LITE_MINDSPORE_LITE_TOOLS_CONVERTER_OPS_OPS_DEF_H_ #define LITE_MINDSPORE_LITE_TOOLS_CONVERTER_OPS_OPS_DEF_H_ -#include "schema/inner/model_generated.h" #include "ops/primitive_c.h" using mindspore::ops::PrimitiveC; @@ -43,9 +42,6 @@ ADD_CONVERTER_ONLY_OP(TensorArraySizeV3); ADD_CONVERTER_ONLY_OP(TensorArrayV3); ADD_CONVERTER_ONLY_OP(TensorArrayWriteV3); ADD_CONVERTER_ONLY_OP(Constant); -ADD_CONVERTER_ONLY_OP(MakeTuple); -ADD_CONVERTER_ONLY_OP(TupleGetItem); -ADD_CONVERTER_ONLY_OP(Return); ADD_CONVERTER_ONLY_OP(Merge); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_model_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_model_parser.cc index 074791695be..ab0eb6c41bb 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_model_parser.cc @@ -25,7 +25,6 @@ #include "tools/common/graph_util.h" #include "tools/common/protobuf_utils.h" #include "tools/common/tensor_util.h" -#include "tools/converter/ops/ops_def.h" #include "ir/func_graph.h" #include "tools/converter/converter_flags.h" #include "tools/converter/converter_context.h" @@ -35,6 +34,9 @@ #include "tools/converter/parser/unify_format.h" #include "nnacl/op_base.h" #include "src/common/log_util.h" +#include "ops/make_tuple.h" +#include "ops/return.h" +#include "ops/tuple_get_item.h" using mindspore::converter::kFmkTypeCaffe; namespace mindspore::lite { @@ -416,7 +418,7 @@ STATUS CaffeModelParser::ConvertGraphOutputs() { caffeInspector.InspectModel(caffe_model_); if (caffeInspector.GetGraphOutput().size() > 1) { std::vector make_tuple_inputs; - auto make_tuple_prim_ptr = std::make_shared(); + auto make_tuple_prim_ptr = std::make_shared(); MSLITE_CHECK_PTR(make_tuple_prim_ptr); auto make_tuple_prim = NewValueNode(make_tuple_prim_ptr); MSLITE_CHECK_PTR(make_tuple_prim); @@ -434,7 +436,7 @@ STATUS CaffeModelParser::ConvertGraphOutputs() { make_tuple_cnode->set_fullname_with_scope("return tuple"); std::vector op_inputs; - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); MSLITE_CHECK_PTR(return_prim_ptr); auto value_node = NewValueNode(return_prim_ptr); MSLITE_CHECK_PTR(value_node); @@ -445,7 +447,7 @@ STATUS CaffeModelParser::ConvertGraphOutputs() { cnode->set_fullname_with_scope("Return"); res_graph_->set_return(cnode); } else { - auto returnPrim = std::make_shared(); + auto returnPrim = std::make_shared(); MSLITE_CHECK_PTR(returnPrim); auto valueNode = NewValueNode(returnPrim); MSLITE_CHECK_PTR(valueNode); @@ -584,7 +586,7 @@ STATUS CaffeModelParser::ConvertTop(const caffe::LayerParameter &layer, const CN return RET_ERROR; } abstract_list.emplace_back(abstract); - auto tuple_get_item_prim_ptr = std::make_shared(); + auto tuple_get_item_prim_ptr = std::make_shared(); if (tuple_get_item_prim_ptr == nullptr) { MS_LOG(ERROR) << "new TupleGetItem failed"; return RET_NULL_PTR; diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc index e63b8e97907..c746a700cb8 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc @@ -26,7 +26,6 @@ #include "tools/common/graph_util.h" #include "tools/common/protobuf_utils.h" #include "tools/common/tensor_util.h" -#include "tools/converter/ops/ops_def.h" #include "ops/tensor_list_stack.h" #include "ir/func_graph.h" #include "tools/converter/converter_flags.h" @@ -38,6 +37,9 @@ #include "tools/converter/parser/unify_format.h" #include "nnacl/op_base.h" #include "src/common/log_util.h" +#include "ops/make_tuple.h" +#include "ops/return.h" +#include "ops/tuple_get_item.h" using mindspore::converter::kFmkTypeOnnx; namespace mindspore { @@ -161,7 +163,7 @@ CNodePtr GetCNodeFromControlFlowNodesMap( STATUS BuildReturnNode(const FuncGraphPtr &anf_graph, const std::vector &return_inputs) { MS_ASSERT(anf_graph != nullptr); - auto return_prim = std::make_shared(); + auto return_prim = std::make_shared(); if (return_prim == nullptr) { MS_LOG(ERROR) << "new Return failed"; return RET_NULL_PTR; @@ -227,7 +229,7 @@ STATUS BuildOpOutputs(const onnx::NodeProto &onnx_node, const FuncGraphPtr &anf_ return RET_ERROR; } abstract_list.emplace_back(abstract_tensor); - auto tuple_get_item_prim_ptr = std::make_shared(); + auto tuple_get_item_prim_ptr = std::make_shared(); if (tuple_get_item_prim_ptr == nullptr) { MS_LOG(ERROR) << "new TupleGetItem failed"; return RET_NULL_PTR; @@ -326,7 +328,7 @@ STATUS ConvertGraphOutputs(const onnx::GraphProto &onnx_graph, const FuncGraphPt } if (onnx_graph.output_size() > 1) { std::vector make_tuple_inputs; - auto make_tuple_prim_ptr = std::make_shared(); + auto make_tuple_prim_ptr = std::make_shared(); if (make_tuple_prim_ptr == nullptr) { MS_LOG(ERROR) << "new MakeTuple failed"; return RET_NULL_PTR; diff --git a/mindspore/lite/tools/converter/parser/tf/functionalize_cond.cc b/mindspore/lite/tools/converter/parser/tf/functionalize_cond.cc index c357f22d8df..2e33d177188 100644 --- a/mindspore/lite/tools/converter/parser/tf/functionalize_cond.cc +++ b/mindspore/lite/tools/converter/parser/tf/functionalize_cond.cc @@ -23,6 +23,7 @@ #include "tools/converter/ops/ops_def.h" #include "nnacl/op_base.h" #include "src/common/log_util.h" +#include "ops/return.h" namespace mindspore::opt { @@ -157,7 +158,7 @@ FuncGraphPtr FunctionalizeCond::CreateBranchGraph(const AnfNodePtr &node, std::s } if (!CheckPrimitiveType(node, prim::kPrimSwitch)) { // graph is not empty - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); if (return_prim_ptr == nullptr) { MS_LOG(ERROR) << "GetReturnPrim return nullptr"; return nullptr; diff --git a/mindspore/lite/tools/converter/parser/tf/functionalize_while.cc b/mindspore/lite/tools/converter/parser/tf/functionalize_while.cc index e865870f3c0..c91ea2dd689 100644 --- a/mindspore/lite/tools/converter/parser/tf/functionalize_while.cc +++ b/mindspore/lite/tools/converter/parser/tf/functionalize_while.cc @@ -19,7 +19,9 @@ #include #include #include "include/errorcode.h" -#include "tools/converter/ops/ops_def.h" +#include "ops/make_tuple.h" +#include "ops/return.h" +#include "ops/tuple_get_item.h" #include "tools/converter/ops/while.h" #include "tools/common/tensor_util.h" #include "src/common/log_util.h" @@ -224,7 +226,7 @@ STATUS FunctionalizeWhile::UpdateExitNodeUser() { return RET_ERROR; } abstract_list.emplace_back(abstract); - auto tuple_get_item_prim_ptr = std::make_shared(); + auto tuple_get_item_prim_ptr = std::make_shared(); if (tuple_get_item_prim_ptr == nullptr) { MS_LOG(ERROR) << "GetTupleGetItemPrim return nullptr"; return RET_NULL_PTR; @@ -370,7 +372,7 @@ STATUS FunctionalizeWhile::IdentifyCondSubgraphInput() { } STATUS FunctionalizeWhile::IdentifyCondSubgraphOutput() { - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); if (return_prim_ptr == nullptr) { MS_LOG(ERROR) << "GetReturnPrim return nullptr"; return RET_NULL_PTR; @@ -531,7 +533,7 @@ STATUS FunctionalizeWhile::IdentifyBodySubgraphOutput() { "_cnode"); } - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); if (return_prim_ptr == nullptr) { MS_LOG(ERROR) << "GetReturnPrim return nullptr"; return RET_NULL_PTR; @@ -548,7 +550,7 @@ STATUS FunctionalizeWhile::IdentifyBodySubgraphOutput() { return_cnode->add_input(tmp_output[0]); } else { std::vector make_tuple_inputs = tmp_output; - auto make_tuple_prim_ptr = std::make_shared(); + auto make_tuple_prim_ptr = std::make_shared(); if (make_tuple_prim_ptr == nullptr) { MS_LOG(ERROR) << "GetMakeTuplePrim return nullptr"; return RET_NULL_PTR; diff --git a/mindspore/lite/tools/converter/parser/tf/tf_model_parser.cc b/mindspore/lite/tools/converter/parser/tf/tf_model_parser.cc index 16700424880..03053f7c40b 100644 --- a/mindspore/lite/tools/converter/parser/tf/tf_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/tf/tf_model_parser.cc @@ -26,7 +26,9 @@ #include "tools/converter/converter_context.h" #include "tools/converter/parser/tf/tf_node_parser_registry.h" #include "tools/optimizer/common/gllo_utils.h" -#include "tools/converter/ops/ops_def.h" +#include "ops/make_tuple.h" +#include "ops/return.h" +#include "ops/tuple_get_item.h" #include "ir/anf.h" #include "abstract/utils.h" #include "tools/converter/converter_flags.h" @@ -884,7 +886,7 @@ STATUS TFModelParser::ConvertOutputTensor(const tensorflow::NodeDef &op, const C return RET_ERROR; } abstract_list.emplace_back(abstract_tensor); - auto tuple_get_item_prim_ptr = std::make_shared(); + auto tuple_get_item_prim_ptr = std::make_shared(); if (tuple_get_item_prim_ptr == nullptr) { MS_LOG(ERROR) << "new TupleGetItem failed"; return RET_NULL_PTR; @@ -1145,7 +1147,7 @@ STATUS TFModelParser::MakeAnfGraphOutputs(const std::vector &output_ } if (output_nodes.size() > 1) { std::vector make_tuple_inputs = output_nodes; - auto make_tuple_prim_ptr = std::make_shared(); + auto make_tuple_prim_ptr = std::make_shared(); if (make_tuple_prim_ptr == nullptr) { MS_LOG(ERROR) << "new MakeTuple failed"; return RET_NULL_PTR; @@ -1157,7 +1159,7 @@ STATUS TFModelParser::MakeAnfGraphOutputs(const std::vector &output_ CHECK_NULL_RETURN(make_tuple_cnode); make_tuple_cnode->set_fullname_with_scope("return_tuple"); - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); if (return_prim_ptr == nullptr) { MS_LOG(ERROR) << "new Return failed"; return RET_NULL_PTR; @@ -1170,7 +1172,7 @@ STATUS TFModelParser::MakeAnfGraphOutputs(const std::vector &output_ cnode->set_fullname_with_scope("Return"); anf_graph->set_return(cnode); } else { - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); if (return_prim_ptr == nullptr) { MS_LOG(ERROR) << "new Return failed"; return RET_NULL_PTR; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc index e737dbdf858..b2f1e34e981 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc @@ -24,7 +24,6 @@ #include "ops/primitive_c.h" #include "ir/func_graph.h" #include "src/common/file_utils.h" -#include "tools/converter/ops/ops_def.h" #include "tools/common/graph_util.h" #include "tools/converter/quant_param_holder.h" #include "tools/converter/converter_context.h" @@ -34,6 +33,9 @@ #include "tools/converter/parser/unify_format.h" #include "nnacl/op_base.h" #include "src/common/log_util.h" +#include "ops/make_tuple.h" +#include "ops/return.h" +#include "ops/tuple_get_item.h" using mindspore::converter::kFmkTypeTflite; namespace mindspore::lite { @@ -479,7 +481,7 @@ STATUS TfliteModelParser::ConvertGraphOutputs(const std::unique_ptr(); + auto make_tuple_prim_ptr = std::make_shared(); if (make_tuple_prim_ptr == nullptr) { MS_LOG(ERROR) << "new MakeTuple failed"; return RET_NULL_PTR; @@ -491,7 +493,7 @@ STATUS TfliteModelParser::ConvertGraphOutputs(const std::unique_ptrNewCNode(make_tuple_inputs); MSLITE_CHECK_PTR(make_tuple_cnode); make_tuple_cnode->set_fullname_with_scope("return_tuple"); - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); if (return_prim_ptr == nullptr) { MS_LOG(ERROR) << "new Return failed"; return RET_NULL_PTR; @@ -505,7 +507,7 @@ STATUS TfliteModelParser::ConvertGraphOutputs(const std::unique_ptrset_fullname_with_scope("Return"); func_graph->set_return(cnode); } else { - auto returnPrim = std::make_shared(); + auto returnPrim = std::make_shared(); if (returnPrim == nullptr) { MS_LOG(ERROR) << "new Return failed"; return RET_NULL_PTR; @@ -774,7 +776,7 @@ STATUS TfliteModelParser::ConvertOutputTensor(const std::unique_ptr(); + auto tuple_get_item_prim_ptr = std::make_shared(); if (tuple_get_item_prim_ptr == nullptr) { MS_LOG(ERROR) << "new TupleGetItem failed"; return RET_NULL_PTR; diff --git a/mindspore/lite/tools/converter/quantizer/calibrator.cc b/mindspore/lite/tools/converter/quantizer/calibrator.cc index 789bde359ef..0d854a07e56 100644 --- a/mindspore/lite/tools/converter/quantizer/calibrator.cc +++ b/mindspore/lite/tools/converter/quantizer/calibrator.cc @@ -17,7 +17,7 @@ #include "tools/converter/quantizer/calibrator.h" #include #include "tools/converter/preprocess/image_preprocess.h" -#include "tools/converter/ops/ops_def.h" +#include "ops/tuple_get_item.h" #include "tools/optimizer/common/gllo_utils.h" #include "include/errorcode.h" #include "src/common/log_adapter.h" @@ -63,7 +63,7 @@ int Calibrator::ComputeThreshold() { for (const auto &output_diverg_info : outputs_diverg_info.second) { auto output_diverg_cnode = output_diverg_info.second->GetCNode(); if (output_diverg_cnode == input_cnode) { - if (NodePrimitiveType(input_cnode) != lite::kNameTupleGetItem) { + if (NodePrimitiveType(input_cnode) != ops::kNameTupleGetItem) { *(input_infos[i]) = *output_diverg_info.second; input_infos[i]->GetCNode() = cnode; already_computed = true; diff --git a/mindspore/lite/tools/converter/quantizer/full_quant_quantizer.cc b/mindspore/lite/tools/converter/quantizer/full_quant_quantizer.cc index 9e246e5c2a9..ddff76f8aa9 100644 --- a/mindspore/lite/tools/converter/quantizer/full_quant_quantizer.cc +++ b/mindspore/lite/tools/converter/quantizer/full_quant_quantizer.cc @@ -28,7 +28,7 @@ #include #include #include "ops/fusion/full_connection.h" -#include "tools/converter/ops/ops_def.h" +#include "ops/tuple_get_item.h" #include "src/tensor.h" #include "tools/converter/quantizer/quant_cast.h" #include "tools/converter/quantizer/quantize_util.h" @@ -462,7 +462,7 @@ int FullQuantQuantizer::QuantNode(const FuncGraphPtr &func_graph) { auto op_type = primitive->name(); MS_LOG(DEBUG) << "OpName: " << op_name; - if (op_type == lite::kNameTupleGetItem) { + if (op_type == mindspore::ops::kNameTupleGetItem) { constexpr int tuple_get_item_input_size = 3; MS_CHECK_TRUE_MSG(cnode->size() == tuple_get_item_input_size, RET_ERROR, "cnode->size() != 3"); auto index_node = cnode->input(THIRD_INPUT); diff --git a/mindspore/lite/tools/optimizer/common/gllo_utils.cc b/mindspore/lite/tools/optimizer/common/gllo_utils.cc index 26db7644f12..79842fed04b 100644 --- a/mindspore/lite/tools/optimizer/common/gllo_utils.cc +++ b/mindspore/lite/tools/optimizer/common/gllo_utils.cc @@ -25,7 +25,7 @@ #include "ops/fusion/conv2d_fusion.h" #include "ops/transpose.h" #include "ops/gather.h" -#include "tools/converter/ops/ops_def.h" +#include "ops/tuple_get_item.h" #include "tools/common/tensor_util.h" #include "frontend/operator/ops.h" #include "backend/optimizer/common/helper.h" @@ -174,121 +174,6 @@ bool IsRealKernel(const AnfNodePtr &node) { #endif return !is_virtual_node; } - -ValueNodePtr CreateValueNodeWithSexp(const BaseRef &sexp) { - if (utils::isa(sexp)) { - return NewValueNode(utils::cast(sexp)); - } - if (utils::isa(sexp)) { - return NewValueNode(utils::cast(sexp)); - } - if (utils::isa(sexp)) { - return NewValueNode(utils::cast(sexp)); - } - if (utils::isa(sexp)) { - return NewValueNode(utils::cast(sexp)); - } - return nullptr; -} - -CNodePtr CreateCNodeWithGraph(const std::vector &input_nodes, const BaseRef &graph) { - if (utils::isa(graph)) { - return std::make_shared(input_nodes, utils::cast(graph)); - } - if (utils::isa(graph)) { - return std::make_shared(input_nodes, utils::cast(graph)); - } - return nullptr; -} - -VarNodePtr CreateVarNodeWithSexp(const BaseRef &sexp, const BaseRef &graph) { - if (utils::isa(graph)) { - MS_LOG(DEBUG) << "make VarPtr " + graph.ToString(); - return std::make_shared(utils::cast(sexp), nullptr); - } - if (utils::isa(graph)) { - MS_LOG(DEBUG) << "VarNode, should input a Var in graph. It's GraphPtr: " + graph.ToString(); - return std::make_shared(utils::cast(sexp), utils::cast(graph)); - } - MS_LOG(ERROR) << "VarNode, should input a Var in graph. It's " + graph.ToString(); - return nullptr; -} - -AnfNodePtr HandleSexpVector(const BaseRef &sexp, const BaseRef &graph, PrimitiveVarMap *primitive_vars, - bool multigraph) { - if (primitive_vars == nullptr) { - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return nullptr; - } - MS_LOG(DEBUG) << "HandleSexpVector sexp: " + sexp.ToString() + ", graph " + graph.ToString(); - std::vector input_nodes; - const auto &tuple = utils::cast(sexp); - if (multigraph && utils::isa(graph)) { - for (auto &x : tuple) { - auto is_var = std::make_shared("G"); - MS_CHECK_TRUE_RET(is_var != nullptr, nullptr); - AnfNodePtr node = SexpToNode(x, is_var, primitive_vars, true); - input_nodes.push_back(node); - } - auto var_ptr = utils::cast(graph); - return std::make_shared(input_nodes, var_ptr); - } - - for (auto &x : tuple) { - AnfNodePtr node = SexpToNode(x, graph, primitive_vars, multigraph); - input_nodes.push_back(node); - } - return CreateCNodeWithGraph(input_nodes, graph); -} - -bool AnfEqualPrimitive(const AnfNodePtr &a_node, const AnfNodePtr &b_node) { - auto a_value_node = a_node->cast(); - auto b_value_node = b_node->cast(); - if (a_value_node == nullptr || b_value_node == nullptr) { - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return false; - } - - auto a_value = a_value_node->value(); - auto b_value = b_value_node->value(); - if (a_value == nullptr || b_value == nullptr) { - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return false; - } - - auto a_prim = a_value->cast(); - auto b_prim = b_value->cast(); - if (a_prim == nullptr || b_prim == nullptr) { - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return false; - } - return a_prim->name() == b_prim->name(); -} - -bool AnfEqualValueNode(const AnfNodePtr &a_node, const AnfNodePtr &b_node) { - auto a_value_node_ptr = a_node->cast(); - auto b_value_node_ptr = b_node->cast(); - if (a_value_node_ptr == nullptr || b_value_node_ptr == nullptr) { - MS_LOG(ERROR) << "cast value node ptr fail"; - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return false; - } - auto a_value_ptr = a_value_node_ptr->value(); - auto b_value_ptr = b_value_node_ptr->value(); - if (a_value_ptr == nullptr || b_value_ptr == nullptr) { - MS_LOG(ERROR) << "value ptr is nullptr"; - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return false; - } - - if (utils::isa(a_value_ptr) && utils::isa(b_value_ptr)) { - auto a_obj = (ops::PrimitiveC *)(a_value_ptr.get()); - auto b_obj = (ops::PrimitiveC *)(b_value_ptr.get()); - return (*a_obj) == (*b_obj); - } else { - return (*a_value_ptr) == (*b_value_ptr); - } -} } // namespace bool CheckInputs(const CNodePtr &cnode) { @@ -414,71 +299,6 @@ bool CheckPrimitiveType(const AnfNodePtr &node, const PrimitivePtr &primitive_ty return false; } -bool AnfEqual(const BaseRef &a, const BaseRef &b) { - if (utils::isa(a) && utils::isa(b)) { - auto a_node = utils::cast(a); - auto b_node = utils::cast(b); - if (a_node == nullptr || b_node == nullptr) { - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return false; - } - if (IsValueNode(a_node) && IsValueNode(b_node)) { - return AnfEqualPrimitive(a_node, b_node); - } - if (a_node->isa() && b_node->isa()) { - return AnfEqualValueNode(a_node, b_node); - } - } - if (a.m_ptr->isa() && b.m_ptr->isa()) { - auto a_value_node_ptr = a.m_ptr->cast(); - auto b_value_node_ptr = b.m_ptr->cast(); - return a_value_node_ptr->name() == b_value_node_ptr->name(); - } - - return a == b; -} - -bool CNodeTypeEqual(const BaseRef &a, const BaseRef &b) { - // To matchCNode and Kernel's type - if (utils::isa(a) && utils::isa(b)) { - return true; - } - return a.type() == b.type(); -} - -AnfNodePtr SexpToNode(const BaseRef &sexp, const BaseRef &graph, PrimitiveVarMap *primitive_vars, bool multigraph) { - MS_LOG(DEBUG) << "SexpToNode sexp: " + sexp.ToString() + ", graph " + graph.ToString(); - if (primitive_vars == nullptr) { - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return nullptr; - } - if (utils::isa(sexp)) { - return HandleSexpVector(sexp, graph, primitive_vars, multigraph); - } - if (utils::isa(sexp)) { - auto var_ptr = utils::cast(sexp); - if (var_ptr == nullptr) { - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return nullptr; - } - if (var_ptr->primitive()) { - (*primitive_vars)[var_ptr->primitive()] = var_ptr; - return NewValueNode(var_ptr->primitive()); - } - return CreateVarNodeWithSexp(sexp, graph); - } - if (utils::isa(sexp)) { - return utils::cast(sexp); - } - auto value_node = CreateValueNodeWithSexp(sexp); - if (value_node == nullptr) { - MS_LOG(ERROR) << "sexp cannot converted. sexp: " << sexp.ToString(); - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return nullptr; - } - return value_node; -} - bool IsOpType(const BaseRef &n, const PrimitivePtr &prim) { if (utils::isa(n)) { auto anf_node = utils::cast(n); @@ -795,31 +615,6 @@ bool IsMultiOutputTensors(const FuncGraphPtr &graph, const AnfNodePtr &node) { return false; } -std::shared_ptr>> GetRealNodeUsedList(const FuncGraphPtr &graph, - const AnfNodePtr &node) { - if (graph == nullptr || node == nullptr) { - MS_LOG(ERROR) << "input parameter is nullptr."; - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return nullptr; - } - auto output_node_list = std::make_shared>>(); - MS_CHECK_TRUE_RET(output_node_list != nullptr, nullptr); - auto manager = graph->manager(); - if (manager == nullptr) { - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); - return nullptr; - } - auto iter = manager->node_users().find(node); - if (iter == manager->node_users().end()) { - MS_LOG(ERROR) << "node has no output in manager"; - lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_ERROR); - return nullptr; - } - auto output_info_list = iter->second; - std::copy(output_info_list.begin(), output_info_list.end(), std::back_inserter(*output_node_list)); - return output_node_list; -} - size_t GetTupleGetItemOutIndex(const CNodePtr &tuple_get_item) { if (tuple_get_item == nullptr || tuple_get_item->size() != kInputSizeThree) { MS_LOG(ERROR) << "The node tuple_get_item is invalid."; @@ -843,43 +638,6 @@ size_t GetTupleGetItemOutIndex(const CNodePtr &tuple_get_item) { return indexes.front(); } -std::shared_ptr>> GetRealNodeUsedListByOutputIdx(const FuncGraphPtr &graph, - const AnfNodePtr &node, - size_t output_index) { - if (graph == nullptr || node == nullptr) { - MS_LOG(ERROR) << "input parameter is nullptr."; - return nullptr; - } - auto output_node_list = std::make_shared>>(); - MS_CHECK_TRUE_RET(output_node_list != nullptr, nullptr); - auto manager = graph->manager(); - MS_CHECK_TRUE_RET(manager != nullptr, nullptr); - auto iter = manager->node_users().find(node); - if (iter == manager->node_users().end()) { - MS_LOG(ERROR) << "node has no output in manager"; - return output_node_list; - } - auto output_info_list = iter->second; - for (const auto &output_info : output_info_list) { - size_t used_output_index; - if (CheckPrimitiveType(output_info.first, prim::kPrimTupleGetItem)) { - used_output_index = GetTupleGetItemOutIndex(utils::cast(output_info.first)); - } else if (CheckPrimitiveType(node, prim::kPrimTupleGetItem)) { - used_output_index = output_index; - } else { - if (output_index != 0) { - MS_LOG(ERROR) << "node has no output in manager"; - return output_node_list; - } - return output_node_list; - } - if (used_output_index == output_index) { - output_node_list->push_back(output_info); - } - } - return output_node_list; -} - STATUS TransFilterFormat(const tensor::TensorPtr &tensor, schema::Format src_format, schema::Format dst_format) { MS_CHECK_TRUE_RET(tensor != nullptr, RET_ERROR); std::unordered_map> @@ -1135,7 +893,7 @@ CNodePtr GenTupleGetItemNode(const FuncGraphPtr &func_graph, const CNodePtr &inp MS_LOG(ERROR) << "input parameter is nullptr, which is invalid."; return nullptr; } - auto tuple_get_item_prim = std::make_shared(); + auto tuple_get_item_prim = std::make_shared(); MS_CHECK_TRUE_RET(tuple_get_item_prim != nullptr, nullptr); auto second_input = NewValueNode(MakeValue(index)); MS_CHECK_TRUE_RET(second_input != nullptr, nullptr); @@ -1238,17 +996,6 @@ int GetDataTypeFromAnfNode(const AnfNodePtr &anf_node, TypeId *type_id) { return RET_OK; } -// not implement for lite, just for api compatible -CNodePtr NewCNode(const std::vector &inputs, const FuncGraphPtr &fg, - const std::vector &orig_nodes) { - return fg->NewCNode(inputs); -} - -// not implement for lite, just for api compatible -CNodePtr NewCNode(const CNodePtr &cnode, const KernelGraphPtr &fg, const std::vector &orig_nodes) { - return nullptr; -} - bool IsQuantParameterNode(const PrimitiveCPtr &prim) { MS_CHECK_TRUE_RET(prim != nullptr, false); auto quant_attr = prim->GetAttr("quant_params"); diff --git a/mindspore/lite/tools/optimizer/common/helper.cc b/mindspore/lite/tools/optimizer/common/helper.cc new file mode 100644 index 00000000000..68b3ea39fc4 --- /dev/null +++ b/mindspore/lite/tools/optimizer/common/helper.cc @@ -0,0 +1,279 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "backend/optimizer/common/helper.h" +#include +#include +#include "tools/optimizer/common/gllo_utils.h" +#include "nnacl/op_base.h" + +namespace mindspore { +namespace opt { +namespace { +ValueNodePtr CreateValueNodeWithSexp(const BaseRef &sexp) { + if (utils::isa(sexp)) { + return NewValueNode(utils::cast(sexp)); + } + if (utils::isa(sexp)) { + return NewValueNode(utils::cast(sexp)); + } + if (utils::isa(sexp)) { + return NewValueNode(utils::cast(sexp)); + } + if (utils::isa(sexp)) { + return NewValueNode(utils::cast(sexp)); + } + return nullptr; +} + +CNodePtr CreateCNodeWithGraph(const std::vector &input_nodes, const BaseRef &graph) { + if (utils::isa(graph)) { + return std::make_shared(input_nodes, utils::cast(graph)); + } + if (utils::isa(graph)) { + return std::make_shared(input_nodes, utils::cast(graph)); + } + return nullptr; +} + +VarNodePtr CreateVarNodeWithSexp(const BaseRef &sexp, const BaseRef &graph) { + if (utils::isa(graph)) { + MS_LOG(DEBUG) << "make VarPtr " + graph.ToString(); + return std::make_shared(utils::cast(sexp), nullptr); + } + if (utils::isa(graph)) { + MS_LOG(DEBUG) << "VarNode, should input a Var in graph. It's GraphPtr: " + graph.ToString(); + return std::make_shared(utils::cast(sexp), utils::cast(graph)); + } + MS_LOG(ERROR) << "VarNode, should input a Var in graph. It's " + graph.ToString(); + return nullptr; +} + +AnfNodePtr HandleSexpVector(const BaseRef &sexp, const BaseRef &graph, PrimitiveVarMap *primitive_vars, + bool multigraph) { + if (primitive_vars == nullptr) { + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return nullptr; + } + MS_LOG(DEBUG) << "HandleSexpVector sexp: " + sexp.ToString() + ", graph " + graph.ToString(); + std::vector input_nodes; + const auto &tuple = utils::cast(sexp); + if (multigraph && utils::isa(graph)) { + for (auto &x : tuple) { + auto is_var = std::make_shared("G"); + MS_CHECK_TRUE_RET(is_var != nullptr, nullptr); + AnfNodePtr node = SexpToNode(x, is_var, primitive_vars, true); + input_nodes.push_back(node); + } + auto var_ptr = utils::cast(graph); + return std::make_shared(input_nodes, var_ptr); + } + + for (auto &x : tuple) { + AnfNodePtr node = SexpToNode(x, graph, primitive_vars, multigraph); + input_nodes.push_back(node); + } + return CreateCNodeWithGraph(input_nodes, graph); +} + +bool AnfEqualPrimitive(const AnfNodePtr &a_node, const AnfNodePtr &b_node) { + auto a_value_node = a_node->cast(); + auto b_value_node = b_node->cast(); + if (a_value_node == nullptr || b_value_node == nullptr) { + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return false; + } + + auto a_value = a_value_node->value(); + auto b_value = b_value_node->value(); + if (a_value == nullptr || b_value == nullptr) { + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return false; + } + + auto a_prim = a_value->cast(); + auto b_prim = b_value->cast(); + if (a_prim == nullptr || b_prim == nullptr) { + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return false; + } + return a_prim->name() == b_prim->name(); +} + +bool AnfEqualValueNode(const AnfNodePtr &a_node, const AnfNodePtr &b_node) { + auto a_value_node_ptr = a_node->cast(); + auto b_value_node_ptr = b_node->cast(); + if (a_value_node_ptr == nullptr || b_value_node_ptr == nullptr) { + MS_LOG(ERROR) << "cast value node ptr fail"; + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return false; + } + auto a_value_ptr = a_value_node_ptr->value(); + auto b_value_ptr = b_value_node_ptr->value(); + if (a_value_ptr == nullptr || b_value_ptr == nullptr) { + MS_LOG(ERROR) << "value ptr is nullptr"; + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return false; + } + + if (utils::isa(a_value_ptr) && utils::isa(b_value_ptr)) { + auto a_obj = (ops::PrimitiveC *)(a_value_ptr.get()); + auto b_obj = (ops::PrimitiveC *)(b_value_ptr.get()); + return (*a_obj) == (*b_obj); + } else { + return (*a_value_ptr) == (*b_value_ptr); + } +} +} // namespace +// not implement for lite, just for api compatible +CNodePtr NewCNode(const std::vector &inputs, const FuncGraphPtr &fg, + const std::vector &orig_nodes) { + return fg->NewCNode(inputs); +} + +// not implement for lite, just for api compatible +CNodePtr NewCNode(const CNodePtr &cnode, const KernelGraphPtr &fg, const std::vector &orig_nodes) { + return nullptr; +} + +std::shared_ptr>> GetRealNodeUsedList(const FuncGraphPtr &graph, + const AnfNodePtr &node) { + if (graph == nullptr || node == nullptr) { + MS_LOG(ERROR) << "input parameter is nullptr."; + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return nullptr; + } + auto output_node_list = std::make_shared>>(); + MS_CHECK_TRUE_RET(output_node_list != nullptr, nullptr); + auto manager = graph->manager(); + if (manager == nullptr) { + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return nullptr; + } + auto iter = manager->node_users().find(node); + if (iter == manager->node_users().end()) { + MS_LOG(ERROR) << "node has no output in manager"; + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_ERROR); + return nullptr; + } + auto output_info_list = iter->second; + std::copy(output_info_list.begin(), output_info_list.end(), std::back_inserter(*output_node_list)); + return output_node_list; +} + +std::shared_ptr>> GetRealNodeUsedListByOutputIdx(const FuncGraphPtr &graph, + const AnfNodePtr &node, + size_t output_index) { + if (graph == nullptr || node == nullptr) { + MS_LOG(ERROR) << "input parameter is nullptr."; + return nullptr; + } + auto output_node_list = std::make_shared>>(); + MS_CHECK_TRUE_RET(output_node_list != nullptr, nullptr); + auto manager = graph->manager(); + MS_CHECK_TRUE_RET(manager != nullptr, nullptr); + auto iter = manager->node_users().find(node); + if (iter == manager->node_users().end()) { + MS_LOG(ERROR) << "node has no output in manager"; + return output_node_list; + } + auto output_info_list = iter->second; + for (const auto &output_info : output_info_list) { + size_t used_output_index; + if (CheckPrimitiveType(output_info.first, prim::kPrimTupleGetItem)) { + used_output_index = GetTupleGetItemOutIndex(utils::cast(output_info.first)); + } else if (CheckPrimitiveType(node, prim::kPrimTupleGetItem)) { + used_output_index = output_index; + } else { + if (output_index != 0) { + MS_LOG(ERROR) << "node has no output in manager"; + return output_node_list; + } + return output_node_list; + } + if (used_output_index == output_index) { + output_node_list->push_back(output_info); + } + } + return output_node_list; +} + +bool AnfEqual(const BaseRef &a, const BaseRef &b) { + if (utils::isa(a) && utils::isa(b)) { + auto a_node = utils::cast(a); + auto b_node = utils::cast(b); + if (a_node == nullptr || b_node == nullptr) { + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return false; + } + if (IsValueNode(a_node) && IsValueNode(b_node)) { + return AnfEqualPrimitive(a_node, b_node); + } + if (a_node->isa() && b_node->isa()) { + return AnfEqualValueNode(a_node, b_node); + } + } + if (a.m_ptr->isa() && b.m_ptr->isa()) { + auto a_value_node_ptr = a.m_ptr->cast(); + auto b_value_node_ptr = b.m_ptr->cast(); + return a_value_node_ptr->name() == b_value_node_ptr->name(); + } + + return a == b; +} + +bool CNodeTypeEqual(const BaseRef &a, const BaseRef &b) { + // To matchCNode and Kernel's type + if (utils::isa(a) && utils::isa(b)) { + return true; + } + return a.type() == b.type(); +} + +AnfNodePtr SexpToNode(const BaseRef &sexp, const BaseRef &graph, PrimitiveVarMap *primitive_vars, bool multigraph) { + MS_LOG(DEBUG) << "SexpToNode sexp: " + sexp.ToString() + ", graph " + graph.ToString(); + if (primitive_vars == nullptr) { + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return nullptr; + } + if (utils::isa(sexp)) { + return HandleSexpVector(sexp, graph, primitive_vars, multigraph); + } + if (utils::isa(sexp)) { + auto var_ptr = utils::cast(sexp); + if (var_ptr == nullptr) { + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return nullptr; + } + if (var_ptr->primitive()) { + (*primitive_vars)[var_ptr->primitive()] = var_ptr; + return NewValueNode(var_ptr->primitive()); + } + return CreateVarNodeWithSexp(sexp, graph); + } + if (utils::isa(sexp)) { + return utils::cast(sexp); + } + auto value_node = CreateValueNodeWithSexp(sexp); + if (value_node == nullptr) { + MS_LOG(ERROR) << "sexp cannot converted. sexp: " << sexp.ToString(); + lite::ReturnCode::GetSingleReturnCode()->UpdateReturnCode(lite::RET_NULL_PTR); + return nullptr; + } + return value_node; +} +} // namespace opt +} // namespace mindspore diff --git a/mindspore/lite/tools/optimizer/fusion/tflite_lstm_cell_fusion.cc b/mindspore/lite/tools/optimizer/fusion/tflite_lstm_cell_fusion.cc index 9734605364e..2955ffbc381 100644 --- a/mindspore/lite/tools/optimizer/fusion/tflite_lstm_cell_fusion.cc +++ b/mindspore/lite/tools/optimizer/fusion/tflite_lstm_cell_fusion.cc @@ -19,7 +19,7 @@ #include #include "ops/lstm.h" #include "ops/squeeze.h" -#include "tools/converter/ops/ops_def.h" +#include "ops/tuple_get_item.h" #include "src/common/utils.h" #include "tools/common/tensor_util.h" #include "utils/utils.h" @@ -608,7 +608,7 @@ CNodePtr TfliteLstmCellFusion::CreateOutputGetItem(const FuncGraphPtr &func_grap const int item_index) { MS_ASSERT(func_graph != nullptr); MS_ASSERT(node != nullptr); - auto tuple_get_item_prim = std::make_shared(); + auto tuple_get_item_prim = std::make_shared(); auto get_item_value = NewValueNode(MakeValue(item_index)); if (tuple_get_item_prim == nullptr || get_item_value == nullptr) { MS_LOG(ERROR) << "NewValueNode is nullptr"; @@ -801,9 +801,7 @@ const AnfNodePtr TfliteLstmCellFusion::Process(const FuncGraphPtr &func_graph, c std::vector squeeze_axis{1}; // our lstm output:0 have an extra axis that tflite not have, it must be squeezed auto squeeze_node = CreateSqueezeNode(func_graph, get_item_node, squeeze_axis); - if (squeeze_node == nullptr) { - return nullptr; - } + MS_CHECK_TRUE_MSG(squeeze_node != nullptr, nullptr, "create a squeeze node failed."); auto cond_cnode_index_pair = std::make_shared(while_cnode, 1); MS_CHECK_TRUE_RET(cond_cnode_index_pair != nullptr, nullptr); diff --git a/mindspore/lite/tools/optimizer/graph/add_tensor_array.cc b/mindspore/lite/tools/optimizer/graph/add_tensor_array.cc index 0296606a610..cae66837d8a 100644 --- a/mindspore/lite/tools/optimizer/graph/add_tensor_array.cc +++ b/mindspore/lite/tools/optimizer/graph/add_tensor_array.cc @@ -23,8 +23,9 @@ #include "ops/tensor_array.h" #include "ops/tensor_array_read.h" #include "ops/tensor_array_write.h" -#include "tools/converter/ops/ops_def.h" #include "nnacl/op_base.h" +#include "ops/make_tuple.h" +#include "ops/return.h" namespace mindspore::opt { constexpr auto kDefaultIndex = 0; @@ -78,7 +79,7 @@ static int SetGraphOutput(const FuncGraphPtr &func_graph, const AnfNodePtr &tens // for single output graph, create tuple for graph output // make_tuple node - auto make_tuple_prim_ptr = std::make_shared(); + auto make_tuple_prim_ptr = std::make_shared(); if (make_tuple_prim_ptr == nullptr) { MS_LOG(ERROR) << "make_tuple_prim_ptr is nullptr"; return lite::RET_NULL_PTR; @@ -93,7 +94,7 @@ static int SetGraphOutput(const FuncGraphPtr &func_graph, const AnfNodePtr &tens make_tuple_cnode->set_fullname_with_scope("return tuple"); // return node - auto return_prim_ptr = std::make_shared(); + auto return_prim_ptr = std::make_shared(); if (return_prim_ptr == nullptr) { MS_LOG(ERROR) << "return_prim_ptr is nullptr"; return lite::RET_NULL_PTR; diff --git a/mindspore/lite/tools/optimizer/graph/redundant_op_remove_pass.cc b/mindspore/lite/tools/optimizer/graph/redundant_op_remove_pass.cc index e227b6add87..89918807eff 100644 --- a/mindspore/lite/tools/optimizer/graph/redundant_op_remove_pass.cc +++ b/mindspore/lite/tools/optimizer/graph/redundant_op_remove_pass.cc @@ -20,7 +20,7 @@ #include #include "include/errorcode.h" #include "tools/anf_exporter/fetch_content.h" -#include "tools/converter/ops/ops_def.h" +#include "ops/make_tuple.h" #include "ops/depend.h" #include "ops/fusion/pad_fusion.h" #include "ops/op_utils.h" @@ -120,7 +120,7 @@ int ProcessInputHaveDependency(const FuncGraphPtr &func_graph, const CNodePtr &c if (ProcessDependencyWithTwoNodes(func_graph, cnode, false) == lite::RET_OK) { return lite::RET_OK; } - auto make_tuple_prim = NewValueNode(std::make_shared()); + auto make_tuple_prim = NewValueNode(std::make_shared()); auto manager = func_graph->manager(); MS_CHECK_TRUE_MSG(make_tuple_prim != nullptr, lite::RET_NULL_PTR, "NewCNode Failed"); MS_ASSERT(manager != nullptr); diff --git a/mindspore/lite/tools/optimizer/parallel/operator_info.cc b/mindspore/lite/tools/optimizer/parallel/operator_info.cc index 703414c095b..219e113036b 100644 --- a/mindspore/lite/tools/optimizer/parallel/operator_info.cc +++ b/mindspore/lite/tools/optimizer/parallel/operator_info.cc @@ -16,10 +16,10 @@ #include "tools/optimizer/parallel/operator_info.h" #include -#include "tools/converter/ops/ops_def.h" #include "tools/optimizer/parallel/split_strategy.h" #include "ops/concat.h" #include "ops/addn.h" +#include "ops/tuple_get_item.h" #include "utils/utils.h" #include "base/core_ops.h" #include "include/errorcode.h" @@ -120,7 +120,7 @@ int OperatorInfo::CreateMultipleOutputsOfAnfNode(const AnfNodePtr &node, size_t auto abstract_scalar = std::make_shared(index); MS_CHECK_TRUE_RET(abstract_scalar != nullptr, lite::RET_ERROR); idx->set_abstract(abstract_scalar); - auto tuple_getitem = func_graph_->NewCNode({NewValueNode(std::make_shared()), node, idx}); + auto tuple_getitem = func_graph_->NewCNode({NewValueNode(std::make_shared()), node, idx}); if (tuple_getitem == nullptr) { MS_LOG(ERROR) << name_ << " : Failed to create output nodes."; return lite::RET_ERROR;