1 /** 2 * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). 3 * 4 * Copyright 2022-2023 Huawei Technologies Co., Ltd 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #ifndef MINDSPORE_PI_JIT_COMPILER_H_ 20 #define MINDSPORE_PI_JIT_COMPILER_H_ 21 22 #include <functional> 23 #include <string> 24 #include "include/common/utils/python_adapter.h" 25 #include "pipeline/jit/pi/common.h" 26 #include "utils/convert_utils_base.h" 27 28 namespace mindspore { 29 namespace pijit { 30 using CallableGraph = std::function<PyObject *(PyObject *, PyObject *)>; 31 // Compiler to parse python byte code 32 class Compiler { 33 public: 34 static CallableGraph Compile(const PyFunctionObject &func, const PyFrameObject &frame, const std::string &phase); 35 36 private: 37 Compiler() = default; 38 }; 39 40 class MindCompiler { 41 public: 42 struct CompileInfo { 43 std::string co_name_; 44 int co_argcount_; 45 int co_kwonlyargcount_; 46 int co_flags_; 47 }; 48 static CallableGraph Compile(const FuncGraphPtr &func_graph, const py::tuple &args, const py::dict &kwargs, 49 const std::string &phase, const CompileInfo &compile_info); 50 51 private: 52 MindCompiler() = default; 53 }; 54 } // namespace pijit 55 } // namespace mindspore 56 57 #endif // MINDSPORE_PI_JIT_COMPILER_H_ 58