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 2.4 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright 2020 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 <memory>
  20. #include "include/ms_tensor.h"
  21. #include "include/lite_utils.h"
  22. namespace mindspore::lite {
  23. /// \brief CpuBindMode defined for holding bind cpu strategy argument.
  24. typedef enum {
  25. NO_BIND = 0, /**< no bind */
  26. HIGHER_CPU = 1, /**< bind higher cpu first */
  27. MID_CPU = 2 /**< bind middle cpu first */
  28. } CpuBindMode;
  29. /// \brief DeviceType defined for holding user's preferred backend.
  30. typedef enum {
  31. DT_CPU, /**< CPU device type */
  32. DT_GPU, /**< GPU device type */
  33. DT_NPU /**< NPU device type, not supported yet */
  34. } DeviceType;
  35. /// \brief CpuDeviceInfo defined for CPU's configuration information.
  36. typedef struct {
  37. bool enable_float16_ = false; /**< prior enable float16 inference */
  38. CpuBindMode cpu_bind_mode_ = MID_CPU;
  39. } CpuDeviceInfo;
  40. /// \brief GpuDeviceInfo defined for GPU's configuration information.
  41. typedef struct {
  42. bool enable_float16_ = false; /**< prior enable float16 inference */
  43. } GpuDeviceInfo;
  44. /// \brief DeviceInfo defined for backend's configuration information.
  45. union DeviceInfo {
  46. CpuDeviceInfo cpu_device_info_;
  47. GpuDeviceInfo gpu_device_info_;
  48. };
  49. /// \brief DeviceContext defined for holding backend's configuration information.
  50. struct DeviceContext {
  51. DeviceType device_type_ = DT_CPU;
  52. DeviceInfo device_info_;
  53. };
  54. /// \brief Context defined for holding environment variables during runtime.
  55. struct Context {
  56. std::string vendor_name_;
  57. int thread_num_ = 2; /**< thread number config for thread pool */
  58. AllocatorPtr allocator = nullptr;
  59. DeviceContextVector device_list_ = {{DT_CPU, {false, MID_CPU}}};
  60. };
  61. } // namespace mindspore::lite
  62. #endif // MINDSPORE_LITE_INCLUDE_CONTEXT_H_