MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _UserDeviceSpec

Class _UserDeviceSpec

tensorflow/python/framework/ops.py:100–144  ·  view source on GitHub ↗

Store user-specified device and provide computation of merged device.

Source from the content-addressed store, hash-verified

98
99
100class _UserDeviceSpec(object):
101 """Store user-specified device and provide computation of merged device."""
102
103 def __init__(self, device_name_or_function):
104 self._device_name_or_function = device_name_or_function
105 self.display_name = str(self._device_name_or_function)
106 self.function = device_name_or_function
107 self.raw_string = None
108
109 if isinstance(device_name_or_function, pydev.MergeDevice):
110 self.is_null_merge = device_name_or_function.is_null_merge
111
112 elif callable(device_name_or_function):
113 self.is_null_merge = False
114 dev_func = self._device_name_or_function
115 func_name = function_utils.get_func_name(dev_func)
116 func_code = function_utils.get_func_code(dev_func)
117 if func_code:
118 fname = func_code.co_filename
119 lineno = func_code.co_firstlineno
120 else:
121 fname = "unknown"
122 lineno = -1
123 self.display_name = "%s<%s, %d>" % (func_name, fname, lineno)
124
125 elif device_name_or_function is None:
126 # NOTE(taylorrobie): This MUST be False. None signals a break in the
127 # device stack, so `is_null_merge` must be False for such a case to
128 # allow callers to safely skip over null merges without missing a None.
129 self.is_null_merge = False
130
131 else:
132 self.raw_string = device_name_or_function
133 self.function = pydev.merge_device(device_name_or_function)
134 self.is_null_merge = self.function.is_null_merge
135
136 # We perform this check in __init__ because it is of non-trivial cost,
137 # and self.string_merge is typically called many times.
138 self.fast_string_merge = isinstance(self.function, pydev.MergeDevice)
139
140 def string_merge(self, node_def):
141 if self.fast_string_merge:
142 return self.function.shortcut_string_merge(node_def)
143
144 return compat.as_str(_device_string(self.function(node_def)))
145
146
147class NullContextmanager(object):

Callers 1

_add_device_to_stackMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected