如何阻止 TensorFlow 使用多线程

How to stop TensorFlow from multi-threading(如何阻止 TensorFlow 使用多线程)

本文介绍了如何阻止 TensorFlow 使用多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 NIST FRVT 编写代码.NIST 希望程序以最多 2 个线程运行(只有 CPU,没有 GPU).我在我的代码中使用 TensorFlow,但它总是产生超过 2 个线程.我尝试了这个解决方案.它减少了线程数,但没有达到 2

I am writing code for NIST FRVT. NIST wants the program to run at max 2 threads(Only CPU, No GPU). I am using TensorFlow in my code but it always spawns much more than 2 threads. I tried this solution. It decreased the number of threads, but not up to 2

我收到此警告

[警告] 我们检测到您的软件在模板创建期间可能正在线程化或使用其他多处理技术.检测到的线程数为 9,应该为 2.根据 API 文档,实现必须运行单线程.在测试环境中,线程没有优势,因为 NIST 会在多个刀片和多个进程之间分配工作负载.我们强烈建议您在提交前解决此问题.

[WARNING] We've detected that your software may be threading or using other multiprocessing techniques during template creation. The number of threads detected was 9 and it should be 2. Per the API document, implementations must run single-threaded. In the test environment, there is no advantage to threading, because NIST will distribute workload across multiple blades and multiple processes. We highly recommend that you fix this issue prior to submission.

NIST 正在通过 top -H -b -n1 | 计算线程数grep validate11 |wc -l

有没有办法强制 TensorFlow 使用最多 2 个线程?

Is there any way to force TensorFlow to use at max 2 threads?

是否有可以在 2 个线程上运行的 TensorFlow 版本?

Is there any TensorFlow version that will run on 2 threads?

(这是因为TensorFlow,我通过从代码中删除TensorFlow部分来检查)

(It is because of TensorFlow, I checked by removing TensorFlow part from the code)

tensorflow 1.8.0 版

tensorflow version 1.8.0

opencv 3.4.1 版

opencv version 3.4.1

g++ 4.8.5 版

g++ version 4.8.5

g++ -std=c++11

g++ -std=c++11

推荐答案

参考以下来源,似乎无法在 1 或 2 个线程上运行 TensorFlow.

With reference to the following sources, it looks like there is no possibility to run TensorFlow on 1 or 2 threads.

  • https://github.com/tensorflow/tensorflow/issues/33627
  • https://github.com/tensorflow/tensorflow/issues/42510
  • https://github.com/theislab/batchglm/issues/27
  • 使用脚本变量 OMP_NUM_THREADS在程序源文件中
  • 使用 C 更改 Tensorflow 推理的线程数API

我提交了具有超过 6 个线程的 NIST-FRVT 实现,NIST 接受了这一点.6 个线程中只有 1 个在运行,其余线程处于睡眠模式.

I submitted my implementation of NIST-FRVT having more than 6 threads, and NIST accepted that. Only 1 out of 6 threads were running and the rest of the threads were in sleeping mode.

这篇关于如何阻止 TensorFlow 使用多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何阻止 TensorFlow 使用多线程