How to stop TensorFlow from multi-threading(如何阻止 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 使用多线程
基础教程推荐
- C++,'if' 表达式中的变量声明 2021-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01