-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract accelerator (step 1) (#2504)
* Establish building block of abstract accelerator * Change .*Tensor variable to @Property * [op builder] add op builder reflection to allow enumerate of builders in all_ops.py and builder_names.py * change @abstractproperty to @Property @AbstractMethod Co-authored-by: Olatunji Ruwase <[email protected]>
- Loading branch information
Showing
7 changed files
with
605 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .abstract_accelerator import DeepSpeedAccelerator | ||
from .real_accelerator import get_accelerator, set_accelerator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
import abc | ||
from abc import ABC | ||
|
||
|
||
class DeepSpeedAccelerator(ABC): | ||
def __init__(self): | ||
self._name = None | ||
self._communication_backend_name = None | ||
|
||
# Device APIs | ||
@abc.abstractmethod | ||
def device_name(self, device_index): | ||
... | ||
|
||
@abc.abstractmethod | ||
def device(self, device_index): | ||
... | ||
|
||
@abc.abstractmethod | ||
def set_device(self, device_index): | ||
... | ||
|
||
@abc.abstractmethod | ||
def current_device(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def current_device_name(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def device_count(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def synchronize(self, device_index=None): | ||
... | ||
|
||
# RNG APIs | ||
@abc.abstractmethod | ||
def random(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def set_rng_state(self, new_state, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def get_rng_state(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def manual_seed(self, seed): | ||
... | ||
|
||
@abc.abstractmethod | ||
def manual_seed_all(self, seed): | ||
... | ||
|
||
@abc.abstractmethod | ||
def initial_seed(self, seed): | ||
... | ||
|
||
@abc.abstractmethod | ||
def default_generator(self, device_index): | ||
... | ||
|
||
# Streams/Events | ||
@abc.abstractmethod | ||
def Stream(self, device=None, priority=0, **kwargs): | ||
... | ||
|
||
@abc.abstractmethod | ||
def StreamContext(self, stream): | ||
... | ||
|
||
@abc.abstractmethod | ||
def stream(self, stream): | ||
... | ||
|
||
@abc.abstractmethod | ||
def current_stream(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def default_stream(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def Event(self, **kwargs): | ||
... | ||
|
||
# Memory management | ||
@abc.abstractmethod | ||
def empty_cache(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def memory_allocated(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def max_memory_allocated(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def reset_max_memory_allocated(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def memory_cached(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def max_memory_cached(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def reset_max_memory_cached(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def memory_stats(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def reset_peak_memory_stats(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def memory_reserved(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def max_memory_reserved(self, device_index=None): | ||
... | ||
|
||
@abc.abstractmethod | ||
def total_memory(self, device_index=None): | ||
... | ||
|
||
# Data types | ||
@abc.abstractmethod | ||
def is_bf16_supported(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def is_fp16_supported(self): | ||
... | ||
|
||
# Misc | ||
@abc.abstractmethod | ||
def amp(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def is_available(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def range_push(self, msg): | ||
... | ||
|
||
@abc.abstractmethod | ||
def range_pop(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def lazy_call(self, callback): | ||
... | ||
|
||
@abc.abstractmethod | ||
def communication_backend_name(self): | ||
... | ||
|
||
# Tensor operations | ||
@property | ||
@abc.abstractmethod | ||
def BFloat16Tensor(self): | ||
... | ||
|
||
@property | ||
@abc.abstractmethod | ||
def ByteTensor(self): | ||
... | ||
|
||
@property | ||
@abc.abstractmethod | ||
def DoubleTensor(self): | ||
... | ||
|
||
@property | ||
@abc.abstractmethod | ||
def FloatTensor(self): | ||
... | ||
|
||
@property | ||
@abc.abstractmethod | ||
def HalfTensor(self): | ||
... | ||
|
||
@property | ||
@abc.abstractmethod | ||
def IntTensor(self): | ||
... | ||
|
||
@property | ||
@abc.abstractmethod | ||
def LongTensor(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def pin_memory(self, tensor): | ||
... | ||
|
||
@abc.abstractmethod | ||
def on_accelerator(self, tensor): | ||
... | ||
|
||
@abc.abstractmethod | ||
def op_builder_dir(self): | ||
... | ||
|
||
@abc.abstractmethod | ||
def create_op_builder(self, class_name): | ||
... | ||
|
||
@abc.abstractmethod | ||
def build_extension(self): | ||
... |
Oops, something went wrong.