Skip to content

Commit 3a07cf7

Browse files
authored
[PY OV] Replace MemoryBuffer with SharedStreamBuffer (#32445)
### Details: - Can be merged after #32571 ### Tickets: - [CVS-174967](https://jira.devtools.intel.com/browse/CVS-174967)
1 parent 5c40eb6 commit 3a07cf7

File tree

3 files changed

+6
-36
lines changed

3 files changed

+6
-36
lines changed

src/bindings/python/src/pyopenvino/core/core.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <random>
1515

1616
#include "common.hpp"
17+
#include "openvino/runtime/shared_buffer.hpp"
1718
#include "pyopenvino/core/remote_context.hpp"
1819
#include "pyopenvino/graph/op_extension.hpp"
1920
#include "pyopenvino/utils/utils.hpp"
@@ -554,8 +555,8 @@ void regclass_Core(py::module m) {
554555
info = py::buffer(model_stream).request();
555556
}
556557

557-
Common::utils::MemoryBuffer mb(reinterpret_cast<char*>(info.ptr), info.size);
558-
std::istream stream(&mb);
558+
ov::SharedStreamBuffer mb{info.ptr, static_cast<size_t>(info.size)};
559+
std::istream stream{&mb};
559560

560561
ConditionalGILScopedRelease release;
561562
return self.import_model(stream, device_name, _properties);

src/bindings/python/src/pyopenvino/frontend/frontend.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "openvino/frontend/exception.hpp"
1313
#include "openvino/frontend/extension/telemetry.hpp"
1414
#include "openvino/frontend/manager.hpp"
15+
#include "openvino/runtime/shared_buffer.hpp"
1516
#include "openvino/util/file_util.hpp"
1617
#include "pyopenvino/graph/model.hpp"
1718
#include "pyopenvino/utils/utils.hpp"
@@ -50,8 +51,8 @@ void regclass_frontend_FrontEnd(py::module m) {
5051
} else if (py::isinstance(py_obj, pybind11::module::import("io").attr("BytesIO"))) {
5152
// support of BytesIO
5253
py::buffer_info info = py::buffer(py_obj.attr("getbuffer")()).request();
53-
Common::utils::MemoryBuffer mb(reinterpret_cast<char*>(info.ptr), info.size);
54-
std::istream _istream(&mb);
54+
ov::SharedStreamBuffer mb{info.ptr, static_cast<size_t>(info.size)};
55+
std::istream _istream{&mb};
5556
return self.load(&_istream, enable_mmap);
5657
} else {
5758
// Extended for one argument only for this time

src/bindings/python/src/pyopenvino/utils/utils.hpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,38 +96,6 @@ class OutPyBuffer : public std::streambuf {
9696
py::object m_py_stream;
9797
};
9898

99-
class MemoryBuffer : public std::streambuf {
100-
public:
101-
MemoryBuffer(char* data, std::size_t size) {
102-
setg(data, data, data + size);
103-
}
104-
105-
protected:
106-
pos_type seekoff(off_type off,
107-
std::ios_base::seekdir dir,
108-
std::ios_base::openmode which = std::ios_base::in) override {
109-
switch (dir) {
110-
case std::ios_base::beg:
111-
setg(eback(), eback() + off, egptr());
112-
break;
113-
case std::ios_base::end:
114-
setg(eback(), egptr() + off, egptr());
115-
break;
116-
case std::ios_base::cur:
117-
setg(eback(), gptr() + off, egptr());
118-
break;
119-
default:
120-
return pos_type(off_type(-1));
121-
}
122-
return (gptr() < eback() || gptr() > egptr()) ? pos_type(off_type(-1)) : pos_type(gptr() - eback());
123-
}
124-
125-
pos_type seekpos(pos_type pos, std::ios_base::openmode which) override {
126-
return seekoff(pos, std::ios_base::beg, which);
127-
}
128-
129-
};
130-
13199
enum class PY_TYPE : int { UNKNOWN = 0, STR, INT, FLOAT, BOOL, PARTIAL_SHAPE, MODEL_DISTRIBUTION_POLICY };
132100

133101
struct EmptyList {};

0 commit comments

Comments
 (0)