Skip to content

Commit a41672c

Browse files
committed
defines offloading helper types
1 parent 9f186c6 commit a41672c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

pyop2/offload_utils.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from enum import IntEnum
2+
3+
4+
class DataAvailability(IntEnum):
5+
"""
6+
Indicates whether the device or host contains valid data.
7+
"""
8+
AVAILABLE_ON_HOST_ONLY = 1
9+
AVAILABLE_ON_DEVICE_ONLY = 2
10+
AVAILABLE_ON_BOTH = 3
11+
12+
13+
class OffloadMixin:
14+
def get_availability(self):
15+
raise NotImplementedError
16+
17+
def ensure_availability_on_host(self):
18+
raise NotImplementedError
19+
20+
def ensure_availaibility_on_device(self):
21+
raise NotImplementedError
22+
23+
def is_available_on_host(self):
24+
return bool(self.get_availability() & AVAILABLE_ON_HOST_ONLY)
25+
26+
def is_available_on_device(self):
27+
return bool(self.get_availability() & AVAILABLE_ON_DEVICE_ONLY)
28+
29+
30+
AVAILABLE_ON_HOST_ONLY = DataAvailability.AVAILABLE_ON_HOST_ONLY
31+
AVAILABLE_ON_DEVICE_ONLY = DataAvailability.AVAILABLE_ON_DEVICE_ONLY
32+
AVAILABLE_ON_BOTH = DataAvailability.AVAILABLE_ON_BOTH

0 commit comments

Comments
 (0)