【问题标题】:Why does TensorFlow only find one CPU device despite having multiple cores?为什么 TensorFlow 尽管有多个内核却只能找到一个 CPU 设备?
【发布时间】:2016-10-06 10:07:23
【问题描述】:

据我了解,TensorFlow 为每个内核创建一个设备。 (来源:https://github.com/samjabrahams/tensorflow-white-paper-notes注意:重申一下-在这种情况下,“单设备”是指使用单个 CPU 内核或单个 GPU,而不是单个机器。同样,“多设备”不是指多个机器,但到多个 CPU 内核和/或 GPU。有关多机器的讨论,请参阅“3.3 分布式执行”。

我的电脑有四个核心,但它只能识别一个:

>>> from tensorflow.python.client import device_lib 
>>> print(device_lib.list_local_devices())
[name: "/cpu:0"
device_type: "CPU"
memory_limit: 268435456
bus_adjacency: BUS_ANY
incarnation: 13835232998165214133
]

你知道为什么吗?

【问题讨论】:

标签: python tensorflow


【解决方案1】:

默认情况下,cpu:0 代表进程可用的所有内核。您可以通过执行以下操作创建设备cpu:0cpu:1,它们分别代表 1 个逻辑核心

config = tf.ConfigProto(device_count={"CPU": 2},
                        inter_op_parallelism_threads=2,
                        intra_op_parallelism_threads=1)
sess = tf.Session(config=config)

然后您可以将设备分配为

with tf.device("/cpu:0"):
  # ...

with tf.device("/cpu:1"):
  # ...

【讨论】:

  • 非常感谢!任务有效。但是,对于其他所有人:请注意 print(device_lib.list_local_devices()) 因为它仍然只列出一个 CPU 设备。
  • 这些值是什么意思,为什么选择这样的值?:inter_op_parallelism_threads=2, intra_op_parallelism_threads=1
  • inter_op_parallelism_threads是Eigen线程池的大小,intra_op_parallelism_threads控制可以并行启动多少个ops
  • 今天的tensorflow.org/guide/using_gpu 版本似乎暗示可以在不配置device_count 等的情况下使用with 构造,除非我从网站上遗漏了一些东西。然而,在实践中,它会在仅在指定的 GPU 上运行操作之前唤醒所有 4 个 GPU。
  • 如何限制 TensorFlow 仅使用 CPU 的 1 个核心?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
  • 2016-05-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多