Tensorflow c++ API 失败设置 gpu/cpu 编号:SetDefaultDevice 错误:具有相同优

Tensorflow c++ api failed set gpu/cpu number: SetDefaultDevice error: Duplicate registration of device factory for type GPU with the same priority 210

本文关键字:错误 SetDefaultDevice 编号 失败 API c++ 设置 gpu cpu Tensorflow      更新时间:2023-10-16

我正在加载一个三角张量流模型并运行它。当我尝试设置 GPU 编号时,会引发错误。

F 张量流/核心/common_runtime/device_factory.cc:77] 复制 具有相同优先级 210 的 GPU 类型的设备工厂注册

我使用的代码是这样的:

tensorflow::GraphDef graph_def;
tensorflow::Status graphLoadedStatus = ReadBinaryProto(tensorflow::Env::Default(),model_path, &graph_def);
if (!graphLoadedStatus.ok()) {
std::cerr <<"Model path : " << graphLoadedStatus.ToString() << std::endl;
return graphLoadedStatus;
}
// set device to be on gpu
tensorflow::graph::SetDefaultDevice("/gpu:3", &graph_def);

谷歌它,除了 tensoeflow 的源代码之外没有结果:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/common_runtime/device_factory.cc

有人遇到过这个吗?或者tf的贡献者可以给我一些线索吗?

这看起来像是一个优先级问题,所以我尝试使用 root 运行,但没有用。

顺便说一句,我正在使用c ++。如果我使用 python,我可以设置没有错误的 GPU 编号。

我从源代码重建张量流并使用新的 libtensorflow_cc.so 和头文件。然后这个问题就消失了。

我认为这是由我的 libtensorflow_cc.so 和头文件不是同一版本引起的。