option.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "ultra_infer/runtime/enum_variables.h"
  17. #include <iostream>
  18. #include <map>
  19. #include <memory>
  20. #include <string>
  21. #include <vector>
  22. namespace ultra_infer {
  23. /*! @brief Option object to configure ONNX Runtime backend
  24. */
  25. struct OrtBackendOption {
  26. /// Level of graph optimization,
  27. /// /-1: mean default(Enable all the optimization strategy)
  28. /// /0: disable all the optimization strategy/1: enable basic strategy
  29. /// /2:enable extend strategy/99: enable all
  30. int graph_optimization_level = -1;
  31. /// Number of threads to execute the operator, -1: default
  32. int intra_op_num_threads = -1;
  33. /// Number of threads to execute the graph,
  34. /// -1: default. This parameter only will bring effects
  35. /// while the `OrtBackendOption::execution_mode` set to 1.
  36. int inter_op_num_threads = -1;
  37. /// Execution mode for the graph, -1: default(Sequential mode)
  38. /// /0: Sequential mode, execute the operators in graph one by one.
  39. /// /1: Parallel mode, execute the operators in graph parallelly.
  40. int execution_mode = -1;
  41. /// Inference device, OrtBackend supports CPU/GPU
  42. Device device = Device::CPU;
  43. /// Inference device id
  44. int device_id = 0;
  45. void *external_stream_ = nullptr;
  46. /// Use fp16 to infer
  47. bool enable_fp16 = false;
  48. std::vector<std::string> ort_disabled_ops_{};
  49. void DisableOrtFP16OpTypes(const std::vector<std::string> &ops) {
  50. ort_disabled_ops_.insert(ort_disabled_ops_.end(), ops.begin(), ops.end());
  51. }
  52. };
  53. } // namespace ultra_infer