Caffe: boost.python wrapper, why?

Created on 29 Dec 2014  路  1Comment  路  Source: BVLC/caffe

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_;
};

question

Most helpful comment

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings