You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

context.h 3.0 kB

5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * Copyright 2020-2021 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 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. #ifndef MINDSPORE_LITE_INCLUDE_CONTEXT_H_
  17. #define MINDSPORE_LITE_INCLUDE_CONTEXT_H_
  18. #include <string>
  19. #include "include/ms_tensor.h"
  20. #include "include/lite_utils.h"
  21. #include "include/lite_types.h"
  22. namespace mindspore::lite {
  23. /// \brief CpuDeviceInfo defined for CPU's configuration information.
  24. typedef struct CpuDeviceInfo {
  25. bool enable_float16_ = false; /**< prior enable float16 inference */
  26. CpuBindMode cpu_bind_mode_ = MID_CPU;
  27. } CpuDeviceInfo;
  28. /// \brief GpuDeviceInfo defined for GPU's configuration information.
  29. typedef struct GpuDeviceInfo {
  30. bool enable_float16_ = false; /**< prior enable float16 inference */
  31. uint32_t gpu_device_id_ = 0;
  32. int rank_id_ = 0;
  33. int group_size_ = 0;
  34. bool enable_gl_texture_ = false; /**<enable sharing OpenGL texture with OpenCL */
  35. } GpuDeviceInfo;
  36. /// \brief NpuDeviceInfo defined for NPU's configuration information.
  37. typedef struct NpuDeviceInfo {
  38. int frequency_ = 3; /**< npu frequency inference, low 1, medium 2, high 3, extreme 4, other values will be set to 3 */
  39. } NpuDeviceInfo;
  40. /// \brief Ascend310DeviceInfo defined for Ascend's configuration information.
  41. typedef struct AscendDeviceInfo {
  42. uint32_t device_id_;
  43. std::string batch_size_;
  44. std::string image_size_;
  45. } AscendDeviceInfo;
  46. /// \brief DeviceInfo defined for backend's configuration information.
  47. struct DeviceInfo {
  48. CpuDeviceInfo cpu_device_info_;
  49. GpuDeviceInfo gpu_device_info_;
  50. NpuDeviceInfo npu_device_info_;
  51. AscendDeviceInfo ascend310_device_info_;
  52. };
  53. /// \brief DeviceContext defined for holding backend's configuration information.
  54. struct DeviceContext {
  55. DeviceType device_type_ = DT_CPU;
  56. DeviceInfo device_info_;
  57. std::string provider_{};
  58. std::string provider_device_{};
  59. AllocatorPtr allocator_ = nullptr;
  60. };
  61. /// \brief Context defined for holding environment variables during runtime.
  62. struct Context {
  63. String vendor_name_;
  64. int thread_num_ = 2; /**< thread number config for thread pool */
  65. bool enable_parallel_ = false;
  66. Vector<int> affinity_core_list_; /**< explicitly specify the core to be bound. priority use affinity core list */
  67. AllocatorPtr allocator = nullptr;
  68. #ifndef NOT_USE_STL
  69. DeviceContextVector device_list_ = {{DT_CPU, {false, MID_CPU}}};
  70. #else
  71. DeviceContextVector device_list_;
  72. #endif // NOT_USE_STL
  73. DelegatePtr delegate = nullptr;
  74. };
  75. } // namespace mindspore::lite
  76. #endif // MINDSPORE_LITE_INCLUDE_CONTEXT_H_