2022-01-19 01:07:49 +03:00
|
|
|
// Copyright (C) 2018-2022 Intel Corporation
|
2019-05-27 21:18:32 +03:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-10-16 13:45:03 +03:00
|
|
|
//
|
|
|
|
|
|
2021-11-29 14:05:08 +03:00
|
|
|
#include "infer_request.hpp"
|
|
|
|
|
|
2018-10-16 13:45:03 +03:00
|
|
|
#include <ie_blob.h>
|
|
|
|
|
#include <ie_layouts.h>
|
2021-11-29 14:05:08 +03:00
|
|
|
|
2019-08-09 19:02:42 +03:00
|
|
|
#include <cassert>
|
2021-11-29 14:05:08 +03:00
|
|
|
#include <description_buffer.hpp>
|
|
|
|
|
#include <ie_algorithm.hpp>
|
2019-08-09 19:02:42 +03:00
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
2018-10-16 13:45:03 +03:00
|
|
|
|
2021-11-29 14:05:08 +03:00
|
|
|
#include "itt.hpp"
|
|
|
|
|
|
2018-10-16 13:45:03 +03:00
|
|
|
using namespace HeteroPlugin;
|
|
|
|
|
using namespace InferenceEngine;
|
2020-06-23 17:23:47 +03:00
|
|
|
using namespace InferenceEngine::details;
|
2018-10-16 13:45:03 +03:00
|
|
|
|
2021-11-29 14:05:08 +03:00
|
|
|
HeteroInferRequest::HeteroInferRequest(
|
|
|
|
|
const std::vector<std::shared_ptr<const ov::Node>>& inputs,
|
|
|
|
|
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
|
|
|
|
|
const SubRequestsList& inferRequests,
|
|
|
|
|
const std::unordered_map<std::string, std::string>& subgraphInputToOutputBlobNames)
|
|
|
|
|
: IInferRequestInternal(inputs, outputs),
|
|
|
|
|
_inferRequests(inferRequests) {
|
2021-10-20 22:08:55 +03:00
|
|
|
CreateInferRequest(subgraphInputToOutputBlobNames);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 14:05:08 +03:00
|
|
|
HeteroInferRequest::HeteroInferRequest(
|
|
|
|
|
InferenceEngine::InputsDataMap networkInputs,
|
|
|
|
|
InferenceEngine::OutputsDataMap networkOutputs,
|
|
|
|
|
const SubRequestsList& inferRequests,
|
|
|
|
|
const std::unordered_map<std::string, std::string>& subgraphInputToOutputBlobNames)
|
|
|
|
|
: IInferRequestInternal(networkInputs, networkOutputs),
|
|
|
|
|
_inferRequests(inferRequests) {
|
2021-10-20 22:08:55 +03:00
|
|
|
CreateInferRequest(subgraphInputToOutputBlobNames);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 14:05:08 +03:00
|
|
|
void HeteroInferRequest::CreateInferRequest(
|
|
|
|
|
const std::unordered_map<std::string, std::string>& subgraphInputToOutputBlobNames) {
|
2018-10-16 13:45:03 +03:00
|
|
|
if (_networkOutputs.empty() || _networkInputs.empty()) {
|
2021-03-23 18:57:12 +03:00
|
|
|
IE_THROW() << "Internal error: no information about network's output/input";
|
2018-10-16 13:45:03 +03:00
|
|
|
}
|
|
|
|
|
|
2021-10-23 01:20:49 +03:00
|
|
|
auto requestBlob([&](const std::string& blobName, InferenceEngine::SoIInferRequestInternal& r, bool output) {
|
2020-06-23 17:23:47 +03:00
|
|
|
std::string intermediateBlobName = blobName;
|
|
|
|
|
auto itName = subgraphInputToOutputBlobNames.find(blobName);
|
|
|
|
|
if (itName != subgraphInputToOutputBlobNames.end()) {
|
|
|
|
|
intermediateBlobName = itName->second;
|
|
|
|
|
}
|
2021-10-23 01:20:49 +03:00
|
|
|
if (output) {
|
|
|
|
|
if (InferenceEngine::details::contains(_networkOutputs, blobName)) {
|
2022-07-06 13:21:17 +08:00
|
|
|
_subRequestFromBlobName.emplace(blobName, r);
|
2021-10-15 10:44:11 +03:00
|
|
|
} else {
|
2021-10-23 01:20:49 +03:00
|
|
|
auto blob = r->GetBlob(blobName);
|
|
|
|
|
_blobs.emplace(intermediateBlobName, r->GetBlob(blobName));
|
2018-10-16 13:45:03 +03:00
|
|
|
}
|
|
|
|
|
} else {
|
2021-10-23 01:20:49 +03:00
|
|
|
if (InferenceEngine::details::contains(_networkInputs, blobName)) {
|
2022-07-06 13:21:17 +08:00
|
|
|
_subRequestFromBlobName.emplace(blobName, r);
|
2021-10-23 01:20:49 +03:00
|
|
|
} else {
|
|
|
|
|
r->SetBlob(blobName, _blobs.at(intermediateBlobName));
|
|
|
|
|
}
|
2018-10-16 13:45:03 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// go over all subnet and create requests
|
2020-02-11 22:48:49 +03:00
|
|
|
for (auto&& desc : _inferRequests) {
|
2021-12-20 12:11:32 +03:00
|
|
|
desc._request = {desc._network->CreateInferRequest(), desc._network._so};
|
2022-01-13 14:54:14 +03:00
|
|
|
desc._request->setModelInputsOutputs(desc._network->getInputs(), desc._network->getOutputs());
|
2018-10-16 13:45:03 +03:00
|
|
|
// go over all inputs and get blobs from subnet infer requests
|
2021-05-19 13:18:58 +03:00
|
|
|
for (auto&& outputInfo : desc._network->GetOutputsInfo()) {
|
2021-10-23 01:20:49 +03:00
|
|
|
requestBlob(outputInfo.first, desc._request, true);
|
2018-10-16 13:45:03 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go over all outputs and get blobs from subnet infer requests
|
2020-02-11 22:48:49 +03:00
|
|
|
for (auto&& desc : _inferRequests) {
|
2021-05-19 13:18:58 +03:00
|
|
|
for (auto&& inputInfo : desc._network->GetInputsInfo()) {
|
2021-10-23 01:20:49 +03:00
|
|
|
requestBlob(inputInfo.first, desc._request, false);
|
2018-10-16 13:45:03 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-15 10:44:11 +03:00
|
|
|
void HeteroInferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& blob) {
|
|
|
|
|
auto itRequest = _subRequestFromBlobName.find(name);
|
|
|
|
|
if (itRequest == _subRequestFromBlobName.end()) {
|
|
|
|
|
IE_THROW() << "There is no infer requests binded to blob with name: " << name;
|
|
|
|
|
}
|
|
|
|
|
itRequest->second->SetBlob(name, blob);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InferenceEngine::Blob::Ptr HeteroInferRequest::GetBlob(const std::string& name) {
|
|
|
|
|
auto itRequest = _subRequestFromBlobName.find(name);
|
|
|
|
|
if (itRequest == _subRequestFromBlobName.end()) {
|
|
|
|
|
IE_THROW() << "There is no infer requests binded to blob with name: " << name;
|
|
|
|
|
}
|
2022-07-06 13:21:17 +08:00
|
|
|
setPointerToSo(itRequest->second._so);
|
2021-10-15 10:44:11 +03:00
|
|
|
return itRequest->second->GetBlob(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HeteroInferRequest::SetBlob(const std::string& name, const Blob::Ptr& blob, const PreProcessInfo& info) {
|
|
|
|
|
auto itRequest = _subRequestFromBlobName.find(name);
|
|
|
|
|
if (itRequest == _subRequestFromBlobName.end()) {
|
|
|
|
|
IE_THROW() << "There is no infer requests binded to blob with name: " << name;
|
|
|
|
|
}
|
|
|
|
|
itRequest->second->SetBlob(name, blob, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const InferenceEngine::PreProcessInfo& HeteroInferRequest::GetPreProcess(const std::string& name) const {
|
|
|
|
|
auto itRequest = _subRequestFromBlobName.find(name);
|
|
|
|
|
if (itRequest == _subRequestFromBlobName.end()) {
|
|
|
|
|
IE_THROW() << "There is no infer requests binded to blob with name: " << name;
|
2020-04-15 19:01:57 +03:00
|
|
|
}
|
2021-10-15 10:44:11 +03:00
|
|
|
return itRequest->second->GetPreProcess(name);
|
2020-04-15 19:01:57 +03:00
|
|
|
}
|
|
|
|
|
|
2018-10-16 13:45:03 +03:00
|
|
|
void HeteroInferRequest::InferImpl() {
|
2021-11-29 14:05:08 +03:00
|
|
|
for (auto&& desc : _inferRequests) {
|
2020-08-03 12:53:00 +03:00
|
|
|
OV_ITT_SCOPED_TASK(itt::domains::HeteroPlugin, desc._profilingTask);
|
2021-11-29 14:05:08 +03:00
|
|
|
auto& r = desc._request;
|
2021-04-21 16:05:30 +03:00
|
|
|
assert(r);
|
2021-05-19 13:18:58 +03:00
|
|
|
r->Infer();
|
2018-10-16 13:45:03 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 12:43:56 +08:00
|
|
|
std::vector<std::shared_ptr<InferenceEngine::IVariableStateInternal>> HeteroInferRequest::QueryState() {
|
|
|
|
|
memoryStates = {};
|
|
|
|
|
for (auto&& desc : _inferRequests) {
|
|
|
|
|
auto& r = desc._request;
|
|
|
|
|
assert(r);
|
|
|
|
|
for (auto&& state : r->QueryState()) {
|
|
|
|
|
memoryStates.emplace_back(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return memoryStates;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-03 19:21:39 +03:00
|
|
|
std::map<std::string, InferenceEngineProfileInfo> HeteroInferRequest::GetPerformanceCounts() const {
|
|
|
|
|
std::map<std::string, InferenceEngineProfileInfo> perfMap;
|
2018-10-16 13:45:03 +03:00
|
|
|
for (size_t i = 0; i < _inferRequests.size(); i++) {
|
2021-05-19 13:18:58 +03:00
|
|
|
auto perfMapRequest = _inferRequests[i]._request->GetPerformanceCounts();
|
2021-11-29 14:05:08 +03:00
|
|
|
for (auto&& r : perfMapRequest) {
|
2018-11-23 16:19:43 +03:00
|
|
|
perfMap[std::string("subgraph") + std::to_string(i) + ": " + r.first] = r.second;
|
2018-10-16 13:45:03 +03:00
|
|
|
}
|
|
|
|
|
}
|
2021-02-03 19:21:39 +03:00
|
|
|
return perfMap;
|
2018-10-16 13:45:03 +03:00
|
|
|
}
|