1 /** 2 * Copyright 2022 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_BACKEND_KERNEL_COMPILER_CPU_PYEXECUTE_KERNEL_H_ 18 #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_PYEXECUTE_KERNEL_H_ 19 20 #include <map> 21 #include <memory> 22 #include <string> 23 #include <vector> 24 #include <Python.h> 25 #include "pybind11/pybind11.h" 26 #include "pybind11/numpy.h" 27 #include "plugin/device/cpu/kernel/cpu_kernel.h" 28 29 namespace py = pybind11; 30 namespace mindspore { 31 namespace kernel { 32 struct PyExecuteOutputUserData { 33 py::object obj; 34 constexpr static char key[] = "PyExecuteOutputUserData"; 35 }; 36 using PyExecuteOutputUserDataPtr = std::shared_ptr<PyExecuteOutputUserData>; 37 38 class PyExecuteCpuKernelMod : public NativeCpuKernelMod { 39 public: PyExecuteCpuKernelMod()40 PyExecuteCpuKernelMod() {} 41 ~PyExecuteCpuKernelMod() = default; 42 43 bool Init(const std::vector<KernelTensor *> &inputs, const std::vector<KernelTensor *> &outputs) override; 44 bool Launch(const std::vector<KernelTensor *> &inputs, const std::vector<KernelTensor *> &, 45 const std::vector<KernelTensor *> &outputs) override; need_user_data()46 bool need_user_data() const override { return true; } 47 48 private: 49 bool is_output_any_{true}; 50 }; 51 } // namespace kernel 52 } // namespace mindspore 53 54 #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_PYEXECUTE_KERNEL_H_ 55