• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "include/api/types.h"
17 #include "src/extendrt/session/single_op_session.h"
18 #include "pybind11/pybind11.h"
19 #include "pybind11/numpy.h"
20 #include "pybind11/stl.h"
21 
22 namespace mindspore::lite {
23 namespace py = pybind11;
24 
25 void ContextPyBind(const py::module &m);
26 void ConverterPyBind(const py::module &m);
27 void ModelPyBind(const py::module &m);
28 #ifdef MSLITE_ENABLE_CLOUD_INFERENCE
29 void LiteInferPyBind(const py::module &m);
30 #endif
31 void ModelParallelRunnerPyBind(const py::module &m);
32 void ModelGroupPyBind(const py::module &m);
33 void TensorPyBind(const py::module &m);
34 void LLMEnginePyBind(const py::module &m);
35 std::shared_ptr<MSTensor> create_tensor(DataType data_type, const std::vector<int64_t> &shape,
36                                         const std::string &device_type, int device_id);
37 std::shared_ptr<MSTensor> create_tensor_by_tensor(const MSTensor &tensor, const std::string &device_type,
38                                                   int device_id);
39 std::shared_ptr<MSTensor> create_tensor_by_numpy(const py::array &input, const std::string &device_type,
40                                                  int32_t device_id);
PYBIND11_MODULE(_c_lite_wrapper,m)41 PYBIND11_MODULE(_c_lite_wrapper, m) {
42   m.doc() = "MindSpore Lite";
43   ContextPyBind(m);
44 #ifdef ENABLE_CONVERTER
45   ConverterPyBind(m);
46 #endif
47   ModelPyBind(m);
48 #ifdef MSLITE_ENABLE_CLOUD_INFERENCE
49   LiteInferPyBind(m);
50 #endif
51   ModelParallelRunnerPyBind(m);
52   ModelGroupPyBind(m);
53   TensorPyBind(m);
54   LLMEnginePyBind(m);
55   m.def("create_tensor", &create_tensor);
56   m.def("create_tensor_by_tensor", &create_tensor_by_tensor);
57   m.def("create_tensor_by_numpy", &create_tensor_by_numpy);
58 
59   // call aclFinalize manually before exit.
60   (void)py::module::import("atexit").attr("register")(
61     py::cpp_function{[&]() -> void { SingleOpInferSession::AscendFinalize(); }});
62 }
63 }  // namespace mindspore::lite
64