16

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
  • 7,611
  • 11
  • 61
  • 115
Zk1001
  • 1,983
  • 4
  • 18
  • 34

1 Answers1

25

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,215
  • 12
  • 21
mrry
  • 123,190
  • 25
  • 396
  • 396
  • 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