enum_variables.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Copyright (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/runtime/enum_variables.h"
  15. namespace ultra_infer {
  16. std::ostream &operator<<(std::ostream &out, const Backend &backend) {
  17. if (backend == Backend::ORT) {
  18. out << "Backend::ORT";
  19. } else if (backend == Backend::TRT) {
  20. out << "Backend::TRT";
  21. } else if (backend == Backend::PDINFER) {
  22. out << "Backend::PDINFER";
  23. } else if (backend == Backend::OPENVINO) {
  24. out << "Backend::OPENVINO";
  25. } else if (backend == Backend::RKNPU2) {
  26. out << "Backend::RKNPU2";
  27. } else if (backend == Backend::SOPHGOTPU) {
  28. out << "Backend::SOPHGOTPU";
  29. } else if (backend == Backend::POROS) {
  30. out << "Backend::POROS";
  31. } else if (backend == Backend::LITE) {
  32. out << "Backend::PDLITE";
  33. } else if (backend == Backend::HORIZONNPU) {
  34. out << "Backend::HORIZONNPU";
  35. } else if (backend == Backend::TVM) {
  36. out << "Backend::TVM";
  37. } else if (backend == Backend::OMONNPU) {
  38. out << "Backend::OMONNPU";
  39. } else {
  40. out << "UNKNOWN-Backend";
  41. }
  42. return out;
  43. }
  44. std::ostream &operator<<(std::ostream &out, const Device &d) {
  45. switch (d) {
  46. case Device::CPU:
  47. out << "Device::CPU";
  48. break;
  49. case Device::GPU:
  50. out << "Device::GPU";
  51. break;
  52. case Device::RKNPU:
  53. out << "Device::RKNPU";
  54. break;
  55. case Device::SUNRISENPU:
  56. out << "Device::SUNRISENPU";
  57. break;
  58. case Device::SOPHGOTPUD:
  59. out << "Device::SOPHGOTPUD";
  60. break;
  61. case Device::TIMVX:
  62. out << "Device::TIMVX";
  63. break;
  64. case Device::KUNLUNXIN:
  65. out << "Device::KUNLUNXIN";
  66. break;
  67. case Device::ASCEND:
  68. out << "Device::ASCEND";
  69. break;
  70. case Device::DIRECTML:
  71. out << "Device::DIRECTML";
  72. break;
  73. default:
  74. out << "Device::UNKOWN";
  75. }
  76. return out;
  77. }
  78. std::ostream &operator<<(std::ostream &out, const ModelFormat &format) {
  79. if (format == ModelFormat::PADDLE) {
  80. out << "ModelFormat::PADDLE";
  81. } else if (format == ModelFormat::ONNX) {
  82. out << "ModelFormat::ONNX";
  83. } else if (format == ModelFormat::RKNN) {
  84. out << "ModelFormat::RKNN";
  85. } else if (format == ModelFormat::SOPHGO) {
  86. out << "ModelFormat::SOPHGO";
  87. } else if (format == ModelFormat::TORCHSCRIPT) {
  88. out << "ModelFormat::TORCHSCRIPT";
  89. } else if (format == ModelFormat::HORIZON) {
  90. out << "ModelFormat::HORIZON";
  91. } else if (format == ModelFormat::TVMFormat) {
  92. out << "ModelFormat::TVMFormat";
  93. } else if (format == ModelFormat::OM) {
  94. out << "ModelFormat::OM";
  95. } else {
  96. out << "UNKNOWN-ModelFormat";
  97. }
  98. return out;
  99. }
  100. std::vector<Backend> GetAvailableBackends() {
  101. std::vector<Backend> backends;
  102. #ifdef ENABLE_ORT_BACKEND
  103. backends.push_back(Backend::ORT);
  104. #endif
  105. #ifdef ENABLE_TRT_BACKEND
  106. backends.push_back(Backend::TRT);
  107. #endif
  108. #ifdef ENABLE_PADDLE_BACKEND
  109. backends.push_back(Backend::PDINFER);
  110. #endif
  111. #ifdef ENABLE_POROS_BACKEND
  112. backends.push_back(Backend::POROS);
  113. #endif
  114. #ifdef ENABLE_OPENVINO_BACKEND
  115. backends.push_back(Backend::OPENVINO);
  116. #endif
  117. #ifdef ENABLE_LITE_BACKEND
  118. backends.push_back(Backend::LITE);
  119. #endif
  120. #ifdef ENABLE_RKNPU2_BACKEND
  121. backends.push_back(Backend::RKNPU2);
  122. #endif
  123. #ifdef ENABLE_HORIZON_BACKEND
  124. backends.push_back(Backend::HORIZONNPU);
  125. #endif
  126. #ifdef ENABLE_SOPHGO_BACKEND
  127. backends.push_back(Backend::SOPHGOTPU);
  128. #endif
  129. #ifdef ENABLE_TVM_BACKEND
  130. backends.push_back(Backend::TVM);
  131. #endif
  132. #ifdef ENABLE_OM_BACKEND
  133. backends.push_back(Backend::OMONNPU);
  134. #endif
  135. return backends;
  136. }
  137. bool IsBackendAvailable(const Backend &backend) {
  138. std::vector<Backend> backends = GetAvailableBackends();
  139. for (size_t i = 0; i < backends.size(); ++i) {
  140. if (backend == backends[i]) {
  141. return true;
  142. }
  143. }
  144. return false;
  145. }
  146. } // namespace ultra_infer