1 /** 2 * Copyright 2022-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 17 #ifndef MINDSPORE_CORE_OPS_PY_EXECUTE_H_ 18 #define MINDSPORE_CORE_OPS_PY_EXECUTE_H_ 19 20 #include <memory> 21 #include <set> 22 #include <vector> 23 24 #include "mindapi/base/types.h" 25 #include "mindapi/src/helper.h" 26 #include "ops/base_operator.h" 27 #include "ops/op_utils.h" 28 #include "utils/check_convert_utils.h" 29 #include "utils/ms_context.h" 30 31 namespace mindspore { 32 namespace ops { 33 constexpr auto kNamePyExecute = "PyExecute"; 34 /// \brief Implement for JIT Fallback. 35 /// Refer to Python API @ref mindspore.ops.PyExecute for more details. 36 class MIND_API PyExecute : public BaseOperator { 37 public: 38 MIND_API_BASE_MEMBER(PyExecute); 39 /// \brief Constructor. PyExecute()40 PyExecute() : BaseOperator(kNamePyExecute) { InitIOName({"script", "local_keys", "local_values"}, {"result"}); } 41 }; 42 43 class MIND_API PyExecuteInfer : public abstract::OpInferBase { 44 public: 45 BaseShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) const override; 46 TypePtr InferType(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) const override; 47 AbstractBasePtr InferShapeAndType(const abstract::AnalysisEnginePtr &engine, const PrimitivePtr &primitive, 48 const std::vector<AbstractBasePtr> &input_args) const override; 49 50 AbstractBasePtr InferPy(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) const; 51 52 std::set<int64_t> GetValueDependArgIndices() const override; 53 54 using InferHandler = abstract::AbstractBasePtr (*)(const PrimitivePtr &, 55 const std::vector<abstract::AbstractBase *> &); set_infer_handler(const InferHandler & infer_handler)56 static void set_infer_handler(const InferHandler &infer_handler) { infer_handler_ = infer_handler; } 57 58 private: 59 inline static InferHandler infer_handler_{nullptr}; 60 }; 61 } // namespace ops 62 } // namespace mindspore 63 #endif // MINDSPORE_CORE_OPS_PY_EXECUTE_H_ 64