forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Async infer and Blob dispatch #17
Merged
akuporos
merged 33 commits into
akuporos:mk/ov_pybind_poc
from
jiwaszki:mk/ov_pybind_poc_async
Apr 2, 2021
Merged
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
40b399f
Added async infer
4ebda00
Merge remote-tracking branch 'akuporos/mk/ov_pybind_poc' into mk/ov_p…
8b3a61c
worksave
b4bec46
worksave queue
abbc19b
no-deadlock async infer
cbc7c13
add lock handle in waitAll
8760df3
Merge remote-tracking branch 'akuporos/mk/ov_pybind_poc' into mk/ov_p…
61dc9de
Merge remote-tracking branch 'upstream/master' into mk/ov_pybind_poc_…
827fad7
fix building issues with includes
e2cd7f8
update of setup and cmakelist
ea73f2b
Merge remote-tracking branch 'akuporos/mk/ov_pybind_poc' into mk/ov_p…
0bd15e1
remove set from cmake
1451543
Update Blob class with precisions
9c28f11
Rewrite test_write_numpy_scalar_int64
f9a6c44
Generic Blob casting in infer queue
d724f39
worksave
be64417
added template for setblob
ecdbd2c
Added blob convert in infer request
f9f05af
Merge remote-tracking branch 'akuporos/mk/ov_pybind_poc' into mk/ov_p…
071e446
move blob casting to common namespace
e64162a
add user_id to callbacks
5ce1689
Merge remote-tracking branch 'akuporos/mk/ov_pybind_poc' into mk/ov_p…
c2b39e7
remove hardcoded root dir
1d1b8cd
refactor code and comments
a584074
blob refactoring
akuporos ac01b25
Fix sync in InferQueue and add default callbacks
c2e6b00
patch for protobuf cmake
66f3768
Merge branch 'mk/ov_pybind_poc' into mk/ov_pybind_poc_async
fbb9655
Merge branch 'mk/ov_pybind_poc_async' of https://github.com/jiwaszki/…
141add9
Merge remote-tracking branch 'akuporos/mk/ov_pybind_poc' into mk/ov_p…
d991366
rename to cast_to_blob in infer queue
dd98585
add missing cast_to_blob
413c1ca
change license
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,79 +6,87 @@ | |
|
||
#include "common.hpp" | ||
|
||
namespace Common { | ||
|
||
namespace { | ||
const std::unordered_map<int, std::string> layout_int_to_str_map = {{0, "ANY"}, | ||
{1, "NCHW"}, | ||
{2, "NHWC"}, | ||
{3, "NCDHW"}, | ||
{4, "NDHWC"}, | ||
{64, "OIHW"}, | ||
{95, "SCALAR"}, | ||
{96, "C"}, | ||
namespace Common | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please, undo this style changes |
||
namespace | ||
{ | ||
const std::unordered_map<int, std::string> layout_int_to_str_map = {{0, "ANY"}, | ||
{1, "NCHW"}, | ||
{2, "NHWC"}, | ||
{3, "NCDHW"}, | ||
{4, "NDHWC"}, | ||
{64, "OIHW"}, | ||
{95, "SCALAR"}, | ||
{96, "C"}, | ||
{128, "CHW"}, | ||
{192, "HW"}, | ||
{193, "NC"}, | ||
{194, "CN"}, | ||
{200, "BLOCKED"}}; | ||
|
||
const std::unordered_map <std::string, InferenceEngine::Layout> layout_str_to_enum = { | ||
{"ANY", InferenceEngine::Layout::ANY}, | ||
{"NHWC", InferenceEngine::Layout::NHWC}, | ||
{"NCHW", InferenceEngine::Layout::NCHW}, | ||
{"NCDHW", InferenceEngine::Layout::NCDHW}, | ||
{"NDHWC", InferenceEngine::Layout::NDHWC}, | ||
{"OIHW", InferenceEngine::Layout::OIHW}, | ||
{"GOIHW", InferenceEngine::Layout::GOIHW}, | ||
{"OIDHW", InferenceEngine::Layout::OIDHW}, | ||
{"GOIDHW", InferenceEngine::Layout::GOIDHW}, | ||
{"SCALAR", InferenceEngine::Layout::SCALAR}, | ||
{"C", InferenceEngine::Layout::C}, | ||
{"CHW", InferenceEngine::Layout::CHW}, | ||
{"HW", InferenceEngine::Layout::HW}, | ||
{"NC", InferenceEngine::Layout::NC}, | ||
{"CN", InferenceEngine::Layout::CN}, | ||
{"BLOCKED", InferenceEngine::Layout::BLOCKED} | ||
}; | ||
} | ||
const std::unordered_map<std::string, InferenceEngine::Layout> layout_str_to_enum = { | ||
{"ANY", InferenceEngine::Layout::ANY}, | ||
{"NHWC", InferenceEngine::Layout::NHWC}, | ||
{"NCHW", InferenceEngine::Layout::NCHW}, | ||
{"NCDHW", InferenceEngine::Layout::NCDHW}, | ||
{"NDHWC", InferenceEngine::Layout::NDHWC}, | ||
{"OIHW", InferenceEngine::Layout::OIHW}, | ||
{"GOIHW", InferenceEngine::Layout::GOIHW}, | ||
{"OIDHW", InferenceEngine::Layout::OIDHW}, | ||
{"GOIDHW", InferenceEngine::Layout::GOIDHW}, | ||
{"SCALAR", InferenceEngine::Layout::SCALAR}, | ||
{"C", InferenceEngine::Layout::C}, | ||
{"CHW", InferenceEngine::Layout::CHW}, | ||
{"HW", InferenceEngine::Layout::HW}, | ||
{"NC", InferenceEngine::Layout::NC}, | ||
{"CN", InferenceEngine::Layout::CN}, | ||
{"BLOCKED", InferenceEngine::Layout::BLOCKED}}; | ||
} // namespace | ||
|
||
InferenceEngine::Layout get_layout_from_string(const std::string &layout) { | ||
InferenceEngine::Layout get_layout_from_string(const std::string& layout) | ||
{ | ||
return layout_str_to_enum.at(layout); | ||
} | ||
|
||
const std::string &get_layout_from_enum(const InferenceEngine::Layout &layout) { | ||
const std::string& get_layout_from_enum(const InferenceEngine::Layout& layout) | ||
{ | ||
return layout_int_to_str_map.at(layout); | ||
} | ||
|
||
PyObject *parse_parameter(const InferenceEngine::Parameter ¶m) { | ||
PyObject* parse_parameter(const InferenceEngine::Parameter& param) | ||
{ | ||
// Check for std::string | ||
if (param.is<std::string>()) { | ||
if (param.is<std::string>()) | ||
{ | ||
return PyUnicode_FromString(param.as<std::string>().c_str()); | ||
} | ||
// Check for int | ||
else if (param.is<int>()) { | ||
// Check for int | ||
else if (param.is<int>()) | ||
{ | ||
auto val = param.as<int>(); | ||
return PyLong_FromLong((long) val); | ||
return PyLong_FromLong((long)val); | ||
} | ||
// Check for unsinged int | ||
else if (param.is<unsigned int>()) { | ||
// Check for unsinged int | ||
else if (param.is<unsigned int>()) | ||
{ | ||
auto val = param.as<unsigned int>(); | ||
return PyLong_FromLong((unsigned long) val); | ||
return PyLong_FromLong((unsigned long)val); | ||
} | ||
// Check for float | ||
else if (param.is<float>()) { | ||
// Check for float | ||
else if (param.is<float>()) | ||
{ | ||
auto val = param.as<float>(); | ||
return PyFloat_FromDouble((double) val); | ||
return PyFloat_FromDouble((double)val); | ||
} | ||
// Check for bool | ||
else if (param.is<bool>()) { | ||
// Check for bool | ||
else if (param.is<bool>()) | ||
{ | ||
auto val = param.as<bool>(); | ||
return val ? Py_True : Py_False; | ||
} | ||
// Check for std::vector<std::string> | ||
else if (param.is < std::vector < std::string >> ()) { | ||
auto val = param.as < std::vector < std::string >> (); | ||
else if (param.is<std::vector<std::string>>()) { | ||
auto val = param.as<std::vector<std::string>>(); | ||
PyObject *list = PyList_New(0); | ||
for (const auto &it : val) { | ||
PyObject *str_val = PyUnicode_FromString(it.c_str()); | ||
|
@@ -87,72 +95,100 @@ namespace Common { | |
return list; | ||
} | ||
// Check for std::vector<int> | ||
else if (param.is < std::vector < int >> ()) { | ||
auto val = param.as < std::vector < int >> (); | ||
else if (param.is<std::vector<int>>()) { | ||
auto val = param.as<std::vector<int>>(); | ||
PyObject *list = PyList_New(0); | ||
for (const auto &it : val) { | ||
PyList_Append(list, PyLong_FromLong(it)); | ||
} | ||
return list; | ||
} | ||
// Check for std::vector<unsigned int> | ||
else if (param.is < std::vector < unsigned int >> ()) { | ||
auto val = param.as < std::vector < unsigned int >> (); | ||
PyObject *list = PyList_New(0); | ||
for (const auto &it : val) { | ||
// Check for std::vector<unsigned int> | ||
else if (param.is<std::vector<unsigned int>>()) | ||
{ | ||
auto val = param.as<std::vector<unsigned int>>(); | ||
PyObject* list = PyList_New(0); | ||
for (const auto& it : val) | ||
{ | ||
PyList_Append(list, PyLong_FromLong(it)); | ||
} | ||
return list; | ||
} | ||
// Check for std::vector<float> | ||
else if (param.is < std::vector < float >> ()) { | ||
auto val = param.as < std::vector < float >> (); | ||
else if (param.is<std::vector<float>>()) { | ||
auto val = param.as<std::vector<float>>(); | ||
PyObject *list = PyList_New(0); | ||
for (const auto &it : val) { | ||
PyList_Append(list, PyFloat_FromDouble((double) it)); | ||
} | ||
return list; | ||
} | ||
// Check for std::tuple<unsigned int, unsigned int> | ||
else if (param.is < std::tuple < unsigned int, unsigned int >> ()) { | ||
auto val = param.as < std::tuple < unsigned int, | ||
unsigned int >> (); | ||
else if (param.is<std::tuple<unsigned int, unsigned int>>()) { | ||
auto val = param.as<std::tuple<unsigned int, unsigned int>>(); | ||
PyObject *tuple = PyTuple_New(2); | ||
PyTuple_SetItem(tuple, 0, PyLong_FromUnsignedLong((unsigned long) std::get<0>(val))); | ||
PyTuple_SetItem(tuple, 1, PyLong_FromUnsignedLong((unsigned long) std::get<1>(val))); | ||
return tuple; | ||
} | ||
// Check for std::tuple<unsigned int, unsigned int, unsigned int> | ||
else if (param.is < std::tuple < unsigned int, unsigned int, unsigned int >> ()) { | ||
auto val = param.as < std::tuple < unsigned int, | ||
unsigned int, unsigned int >> (); | ||
else if (param.is<std::tuple<unsigned int, unsigned int, unsigned int>>()) { | ||
auto val = param.as<std::tuple<unsigned int, unsigned int, unsigned int>>(); | ||
PyObject *tuple = PyTuple_New(3); | ||
PyTuple_SetItem(tuple, 0, PyLong_FromUnsignedLong((unsigned long) std::get<0>(val))); | ||
PyTuple_SetItem(tuple, 1, PyLong_FromUnsignedLong((unsigned long) std::get<1>(val))); | ||
PyTuple_SetItem(tuple, 2, PyLong_FromUnsignedLong((unsigned long) std::get<2>(val))); | ||
return tuple; | ||
} | ||
// Check for std::map<std::string, std::string> | ||
else if (param.is < std::map < std::string, std::string >> ()) { | ||
auto val = param.as < std::map < std::string, std::string>>(); | ||
else if (param.is <std::map<std::string, std::string>>()) { | ||
auto val = param.as <std::map<std::string, std::string>>(); | ||
PyObject *dict = PyDict_New(); | ||
for (const auto &it : val) { | ||
PyDict_SetItemString(dict, it.first.c_str(), PyUnicode_FromString(it.second.c_str())); | ||
} | ||
return dict; | ||
} | ||
// Check for std::map<std::string, int> | ||
else if (param.is < std::map < std::string, int >> ()) { | ||
auto val = param.as < std::map < std::string, | ||
int >> (); | ||
else if (param.is<std::map<std::string, int>>()) { | ||
auto val = param.as<std::map<std::string, int>>(); | ||
PyObject *dict = PyDict_New(); | ||
for (const auto &it : val) { | ||
PyDict_SetItemString(dict, it.first.c_str(), PyLong_FromLong((long) it.second)); | ||
} | ||
return dict; | ||
} | ||
else | ||
{ | ||
PyErr_SetString(PyExc_TypeError, | ||
"Failed to convert parameter to Python representation!"); | ||
return (PyObject*)NULL; | ||
} | ||
} | ||
|
||
const std::shared_ptr<InferenceEngine::Blob> convert_to_blob(const py::handle& blob) { | ||
if (py::isinstance<InferenceEngine::TBlob<float>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<float>> &>(); | ||
} else if (py::isinstance<InferenceEngine::TBlob<double>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<double>> &>(); | ||
} else if (py::isinstance<InferenceEngine::TBlob<int8_t>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<int8_t>> &>(); | ||
} else if (py::isinstance<InferenceEngine::TBlob<int16_t>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<int16_t>> &>(); | ||
} else if (py::isinstance<InferenceEngine::TBlob<int32_t>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<int32_t>> &>(); | ||
} else if (py::isinstance<InferenceEngine::TBlob<int64_t>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<int64_t>> &>(); | ||
} else if (py::isinstance<InferenceEngine::TBlob<uint8_t>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<uint8_t>> &>(); | ||
} else if (py::isinstance<InferenceEngine::TBlob<uint16_t>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<uint16_t>> &>(); | ||
} else if (py::isinstance<InferenceEngine::TBlob<uint32_t>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<uint32_t>> &>(); | ||
} else if (py::isinstance<InferenceEngine::TBlob<uint64_t>>(blob)) { | ||
return blob.cast<const std::shared_ptr<InferenceEngine::TBlob<uint64_t>> &>(); | ||
} else { | ||
PyErr_SetString(PyExc_TypeError, "Failed to convert parameter to Python representation!"); | ||
return (PyObject *) NULL; | ||
// Throw error | ||
} | ||
} | ||
}; | ||
}; // namespace Common |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already imported above