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_PI_JIT_STRATEGY_H 17 #define MINDSPORE_PI_JIT_STRATEGY_H 18 19 #include <vector> 20 #include "pybind11/pybind11.h" 21 #include "pipeline/jit/pi/graph_guard/perf.h" 22 #include "pipeline/jit/pi/graph_guard/cache.h" 23 #include "mindapi/base/shape_vector.h" 24 #include "utils/convert_utils_base.h" 25 26 using PyObjectArray = std::vector<PyObject *>; 27 28 namespace mindspore { 29 namespace pijit { 30 31 class OptStrategy { 32 public: 33 typedef enum { 34 kExecPyNative = 0, 35 kExecGraph, 36 kExecCount, 37 } ExecKind; 38 static ExecKind MakeExecStrategyByPerf(OptPerfPtr graph_perf, OptPerfPtr pynative_perf, int count, 39 double adj_coef = 0.1); 40 static ExecKind MakeExecStrategyByComplex(PyCodeObject *code, int threshold); 41 static void MakeGCStrategy(OptCodeHubPtr hub, int limit_size, int limit_count, bool enable_dynamicshape, 42 OptCodePtr except); 43 typedef enum { 44 kCalcUnsupported = 0, 45 kCalcShape, 46 kCalcValue, 47 kCalcCount, 48 } CalcKind; 49 static CalcKind MakeCalcStrategyByInputs(int bytecode, int opargs, const PyObjectArray &objs); 50 static CalcKind MakeCalcStrategyByShape(const ShapeVector &shape); 51 static OptCodeSet MakeGuardListStrategyByFrame(const PyFrameObject *frame, const OptCodeSet &codes); 52 static GuardItemVector MakeGuardItemListStrategyByFrame(const PyFrameObject *frame, const GuardItemVector &list); 53 }; 54 55 } // namespace pijit 56 } // namespace mindspore 57 58 #endif // MINDSPORE_PI_JIT_STRATEGY_H 59