abstract_accelerator.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. # Copyright (c) Microsoft Corporation.
  2. # SPDX-License-Identifier: Apache-2.0
  3. # DeepSpeed Team
  4. import abc
  5. from abc import ABC
  6. class DeepSpeedAccelerator(ABC):
  7. def __init__(self):
  8. self._name = None
  9. self._communication_backend_name = None
  10. self._compile_backend = None
  11. @abc.abstractmethod
  12. def is_synchronized_device(self):
  13. ...
  14. @abc.abstractmethod
  15. def use_host_timers(self):
  16. ...
  17. @abc.abstractmethod
  18. def resolves_data_dependency(self):
  19. ...
  20. @abc.abstractmethod
  21. def handles_memory_backpressure(self):
  22. ...
  23. # Device APIs
  24. @abc.abstractmethod
  25. def device_name(self, device_index):
  26. ...
  27. @abc.abstractmethod
  28. def device(self, device_index):
  29. ...
  30. @abc.abstractmethod
  31. def set_device(self, device_index):
  32. ...
  33. @abc.abstractmethod
  34. def current_device(self):
  35. ...
  36. @abc.abstractmethod
  37. def current_device_name(self):
  38. ...
  39. @abc.abstractmethod
  40. def device_count(self):
  41. ...
  42. @abc.abstractmethod
  43. def synchronize(self, device_index=None):
  44. ...
  45. # RNG APIs
  46. @abc.abstractmethod
  47. def random(self):
  48. ...
  49. @abc.abstractmethod
  50. def set_rng_state(self, new_state, device_index=None):
  51. ...
  52. @abc.abstractmethod
  53. def get_rng_state(self, device_index=None):
  54. ...
  55. @abc.abstractmethod
  56. def manual_seed(self, seed):
  57. ...
  58. @abc.abstractmethod
  59. def manual_seed_all(self, seed):
  60. ...
  61. @abc.abstractmethod
  62. def initial_seed(self):
  63. ...
  64. @abc.abstractmethod
  65. def default_generator(self, device_index):
  66. ...
  67. # Streams/Events
  68. @property
  69. @abc.abstractmethod
  70. def Stream(self):
  71. ...
  72. @abc.abstractmethod
  73. def stream(self, stream):
  74. ...
  75. @abc.abstractmethod
  76. def current_stream(self, device_index=None):
  77. ...
  78. @abc.abstractmethod
  79. def default_stream(self, device_index=None):
  80. ...
  81. @property
  82. @abc.abstractmethod
  83. def Event(self):
  84. ...
  85. # Memory management
  86. @abc.abstractmethod
  87. def empty_cache(self):
  88. ...
  89. @abc.abstractmethod
  90. def memory_allocated(self, device_index=None):
  91. ...
  92. @abc.abstractmethod
  93. def max_memory_allocated(self, device_index=None):
  94. ...
  95. @abc.abstractmethod
  96. def reset_max_memory_allocated(self, device_index=None):
  97. ...
  98. @abc.abstractmethod
  99. def memory_cached(self, device_index=None):
  100. ...
  101. @abc.abstractmethod
  102. def max_memory_cached(self, device_index=None):
  103. ...
  104. @abc.abstractmethod
  105. def reset_max_memory_cached(self, device_index=None):
  106. ...
  107. @abc.abstractmethod
  108. def memory_stats(self, device_index=None):
  109. ...
  110. @abc.abstractmethod
  111. def reset_peak_memory_stats(self, device_index=None):
  112. ...
  113. @abc.abstractmethod
  114. def memory_reserved(self, device_index=None):
  115. ...
  116. @abc.abstractmethod
  117. def max_memory_reserved(self, device_index=None):
  118. ...
  119. @abc.abstractmethod
  120. def total_memory(self, device_index=None):
  121. ...
  122. @abc.abstractmethod
  123. def available_memory(self, device_index=None):
  124. ...
  125. # Data types
  126. @abc.abstractmethod
  127. def is_bf16_supported(self):
  128. ...
  129. @abc.abstractmethod
  130. def is_fp16_supported(self):
  131. ...
  132. @abc.abstractmethod
  133. def supported_dtypes(self):
  134. ...
  135. # Misc
  136. @abc.abstractmethod
  137. def amp(self):
  138. ...
  139. @abc.abstractmethod
  140. def is_available(self):
  141. ...
  142. @abc.abstractmethod
  143. def range_push(self, msg):
  144. ...
  145. @abc.abstractmethod
  146. def range_pop(self):
  147. ...
  148. @abc.abstractmethod
  149. def lazy_call(self, callback):
  150. ...
  151. @abc.abstractmethod
  152. def communication_backend_name(self):
  153. ...
  154. @abc.abstractmethod
  155. def is_triton_supported(self):
  156. ...
  157. # Graph operations
  158. @abc.abstractmethod
  159. def create_graph(self):
  160. ...
  161. @abc.abstractmethod
  162. def capture_to_graph(self, graph, pool=None, stream=None):
  163. ...
  164. @abc.abstractmethod
  165. def replay_graph(self, graph):
  166. ...
  167. # Tensor operations
  168. @property
  169. @abc.abstractmethod
  170. def BFloat16Tensor(self):
  171. ...
  172. @property
  173. @abc.abstractmethod
  174. def ByteTensor(self):
  175. ...
  176. @property
  177. @abc.abstractmethod
  178. def DoubleTensor(self):
  179. ...
  180. @property
  181. @abc.abstractmethod
  182. def FloatTensor(self):
  183. ...
  184. @property
  185. @abc.abstractmethod
  186. def HalfTensor(self):
  187. ...
  188. @property
  189. @abc.abstractmethod
  190. def IntTensor(self):
  191. ...
  192. @property
  193. @abc.abstractmethod
  194. def LongTensor(self):
  195. ...
  196. @abc.abstractmethod
  197. def pin_memory(self, tensor, align_bytes=1):
  198. ...
  199. @abc.abstractmethod
  200. def is_pinned(self, tensor):
  201. ...
  202. @abc.abstractmethod
  203. def on_accelerator(self, tensor):
  204. ...
  205. @abc.abstractmethod
  206. def op_builder_dir(self):
  207. ...
  208. # create an instance of op builder, specified by class_name
  209. @abc.abstractmethod
  210. def create_op_builder(self, class_name):
  211. ...
  212. # return an op builder class, specified by class_name
  213. @abc.abstractmethod
  214. def get_op_builder(self, class_name):
  215. ...
  216. @abc.abstractmethod
  217. def build_extension(self):
  218. ...
  219. @abc.abstractmethod
  220. def export_envs(self):
  221. ...
  222. @abc.abstractmethod
  223. def visible_devices_envs(self):
  224. ...
  225. @abc.abstractmethod
  226. def set_visible_devices_envs(self, current_env, local_accelerator_ids):
  227. ...
  228. @abc.abstractmethod
  229. def get_compile_backend(self):
  230. ...
  231. @abc.abstractmethod
  232. def set_compile_backend(self, backend):
  233. ...