TensorFlow c++ SetDefaultDevice 在多 GPU 模式下
tensorflow c++ SetDefaultDevice in multi-gpu mode
我想在多个GPU上加载相同的图形以进行推理,但是我无法使用graph::SetDefaultDevice将图形与设备相关联。 此问题不是在 SetDefaultDevice 中发生,而是在稍后使用图形创建会话时发生。这是一个从张量流的 example_trainer.cc 中提取的简单示例
#include <tensorflow/core/platform/env.h>
#include <tensorflow/core/public/session.h>
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/graph/default_device.h"
int main() {
using namespace tensorflow;
using namespace tensorflow::ops;
Scope root = Scope::NewRootScope();
auto A = Const(root, { {3.f, 2.f}, {-1.f, 0.f} });
auto b = Const(root, { {3.f, 5.f} });
auto v = MatMul(root.WithOpName("v"), A, b, MatMul::TransposeB(true));
GraphDef def;
TF_CHECK_OK(root.ToGraphDef(&def));
graph::SetDefaultDevice(false ? "/device:GPU:0" : "/cpu:0", &def);
/*
for (auto &node: *def.mutable_node()) {
node.set_device("/cpu:0");
std::cout << node.name() << " = '" << node.device() <<"'"<< std::endl;
}
std::cout << "=======================n";
*/
SessionOptions options;
std::unique_ptr<Session> session(NewSession(options));
TF_CHECK_OK(session->Create(def));
return 0;
}
运行时出现以下错误
2018-09-06 18:18:13.853316: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-09-06 18:18:13.856079: F /home/daniel/tensorflow_cc/example/example.cpp:27] Non-OK-status: session->Create(def) status: Not found: No attr named '/cpu:0' in NodeDef:
[[Node: Const = Const[dtype=DT_FLOAT, value=Tensor<type: float shape: [2,2] values: [3 2][-1]...>, _device="/cpu:0"]()]]
[[Node: Const = Const[dtype=DT_FLOAT, value=Tensor<type: float shape: [2,2] values: [3 2][-1]...>, _device="/cpu:0"]()]]
Aborted (core dumped)
如果我删除 SetDefault 设备调用,它可以完美运行。我也尝试在带有GPU的机器上执行此操作,但它不起作用。
我知道问题不在于 SetDefaultDevice,因为手动设置每个节点的设备在创建会话时会遇到相同的问题。
Const = '/cpu:0'
Const_1 = '/cpu:0'
v = '/cpu:0'
=======================
2018-09-06 18:15:05.966337: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-09-06 18:15:05.969048: F /home/daniel/tensorflow_cc/example/example.cpp:26] Non-OK-status: session->Create(def) status: Not found: No attr named '/cpu:0' in NodeDef:
[[Node: Const = Const[dtype=DT_FLOAT, value=Tensor<type: float shape: [2,2] values: [3 2][-1]...>, _device="/cpu:0"]()]]
[[Node: Const = Const[dtype=DT_FLOAT, value=Tensor<type: float shape: [2,2] values: [3 2][-1]...>, _device="/cpu:0"]()]]
Aborted (core dumped)
这似乎只是整体式构建(--config=整体式(的问题,即构建libtensorflow_cc.so时。我不确定,但可能与
https://github.com/tensorflow/tensorflow/issues/5379 https://github.com/tensorflow/tensorflow/issues/16291
相关文章:
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 为什么在保护模式下继承升级不起作用
- 如何在全屏模式下(在OpenGL中)使背景透明
- 为什么使用__LINE_的代码在发布模式下在MSVC下编译,而不是在调试模式下
- 派生类是否可以在抽象工厂设计模式中具有数据成员
- 此模式的C++RegEx
- avrogencpp能为模式中的每种类型生成单独的头文件吗
- 使用可变模板的Broadcaster/Listener模式
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- c++方法参数只能在linux的发布模式下自行更改
- 资源管理设计模式
- 使用 mod_gsoap 部署服务时,如何在 Gsoap 中更改 soap 上下文的模式?
- C++ 无法在字符数组中使用 for 循环打印字母模式
- 有没有办法简单地从 GPU 调用多个 cpp 输出文件?
- 小字符串优化(调试与发布模式)
- 可视化C++:发布模式的运行时库作为'Multi-threaded Debug DLL'
- 如何设计具有不同类型的通知和观察器的观察者模式?
- 在C++的一系列数字中查找重复模式
- 是否允许使用带有"w+"模式的 freopen 进行标准设置?
- TensorFlow c++ SetDefaultDevice 在多 GPU 模式下