diff --git a/mindspore/ccsrc/CMakeLists.txt b/mindspore/ccsrc/CMakeLists.txt index 4a6e51b8aa..53300acda4 100644 --- a/mindspore/ccsrc/CMakeLists.txt +++ b/mindspore/ccsrc/CMakeLists.txt @@ -138,7 +138,7 @@ set(SUB_COMP frontend/operator pipeline/jit pipeline/pynative - common debug gvar predict pybind_api utils vm base abstract + common debug gvar predict pybind_api utils vm ) foreach (_comp ${SUB_COMP}) @@ -149,9 +149,13 @@ foreach (_comp ${SUB_COMP}) add_dependencies(_mindspore_${sub}_obj proto_input flat_input) endif () endforeach () +add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/base base) +list(APPEND SUB_OBJECTS_SRC $) +add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/abstract abstract) +list(APPEND SUB_OBJECTS_SRC $) add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/ir ir) list(APPEND SUB_OBJECTS_SRC $) -add_dependencies(_mindspore_ir_obj proto_input flat_input) +add_dependencies(_mindspore_base_obj _mindspore_ir_obj _mindspore_abstract_obj proto_input flat_input) set_property(SOURCE ${SUB_OBJECTS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_ME) add_library(mindspore STATIC ${SUB_OBJECTS_SRC}) diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.cc b/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.cc index acecb2980e..b9e747a70b 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.cc +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.cc @@ -612,10 +612,34 @@ EvalResultPtr AnfNodeConfig::GetEvaluatedValue() { return engine_.lock()->GetEvaluatedValue(self); } +abstract::AbstractBasePtr MakeAbstractClosure(const FuncGraphPtr &func_graph, + const abstract::AnalysisContextPtr &context) { + AnalysisContextPtr temp_context = context; + if (temp_context == nullptr) { + temp_context = abstract::AnalysisContext::DummyContext(); + } + return std::make_shared(func_graph, temp_context); +} + +abstract::AbstractBasePtr MakeAbstractClosure(const MetaFuncGraphPtr &meta_func_graph, const AnfNodePtr &anf_node) { + abstract::MetaFuncGraphAbstractClosurePtr meta_func_graph_fn; + if (anf_node == nullptr) { + meta_func_graph_fn = std::make_shared(meta_func_graph); + } else { + meta_func_graph_fn = std::make_shared(meta_func_graph, anf_node->scope()); + } + return meta_func_graph_fn; +} + +abstract::AbstractBasePtr MakeAbstractClosure(const PrimitivePtr &primitive, const AnfNodePtr &anf_node) { + auto prim_func = std::make_shared(primitive, anf_node); + return prim_func; +} + AbstractBasePtr ToAbstract(const ValuePtr &value, const AnalysisContextPtr &context, const AnfNodeConfigPtr &conf) { if (value->isa()) { auto func_graph = value->cast(); - return func_graph->MakeAbstractClosure(context); + return MakeAbstractClosure(func_graph, context); } AnfNodePtr anf_node = nullptr; if (conf != nullptr) { @@ -623,11 +647,11 @@ AbstractBasePtr ToAbstract(const ValuePtr &value, const AnalysisContextPtr &cont } if (value->isa()) { auto meta_func_graph = value->cast(); - return meta_func_graph->MakeAbstractClosure(anf_node); + return MakeAbstractClosure(meta_func_graph, anf_node); } if (value->isa()) { auto prim = value->cast(); - return prim->ToPrimAbstract(anf_node); + return MakeAbstractClosure(prim, anf_node); } return value->ToAbstract(); } diff --git a/mindspore/ccsrc/abstract/CMakeLists.txt b/mindspore/core/abstract/CMakeLists.txt similarity index 100% rename from mindspore/ccsrc/abstract/CMakeLists.txt rename to mindspore/core/abstract/CMakeLists.txt diff --git a/mindspore/ccsrc/abstract/abstract_value.cc b/mindspore/core/abstract/abstract_value.cc similarity index 100% rename from mindspore/ccsrc/abstract/abstract_value.cc rename to mindspore/core/abstract/abstract_value.cc diff --git a/mindspore/ccsrc/abstract/abstract_value.h b/mindspore/core/abstract/abstract_value.h similarity index 100% rename from mindspore/ccsrc/abstract/abstract_value.h rename to mindspore/core/abstract/abstract_value.h diff --git a/mindspore/ccsrc/abstract/analysis_context.cc b/mindspore/core/abstract/analysis_context.cc similarity index 100% rename from mindspore/ccsrc/abstract/analysis_context.cc rename to mindspore/core/abstract/analysis_context.cc diff --git a/mindspore/ccsrc/abstract/analysis_context.h b/mindspore/core/abstract/analysis_context.h similarity index 100% rename from mindspore/ccsrc/abstract/analysis_context.h rename to mindspore/core/abstract/analysis_context.h diff --git a/mindspore/ccsrc/abstract/dshape.cc b/mindspore/core/abstract/dshape.cc similarity index 100% rename from mindspore/ccsrc/abstract/dshape.cc rename to mindspore/core/abstract/dshape.cc diff --git a/mindspore/ccsrc/abstract/dshape.h b/mindspore/core/abstract/dshape.h similarity index 100% rename from mindspore/ccsrc/abstract/dshape.h rename to mindspore/core/abstract/dshape.h diff --git a/mindspore/ccsrc/abstract/param_validator.cc b/mindspore/core/abstract/param_validator.cc similarity index 100% rename from mindspore/ccsrc/abstract/param_validator.cc rename to mindspore/core/abstract/param_validator.cc diff --git a/mindspore/ccsrc/abstract/param_validator.h b/mindspore/core/abstract/param_validator.h similarity index 100% rename from mindspore/ccsrc/abstract/param_validator.h rename to mindspore/core/abstract/param_validator.h diff --git a/mindspore/ccsrc/abstract/utils.cc b/mindspore/core/abstract/utils.cc similarity index 100% rename from mindspore/ccsrc/abstract/utils.cc rename to mindspore/core/abstract/utils.cc diff --git a/mindspore/ccsrc/abstract/utils.h b/mindspore/core/abstract/utils.h similarity index 100% rename from mindspore/ccsrc/abstract/utils.h rename to mindspore/core/abstract/utils.h diff --git a/mindspore/ccsrc/base/CMakeLists.txt b/mindspore/core/base/CMakeLists.txt similarity index 100% rename from mindspore/ccsrc/base/CMakeLists.txt rename to mindspore/core/base/CMakeLists.txt diff --git a/mindspore/ccsrc/base/base.cc b/mindspore/core/base/base.cc similarity index 100% rename from mindspore/ccsrc/base/base.cc rename to mindspore/core/base/base.cc diff --git a/mindspore/ccsrc/base/base.h b/mindspore/core/base/base.h similarity index 100% rename from mindspore/ccsrc/base/base.h rename to mindspore/core/base/base.h diff --git a/mindspore/core/ir/anf_extends.cc b/mindspore/core/ir/anf_extends.cc index 1caf7f1b36..b70a660aae 100644 --- a/mindspore/core/ir/anf_extends.cc +++ b/mindspore/core/ir/anf_extends.cc @@ -22,7 +22,7 @@ #include #include "ir/visitor.h" -#include "pipeline/jit/static_analysis/static_analysis.h" +#include "ir/func_graph.h" #include "frontend/operator/ops.h" #include "frontend/parallel/ops_info/ops_utils.h" #include "debug/label.h" diff --git a/mindspore/core/ir/func_graph.h b/mindspore/core/ir/func_graph.h index 70e53f4828..712c75b431 100644 --- a/mindspore/core/ir/func_graph.h +++ b/mindspore/core/ir/func_graph.h @@ -149,7 +149,6 @@ class FuncGraph : public FuncGraphBase { // get the graph's abstract abstract::AbstractFunctionPtr abstract(); - abstract::AbstractBasePtr MakeAbstractClosure(const abstract::AnalysisContextPtr &context); // return the graph's output, or nullptr if not yet deduced AnfNodePtr output() const; diff --git a/mindspore/core/ir/func_graph_extends.cc b/mindspore/core/ir/func_graph_extends.cc index 27f9958a5e..579409b05e 100644 --- a/mindspore/core/ir/func_graph_extends.cc +++ b/mindspore/core/ir/func_graph_extends.cc @@ -25,9 +25,6 @@ #include "frontend/operator/ops.h" #include "utils/ordered_set.h" #include "abstract/abstract_value.h" -#include "pipeline/jit/static_analysis/static_analysis.h" -#include "pipeline/jit/static_analysis/abstract_function.h" - #include "debug/anf_ir_dump.h" #include "debug/trace.h" #include "debug/draw.h" @@ -60,14 +57,6 @@ AbstractFunctionPtr FuncGraph::abstract() { return std::make_shared(args_spec_list, output()->abstract()); } -abstract::AbstractBasePtr FuncGraph::MakeAbstractClosure(const abstract::AnalysisContextPtr &context) { - AnalysisContextPtr temp_context = context; - if (temp_context == nullptr) { - temp_context = abstract::AnalysisContext::DummyContext(); - } - return std::make_shared(shared_from_base(), temp_context); -} - void FuncGraph::set_output(const AnfNodePtr &value, bool force_new_ret) { if (force_new_ret || return_ == nullptr) { std::vector params({NewValueNode(prim::kPrimReturn), value}); diff --git a/mindspore/core/ir/meta_func_graph.cc b/mindspore/core/ir/meta_func_graph.cc index df07ea1b67..c0cf9d4d2f 100644 --- a/mindspore/core/ir/meta_func_graph.cc +++ b/mindspore/core/ir/meta_func_graph.cc @@ -17,22 +17,9 @@ */ #include "ir/meta_func_graph.h" -#include "pipeline/jit/static_analysis/static_analysis.h" -#include "pipeline/jit/static_analysis/abstract_function.h" // namespace to support intermediate representation definition namespace mindspore { -abstract::AbstractBasePtr MetaFuncGraph::MakeAbstractClosure(const AnfNodePtr &anf_node) { - abstract::MetaFuncGraphAbstractClosurePtr meta_func_graph_fn; - if (anf_node == nullptr) { - meta_func_graph_fn = std::make_shared(shared_from_base()); - } else { - meta_func_graph_fn = - std::make_shared(shared_from_base(), anf_node->scope()); - } - return meta_func_graph_fn; -} - FuncGraphPtr MetaFuncGraph::GenerateFuncGraph(const abstract::AbstractBasePtrList &args_spec_list) { TypePtrList types; (void)std::transform(args_spec_list.begin(), args_spec_list.end(), std::back_inserter(types), diff --git a/mindspore/core/ir/meta_func_graph.h b/mindspore/core/ir/meta_func_graph.h index bc7fb78957..933c3f700d 100644 --- a/mindspore/core/ir/meta_func_graph.h +++ b/mindspore/core/ir/meta_func_graph.h @@ -44,7 +44,6 @@ class MetaFuncGraph : public FuncGraphBase { ~MetaFuncGraph() override = default; MS_DECLARE_PARENT(MetaFuncGraph, FuncGraphBase); - abstract::AbstractBasePtr MakeAbstractClosure(const AnfNodePtr &anf_node); // Return normalized versions of the arguments. // By default, this returns args unchanged. virtual abstract::AbstractBasePtrList NormalizeArgs(const abstract::AbstractBasePtrList &args_spec_list) const { diff --git a/mindspore/core/ir/primitive_extends.cc b/mindspore/core/ir/primitive_extends.cc deleted file mode 100644 index 8e04ba8233..0000000000 --- a/mindspore/core/ir/primitive_extends.cc +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright 2020 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 "ir/primitive.h" -#include "pipeline/jit/static_analysis/abstract_function.h" - -namespace mindspore { -abstract::AbstractBasePtr Primitive::ToPrimAbstract(const AnfNodePtr &anf_node) { - auto prim_func = std::make_shared(shared_from_base(), anf_node); - return prim_func; -} -} // namespace mindspore diff --git a/tests/ut/cpp/CMakeLists.txt b/tests/ut/cpp/CMakeLists.txt index ef19433c4d..880a281037 100644 --- a/tests/ut/cpp/CMakeLists.txt +++ b/tests/ut/cpp/CMakeLists.txt @@ -52,8 +52,8 @@ else() endif() file(GLOB_RECURSE MINDSPORE_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - "../../../mindspore/ccsrc/base/*.cc" - "../../../mindspore/ccsrc/abstract/*.cc" + "../../../mindspore/core/base/*.cc" + "../../../mindspore/core/abstract/*.cc" "../../../mindspore/core/ir/*.cc" "../../../mindspore/ccsrc/common/*.cc" "../../../mindspore/ccsrc/utils/*.cc"