option.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #pragma once
  15. #include "ultra_infer/core/fd_type.h"
  16. #include <iostream>
  17. #include <map>
  18. #include <memory>
  19. #include <set>
  20. #include <string>
  21. #include <vector>
  22. namespace ultra_infer {
  23. /*! @brief Option object to configure OpenVINO backend
  24. */
  25. struct OpenVINOBackendOption {
  26. std::string device = "CPU";
  27. int cpu_thread_num = -1;
  28. /// Number of streams while use OpenVINO
  29. int num_streams = 1;
  30. /// Affinity mode
  31. std::string affinity = "YES";
  32. /// Performance hint mode
  33. std::string hint = "UNDEFINED";
  34. /**
  35. * @brief Set device name for OpenVINO, default 'CPU', can also be 'AUTO',
  36. * 'GPU', 'GPU.1'....
  37. */
  38. void SetDevice(const std::string &name = "CPU") { device = name; }
  39. /**
  40. * @brief Set shape info for OpenVINO
  41. */
  42. void SetShapeInfo(
  43. const std::map<std::string, std::vector<int64_t>> &_shape_infos) {
  44. shape_infos = _shape_infos;
  45. }
  46. /**
  47. * @brief While use OpenVINO backend with intel GPU, use this interface to
  48. * specify operators run on CPU
  49. */
  50. void SetCpuOperators(const std::vector<std::string> &operators) {
  51. for (const auto &op : operators) {
  52. cpu_operators.insert(op);
  53. }
  54. }
  55. /**
  56. * @brief Set Affinity mode
  57. */
  58. void SetAffinity(const std::string &_affinity) {
  59. FDASSERT(_affinity == "YES" || _affinity == "NO" || _affinity == "NUMA" ||
  60. _affinity == "HYBRID_AWARE",
  61. "The affinity mode should be one of the list "
  62. "['YES', 'NO', 'NUMA', "
  63. "'HYBRID_AWARE'] ");
  64. affinity = _affinity;
  65. }
  66. /**
  67. * @brief Set the Performance Hint
  68. */
  69. void SetPerformanceHint(const std::string &_hint) {
  70. FDASSERT(_hint == "LATENCY" || _hint == "THROUGHPUT" ||
  71. _hint == "CUMULATIVE_THROUGHPUT" || _hint == "UNDEFINED",
  72. "The performance hint should be one of the list "
  73. "['LATENCY', 'THROUGHPUT', 'CUMULATIVE_THROUGHPUT', "
  74. "'UNDEFINED'] ");
  75. hint = _hint;
  76. }
  77. /**
  78. * @brief Set the number of streams
  79. */
  80. void SetStreamNum(int _num_streams) {
  81. FDASSERT(_num_streams > 0, "The stream_num must be greater than 0.");
  82. num_streams = _num_streams;
  83. }
  84. std::map<std::string, std::vector<int64_t>> shape_infos;
  85. std::set<std::string> cpu_operators{"MulticlassNms"};
  86. };
  87. } // namespace ultra_infer