为什么 TensorFlow 有多个内核,但只找到一个 CPU 设备? [英] Why does TensorFlow only find one CPU device despite having multiple cores?

查看:53
本文介绍了为什么 TensorFlow 有多个内核,但只找到一个 CPU 设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<预><代码>>>>从 tensorflow.python.client 导入 device_lib>>>打印(device_lib.list_local_devices())[名称:/CPU:0"设备类型:CPU"内存限制:268435456bus_adjacency: BUS_ANY化身:13835232998165214133]

你知道为什么吗?

解决方案

默认情况下 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"):# ...使用 tf.device("/cpu:1"):# ...

as far as I understood TensorFlow creates one device per core. (source: https://github.com/samjabrahams/tensorflow-white-paper-notes: NOTE: To reiterate- in this context, "single device" means using a single CPU core or single GPU, not a single machine. Similarly, "multi-device" does not refer to multiple machines, but to multiple CPU cores and/or GPUs. See "3.3 Distributed Execution" for multiple machine discussion.)

My computer has four cores but it only recognises one:

>>> 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
]

Do you have any idea why?

解决方案

By default cpu:0 represents all cores available to the process. You can create devices cpu:0, cpu:1 which represent 1 logical core each by doing something like this

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

Then you can assign to devices as

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

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

这篇关于为什么 TensorFlow 有多个内核,但只找到一个 CPU 设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆