option_pybind.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Cropyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "ultra_infer/pybind/main.h"
  15. namespace ultra_infer {
  16. void BindLiteOption(pybind11::module &m);
  17. void BindOpenVINOOption(pybind11::module &m);
  18. void BindOrtOption(pybind11::module &m);
  19. void BindTrtOption(pybind11::module &m);
  20. void BindPaddleOption(pybind11::module &m);
  21. void BindPorosOption(pybind11::module &m);
  22. void BindRKNPU2Option(pybind11::module &m);
  23. void BindOption(pybind11::module &m) {
  24. BindLiteOption(m);
  25. BindOpenVINOOption(m);
  26. BindOrtOption(m);
  27. BindTrtOption(m);
  28. BindPaddleOption(m);
  29. BindPorosOption(m);
  30. BindRKNPU2Option(m);
  31. pybind11::class_<RuntimeOption>(m, "RuntimeOption")
  32. .def(pybind11::init())
  33. .def("set_model_path", &RuntimeOption::SetModelPath)
  34. .def("set_model_buffer", &RuntimeOption::SetModelBuffer)
  35. .def("use_gpu", &RuntimeOption::UseGpu)
  36. .def("use_cpu", &RuntimeOption::UseCpu)
  37. .def("use_rknpu2", &RuntimeOption::UseRKNPU2)
  38. .def("use_sophgo", &RuntimeOption::UseSophgo)
  39. .def("use_ascend", &RuntimeOption::UseAscend)
  40. .def("use_kunlunxin", &RuntimeOption::UseKunlunXin)
  41. .def("disable_valid_backend_check",
  42. &RuntimeOption::DisableValidBackendCheck)
  43. .def("enable_valid_backend_check",
  44. &RuntimeOption::EnableValidBackendCheck)
  45. .def_readwrite("paddle_lite_option", &RuntimeOption::paddle_lite_option)
  46. .def_readwrite("openvino_option", &RuntimeOption::openvino_option)
  47. .def_readwrite("ort_option", &RuntimeOption::ort_option)
  48. .def_readwrite("trt_option", &RuntimeOption::trt_option)
  49. .def_readwrite("poros_option", &RuntimeOption::poros_option)
  50. .def_readwrite("paddle_infer_option", &RuntimeOption::paddle_infer_option)
  51. .def("set_external_stream", &RuntimeOption::SetExternalStream)
  52. .def("set_external_raw_stream",
  53. [](RuntimeOption &self, size_t external_stream) {
  54. self.SetExternalStream(reinterpret_cast<void *>(external_stream));
  55. })
  56. .def("set_cpu_thread_num", &RuntimeOption::SetCpuThreadNum)
  57. .def("use_paddle_backend", &RuntimeOption::UsePaddleBackend)
  58. .def("use_poros_backend", &RuntimeOption::UsePorosBackend)
  59. .def("use_tvm_backend", &RuntimeOption::UseTVMBackend)
  60. .def("use_ort_backend", &RuntimeOption::UseOrtBackend)
  61. .def("use_trt_backend", &RuntimeOption::UseTrtBackend)
  62. .def("use_openvino_backend", &RuntimeOption::UseOpenVINOBackend)
  63. .def("use_lite_backend", &RuntimeOption::UseLiteBackend)
  64. .def("use_om_backend", &RuntimeOption::UseOMBackend)
  65. .def("enable_pinned_memory", &RuntimeOption::EnablePinnedMemory)
  66. .def("disable_pinned_memory", &RuntimeOption::DisablePinnedMemory)
  67. .def("use_ipu", &RuntimeOption::UseIpu)
  68. .def("enable_profiling", &RuntimeOption::EnableProfiling)
  69. .def("disable_profiling", &RuntimeOption::DisableProfiling)
  70. .def_readwrite("model_file", &RuntimeOption::model_file)
  71. .def_readwrite("params_file", &RuntimeOption::params_file)
  72. .def_readwrite("model_format", &RuntimeOption::model_format)
  73. .def_readwrite("backend", &RuntimeOption::backend)
  74. .def_readwrite("external_stream", &RuntimeOption::external_stream_)
  75. .def_readwrite("model_from_memory", &RuntimeOption::model_from_memory_)
  76. .def_readwrite("cpu_thread_num", &RuntimeOption::cpu_thread_num)
  77. .def_readwrite("device_id", &RuntimeOption::device_id)
  78. .def_readwrite("device", &RuntimeOption::device);
  79. }
  80. } // namespace ultra_infer