MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / Device

Class Device

imperative/python/megengine/core/_wrap.py:8–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class Device:
9 def __init__(self, device=None):
10 if device is None:
11 self._cn = CompNode()
12 elif isinstance(device, Device):
13 self._cn = device._cn
14 elif isinstance(device, CompNode):
15 self._cn = device
16 else:
17 self._cn = CompNode(device)
18
19 self._logical_name = None
20
21 @property
22 def logical_name(self):
23 if self._logical_name:
24 return self._logical_name
25 self._logical_name = self._cn.logical_name
26 return self._logical_name
27
28 def to_c(self):
29 return self._cn
30
31 def __repr__(self):
32 return "{}({})".format(type(self).__qualname__, repr(self._cn))
33
34 def __str__(self):
35 return str(self._cn)
36
37 def __hash__(self):
38 return hash(str(self._cn))
39
40 def __eq__(self, rhs):
41 if not isinstance(rhs, Device):
42 rhs = Device(rhs)
43 return self._cn == rhs._cn
44
45
46def as_device(obj):

Callers 5

fwdFunction · 0.90
__eq__Method · 0.70
as_deviceFunction · 0.70
__init__Method · 0.50
loadMethod · 0.50

Calls

no outgoing calls

Tested by 1

fwdFunction · 0.72