tensorflow_调用具体gpu记录

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_30362711/article/details/89025522

查看设备名字:
 

tf.test.gpu_device_name()

Returns the name of a GPU device if available or the empty string.

tf.contrib.eager.list_devices()

Names of the available devices, as a list.

使用具体设备的函数

# Place the operations on device "GPU:0" in the "ps" job.
device_spec = DeviceSpec(job="ps", device_type="GPU", device_index=0)
with tf.device(device_spec):
  # Both my_var and squared_var will be placed on /job:ps/device:GPU:0.
  my_var = tf.Variable(..., name="my_variable")
  squared_var = tf.square(my_var)

If a DeviceSpec is partially specified, it will be merged with other DeviceSpecs according to the scope in which it is defined. DeviceSpec components defined in inner scopes take precedence over those defined in outer scopes.

with tf.device(DeviceSpec(job="train", )):
  with tf.device(DeviceSpec(job="ps", device_type="GPU", device_index=0):
    # Nodes created here will be assigned to /job:ps/device:GPU:0.
  with tf.device(DeviceSpec(device_type="GPU", device_index=1):
    # Nodes created here will be assigned to /job:train/device:GPU:1.

DeviceSpec consists of 5 components -- each of which is optionally specified:

  • Job: The job name.
  • Replica: The replica index.
  • Task: The task index.
  • Device type: The device type string (e.g. "CPU" or "GPU").
  • Device index: The device index.

__init__

__init__(
    job=None,
    replica=None,
    task=None,
    device_type=None,
    device_index=None
)

Create a new DeviceSpec object.

Args:

  • job: string. Optional job name.
  • replica: int. Optional replica index.
  • task: int. Optional task index.
  • device_type: Optional device type string (e.g. "CPU" or "GPU")
  • device_index: int. Optional device index. If left unspecified, device represents 'any' device_index.

封装好的一个分支

tf.distribute

猜你喜欢

转载自blog.csdn.net/qq_30362711/article/details/89025522