可以直接从gpu给Caffe或Caffe2输入数据吗? [英] Can Caffe or Caffe2 be given input data directly from gpu?

查看:99
本文介绍了可以直接从gpu给Caffe或Caffe2输入数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了caffe2教程并尝试了预训练模型。我知道caffe2将利用GPU来运行模型/网络。但是输入数据似乎总是从CPU(即主机)内存中给出的。例如,在在模型之后加载加载后,我们可以通过

I've read caffe2 tutorials and tried pre-trained models. I knew caffe2 will leverge GPU to run the model/net. But the input data seems always be given from CPU(ie. Host) memory. For example, in Loading Pre-Trained Models, after model is loaded, we can predict an image by

result = p.run([img])

但是,图像 img应该在CPU范围内读取。我要寻找的是一个框架,该框架可以将图像(从视频中解码并仍驻留在GPU内存中)直接插入预测模型,而不是将其从GPU复制到CPU作用域,然后再次传输到GPU进行预测结果。 Caffe或Caffe2是否为python或C ++提供了此类功能或接口?还是我需要给Caffe打补丁?谢谢。

However, image "img" should be read in CPU scope. What I look for is a framework that can pipline the images (which is decoded from a video and still resides in GPU memory) directly to the prediction model, instead of copying it from GPU to CPU scope, and then transfering to GPU again to predict result. Is Caffe or Caffe2 provides such functions or interfaces for python or C++? Or should I need to patch Caffe to do so? Thanks at all.

这是我的解决方法:

我在 tensor.h 中发现,函数 ShareExternalPointer()可以完全满足我的要求。

I'd found in tensor.h, function ShareExternalPointer() can exactly do what I want.

以这种方式输入gpu数据,

Feed gpu data this way,

pInputTensor->ShareExternalPointer(pGpuInput, InputSize);

然后运行预测网

pPredictNet->Run();

其中 pInputTensor 是入口的张量预测净额 pPredictNet

where pInputTensor is the entrance tensor for the predict net pPredictNet

推荐答案

我认为您无法做到在 caffe 的问题。

但我认为可以使用c ++来实现:在c ++中,您可以访问 Blob mutable_gpu_data()。您可以编写在设备上运行的代码,然后直接从gpu填充输入Blob的 mutable_gpu_data()。完成此更新后,caffe应该可以从此处继续其 net-> forward()

I don't think you can do it in caffe with python interface.
But I think that it can be accomplished using the c++: In c++ you have access to the Blob's mutable_gpu_data(). You may write code that run on device and "fill" the input Blob's mutable_gpu_data() directly from gpu. Once you made this update, caffe should be able to continue its net->forward() from there.

更新

2017年9月19日 PR #5904 被合并为master。此PR通过python接口公开blob的GPU指针。

您可以访问 blob._gpu_data_ptr blob._gpu_diff_ptr 直接来自python ,后果自负

UPDATE
On Sep 19th, 2017 PR #5904 was merged into master. This PR exposes GPU pointers of blobs via the python interface.
You may access blob._gpu_data_ptr and blob._gpu_diff_ptr directly from python at your own risk.

这篇关于可以直接从gpu给Caffe或Caffe2输入数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆