1 /** 2 * Copyright 2021 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_LITE_TOOLS_OPTIMIZER_PARALLEL_MULTI_NODE_SPLIT_H 17 #define MINDSPORE_LITE_TOOLS_OPTIMIZER_PARALLEL_MULTI_NODE_SPLIT_H 18 #include <utility> 19 #include <memory> 20 #include "tools/optimizer/parallel/split_strategy.h" 21 #include "schema/model_generated.h" 22 #include "include/errorcode.h" 23 #include "base/base.h" 24 25 using mindspore::schema::PrimitiveType; 26 namespace mindspore { 27 namespace opt { 28 class MultiNodeSplit { 29 public: 30 MultiNodeSplit() = default; 31 32 virtual ~MultiNodeSplit() = default; 33 34 virtual AnfNodePtr DoSplit(const FuncGraphPtr &func_graph, const AnfNodePtr &node) = 0; 35 }; 36 37 class MultiNodeSplitProxy : public MultiNodeSplit { 38 public: 39 explicit MultiNodeSplitProxy(const SplitStrategy &strategy, PrimitiveType primitive_type, int32_t fmk_type = -1, 40 int32_t num = 3) MultiNodeSplit()41 : MultiNodeSplit(), strategy_(strategy), primitive_type_(primitive_type), fmk_type_(fmk_type), num_(num) {} 42 43 ~MultiNodeSplitProxy() override = default; 44 45 AnfNodePtr DoSplit(const FuncGraphPtr &func_graph, const AnfNodePtr &node) override; 46 47 private: 48 int InitResource(); 49 void FreeResource(); 50 51 private: 52 SplitMode split_mode_{NoSplit}; 53 SplitStrategy strategy_{}; 54 PrimitiveType primitive_type_{schema::PrimitiveType_NONE}; 55 int32_t fmk_type_{-1}; 56 int32_t num_{0}; 57 std::shared_ptr<MultiNodeSplit> multi_node_split_{nullptr}; 58 }; 59 } // namespace opt 60 } // namespace mindspore 61 #endif // MINDSPORE_LITE_TOOLS_OPTIMIZER_PARALLEL_MULTI_NODE_SPLIT_H 62