首页 文章

尽管有多个内核,为什么TensorFlow只找到一个CPU设备?

提问于
浏览
1

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

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

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

你知道为什么吗?

1 回答

  • 3

    默认情况下, 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"):
      # ...
    

相关问题