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_c.h 6.5 kB

4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. * Copyright 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 to 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_INCLUDE_C_API_CONTEXT_C_H
  17. #define MINDSPORE_INCLUDE_C_API_CONTEXT_C_H
  18. #include <stddef.h>
  19. #include <stdint.h>
  20. #include <stdbool.h>
  21. #include "include/c_api/types_c.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. typedef void *MSContextHandle;
  26. typedef void *MSDeviceInfoHandle;
  27. /// \brief Create a context object.
  28. ///
  29. /// \return Context object handle.
  30. MS_API MSContextHandle MSContextCreate();
  31. /// \brief Destroy the context object.
  32. ///
  33. /// \param[in] context Context object handle address.
  34. MS_API void MSContextDestroy(MSContextHandle *context);
  35. /// \brief Set the number of threads at runtime.
  36. ///
  37. /// \param[in] context Context object handle.
  38. /// \param[in] thread_num the number of threads at runtime.
  39. MS_API void MSContextSetThreadNum(MSContextHandle context, int32_t thread_num);
  40. /// \brief Obtain the current thread number setting.
  41. ///
  42. /// \param[in] context Context object handle.
  43. ///
  44. /// \return The current thread number setting.
  45. MS_API int32_t MSContextGetThreadNum(const MSContextHandle context);
  46. /// \brief Set the thread affinity to CPU cores.
  47. ///
  48. /// \param[in] context Context object handle.
  49. /// \param[in] mode: 0: no affinities, 1: big cores first, 2: little cores first
  50. MS_API void MSContextSetThreadAffinityMode(MSContextHandle context, int mode);
  51. /// \brief Obtain the thread affinity of CPU cores.
  52. ///
  53. /// \param[in] context Context object handle.
  54. ///
  55. /// \return Thread affinity to CPU cores. 0: no affinities, 1: big cores first, 2: little cores first
  56. MS_API int MSContextGetThreadAffinityMode(const MSContextHandle context);
  57. /// \brief Set the thread lists to CPU cores.
  58. ///
  59. /// \note If core_list and mode are set by MSContextSetThreadAffinityMode at the same time,
  60. /// the core_list is effective, but the mode is not effective.
  61. ///
  62. /// \param[in] context Context object handle.
  63. /// \param[in] core_list: a array of thread core lists.
  64. /// \param[in] core_num The number of core.
  65. MS_API void MSContextSetThreadAffinityCoreList(MSContextHandle context, const int32_t *core_list, size_t core_num);
  66. /// \brief Obtain the thread lists of CPU cores.
  67. ///
  68. /// \param[in] context Context object handle.
  69. /// \param[out] core_num The number of core.
  70. ///
  71. /// \return a array of thread core lists.
  72. MS_API const int32_t *MSContextGetThreadAffinityCoreList(const MSContextHandle context, size_t *core_num);
  73. /// \brief Set the status whether to perform model inference or training in parallel.
  74. ///
  75. /// \param[in] context Context object handle.
  76. /// \param[in] is_parallel: true, parallel; false, not in parallel.
  77. MS_API void MSContextSetEnableParallel(MSContextHandle context, bool is_parallel);
  78. /// \brief Obtain the status whether to perform model inference or training in parallel.
  79. ///
  80. /// \param[in] context Context object handle.
  81. ///
  82. /// \return Bool value that indicates whether in parallel.
  83. MS_API bool MSContextGetEnableParallel(const MSContextHandle context);
  84. /// \brief Add device info to context object.
  85. ///
  86. /// \param[in] context Context object handle.
  87. /// \param[in] device_info Device info object handle.
  88. MS_API void MSContextAddDeviceInfo(MSContextHandle context, MSDeviceInfoHandle device_info);
  89. /// \brief Create a device info object.
  90. ///
  91. /// \param[in] device_info Device info object handle.
  92. ///
  93. /// \return Device info object handle.
  94. MS_API MSDeviceInfoHandle MSDeviceInfoCreate(MSDeviceType device_type);
  95. /// \brief Destroy the device info object.
  96. ///
  97. /// \param[in] device_info Device info object handle address.
  98. MS_API void MSDeviceInfoDestroy(MSDeviceInfoHandle *device_info);
  99. /// \brief Set provider's name.
  100. ///
  101. /// \param[in] device_info Device info object handle.
  102. /// \param[in] provider define the provider's name.
  103. MS_API void MSDeviceInfoSetProvider(MSDeviceInfoHandle device_info, const char *provider);
  104. /// \brief Obtain provider's name
  105. ///
  106. /// \param[in] device_info Device info object handle.
  107. ///
  108. /// \return provider's name.
  109. MS_API const char *MSDeviceInfoGetProvider(const MSDeviceInfoHandle device_info);
  110. /// \brief Set provider's device type.
  111. ///
  112. /// \param[in] device_info Device info object handle.
  113. /// \param[in] device define the provider's device type. EG: CPU.
  114. MS_API void MSDeviceInfoSetProviderDevice(MSDeviceInfoHandle device_info, const char *device);
  115. /// \brief Obtain provider's device type.
  116. ///
  117. /// \param[in] device_info Device info object handle.
  118. ///
  119. /// \return provider's device type.
  120. MS_API const char *MSDeviceInfoGetProviderDevice(const MSDeviceInfoHandle device_info);
  121. /// \brief Obtain the device type of the device info.
  122. ///
  123. /// \param[in] device_info Device info object handle.
  124. ///
  125. /// \return Device Type of the device info.
  126. MS_API MSDeviceType MSDeviceInfoGetDeviceType(const MSDeviceInfoHandle device_info);
  127. /// \brief Set enables to perform the float16 inference, Only valid for CPU/GPU.
  128. ///
  129. /// \param[in] device_info Device info object handle.
  130. /// \param[in] is_fp16 Enable float16 inference or not.
  131. MS_API void MSDeviceInfoSetEnableFP16(MSDeviceInfoHandle device_info, bool is_fp16);
  132. /// \brief Obtain enables to perform the float16 inference, Only valid for CPU/GPU.
  133. ///
  134. /// \param[in] device_info Device info object handle.
  135. ///
  136. /// \return Whether enable float16 inference.
  137. MS_API bool MSDeviceInfoGetEnableFP16(const MSDeviceInfoHandle device_info);
  138. /// \brief Set the NPU frequency, Only valid for NPU.
  139. ///
  140. /// \param[in] device_info Device info object handle.
  141. /// \param[in] frequency Can be set to 1 (low power consumption), 2 (balanced), 3 (high performance), 4 (extreme
  142. /// performance), default as 3.
  143. MS_API void MSDeviceInfoSetFrequency(MSDeviceInfoHandle device_info, int frequency);
  144. /// \brief Obtain the NPU frequency, Only valid for NPU.
  145. ///
  146. /// \param[in] device_info Device info object handle.
  147. ///
  148. /// \return NPU frequency
  149. MS_API int MSDeviceInfoGetFrequency(const MSDeviceInfoHandle device_info);
  150. #ifdef __cplusplus
  151. }
  152. #endif
  153. #endif // MINDSPORE_INCLUDE_C_API_CONTEXT_C_H