MCPcopy Create free account
hub / github.com/apache/singa / device_check

Method device_check

python/singa/layer.py:187–205  ·  view source on GitHub ↗

Check if the devices of the input tensor are the same. Keep the device where each tensors is located the same as the first tensor. Copy data to the device of the first tensor if the device does not match. Args: *inputs: input args consisting of only PyT

(self, *inputs)

Source from the content-addressed store, hash-verified

185 inputs[0].device.EnableGraph(flag)
186
187 def device_check(self, *inputs):
188 """ Check if the devices of the input tensor are the same.
189
190 Keep the device where each tensors is located the same as the
191 first tensor. Copy data to the device of the first tensor if
192 the device does not match.
193
194 Args:
195 *inputs: input args consisting of only PyTensors
196 """
197 # disabled the graph to prevent buffering data transfer operator
198 x_device = inputs[0].device
199 prev_state = x_device.graph_enabled()
200 x_device.EnableGraph(False)
201 x_dev_id = x_device.id()
202 for var in inputs:
203 if var.device.id() != x_dev_id:
204 var.to_device(x_device)
205 x_device.EnableGraph(prev_state)
206
207 def _has_layer_param(self, layer, names):
208 """ Determine whether names contains parameter names in the layer

Callers 15

forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
applyMethod · 0.45
applyMethod · 0.45
applyMethod · 0.45
applyMethod · 0.45
forwardMethod · 0.45

Calls 4

graph_enabledMethod · 0.80
EnableGraphMethod · 0.80
idMethod · 0.45
to_deviceMethod · 0.45

Tested by

no test coverage detected