1 /** 2 * Copyright 2023 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINDSPORE_CCSRC_BACKEND_COMMON_GRAPH_KERNEL_SYMBOL_ENGINE_MULTI_SYMBOL_ENGINE_H_ 17 #define MINDSPORE_CCSRC_BACKEND_COMMON_GRAPH_KERNEL_SYMBOL_ENGINE_MULTI_SYMBOL_ENGINE_H_ 18 19 #include <string> 20 #include <memory> 21 #include <vector> 22 #include <map> 23 #include "include/common/symbol_engine/symbol_engine_impl.h" 24 25 namespace mindspore { 26 namespace graphkernel { 27 namespace symshape { 28 using mindspore::symshape::SymbolEngineImpl; 29 30 /// \brief SymbolEngine for a graph. new symbol engines will be created for subgraphs. 31 class MultiSymbolEngine : public SymbolEngineImpl { 32 public: 33 using SymbolEngineImpl::SymbolEngineImpl; 34 ~MultiSymbolEngine() = default; 35 MS_DECLARE_PARENT(MultiSymbolEngine, SymbolEngineImpl) 36 37 static void Build(const FuncGraphPtr &func_graph); 38 static void BuildSubEngine(const AnfNodePtr &node); 39 ToString()40 std::string ToString() const override { return "MultiSymbolEngine_" + name_; } 41 void BuildSubgraphImpl(const CNodePtr &cnode, const FuncGraphPtr &sub_fg, size_t begin_input_index) override; 42 void PreBuildQuerySubgraphDependStatus(const CNodePtr &cnode, const FuncGraphPtr &sub_fg, 43 size_t begin_input_index) override; 44 45 protected: 46 void SaveInputParaMap(std::map<SymbolPtr, SymbolPtr> *input_para_map, const SymbolPtr &inp, const SymbolPtr ¶); 47 ListSymbolPtr BuildShapeWithInputHint(const AbstractBasePtr ¶_abs, const std::vector<ListSymbolPtr> &inputs, 48 std::map<SymbolPtr, SymbolPtr> *input_para_map); 49 void GenInputSymbols(const CNodePtr &cnode, const FuncGraphPtr &sub_fg, size_t begin_input_index); 50 }; 51 } // namespace symshape 52 using MultiSymbolEnginePtr = std::shared_ptr<symshape::MultiSymbolEngine>; 53 } // namespace graphkernel 54 } // namespace mindspore 55 #endif // MINDSPORE_CCSRC_BACKEND_COMMON_GRAPH_KERNEL_SYMBOL_ENGINE_MULTI_SYMBOL_ENGINE_H_ 56