C ++ Tensorflow, how to do session-> Run () with multithreaded or spend less time

I run lower and lower on the CPU. I run the sample process / examples / label_image takes 7 ~ 8 seconds. As I know, python takes about 0.5 seconds to process the same sample, and this is because "the Session TensorFlow object is multi-threaded, so multiple threads can easily use the same session and run ops in parallel." BUT, how can I set multithreading in a session with C ++.

What am I trying ... I hardcode the string 81 to "tensorflow / tensorflow / core / common_runtime / direct_session.cc": "const int32 num_threads = 16;" However, this does not work.

How to configure any configure or what should I do?

+5
source share
1 answer

How about multiple threads?

std::vector<std::thread> threads; for (std::size_t i = 0; i < 10; ++i) { threads.push_back(std::thread([&]{ session->Run(); })); } for (std::size_t i = 0; i < 10; ++i) { threads[i].join(); } 
+3
source

Source: https://habr.com/ru/post/1262979/


All Articles