Files
openvino/src/plugins/hetero/infer_request.cpp

152 lines
5.7 KiB
C++
Raw Normal View History

// Copyright (C) 2018-2022 Intel Corporation
// 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) {
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) {
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()) {
IE_THROW() << "Internal error: no information about network's output/input";
2018-10-16 13:45:03 +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;
}
if (output) {
if (InferenceEngine::details::contains(_networkOutputs, blobName)) {
Bell/fix lifecycle coredump (#11934) * enable binder schedule Signed-off-by: fishbell <bell.song@intel.com> * add cases Signed-off-by: fishbell <bell.song@intel.com> * refine Signed-off-by: fishbell <bell.song@intel.com> * fix build failure Signed-off-by: fishbell <bell.song@intel.com> * fix coredump Signed-off-by: fishbell <bell.song@intel.com> * do not return hw requests directly, potential issues Signed-off-by: fishbell <bell.song@intel.com> * fix bug Signed-off-by: fishbell <bell.song@intel.com> typo Signed-off-by: fishbell <bell.song@intel.com> * optimize memory Signed-off-by: fishbell <bell.song@intel.com> * hold the hw plugin Signed-off-by: fishbell <bell.song@intel.com> * Revert "hold the hw plugin" This reverts commit 5b537f5b6fe3214ca3866560732ccbfe2b179679. * apply the fix Signed-off-by: fishbell <bell.song@intel.com> apply the fix Signed-off-by: fishbell <bell.song@intel.com> * hold the plugin library for destructing tensor Signed-off-by: fishbell <bell.song@intel.com> * solve the virtuual plugin Getblob life cycle issue Signed-off-by: fishbell <bell.song@intel.com> * remove log Signed-off-by: fishbell <bell.song@intel.com> * refine interface Signed-off-by: fishbell <bell.song@intel.com> * fix build failure Signed-off-by: fishbell <bell.song@intel.com> * fix for hetero plugin Signed-off-by: fishbell <bell.song@intel.com> * replace with vector * enable life time tests for virtual plugins Signed-off-by: fishbell <bell.song@intel.com> rework cases due to vpux build issue Signed-off-by: fishbell <bell.song@intel.com> disable context test for now Signed-off-by: fishbell <bell.song@intel.com> Co-authored-by: Chen Peter <peter.chen@intel.com>
2022-07-06 13:21:17 +08:00
_subRequestFromBlobName.emplace(blobName, r);
} else {
auto blob = r->GetBlob(blobName);
_blobs.emplace(intermediateBlobName, r->GetBlob(blobName));
2018-10-16 13:45:03 +03:00
}
} else {
if (InferenceEngine::details::contains(_networkInputs, blobName)) {
Bell/fix lifecycle coredump (#11934) * enable binder schedule Signed-off-by: fishbell <bell.song@intel.com> * add cases Signed-off-by: fishbell <bell.song@intel.com> * refine Signed-off-by: fishbell <bell.song@intel.com> * fix build failure Signed-off-by: fishbell <bell.song@intel.com> * fix coredump Signed-off-by: fishbell <bell.song@intel.com> * do not return hw requests directly, potential issues Signed-off-by: fishbell <bell.song@intel.com> * fix bug Signed-off-by: fishbell <bell.song@intel.com> typo Signed-off-by: fishbell <bell.song@intel.com> * optimize memory Signed-off-by: fishbell <bell.song@intel.com> * hold the hw plugin Signed-off-by: fishbell <bell.song@intel.com> * Revert "hold the hw plugin" This reverts commit 5b537f5b6fe3214ca3866560732ccbfe2b179679. * apply the fix Signed-off-by: fishbell <bell.song@intel.com> apply the fix Signed-off-by: fishbell <bell.song@intel.com> * hold the plugin library for destructing tensor Signed-off-by: fishbell <bell.song@intel.com> * solve the virtuual plugin Getblob life cycle issue Signed-off-by: fishbell <bell.song@intel.com> * remove log Signed-off-by: fishbell <bell.song@intel.com> * refine interface Signed-off-by: fishbell <bell.song@intel.com> * fix build failure Signed-off-by: fishbell <bell.song@intel.com> * fix for hetero plugin Signed-off-by: fishbell <bell.song@intel.com> * replace with vector * enable life time tests for virtual plugins Signed-off-by: fishbell <bell.song@intel.com> rework cases due to vpux build issue Signed-off-by: fishbell <bell.song@intel.com> disable context test for now Signed-off-by: fishbell <bell.song@intel.com> Co-authored-by: Chen Peter <peter.chen@intel.com>
2022-07-06 13:21:17 +08:00
_subRequestFromBlobName.emplace(blobName, r);
} 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};
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
for (auto&& outputInfo : desc._network->GetOutputsInfo()) {
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) {
for (auto&& inputInfo : desc._network->GetInputsInfo()) {
requestBlob(inputInfo.first, desc._request, false);
2018-10-16 13:45:03 +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;
}
Bell/fix lifecycle coredump (#11934) * enable binder schedule Signed-off-by: fishbell <bell.song@intel.com> * add cases Signed-off-by: fishbell <bell.song@intel.com> * refine Signed-off-by: fishbell <bell.song@intel.com> * fix build failure Signed-off-by: fishbell <bell.song@intel.com> * fix coredump Signed-off-by: fishbell <bell.song@intel.com> * do not return hw requests directly, potential issues Signed-off-by: fishbell <bell.song@intel.com> * fix bug Signed-off-by: fishbell <bell.song@intel.com> typo Signed-off-by: fishbell <bell.song@intel.com> * optimize memory Signed-off-by: fishbell <bell.song@intel.com> * hold the hw plugin Signed-off-by: fishbell <bell.song@intel.com> * Revert "hold the hw plugin" This reverts commit 5b537f5b6fe3214ca3866560732ccbfe2b179679. * apply the fix Signed-off-by: fishbell <bell.song@intel.com> apply the fix Signed-off-by: fishbell <bell.song@intel.com> * hold the plugin library for destructing tensor Signed-off-by: fishbell <bell.song@intel.com> * solve the virtuual plugin Getblob life cycle issue Signed-off-by: fishbell <bell.song@intel.com> * remove log Signed-off-by: fishbell <bell.song@intel.com> * refine interface Signed-off-by: fishbell <bell.song@intel.com> * fix build failure Signed-off-by: fishbell <bell.song@intel.com> * fix for hetero plugin Signed-off-by: fishbell <bell.song@intel.com> * replace with vector * enable life time tests for virtual plugins Signed-off-by: fishbell <bell.song@intel.com> rework cases due to vpux build issue Signed-off-by: fishbell <bell.song@intel.com> disable context test for now Signed-off-by: fishbell <bell.song@intel.com> Co-authored-by: Chen Peter <peter.chen@intel.com>
2022-07-06 13:21:17 +08:00
setPointerToSo(itRequest->second._so);
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;
}
return itRequest->second->GetPreProcess(name);
}
2018-10-16 13:45:03 +03:00
void HeteroInferRequest::InferImpl() {
2021-11-29 14:05:08 +03:00
for (auto&& desc : _inferRequests) {
OV_ITT_SCOPED_TASK(itt::domains::HeteroPlugin, desc._profilingTask);
2021-11-29 14:05:08 +03:00
auto& r = desc._request;
assert(r);
r->Infer();
2018-10-16 13:45:03 +03: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;
}
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++) {
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
}
}
return perfMap;
2018-10-16 13:45:03 +03:00
}