【问题标题】:tensorflow c_api.h Why GPU is slower than CPUtensorflow c_api.h 为什么GPU比CPU慢
【发布时间】:2018-11-09 00:54:01
【问题描述】:

我已经训练了一个lstm mode,并将模型加载到我的 C 项目中以预测我的数据。我发现 GPU 比 CPU 慢。

这是我的配置:

  • gpu:nvidia TITAN X
  • CUDA:9.0
  • cudnn:7.0
  • cpu: 英特尔 E5
  • 张量流:1.11.0

我预测了大约200个数据项,每个数据项都调用函数:

TF_SessionRun(sess,
nullptr, // Run options.
&input_op, &input_tensor, 1, // Input tensors, input tensor values, number of inputs.
&out_op, &output_tensor, 1, // Output tensors, output tensor values, number of outputs.
nullptr, 0, // Target operations, number of targets.
nullptr, // Run metadata.
status // Output status.
);

每次 GPU 都比 CPU 慢。

我的方法错了吗?

有没有办法提高速度?

我可以批量输入数据进行预测吗?如果可以,如何输入?

这是 c_api.h enter link description here

【问题讨论】:

  • 我不知道 C 有 tensorflow,我一直以为它是一个 python 库。这无助于回答您的问题,但感谢您提出问题 :)

标签: c++ c api tensorflow


【解决方案1】:

将数据传输到 GPU 内存会产生开销,您有时甚至在 Python 中对于极小的数据集也会看到这种趋势,其中 CPU 有时会胜过 GPU,因为大多数时候 GPU 没有被利用,而是在等待下一批数据进来,数据集大小为 200,这似乎是最合理的原因。

至于让它更快更快,Python api 有一个批处理模式的选项,可以将数据预加载到 gpu 中,这在一定程度上解决了这个问题,请检查 c api 中的类似选项

【讨论】:

    猜你喜欢
    • 2019-07-10
    • 2019-11-06
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 2021-02-09
    相关资源
    最近更新 更多