c++ - 如何在单核、单线程 CPP 上运行 Tensorflow?
问题描述
我正在尝试限制 TensorFlow 生成的线程数。在 python 中,我知道我们需要使用此处指出的以下步骤。我试图在 CPP 中做同样的事情,但看起来并不那么简单。问题:
- 如何正确修改intra_op_parallelism_threads和inter_op_parallelism_threads?
- 如何修改 device_count 来控制核心?
SessionOptions options;
ConfigProto* config = &options.config;
string key = "CPU";
//not sure if this is the correct way to do it.
(*config->mutable_device_count())[key] = 1;
config->set_inter_op_parallelism_threads(1);
config->set_intra_op_parallelism_threads(1);
解决方案
正如 Fisa 指出的那样,对 1 的回答是正确的。只需稍作调整,因为 config 是一个指针。
SessionOptions options;
ConfigProto* config = &options.config;
//single thread control//
config->set_inter_op_parallelism_threads(1);
config->set_intra_op_parallelism_threads(1);
fSession.reset(NewSession(options));
推荐阅读
- php - 从多维数组 PHP 中选择唯一的组合
- jquery - TableSorter:在列上随机排序
- python - “ipywidgets 下拉小部件:什么是 onchange 事件?”的基本问题
- react-pdf - 包含 react-pdf 渲染器时的开玩笑错误
- javascript - 让一个项目有条件地出现在另一个组件中
- javascript - 如何在 Node.js/Javascript 中添加新的键值对
- kernel - KMDF windows 驱动程序中的 ibv_post_send 性能优化
- r - 如果连续值出现在组 id 的末尾,则删除
- python - 连接具有相同 ID 的记录的值 | 熊猫
- python - 在 Pandas DataFrame 中将 C 和 D 列附加到 A 和 B