ngraph constant mem reuse (#2548)

* Memory re-use for nGraph Consstant

* Code style fixes

* Did remove setWeights from public API

* Fixes for tests

* Moving setWeightsPtr to CNNNetwork

* Removing setWeights function, set blob ptr directly to preallocated ngraph buffer

* Fix for code style

* Preallocated buffer refactored, rename to Shared, remove declaration from AlignedBuffer

* Fix for code style

* Remove setWeightsBlobPtr from mock classes.

* fixing bugs after merge

* Test fix

* Fix for cpu Functional tests

* Fix for Windows build

* Try to fix GNMT test failure.

* Releasing pointers what holds CNNNetwork

* Fix after merge

* mkl-dnn submodule update

* reverting back cloned network cleanup

* Fix for double allocation

* Code style...

* update mkl-dnn

* update mkl-dnn

* mkl-dnn bump

* update mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* update mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* mkl-dnn bump

* bump mkl-dnn

* update mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* mkl-dnn bump

* update mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* mkl-dnn bump

* update mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* update mkl-dnn

* bump mkl-dnn

* mkl-dnn bump

Co-authored-by: Tony Reina <g.anthony.reina@intel.com>
This commit is contained in:
Dmitrii Ryzhkov 2020-11-19 03:03:12 -08:00 committed by GitHub
parent b77bedcb64
commit 70c02d0fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 214 additions and 135 deletions

View File

@ -45,7 +45,8 @@ public:
*
* @param network Pointer to the network object
*/
explicit CNNNetwork(std::shared_ptr<ICNNNetwork> network): network(network) {
explicit CNNNetwork(std::shared_ptr<ICNNNetwork> network)
: network(network) {
actual = network.get();
if (actual == nullptr) THROW_IE_EXCEPTION << "CNNNetwork was not initialized.";
}

View File

@ -79,7 +79,7 @@ public:
auto reader = getReaderPtr();
return reader->read(model, exts);
}
CNNNetwork read(std::istream& model, std::istream& weights, const std::vector<IExtensionPtr>& exts) const override {
CNNNetwork read(std::istream& model, const Blob::CPtr& weights, const std::vector<IExtensionPtr>& exts) const override {
auto reader = getReaderPtr();
return reader->read(model, weights, exts);
}
@ -210,8 +210,19 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath, const std::string&
if (!binStream.is_open())
THROW_IE_EXCEPTION << "Weights file " << bPath << " cannot be opened!";
binStream.seekg(0, std::ios::end);
size_t fileSize = binStream.tellg();
binStream.seekg(0, std::ios::beg);
Blob::Ptr weights = make_shared_blob<uint8_t>({Precision::U8, { fileSize }, C });
weights->allocate();
binStream.read(weights->buffer(), fileSize);
binStream.close();
// read model with weights
auto network = reader->read(modelStream, binStream, exts);
auto network = reader->read(modelStream, weights, exts);
modelStream.close();
return network;
}
@ -236,7 +247,7 @@ CNNNetwork details::ReadNetwork(const std::string& model, const Blob::CPtr& weig
auto reader = it->second;
if (reader->supportModel(modelStream)) {
if (weights)
return reader->read(modelStream, binStream, exts);
return reader->read(modelStream, weights, exts);
return reader->read(modelStream, exts);
}
}

View File

@ -22,6 +22,8 @@ endif()
# Create object library
file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
add_library(${TARGET_NAME}_obj OBJECT
${LIBRARY_SRC}
${PUBLIC_HEADERS})
@ -47,7 +49,9 @@ target_compile_definitions(${TARGET_NAME}_obj PRIVATE $<TARGET_PROPERTY:ngraph::
# Create shared library
add_library(${TARGET_NAME} SHARED $<TARGET_OBJECTS:${TARGET_NAME}_obj>)
add_library(${TARGET_NAME} SHARED
${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
$<TARGET_OBJECTS:${TARGET_NAME}_obj>)
ie_add_vs_version_file(NAME ${TARGET_NAME}
FILEDESCRIPTION "Inference Engine Legacy library")
@ -60,7 +64,7 @@ target_link_libraries(${TARGET_NAME} PUBLIC inference_engine
target_include_directories(${TARGET_NAME} INTERFACE ${PUBLIC_HEADERS_DIR})
add_cpplint_target(${TARGET_NAME}_cpplint FOR_TARGETS ${TARGET_NAME})
add_cpplint_target(${TARGET_NAME}_cpplint FOR_TARGETS ${TARGET_NAME} EXCLUDE_PATTERNS ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
ie_add_api_validator_post_build_step(TARGET ${TARGET_NAME})

View File

@ -727,7 +727,12 @@ void MKLDNNNormalizeNode::getSupportedDescriptors() {
weights_prec = tweights->getTensorDesc().getPrecision();
if (weights_prec == Precision::FP32) {
weights_blob = tweights;
TensorDesc td(Precision::FP32, tweights->getTensorDesc().getDims(), tweights->getTensorDesc().getLayout());
weights_blob = make_shared_blob<float>(td);
weights_blob->allocate();
float* src = layer->blobs.at("weights")->buffer();
float* dst = weights_blob->wmap();
memcpy(dst, src, layer->blobs.at("weights")->byteSize());
} else if (weights_prec == Precision::BF16) {
MKLDNNPlugin::BF16Transformer transformer;
weights_blob = transformer.convertBF16ToFloat(tweights);

View File

@ -442,11 +442,8 @@ void MKLDNNRNN::createPrimitive() {
auto b_ptr = static_cast<float*>(w_bias_mem->GetData());
for (int g = 0; g < Gb; g++) {
float *l_b_ptr = b_ptr + gate_map[g]*SC;
for (int out_i = 0; out_i < SC; out_i++) {
*l_b_ptr = *ie_b_ptr;
ie_b_ptr++;
l_b_ptr++;
}
const float *l_ie_b_ptr = ie_b_ptr + g * SC;
memcpy(l_b_ptr, l_ie_b_ptr, SC * sizeof(float));
}
}
}

View File

@ -47,8 +47,8 @@ IRParser::IRParser(size_t version, const std::vector<InferenceEngine::IExtension
}
}
std::shared_ptr<ICNNNetwork> IRParser::parse(const pugi::xml_node& root, std::istream& binStream) {
return parser->parse(root, binStream);
std::shared_ptr<ICNNNetwork> IRParser::parse(const pugi::xml_node& root, const Blob::CPtr& weights) {
return parser->parse(root, weights);
}
/**
@ -83,7 +83,7 @@ V10Parser::V10Parser(const std::vector<IExtensionPtr>& exts) : _exts(exts) {
}
}
std::shared_ptr<ICNNNetwork> V10Parser::parse(const pugi::xml_node& root, std::istream& binStream) {
std::shared_ptr<ICNNNetwork> V10Parser::parse(const pugi::xml_node& root, const Blob::CPtr& weights) {
OV_ITT_TASK_CHAIN(taskChain, itt::domains::V10Reader_RT, "V10Parser", "Parse");
using node_params = struct {
@ -158,7 +158,7 @@ std::shared_ptr<ICNNNetwork> V10Parser::parse(const pugi::xml_node& root, std::i
input_node->output(p_output.getRealOutputPortId(e.fromPortId));
}
auto node = createNode(inputs, p.xml, binStream, p.params);
auto node = createNode(inputs, p.xml, weights, p.params);
id_to_node[layer_id] = node;
// Check that output shape after nGraph node validation the same as in IR
@ -204,12 +204,12 @@ std::shared_ptr<ICNNNetwork> V10Parser::parse(const pugi::xml_node& root, std::i
CNNNetwork net(function, _exts);
parsePreProcess(net, root, binStream);
parsePreProcess(net, root, weights);
return net;
}
void V10Parser::parsePreProcess(CNNNetwork& network, const pugi::xml_node& root, std::istream& binStream) {
void V10Parser::parsePreProcess(CNNNetwork& network, const pugi::xml_node& root, const Blob::CPtr& weights) {
/*
<pre-process mean-precision="FP32">
<channel id = 0>
@ -314,8 +314,8 @@ void V10Parser::parsePreProcess(CNNNetwork& network, const pugi::xml_node& root,
preProcessChannel->meanData->allocate();
auto lockedMem = preProcessChannel->meanData->buffer();
char* data = lockedMem.as<char *>();
binStream.seekg(offset, std::ios::beg);
binStream.read(data, size);
uint8_t* src_data = weights->cbuffer().as<uint8_t*>() + offset;
memcpy(data, src_data, size);
}
}
}
@ -393,7 +393,7 @@ bool V10Parser::LayerBaseCreator::shouldCreate(const std::string& nodeType) cons
}
std::shared_ptr<ngraph::Node> V10Parser::createNode(const std::vector<ngraph::Output<ngraph::Node>>& inputs,
const pugi::xml_node& node, std::istream& binStream,
const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& params) {
static std::vector<std::shared_ptr<LayerBaseCreator>> creators = {
std::make_shared<LayerCreator<ngraph::op::v1::AvgPool>>("AvgPool"),
@ -495,7 +495,7 @@ std::shared_ptr<ngraph::Node> V10Parser::createNode(const std::vector<ngraph::Ou
useCreator |= opset.contains_type(creator->getNodeType()) || !opset.contains_type(params.type);
}
if (useCreator)
ngraphNode = creator->createLayer(inputs, node, binStream, params);
ngraphNode = creator->createLayer(inputs, node, weights, params);
break;
}
}
@ -530,8 +530,7 @@ std::shared_ptr<ngraph::Node> V10Parser::createNode(const std::vector<ngraph::Ou
auto blobs = node.child("blobs");
if (!blobs.empty()) {
binStream.seekg(0, std::ios::end);
std::streampos length = binStream.tellg();
size_t length = weights->byteSize();
for (pugi::xml_node blob = blobs.first_child(); !blob.empty(); blob = blob.next_sibling()) {
size_t size = GetUInt64Attr(blob, "size", 0);
@ -547,13 +546,9 @@ std::shared_ptr<ngraph::Node> V10Parser::createNode(const std::vector<ngraph::Ou
if (static_cast<uint64_t>(length) < offset + size)
THROW_IE_EXCEPTION << "Cannot create " << params.type << " layer with name: " << params.name
<< ". Layer has incorrect weights!";
Blob::Ptr wBlob = make_blob_with_precision(TensorDesc(precision, {size / precision.size()}, Layout::C));
wBlob->allocate();
char* data = wBlob->buffer().as<char*>();
binStream.seekg(offset, std::ios::beg);
binStream.read(data, size);
uint8_t* data = weights->cbuffer().as<uint8_t*>() + offset;
Blob::Ptr wBlob = make_shared_blob<uint8_t>({Precision::U8, { size / precision.size() }, C }, data);
Blob::CPtr cBlob = wBlob;
parameters[blob.name()] = wBlob;
}
}
@ -594,7 +589,7 @@ namespace InferenceEngine {
// SubGraph layer
std::shared_ptr<ngraph::Node>
V10Parser::LayerBaseCreator::fillSubGraphLayer(const ngraph::OutputVector &inputs, const pugi::xml_node &node,
std::istream &binStream,
const Blob::CPtr& weights,
const V10Parser::GenericLayerParams &layerParsePrms,
std::shared_ptr<ngraph::op::util::SubGraphOp> subgraph_op) {
subgraph_op->set_friendly_name(GetStrAttr(node, "name"));
@ -618,7 +613,7 @@ V10Parser::LayerBaseCreator::fillSubGraphLayer(const ngraph::OutputVector &input
// Create ngraph::Function and set it as body of TensorIterator layer
IRParser parser(10);
auto ngraph_function = parser.parse(node.child("body"), binStream)->getFunction();
auto ngraph_function = parser.parse(node.child("body"), weights)->getFunction();
auto parameter_nodes = ngraph_function->get_parameters();
auto result_nodes = ngraph_function->get_results();
// Disabled reshape for generic operations in the TI body
@ -768,25 +763,25 @@ V10Parser::LayerBaseCreator::fillSubGraphLayer(const ngraph::OutputVector &input
// TensorIterator layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::TensorIterator>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
auto ti = std::make_shared<ngraph::op::TensorIterator>();
return fillSubGraphLayer(inputs, node, binStream, layerParsePrms, ti);
return fillSubGraphLayer(inputs, node, weights, layerParsePrms, ti);
}
// Loop layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::opset5::Loop>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
auto loop = std::make_shared<ngraph::opset5::Loop>(inputs[0], inputs[1]);
return fillSubGraphLayer(inputs, node, binStream, layerParsePrms, loop);
return fillSubGraphLayer(inputs, node, weights, layerParsePrms, loop);
}
// PriorBoxClustered layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::PriorBoxClustered>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -814,7 +809,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::PriorBoxCluste
// PriorBox layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::PriorBox>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -842,7 +837,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::PriorBox>::cre
// FakeQuantize layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::FakeQuantize>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 5);
pugi::xml_node dn = node.child("data");
@ -856,7 +851,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::FakeQuantize>:
// ReverseSequence layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::ReverseSequence>::createLayer(const ngraph::OutputVector & inputs, const pugi::xml_node& node,
std::istream& binStream,
const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -866,7 +861,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::ReverseSequenc
// Covnert layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Convert>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -880,7 +875,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Convert>::crea
// LSTMCell layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v0::LSTMCell>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 6);
pugi::xml_node dn = node.child("data");
@ -899,7 +894,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v0::LSTMCell>:
// CTCGreedyDecoder layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::CTCGreedyDecoder>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -913,7 +908,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::CTCGreedyDecod
// Pad layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Pad>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
pugi::xml_node dn = node.child("data");
@ -950,7 +945,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Pad>::crea
// SquaredDifference layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::SquaredDifference>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::SquaredDifference>(inputs[0], inputs[1]);
@ -959,7 +954,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::SquaredDiffere
// GreaterEqual layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::GreaterEqual>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::GreaterEqual>(inputs[0], inputs[1]);
@ -968,7 +963,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::GreaterEqu
// LessEqual layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LessEqual>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::LessEqual>(inputs[0], inputs[1]);
@ -977,7 +972,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LessEqual>
// Equal layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Equal>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::Equal>(inputs[0], inputs[1]);
@ -986,7 +981,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Equal>::cr
// NotEqual layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::NotEqual>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::NotEqual>(inputs[0], inputs[1]);
@ -995,7 +990,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::NotEqual>:
// FloorMod layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::FloorMod>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::FloorMod>(inputs[0], inputs[1]);
@ -1004,7 +999,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::FloorMod>:
// MVN layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::MVN>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1021,7 +1016,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::MVN>::createLa
// LRN layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::LRN>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -1039,7 +1034,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::LRN>::createLa
// Clamp layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Clamp>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1055,7 +1050,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Clamp>::create
// VariadicSplit layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::VariadicSplit>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 3);
return std::make_shared<ngraph::op::VariadicSplit>(inputs[0], inputs[1], inputs[2]);
@ -1064,7 +1059,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::VariadicSplit>
// Split layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Split>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
pugi::xml_node dn = node.child("data");
@ -1079,7 +1074,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Split>::cr
// ELU layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Elu>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1093,7 +1088,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Elu>::createLa
// SpaceToDepth layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::SpaceToDepth>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1107,7 +1102,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::SpaceToDepth>:
// DepthToSpace layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::DepthToSpace>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1121,7 +1116,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::DepthToSpace>:
// SeLU layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v0::Selu>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 3);
return std::make_shared<ngraph::op::v0::Selu>(inputs[0], inputs[1], inputs[2]);
@ -1130,7 +1125,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v0::Selu>::cre
// PReLU layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::PRelu>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::PRelu>(inputs[0], inputs[1]);
@ -1139,7 +1134,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::PRelu>::create
// ReLU layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Relu>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
return std::make_shared<ngraph::op::Relu>(inputs[0]);
@ -1148,7 +1143,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Relu>::createL
// Tanh layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Tanh>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
return std::make_shared<ngraph::op::Tanh>(inputs[0]);
@ -1157,7 +1152,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Tanh>::createL
// Result layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Result>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
return std::make_shared<ngraph::op::Result>(inputs[0]);
@ -1166,7 +1161,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Result>::creat
// Tile layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v0::Tile>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v0::Tile>(inputs[0], inputs[1]);
@ -1175,7 +1170,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v0::Tile>::cre
// StridedSlice layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::StridedSlice>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
pugi::xml_node dn = node.child("data");
@ -1200,7 +1195,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::StridedSli
// Reshape layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Reshape>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
@ -1214,7 +1209,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Reshape>::
// Minimum layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Minimum>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::Minimum>(inputs[0], inputs[1]);
@ -1223,7 +1218,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Minimum>::
// Subtract layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Subtract>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::Subtract>(inputs[0], inputs[1]);
@ -1232,7 +1227,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Subtract>:
// Broadcast layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Broadcast>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
if (inputs.size() == 2) {
return std::make_shared<ngraph::op::v1::Broadcast>(inputs[0], inputs[1]);
@ -1245,7 +1240,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Broadcast>
// Constant layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Constant>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 0);
pugi::xml_node dn = node.child("data");
@ -1256,8 +1251,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Constant>::cre
size_t offset = GetUInt64Attr(dn, "offset");
size_t size = GetUInt64Attr(dn, "size");
binStream.seekg(0, std::ios::end);
std::streampos length = binStream.tellg();
size_t length = weights->byteSize();
if (!length)
THROW_IE_EXCEPTION << "Cannot read network! The model requires weights data! "
<< "Bin file cannot be found! Please specify the path to bin file.";
@ -1271,17 +1265,20 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::Constant>::cre
if (size < std::ceil(ngraph::shape_size(shape) * el_type.bitwidth() / 8.f))
THROW_IE_EXCEPTION << "Cannot create Constant op " << layerParsePrms.name << " size attribute and shape size are inconsistent!";
auto constant = std::make_shared<ngraph::op::Constant>(port.precision, shape);
char* data = const_cast<char*>(reinterpret_cast<const char*>(constant->get_data_ptr()));
binStream.seekg(offset, std::ios::beg);
binStream.read(data, size);
char* data = weights->cbuffer().as<char*>() + offset;
using SharedBuffer = ngraph::runtime::SharedBuffer<const Blob::CPtr>;
auto buffer = std::make_shared<SharedBuffer>(data, size, weights);
auto constant = std::make_shared<ngraph::op::Constant>(port.precision, shape, buffer);
return constant;
}
// Power layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Power>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::Power>(inputs[0], inputs[1]);
@ -1290,7 +1287,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Power>::cr
// MatMul layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::MatMul>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -1304,7 +1301,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::MatMul>::creat
// Softmax layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Softmax>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1318,7 +1315,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Softmax>::
// RegionYolo layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::RegionYolo>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1342,7 +1339,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::RegionYolo>::c
// ReorgYolo layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::ReorgYolo>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1357,7 +1354,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::ReorgYolo>::cr
// BinaryConvolution layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::BinaryConvolution>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -1392,7 +1389,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::BinaryConv
// Convolution layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Convolution>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -1422,7 +1419,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Convolutio
// GroupConvolution layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::GroupConvolution>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -1452,7 +1449,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::GroupConvo
// DeformableConvolution layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::DeformableConvolution>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 3);
pugi::xml_node dn = node.child("data");
@ -1485,7 +1482,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Deformable
// ConvolutionBackpropData layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::ConvolutionBackpropData>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
pugi::xml_node dn = node.child("data");
@ -1523,7 +1520,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Convolutio
// GroupConvolutionBackpropData layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::GroupConvolutionBackpropData>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
pugi::xml_node dn = node.child("data");
@ -1562,7 +1559,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::GroupConvo
// AvgPool layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::AvgPool>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1603,7 +1600,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::AvgPool>::
// MaxPool layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::MaxPool>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1643,7 +1640,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::MaxPool>::
// ROIPooling layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::ROIPooling>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -1662,7 +1659,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::ROIPooling>::c
// PSROIPooling layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::PSROIPooling>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -1686,7 +1683,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::PSROIPooling>:
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::DeformablePSROIPooling>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
pugi::xml_node dn = node.child("data");
@ -1721,7 +1718,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Deformable
// Gather layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Gather>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 3);
return std::make_shared<ngraph::op::v1::Gather>(inputs[0], inputs[1], inputs[2]);
@ -1730,7 +1727,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::Gather>::c
// GatherTree layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::GatherTree>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 4);
return std::make_shared<ngraph::op::v1::GatherTree>(inputs[0], inputs[1], inputs[2], inputs[3]);
@ -1739,7 +1736,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::GatherTree
// OneHot layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::OneHot>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 4);
@ -1753,7 +1750,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::OneHot>::c
// NormalizeL2 layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::NormalizeL2>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
pugi::xml_node dn = node.child("data");
@ -1778,7 +1775,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::NormalizeL2>::
// HardSigmoid layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::HardSigmoid>::createLayer(
const ngraph::OutputVector & inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector & inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 3);
return std::make_shared<ngraph::op::HardSigmoid>(inputs[0], inputs[1], inputs[2]);
@ -1787,7 +1784,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::HardSigmoid>::
// GRN layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::GRN>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
pugi::xml_node dn = node.child("data");
@ -1801,7 +1798,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::GRN>::createLa
// LogicalAnd layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LogicalAnd>::createLayer(
const ngraph::OutputVector & inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector & inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::LogicalAnd>(inputs[0], inputs[1]);
@ -1810,7 +1807,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LogicalAnd
// LogicalOr layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LogicalOr>::createLayer(
const ngraph::OutputVector & inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector & inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::LogicalOr>(inputs[0], inputs[1]);
@ -1819,7 +1816,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LogicalOr>
// LogicalXor layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LogicalXor>::createLayer(
const ngraph::OutputVector & inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector & inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 2);
return std::make_shared<ngraph::op::v1::LogicalXor>(inputs[0], inputs[1]);
@ -1828,7 +1825,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LogicalXor
// LogicalNot layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LogicalNot>::createLayer(
const ngraph::OutputVector & inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector & inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
checkParameters(inputs, layerParsePrms, 1);
return std::make_shared<ngraph::op::v1::LogicalNot>(inputs[0]);
@ -1837,7 +1834,7 @@ std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::LogicalNot
// NonMaxSuppression layer
template <>
std::shared_ptr<ngraph::Node> V10Parser::LayerCreator<ngraph::op::v1::NonMaxSuppression>::createLayer(
const ngraph::OutputVector& inputs, const pugi::xml_node& node, std::istream& binStream,
const ngraph::OutputVector& inputs, const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) {
pugi::xml_node dn = node.child("data");

View File

@ -30,14 +30,14 @@ class IParser {
public:
using Ptr = std::shared_ptr<IParser>;
virtual ~IParser() = default;
virtual std::shared_ptr<ICNNNetwork> parse(const pugi::xml_node& root, std::istream& binStream) = 0;
virtual std::shared_ptr<ICNNNetwork> parse(const pugi::xml_node& root, const Blob::CPtr& weights) = 0;
};
class IRParser {
public:
explicit IRParser(size_t version);
IRParser(size_t version, const std::vector<InferenceEngine::IExtensionPtr>& exts);
std::shared_ptr<ICNNNetwork> parse(const pugi::xml_node& root, std::istream& binStream);
std::shared_ptr<ICNNNetwork> parse(const pugi::xml_node& root, const Blob::CPtr& weights);
virtual ~IRParser() = default;
private:
@ -47,7 +47,7 @@ private:
class CNNParser : public IParser {
public:
CNNParser() = default;
std::shared_ptr<ICNNNetwork> parse(const pugi::xml_node& root, std::istream& binStream) override;
std::shared_ptr<ICNNNetwork> parse(const pugi::xml_node& root, const Blob::CPtr& weights) override;
};
#ifdef IR_READER_V10
@ -55,7 +55,7 @@ public:
class V10Parser : public IParser {
public:
explicit V10Parser(const std::vector<IExtensionPtr>& exts);
std::shared_ptr<ICNNNetwork> parse(const pugi::xml_node& root, std::istream& binStream) override;
std::shared_ptr<ICNNNetwork> parse(const pugi::xml_node& root, const Blob::CPtr& weights) override;
private:
std::map<std::string, ngraph::OpSet> opsets;
@ -104,7 +104,7 @@ private:
protected:
static std::shared_ptr<ngraph::Node> fillSubGraphLayer(const ngraph::OutputVector& inputs, const pugi::xml_node& node,
std::istream& binStream,
const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms,
std::shared_ptr<ngraph::op::util::SubGraphOp> subgraph_op);
explicit LayerBaseCreator(const std::string& type): type(type) {}
@ -152,7 +152,7 @@ private:
public:
virtual ~LayerBaseCreator() {}
virtual std::shared_ptr<ngraph::Node> createLayer(const ngraph::OutputVector& inputs,
const pugi::xml_node& node, std::istream& binStream,
const pugi::xml_node& node, const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) = 0;
bool shouldCreate(const std::string& nodeType) const;
@ -164,7 +164,7 @@ private:
public:
explicit LayerCreator(const std::string& type): LayerBaseCreator(type) {}
std::shared_ptr<ngraph::Node> createLayer(const ngraph::OutputVector& inputs, const pugi::xml_node& node,
std::istream& binStream,
const Blob::CPtr& weights,
const GenericLayerParams& layerParsePrms) override;
ngraph::NodeTypeInfo getNodeType() const override {
return T::type_info;
@ -172,10 +172,10 @@ private:
};
std::shared_ptr<ngraph::Node> createNode(const ngraph::OutputVector& inputs, const pugi::xml_node& node,
std::istream& binStream, const GenericLayerParams& params);
const Blob::CPtr& weights, const GenericLayerParams& params);
GenericLayerParams parseGenericParams(const pugi::xml_node& node);
void parsePreProcess(CNNNetwork& network, const pugi::xml_node& root, std::istream& binStream);
void parsePreProcess(CNNNetwork& network, const pugi::xml_node& root, const Blob::CPtr& weights);
std::map<std::string, DataPtr> portsToData;
std::map<std::string, GenericLayerParams> layersParseInfo;
@ -324,4 +324,4 @@ private:
#endif // IR_READER_V10
} // namespace InferenceEngine
} // namespace InferenceEngine

View File

@ -30,11 +30,10 @@ bool IRReader::supportModel(std::istream& model) const {
}
CNNNetwork IRReader::read(std::istream& model, const std::vector<IExtensionPtr>& exts) const {
std::istringstream emptyStream;
return read(model, emptyStream, exts);
return read(model, nullptr, exts);
}
CNNNetwork IRReader::read(std::istream& model, std::istream& weights, const std::vector<IExtensionPtr>& exts) const {
CNNNetwork IRReader::read(std::istream& model, const Blob::CPtr& weights, const std::vector<IExtensionPtr>& exts) const {
OV_ITT_SCOPED_TASK(itt::domains::V10Reader, "IRReader::read");
pugi::xml_document xmlDoc;

View File

@ -52,12 +52,12 @@ public:
/**
* @brief Reads the model to CNNNetwork
* @param model stream with model
* @param weights stream with binary data
* @param weights blob with binary data
* @param exts vector with extensions
*
* @return CNNNetwork
*/
CNNNetwork read(std::istream& model, std::istream& weights, const std::vector<IExtensionPtr>& exts) const override;
CNNNetwork read(std::istream& model, const Blob::CPtr& weights, const std::vector<IExtensionPtr>& exts) const override;
std::vector<std::string> getDataFileExtensions() const override {
return {"bin"};

View File

@ -19,8 +19,8 @@ IRParser::IRParser(size_t version, const std::vector<InferenceEngine::IExtension
}
}
std::shared_ptr<ICNNNetwork> IRParser::parse(const pugi::xml_node& root, std::istream& binStream) {
return parser->parse(root, binStream);
std::shared_ptr<ICNNNetwork> IRParser::parse(const pugi::xml_node& root, const Blob::CPtr& weights) {
return parser->parse(root, weights);
}
/**
@ -36,7 +36,7 @@ public:
originBlob(weights) { }
};
std::shared_ptr<ICNNNetwork> CNNParser::parse(const pugi::xml_node& root, std::istream& binStream) {
std::shared_ptr<ICNNNetwork> CNNParser::parse(const pugi::xml_node& root, const Blob::CPtr& weights) {
auto getBlobStream = [](std::istream& binStream) {
details::BlobStream* blobStream = dynamic_cast<details::BlobStream*>(&binStream);
if (blobStream == nullptr) {
@ -53,21 +53,14 @@ std::shared_ptr<ICNNNetwork> CNNParser::parse(const pugi::xml_node& root, std::i
StatusCode ret = reader.ReadNetwork(root, &resp);
if (ret != OK)
THROW_IE_EXCEPTION << resp.msg;
TBlob<uint8_t>::Ptr weightsPtr;
// Try to get BlobStream to work with original blob
details::BlobStream* blobStream = getBlobStream(binStream);
if (blobStream != nullptr) {
weightsPtr = std::make_shared<WeightsHolderBlob>(blobStream->getBlob());
if (weights != nullptr) {
weightsPtr = TBlob<uint8_t>::Ptr(new WeightsHolderBlob(weights));
} else {
// Allocate a blob for weights
binStream.seekg(0, std::ios::end);
size_t length = binStream.tellg();
weightsPtr = std::make_shared<TBlob<uint8_t>>(TensorDesc(Precision::U8, {length}, Layout::C));
weightsPtr = std::make_shared<TBlob<uint8_t>>(TensorDesc(Precision::U8, { 0 }, Layout::C));
weightsPtr->allocate();
char* data = weightsPtr->buffer().as<char*>();
binStream.seekg(0, std::ios::beg);
binStream.read(data, length);
}
ret = reader.SetWeights(weightsPtr, &resp);
if (ret != OK)

View File

@ -30,12 +30,12 @@ public:
/**
* @brief Reads the model to CNNNetwork
* @param model stream with model
* @param weights stream with binary data
* @param weights blob with binary data
* @param exts vector with extensions
*
* @return CNNNetwork
*/
CNNNetwork read(std::istream& model, std::istream& weights, const std::vector<IExtensionPtr>& exts) const override {
CNNNetwork read(std::istream& model, const Blob::CPtr& weights, const std::vector<IExtensionPtr>& exts) const override {
THROW_IE_EXCEPTION << "ONNX reader cannot read model with weights!";
}

View File

@ -41,7 +41,7 @@ public:
*
* @return CNNNetwork
*/
virtual CNNNetwork read(std::istream& model, std::istream& weights, const std::vector<IExtensionPtr>& exts) const = 0;
virtual CNNNetwork read(std::istream& model, const Blob::CPtr& weights, const std::vector<IExtensionPtr>& exts) const = 0;
/**
* @brief Returns all supported extensions for data files

View File

@ -24,6 +24,7 @@
#include "ngraph/node.hpp"
#include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/runtime/host_tensor.hpp"
#include "ngraph/runtime/shared_buffer.hpp"
#include "ngraph/type/element_type.hpp"
#include "ngraph/type/element_type_traits.hpp"
#include "ngraph/util.hpp"
@ -233,6 +234,22 @@ namespace ngraph
/// \param data A void* to constant data.
Constant(const element::Type& type, const Shape& shape, const void* data);
/// \brief Constructs a tensor constant with the supplied data
///
/// \param type The element type of the tensor constant.
/// \param shape The shape of the tensor constant.
/// \param data A pointer to pre-allocated shared data.
template <typename T>
Constant(const element::Type& type,
const Shape& shape,
std::shared_ptr<runtime::SharedBuffer<T>> data)
: m_element_type(type)
, m_shape(shape)
{
m_data = data;
constructor_validate_and_infer_types();
}
Constant(const Constant& other);
Constant& operator=(const Constant&) = delete;

View File

@ -70,6 +70,7 @@ private:
AlignedBuffer(const AlignedBuffer&) = delete;
AlignedBuffer& operator=(const AlignedBuffer&) = delete;
protected:
char* m_allocated_buffer;
char* m_aligned_buffer;
size_t m_byte_size;

View File

@ -0,0 +1,54 @@
//*****************************************************************************
// Copyright 2017-2020 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#pragma once
#include <cstddef>
#include "ngraph/runtime/aligned_buffer.hpp"
namespace ngraph
{
namespace runtime
{
template <typename T>
class SharedBuffer;
}
}
/// \brief SharedBuffer class to store pointer to pre-acclocated buffer.
template <typename T>
class ngraph::runtime::SharedBuffer : public ngraph::runtime::AlignedBuffer
{
public:
SharedBuffer(char* data, size_t size, T& shared_object)
: _shared_object(shared_object)
{
m_allocated_buffer = data;
m_aligned_buffer = data;
m_byte_size = size;
}
virtual ~SharedBuffer()
{
m_aligned_buffer = nullptr;
m_allocated_buffer = nullptr;
m_byte_size = 0;
}
private:
T _shared_object;
};