TimZaman
TimZaman

Reputation: 2707

How do I get the device an Op will be, or is, placed under?

This question is similar to: How to get current TensorFlow name scope

But this questions is about the Device scope. I understand it's slightly more complicated, as the device might not have been explicitly scoped, and no guarantees might be given.

Is there any way to get insight into this?

Upvotes: 1

Views: 57

Answers (1)

Yaroslav Bulatov
Yaroslav Bulatov

Reputation: 57953

I use the following utility

class _DeviceCaptureOp(object):
  def __init__(self):
    self.device = None
  def _set_device(self, device):
    self.device = device

def get_current_device():
  """Returns device string of current graph context."""

  g = tf.get_default_graph()
  op = _DeviceCaptureOp()
  g._apply_device_functions(op)
  return op.device

Upvotes: 1

Related Questions