diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index 517f4042656..457f665a8f6 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -281,8 +281,6 @@ if(PLATFORM_ARM64) COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${ABSTRACT_HEADER} DESTINATION ${CONVERTER_ROOT_DIR}/include/core/abstract COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${API_IR_HEADER} DESTINATION ${CONVERTER_ROOT_DIR}/include/core/api/ir - COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${BASE_HEADER} DESTINATION ${CONVERTER_ROOT_DIR}/include/core/base COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${IR_DTYPE_HEADER} DESTINATION ${CONVERTER_ROOT_DIR}/include/core/ir/dtype @@ -656,8 +654,6 @@ else() COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${ABSTRACT_HEADER} DESTINATION ${CONVERTER_ROOT_DIR}/include/core/abstract COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${API_IR_HEADER} DESTINATION ${CONVERTER_ROOT_DIR}/include/core/api/ir - COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${BASE_HEADER} DESTINATION ${CONVERTER_ROOT_DIR}/include/core/base COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${IR_DTYPE_HEADER} DESTINATION ${CONVERTER_ROOT_DIR}/include/core/ir/dtype diff --git a/mindspore/core/abstract/primitive_infer_map.cc b/mindspore/core/abstract/primitive_infer_map.cc index 0021f684982..30de7f261cb 100644 --- a/mindspore/core/abstract/primitive_infer_map.cc +++ b/mindspore/core/abstract/primitive_infer_map.cc @@ -1,7 +1,7 @@ /** * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). * - * Copyright 2019-2021 Huawei Technologies Co., Ltd + * Copyright 2019-2022 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. @@ -16,7 +16,6 @@ * limitations under the License. */ -#define USE_DEPRECATED_API #include "abstract/primitive_infer_map.h" #include #include diff --git a/mindspore/core/api/ir/OWNERS b/mindspore/core/api/ir/OWNERS deleted file mode 100644 index d3d1f24870c..00000000000 --- a/mindspore/core/api/ir/OWNERS +++ /dev/null @@ -1,13 +0,0 @@ -reviewers: -- zh_qh -- hwhewei -- xychow -- ginfung -- chenfei52 -- zhangzhaoju -- lanzhineng -- lianliguang -- Margaret_wangrui -- irmo -- huangbingjian -- liangzhibo diff --git a/mindspore/core/api/ir/func_graph.h b/mindspore/core/api/ir/func_graph.h deleted file mode 100644 index a5dfdd82eda..00000000000 --- a/mindspore/core/api/ir/func_graph.h +++ /dev/null @@ -1,157 +0,0 @@ -/** - * 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_API_IR_FUNC_GRAPH_H_ -#define MINDSPORE_CORE_API_IR_FUNC_GRAPH_H_ - -#include -#include -#include - -#include "utils/visible.h" -#include "api/ir/func_graph_manager.h" - -namespace mindspore::deprecated::api { -/// \brief FuncGraph defines interface for a function graph. -class MS_CORE_API FuncGraph { - public: - /// \brief Constructor of FuncGraph. - FuncGraph() = default; - - /// \brief Destructor of FuncGraph. - virtual ~FuncGraph() = default; - - /// \brief Get the input parameters. - /// - /// \return Input parameters of this graph. - virtual const std::vector get_inputs() const = 0; - - /// \brief Get all parameters. - /// - /// \return All parameters of this graph. - virtual const std::vector ¶meters() const = 0; - - /// \brief Adds a parameter to this graph. - /// - /// \param[in] p The parameter to be added. - virtual void add_parameter(const ParameterPtr &p) = 0; - - /// \brief Adds a new parameter to this graph. - /// - /// \return The new added parameter. - virtual ParameterPtr add_parameter() = 0; - - /// \brief Get the output node. - /// - /// \return The output node, nullptr if output not set. - virtual AnfNodePtr output() const = 0; - - /// \brief Get the return CNode. - /// - /// \return The return CNode, nullptr if no return node. - virtual CNodePtr get_return() const = 0; - - /// \brief Set the output node. - /// - /// \param[in] value The output node to be set. - /// \param[in] force_new_ret If true, a new return node is always created. - virtual void set_output(const AnfNodePtr &value, bool force_new_ret = false) = 0; - - /// \brief Set the return node. - /// - /// \param[in] cnode The return CNode to be set. - virtual void set_return(const CNodePtr &cnode) = 0; - - /// \brief Creates a new CNode in this graph. - /// - /// \param[in] inputs The input nodes of the new CNode. - /// - /// \return The created CNode. - virtual CNodePtr NewCNode(const std::vector &inputs = std::vector()) = 0; - - /// \brief Creates a new primitive CNode in this graph. - /// - /// \param[in] primitive The primitive of the new CNode. - /// \param[in] prim_inputs The argument inputs of the primitive CNode. - /// - /// \return The created primitive CNode. - virtual CNodePtr NewCNode(const PrimitivePtr &primitive, const std::vector &prim_inputs) = 0; - - /// \brief Get all nodes in this graph. - /// - /// \return All nodes in this graph. - virtual const AnfNodeSet &nodes() const = 0; - - /// \brief Check whether an attribute is set for this graph. - /// - /// \param[in] key The attribute key (name). - /// - /// \return True if the attribute with the given key is set, false otherwise. - virtual bool has_attr(const std::string &key) const = 0; - - /// \brief Get an attribute value by its key. - /// - /// \param[in] key The attribute key (name). - /// - /// \return The attribute value for the given key, nullptr if attribute not found. - virtual ValuePtr get_attr(const std::string &key) const = 0; - - /// \brief Set an attribute value. - /// - /// \param[in] key The attribute key (name). - /// \param[in] value The attribute value. - virtual void set_attr(const std::string &key, const ValuePtr &value) = 0; - - /// \brief Get the manager for this graph. - /// - /// \return The manager of this graph, nullptr if not set. - virtual FuncGraphManagerPtr get_manager() const = 0; - - /// \brief Topological sort a graph from the given end node. - /// - /// \param[in] node The end node of the graph to be sorted. - /// - /// \return The sorted nodes. - static std::vector TopoSort(const AnfNodePtr &node); - - /// \brief Creates an empty function graph. - /// - /// \return The created graph. - static FuncGraphPtr Create(); - - /// \brief Creates a value node that holds the given function graph. - /// - /// \param[in] func_graph The given function graph. - // - /// \return The created value node that holds the given function graph. - static AnfNodePtr MakeValueNode(const FuncGraphPtr &func_graph); - - /// \brief Get the function graph from the input node. - /// - /// \param[in] input The input node. - // - /// \return The function graph if the input is value node that holds the graph, nullptr otherwise. - static FuncGraphPtr GetFuncGraphFromAnfNode(const AnfNodePtr &input); -}; - -#ifndef USE_DEPRECATED_API -#define USE_DEPRECATED_API -namespace mindspore { -namespace api = deprecated::api; -} -#endif -} // namespace mindspore::deprecated::api -#endif // MINDSPORE_CORE_API_IR_FUNC_GRAPH_H_ diff --git a/mindspore/core/api/ir/func_graph_manager.h b/mindspore/core/api/ir/func_graph_manager.h deleted file mode 100644 index b8697a01429..00000000000 --- a/mindspore/core/api/ir/func_graph_manager.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - * 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_API_IR_FUNC_GRAPH_MANAGER_H_ -#define MINDSPORE_CORE_API_IR_FUNC_GRAPH_MANAGER_H_ - -#include -#include - -#include "utils/visible.h" -#include "utils/compact_set.h" -#include "utils/hash_map.h" -#include "utils/hashing.h" -#include "ir/anf.h" - -namespace mindspore::deprecated::api { -class FuncGraph; -using FuncGraphPtr = std::shared_ptr; - -class FuncGraphManager; -using FuncGraphManagerPtr = std::shared_ptr; - -using AnfNodeIndexSet = CompactSet>; -using NodeUsersMap = mindspore::HashMap>; - -/// \brief FuncGraphManager defines interface for function graph management. -class MS_CORE_API FuncGraphManager { - public: - /// \brief Constructor of FuncGraphManager. - FuncGraphManager() = default; - - /// \brief Destructor of FuncGraphManager. - virtual ~FuncGraphManager() = default; - - /// \brief Replace an old node with a new node, related edges are all updated. - /// - /// \param[in] old_node The old node to be replaced. - /// \param[in] new_node The new node that replace the old one. - /// - /// \return True if the node is successfully replaced, false otherwise. - virtual bool Replace(const AnfNodePtr &old_node, const AnfNodePtr &new_node) = 0; - - /// \brief Change an existed edge by replace its input node. - /// - /// \param[in] node The output node of the edge. - /// \param[in] index The input index in output node. - /// \param[in] value The new input node of the edge. - virtual void SetEdge(const AnfNodePtr &node, int index, const AnfNodePtr &value) = 0; - - /// \brief Adds a new edge between the given two nodes. - /// - /// \param[in] node The output node of the edge. - /// \param[in] value The input node of the edge. - virtual void AddEdge(const AnfNodePtr &node, const AnfNodePtr &value) = 0; - - /// \brief Get the node to users map. - /// - /// \return The node to users map. - virtual const NodeUsersMap &node_users() const = 0; - - /// \brief Manage the give function graph. - /// - /// \param[in] func_graph The function graph to be managed. - /// \param[in] manage If true, the created manager will be set in graph. - /// - /// \return The manager that manages the given function graph. - static FuncGraphManagerPtr Manage(const FuncGraphPtr &func_graph, bool manage = true); -}; -} // namespace mindspore::deprecated::api - -#ifndef USE_DEPRECATED_API -#define USE_DEPRECATED_API -namespace mindspore { -namespace api = deprecated::api; -} -#endif - -#endif // MINDSPORE_CORE_API_IR_FUNC_GRAPH_MANAGER_H_ diff --git a/mindspore/core/ir/func_graph.cc b/mindspore/core/ir/func_graph.cc index 8ec057399bd..f9269b47c48 100644 --- a/mindspore/core/ir/func_graph.cc +++ b/mindspore/core/ir/func_graph.cc @@ -784,24 +784,10 @@ void FuncGraph::set_used_forward_nodes(const std::vector &used_forwa }); } +std::vector FuncGraph::TopoSort(const AnfNodePtr &node) { return mindspore::TopoSort(node); } + SeenNum NewFgSeenGeneration() { static SeenNum fg_seen_generation = 0; return ++fg_seen_generation; } - -// Implement TopoSort api. -std::vector api::FuncGraph::TopoSort(const AnfNodePtr &node) { return mindspore::TopoSort(node); } - -// Create an api::FuncGraph instance. -api::FuncGraphPtr api::FuncGraph::Create() { return std::make_shared(); } - -AnfNodePtr api::FuncGraph::MakeValueNode(const api::FuncGraphPtr &func_graph) { - auto fg = std::dynamic_pointer_cast(func_graph); - return NewValueNode(fg); -} - -api::FuncGraphPtr api::FuncGraph::GetFuncGraphFromAnfNode(const AnfNodePtr &input) { - auto fg = GetValueNode(input); - return fg; -} } // namespace mindspore diff --git a/mindspore/core/ir/func_graph.h b/mindspore/core/ir/func_graph.h index 8a52b202492..202a30c403f 100644 --- a/mindspore/core/ir/func_graph.h +++ b/mindspore/core/ir/func_graph.h @@ -39,7 +39,6 @@ #include "base/effect_info.h" #include "ir/func_graph_cloner.h" #include "abstract/abstract_value.h" -#include "api/ir/func_graph.h" #include "ir/func_graph_transform.h" #include "ir/func_graph_base.h" #include "utils/visible.h" @@ -98,7 +97,7 @@ const char kFuncGraphFlagBackPropEntry[] = "BackPropEntry"; const char kFuncGraphFlagReAutoMonad[] = "ReAutoMonad"; const char kFuncGraphFlagRecursive[] = "Recursive"; -class MS_CORE_API FuncGraph : public deprecated::api::FuncGraph, public FuncGraphBase, public EffectInfoHolder { +class MS_CORE_API FuncGraph : public FuncGraphBase, public EffectInfoHolder { public: using Drawer = std::function; @@ -114,16 +113,16 @@ class MS_CORE_API FuncGraph : public deprecated::api::FuncGraph, public FuncGrap abstract::AbstractBasePtr ToAbstract() override; // get function graph inputs, but parameters - const std::vector get_inputs() const final; + const std::vector get_inputs() const; // Return the graph's output, or nullptr if not yet deduced. - AnfNodePtr output() const final; + AnfNodePtr output() const; void set_output(const AnfNodePtr &value, bool force_new_ret = false); - const std::vector ¶meters() const final { return parameters_; } + const std::vector ¶meters() const { return parameters_; } // Append - ParameterPtr add_parameter() override; + virtual ParameterPtr add_parameter(); ParameterPtr add_parameter(NodeDebugInfoPtr &&debug_info); - void add_parameter(const ParameterPtr &p) final; + void add_parameter(const ParameterPtr &p); void append_parameter(const ParameterPtr &p) { parameters_.push_back(p); } // Prepend virtual ParameterPtr InsertFrontParameter(); @@ -136,8 +135,8 @@ class MS_CORE_API FuncGraph : public deprecated::api::FuncGraph, public FuncGrap // Create a cnode with given inputs, bound to this graph. virtual CNodePtr NewCNode(std::vector &&inputs); - CNodePtr NewCNode(const std::vector &inputs = std::vector()) override; - CNodePtr NewCNode(const PrimitivePtr &primitive, const std::vector &prim_inputs) final; + virtual CNodePtr NewCNode(const std::vector &inputs = std::vector()); + CNodePtr NewCNode(const PrimitivePtr &primitive, const std::vector &prim_inputs); // Create a cnode with given inputs, bound to this graph and push back to order list. CNodePtr NewCNodeInOrder(std::vector &&inputs); @@ -194,24 +193,22 @@ class MS_CORE_API FuncGraph : public deprecated::api::FuncGraph, public FuncGrap void set_flag(const std::string &key, bool flag) { attrs_[key] = MakeValue(flag); } void erase_flag(const std::string &key) { (void)attrs_.erase(key); } - bool has_attr(const std::string &key) const final; - ValuePtr get_attr(const std::string &key) const final; - void set_attr(const std::string &key, const ValuePtr &value) final { attrs_[key] = value; } + bool has_attr(const std::string &key) const; + ValuePtr get_attr(const std::string &key) const; + void set_attr(const std::string &key, const ValuePtr &value) { attrs_[key] = value; } mindspore::HashMap &transforms() { return transforms_; } void set_transforms(const mindspore::HashMap &transforms) { transforms_ = transforms; } - CNodePtr get_return() const final { return return_; } - void set_return(const CNodePtr &cnode) final { return_ = cnode; } + CNodePtr get_return() const { return return_; } + void set_return(const CNodePtr &cnode) { return_ = cnode; } const CNodePtr &return_node() const { return return_; } FuncGraphManagerPtr manager() const { return manager_.lock(); } void set_manager(const FuncGraphManagerPtr &m) { manager_ = std::weak_ptr(m); } - deprecated::api::FuncGraphManagerPtr get_manager() const final { return manager_.lock(); } - std::string ToString() const override; GraphDebugInfoPtr debug_info(); void set_debug_info(const GraphDebugInfoPtr &info) { @@ -221,7 +218,7 @@ class MS_CORE_API FuncGraph : public deprecated::api::FuncGraph, public FuncGrap this->debug_info_ = info; } // Get all nodes belonging to this func graph. - const AnfNodeSet &nodes() const final; + const AnfNodeSet &nodes() const; void CopyNodes(const FuncGraphPtr &source); void ClearNodes(); void AddNode(const AnfNodePtr &node); @@ -371,6 +368,13 @@ class MS_CORE_API FuncGraph : public deprecated::api::FuncGraph, public FuncGrap is_tensor_condition_branch_ = is_tensor_condition_branch; } + /// \brief Topological sort a graph from the given end node. + /// + /// \param[in] node The end node of the graph to be sorted. + /// + /// \return The sorted nodes. + static std::vector TopoSort(const AnfNodePtr &node); + private: // Only used for func_graph manager to control resource free. int attached_mng_cnt() const { return attached_mng_cnt_; } diff --git a/mindspore/core/ir/manager.cc b/mindspore/core/ir/manager.cc index a5ff6e4cba9..b05f3e97d35 100644 --- a/mindspore/core/ir/manager.cc +++ b/mindspore/core/ir/manager.cc @@ -203,10 +203,6 @@ FuncGraphManagerPtr Manage(FuncGraphPtr func_graph, bool manage) { return Manage(func_graphs, manage); } -api::FuncGraphManagerPtr api::FuncGraphManager::Manage(const api::FuncGraphPtr &func_graph, bool manage) { - return mindspore::Manage(std::dynamic_pointer_cast(func_graph), manage); -} - FuncGraphManager::FuncGraphManager(const std::vector &roots, bool manage) : roots_(roots), is_manage_(manage) { Reset(); diff --git a/mindspore/core/ir/manager.h b/mindspore/core/ir/manager.h index fb609d48deb..406dd1c26d6 100644 --- a/mindspore/core/ir/manager.h +++ b/mindspore/core/ir/manager.h @@ -33,13 +33,13 @@ #include "utils/signal.h" #include "utils/hash_map.h" #include "utils/hash_set.h" +#include "utils/compact_set.h" #include "utils/ordered_set.h" #include "utils/ordered_map.h" #include "ir/anf.h" #include "ir/graph_utils.h" #include "utils/hashing.h" #include "base/base_ref.h" -#include "api/ir/func_graph_manager.h" namespace mindspore { namespace change { @@ -55,9 +55,9 @@ class FuncGraphTransaction; class FuncGraphManager; using FuncGraphManagerPtr = std::shared_ptr; -using AnfNodeIndexSet = deprecated::api::AnfNodeIndexSet; -// NodeUsersMap, for node B input i use node A, it will be one item in map with key: A, and value: (B, i) -using NodeUsersMap = deprecated::api::NodeUsersMap; +using AnfNodeIndexSet = CompactSet>; +using NodeUsersMap = mindspore::HashMap>; + using FuncGraphSetPair = std::pair; using FuncGraphSetPtr = std::shared_ptr; @@ -278,8 +278,7 @@ class FuncGraphMetaFgPrimTotalComputer final : public DepComputer { bool SeekMetaFgPrim(const FuncGraphPtr &fg, SeenNum seen_num); }; -class MS_CORE_API FuncGraphManager : public std::enable_shared_from_this, - public deprecated::api::FuncGraphManager { +class MS_CORE_API FuncGraphManager : public std::enable_shared_from_this { public: explicit FuncGraphManager(const std::vector &roots, bool manage = true); virtual ~FuncGraphManager() { @@ -299,10 +298,10 @@ class MS_CORE_API FuncGraphManager : public std::enable_shared_from_this #include "mindapi/ir/func_graph.h" #include "mindapi/src/helper.h" -#define USE_DEPRECATED_API #include "ir/anf.h" #include "ir/value.h" #include "ir/func_graph.h" diff --git a/mindspore/core/mindapi/src/utils.cc b/mindspore/core/mindapi/src/utils.cc index 483ea44c8cd..63bb8981c49 100644 --- a/mindspore/core/mindapi/src/utils.cc +++ b/mindspore/core/mindapi/src/utils.cc @@ -1,5 +1,5 @@ /** - * Copyright 2021 Huawei Technologies Co., Ltd + * Copyright 2021-2022 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. @@ -16,7 +16,6 @@ #include "mindapi/ir/utils.h" #include "mindapi/src/helper.h" -#define USE_DEPRECATED_API #include "ir/anf.h" #include "ir/value.h" #include "ir/func_graph_cloner.h" diff --git a/mindspore/lite/cmake/file_list.cmake b/mindspore/lite/cmake/file_list.cmake index 548dbb2eb0b..3d560ddc046 100644 --- a/mindspore/lite/cmake/file_list.cmake +++ b/mindspore/lite/cmake/file_list.cmake @@ -12,10 +12,6 @@ set(ABSTRACT_HEADER ${CORE_DIR}/abstract/primitive_infer_map.h ${CORE_DIR}/abstract/utils.h ) -set(API_IR_HEADER - ${CORE_DIR}/api/ir/func_graph.h - ${CORE_DIR}/api/ir/func_graph_manager.h - ) file(GLOB MINDAPI_BASE_HEADER ${CORE_DIR}/mindapi/base/*.h) file(GLOB MINDAPI_IR_HEADER ${CORE_DIR}/mindapi/ir/*.h) set(BASE_HEADER