forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infer_request.cpp
131 lines (115 loc) · 5.04 KB
/
infer_request.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "infer_request.hpp"
#include <ie_input_info.hpp>
#include <cpp_interfaces/interface/ie_iinfer_request_internal.hpp>
#include <blob_factory.hpp>
namespace MultiDevicePlugin {
using namespace InferenceEngine;
// ------------------------------MultiDeviceInferRequest----------------------------
MultiDeviceInferRequest::MultiDeviceInferRequest(const std::vector<std::shared_ptr<const ov::Node>>& inputs,
const std::vector<std::shared_ptr<const ov::Node>>& outputs,
const InferenceEngine::SoIInferRequestInternal & request_to_share_blobs_with,
InferenceEngine::RemoteContext::Ptr ctx)
: IInferRequestInternal(inputs, outputs),
_sharedRequest(request_to_share_blobs_with) {
CreateInferRequest(request_to_share_blobs_with, ctx);
}
MultiDeviceInferRequest::MultiDeviceInferRequest(const InputsDataMap& networkInputs,
const OutputsDataMap& networkOutputs,
const SoIInferRequestInternal & request_to_share_blobs_with,
InferenceEngine::RemoteContext::Ptr ctx)
: IInferRequestInternal(networkInputs, networkOutputs),
_sharedRequest(request_to_share_blobs_with) {
CreateInferRequest(request_to_share_blobs_with, ctx);
}
void MultiDeviceInferRequest::CreateInferRequest(const InferenceEngine::SoIInferRequestInternal& request_to_share_blobs_with,
InferenceEngine::RemoteContext::Ptr ctx) {
if (request_to_share_blobs_with) {
// do not need to touch multi memory blobs
return;
}
// Allocate all input blobs
for (const auto &it : _networkInputs) {
auto l = it.second->getLayout();
auto p = it.second->getPrecision();
auto dims = it.second->getTensorDesc().getDims();
TensorDesc desc = TensorDesc(p, dims, l);
if (ctx) {
_inputs[it.first] = ctx->CreateHostBlob(desc);
} else {
_inputs[it.first] = make_blob_with_precision(desc);
}
_inputs[it.first]->allocate();
}
// Allocate all output blobs
for (const auto &it : _networkOutputs) {
auto l = it.second->getLayout();
auto p = it.second->getPrecision();
auto dims = it.second->getTensorDesc().getDims();
TensorDesc desc = TensorDesc(p, dims, l);
if (ctx) {
_outputs[it.first] = ctx->CreateHostBlob(desc);
} else {
_outputs[it.first] = make_blob_with_precision(desc);
}
_outputs[it.first]->allocate();
}
}
void MultiDeviceInferRequest::SetBlobsToAnotherRequest(const SoIInferRequestInternal& req) {
for (const auto &it : _networkInputs) {
auto &name = it.first;
// this request is already in BUSY state, so using the internal functions safely
auto blob = GetBlob(name);
if (req->GetBlob(name) != blob)
req->SetBlob(name, blob);
}
for (const auto &it : _networkOutputs) {
auto &name = it.first;
// this request is already in BUSY state, so using the internal functions safely
auto blob = GetBlob(name);
if (req->GetBlob(name) != blob)
req->SetBlob(name, blob);
}
}
void MultiDeviceInferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob::Ptr& blob) {
if (_sharedRequest)
_sharedRequest->SetBlob(name, blob);
else
IInferRequestInternal::SetBlob(name, blob);
}
void MultiDeviceInferRequest::SetBlob(const std::string& name, const Blob::Ptr& blob, const PreProcessInfo& info) {
if (_sharedRequest)
_sharedRequest->SetBlob(name, blob, info);
else
IInferRequestInternal::SetBlob(name, blob, info);
}
InferenceEngine::Blob::Ptr MultiDeviceInferRequest::GetBlob(const std::string& name) {
if (_sharedRequest)
return _sharedRequest->GetBlob(name);
else
return IInferRequestInternal::GetBlob(name);
}
std::map<std::string, InferenceEngine::InferenceEngineProfileInfo> MultiDeviceInferRequest::GetPerformanceCounts() const {
if (_sharedRequest) {
return _sharedRequest->GetPerformanceCounts();
} else {
// get the profiling info directly from target infer request
// not thread-safe for plugin like GPU, see CVS-86034
if (_scheduledRequest)
return _scheduledRequest->GetPerformanceCounts();
else
IE_THROW() << "Performance counters were not enabled";
}
}
std::vector<std::shared_ptr<InferenceEngine::IVariableStateInternal>> MultiDeviceInferRequest::QueryState() {
if (_sharedRequest)
return _sharedRequest->QueryState();
IE_THROW(NotImplemented);
}
void MultiDeviceInferRequest::InferImpl() {
IE_THROW(NotImplemented);
}
} // namespace MultiDevicePlugin