-1

I want to share a tensorflow FIFOQueue using the C++ API where a producer and consumer are running asynchronously (as very briefly discussed here in a python context: TensorFlow C++, runtime issue). I have the impression that I need to use DirectSession and its thread pooling support (as discussed here: Changing the number of threads in TensorFlow on Cifar10). So the direct_session_test.cc file with the examples using BlockingOp and BlockingOpState look like they might be a good template.

But direct_session.h marks important methods as experimental (especially .Run()) so any tips and advice on proceeding would be welcome.

Note that DirectSession has very little documentation including the header direct_session.h. Some of the differences between tensorflow's other C++ Session classes (e.g. Session, ClientSession Interactive) are discussed elsewhere:

This thread compares Session and ClientSession: Difference between ClientSession and Session in TensorFlow C++ API

This thread compares Session and InteractiveSession: difference between tf.Session() and tf.InteractiveSession()?

PhilAW
  • 39
  • 4

1 Answers1

0

You shouldn't need to use DirectSession directly. ClientSession should be good enough, and its thread pool can be configured via the configproto as usual.

Alexandre Passos
  • 5,186
  • 1
  • 14
  • 19
  • Good to hear that ClientSession is sufficient. But it remains how to deal with the contention of the FIFOQueue node from the producer and consumer nodes with a lock (mutex). The direct_session_test.cc gives an idea with the BlockingOp, but this queue example seems like a useful use case that could have a more specific example. Any suggestions? – PhilAW Jul 13 '17 at 19:35
  • The FIFOQueue has an internal mutex. Why do you need another one? – Alexandre Passos Jul 14 '17 at 20:06
  • Right, thanks, the mutex is available at the C++ API level (unlike the Python level which seems to require the use of QueueRunner). An example of its use in an asynchonous consumer/producer context would be very helpful. For example should EnqueueOp and DequeueOp be used or should the FIFOQueue.TryEnqueue() and Try? – PhilAW Jul 15 '17 at 20:11
  • TryDequeue() be used? – PhilAW Jul 15 '17 at 20:18
  • The python level doesn't require the use of QueueRunner. A QueueRunner is just a python thread calling session.run(queue.enqueue()) in an infinite* loop. – Alexandre Passos Jul 16 '17 at 20:25