1 /** 2 * Copyright 2020 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_PIPELINE_PYNATIVE_BASE_H_ 18 #define MINDSPORE_CCSRC_PIPELINE_PYNATIVE_BASE_H_ 19 20 #include <vector> 21 #include <utility> 22 #include <string> 23 #include <memory> 24 #include <set> 25 #include <unordered_map> 26 #include <unordered_set> 27 28 #include "pybind11/pybind11.h" 29 #include "ir/anf.h" 30 #include "pybind_api/ir/primitive_py.h" 31 #include "pipeline/jit/parse/parse.h" 32 #include "abstract/abstract_value.h" 33 34 namespace mindspore { 35 namespace pynative { 36 namespace py = pybind11; 37 38 enum PynativeStatusCode { 39 PYNATIVE_SUCCESS = 0, 40 PYNATIVE_OP_NOT_IMPLEMENTED_ERR = 1, 41 PYNATIVE_OP_INPUTS_ERR = 2, 42 PYNATIVE_OP_PARAMS_ERR = 3, 43 PYNATIVE_OP_ATTRS_ERR = 4, 44 PYNATIVE_GRAPH_MANAGER_ERR = 5, 45 PYNATIVE_GRAPH_GE_BUILD_ERR = 6, 46 PYNATIVE_GRAPH_GE_RUN_ERR = 7, 47 PYNATIVE_UNKNOWN_STATE = 0XFF 48 }; 49 50 enum RunOpArgsEnum { PY_PRIM = 0, PY_NAME, PY_INPUTS, PY_ARGS_NUM }; 51 52 struct OpExecInfo { 53 bool is_dynamic_shape = false; 54 bool is_mixed_precision_cast = false; 55 size_t next_input_index = 0; 56 std::string op_name; 57 std::string op_info; 58 std::string next_op_name = ""; 59 PrimitivePyPtr py_primitive; 60 AbstractBasePtr abstract; 61 py::list op_inputs; 62 #ifdef ENABLE_GE 63 py::dict op_attrs; 64 #endif 65 std::vector<int64_t> inputs_mask; 66 bool lazy_build = false; 67 }; 68 using OpExecInfoPtr = std::shared_ptr<OpExecInfo>; 69 70 const std::set<std::string> ignore_infer_prim = {"mixed_precision_cast"}; 71 const std::set<std::string> force_infer_prim = {"TopK", "DropoutGenMask"}; 72 const std::set<std::string> dynamic_shape_const_input_to_attr = {"Cast", "ExpandDims", "Reshape", "EmbeddingLookup", 73 "Transpose"}; 74 } // namespace pynative 75 } // namespace mindspore 76 77 #endif // MINDSPORE_CCSRC_PIPELINE_PYNATIVE_BASE_H_ 78