1 /** 2 * Copyright 2024 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 17 #ifndef MINDSPORE_CCSRC_FRONTEND_PARALLEL_DYNAMIC_SHAPE_DYNAMIC_SHAPE_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_DYNAMIC_SHAPE_DYNAMIC_SHAPE_H_ 19 20 #include <set> 21 #include <utility> 22 #include <string> 23 #include <memory> 24 #include <vector> 25 #include "ir/value.h" 26 #include "ir/graph_utils.h" 27 #include "base/base.h" 28 #include "utils/hash_map.h" 29 #include "mindspore/core/symbolic_shape/symbol.h" 30 #include "mindspore/core/symbolic_shape/symbol_info.h" 31 #include "frontend/parallel/step_parallel.h" 32 #include "frontend/parallel/graph_util/generate_graph.h" 33 #include "ops/array_ops.h" 34 35 namespace mindspore { 36 namespace parallel { 37 struct SymbolElement { 38 int64_t max = 1; 39 int64_t min = 1; 40 int64_t divisor = 1; 41 int64_t remainder = 0; 42 }; 43 44 using Symbol = std::vector<SymbolElement>; 45 using Symbols = std::vector<Symbol>; 46 constexpr size_t INPUT_SYMBOLS_INDEX = 0; 47 constexpr size_t OUTPUT_SYMBOLS_INDEX = 1; 48 constexpr size_t INPUT_OUTPUT_SYMBOLS_SIZE = 2; 49 50 void PrintSymbolInfo(const std::vector<symshape::SymbolInfoList> &symbol_infos); 51 std::vector<symshape::SymbolInfoList> ParallelSymbolInfo(const std::vector<symshape::SymbolInfoList> &symbol_infos, 52 bool has_dyn_shape); 53 bool IsParallelDynamicShape(const FuncGraphPtr &func_graph); 54 Symbols GetNodeSymbol(const AnfNodePtr &node); 55 Symbols StaticShapesToSymbols(const Shapes &shapes); 56 std::string DivisorOfSymbolsToString(const Symbols &symbols); 57 std::string RemainderOfSymbolsToString(const Symbols &symbols); 58 59 // get real divisor symbols for input or output 60 Shapes GetRealDivisorSymbols(const Shapes &shapes, const Symbols &symbols); 61 62 void TagDynamicShapeFuncGraph(const FuncGraphPtr &root); 63 bool InDynamicGraph(const CNodePtr &node); 64 bool IsDynamicShapesList(const std::vector<Shapes> &shapes_list); 65 bool IsDynamicShapes(const Shapes &shapes); 66 bool IsDynamicShape(const Shape &shape); 67 bool IsSemiOrAutoParallelMode(); 68 void UpdateParamSymbolicShape(const FuncGraphPtr &root); 69 } // namespace parallel 70 } // namespace mindspore 71 72 #endif // MINDSPORE_CCSRC_FRONTEND_PARALLEL_DYNAMIC_SHAPE_DYNAMIC_SHAPE_H_ 73