Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
116 views
in Technique[技术] by (71.8m points)

How can I run Tensorflow on one single core?

I'm using Tensorflow on a cluster and I want to tell Tensorflow to run only on one single core (even though there are more available).

Does someone know if this is possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To run Tensorflow on one single CPU thread, I use:

session_conf = tf.ConfigProto(
      intra_op_parallelism_threads=1,
      inter_op_parallelism_threads=1)
sess = tf.Session(config=session_conf)

device_count limits the number of CPUs being used, not the number of cores or threads.

tensorflow/tensorflow/core/protobuf/config.proto says:

message ConfigProto {
  // Map from device type name (e.g., "CPU" or "GPU" ) to maximum
  // number of devices of that type to use.  If a particular device
  // type is not found in the map, the system picks an appropriate
  // number.
  map<string, int32> device_count = 1;

On Linux you can run sudo dmidecode -t 4 | egrep -i "Designation|Intel|core|thread" to see how many CPUs/cores/threads you have, e.g. the following has 2 CPUs, each of them has 8 cores, each of them has 2 threads, which gives a total of 2*8*2=32 threads:

fra@s:~$ sudo dmidecode -t 4 | egrep -i "Designation|Intel|core|thread"
    Socket Designation: CPU1
    Manufacturer: Intel
            HTT (Multi-threading)
    Version: Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz
    Core Count: 8
    Core Enabled: 8
    Thread Count: 16
            Multi-Core
            Hardware Thread
    Socket Designation: CPU2
    Manufacturer: Intel
            HTT (Multi-threading)
    Version: Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz
    Core Count: 8
    Core Enabled: 8
    Thread Count: 16
            Multi-Core
            Hardware Thread

Tested with Tensorflow 0.12.1 and 1.0.0 with Ubuntu 14.04.5 LTS x64 and Ubuntu 16.04 LTS x64.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...