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
: PyBlob
bp::object get_data();
bp::object get_diff();
private:
PyObject *self_;
};
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.
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
PyBlobwrapper 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.