17

Whenever I run the cifar10_eval.py, in creates 32 threads as following:

I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 32

I think this number of threads is the number of threads running on CPUs, but when I check the usage, only 400-500% of CPUs are used. Is there anyway to change this number of threads?

Seanny123
  • 8,776
  • 13
  • 68
  • 124
Zk1001
  • 2,033
  • 4
  • 19
  • 36

1 Answers1

26

To configure this value, you can pass a tf.ConfigProto argument when constructing the tf.Session:

NUM_THREADS = …
sess = tf.Session(config=tf.ConfigProto(
    intra_op_parallelism_threads=NUM_THREADS))
Zichen Wang
  • 1,294
  • 13
  • 22
mrry
  • 125,488
  • 26
  • 399
  • 400
  • 6
    The threads are standard pthreads that operate a thread pool, created by the C++ code in [this file](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/common_runtime/direct_session.cc). – mrry Dec 21 '15 at 07:21
  • @mrry This is useful. Can you please answer [this](http://stackoverflow.com/questions/39774250/run-syntaxnet-on-multiple-cores) – kskp Oct 03 '16 at 16:06
  • 1
    it's safe to include also the inter_op_parallelism_threads option as `session = tf.Session(config=tf.ConfigProto( intra_op_parallelism_threads=1, inter_op_parallelism_threads=1))` – Agile Bean Dec 01 '18 at 15:45