Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost.python wrapper, why? #1651

Closed
yaoli opened this issue Dec 29, 2014 · 1 comment
Closed

boost.python wrapper, why? #1651

yaoli opened this issue Dec 29, 2014 · 1 comment
Labels

Comments

@yaoli
Copy link

yaoli commented Dec 29, 2014

I don't quite understand the logic of using PyBlobWrap, can someone explain to me please?

// We need another wrapper (used as boost::python's HeldType) that receives a
// self PyObject * which we can use as ndarray.base, so that data/diff memory
// is not freed while still being used in Python.
class PyBlobWrap : public PyBlob {
public:
PyBlobWrap(PyObject *p, const PyBlob &blob)
: PyBlob(blob), self_(p) {}

bp::object get_data();
bp::object get_diff();

private:
PyObject *self_;
};

@shelhamer
Copy link
Member

Python and Caffe have to share memory. Instead of doing pointless copies that cost memory, the Caffe blob and Python ndarray share the same pointer to host memory. The PyBlob wrapper keeps Caffe from de-allocating a blob memory if its still in use on the Python side.

Note that this is all made simpler in #1703.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants