Skip to content

Commit bd32f51

Browse files
ericcrawsfatimar
andauthored
Remove unintended model copies during compilation (#584)
Co-authored-by: sfatimar <sahar.fatima@intel.com>
1 parent ec62bf3 commit bd32f51

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

onnxruntime/core/providers/openvino/backend_utils.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ bool IsCILogEnabled() {
137137
}
138138

139139
std::shared_ptr<const OVNetwork>
140-
CreateOVModel(const std::string model,
140+
CreateOVModel(std::string&& model,
141141
const SessionContext& session_context,
142142
std::map<std::string, std::shared_ptr<ov::Node>>& const_outputs_map) {
143143
if (IsCILogEnabled()) {
144144
std::cout << "CreateNgraphFunc" << std::endl;
145145
}
146146
try {
147-
auto ov_model = OVCore::Get()->ReadModel(model, session_context.onnx_model_path_name.string());
147+
auto ov_model = OVCore::Get()->ReadModel(std::move(model), session_context.onnx_model_path_name.string());
148148

149149
// Check for Constant Folding
150150
if ((session_context.device_type != "NPU") && !session_context.is_wholly_supported_graph) {

onnxruntime/core/providers/openvino/backend_utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void FillOutputBlob(OVTensorPtr outputBlob, Ort::UnownedValue& output_tensor,
6262
size_t batch_slice_idx);
6363

6464
std::shared_ptr<const OVNetwork>
65-
CreateOVModel(const std::string model,
65+
CreateOVModel(std::string&& model,
6666
const SessionContext& session_context,
6767
std::map<std::string, std::shared_ptr<ov::Node>>& const_outputs_map);
6868

onnxruntime/core/providers/openvino/backends/basic_backend.cc

+8-14
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,11 @@ BasicBackend::BasicBackend(std::unique_ptr<ONNX_NAMESPACE::ModelProto>& model_pr
6969
subgraph_context_.subgraph_name);
7070
model_stream.reset(); // Delete stream after it is no longer needed
7171
} else {
72-
std::shared_ptr<const OVNetwork> ov_model;
73-
{
74-
const std::string model = model_proto->SerializeAsString();
75-
if (!subgraph_context.has_dynamic_input_shape) {
76-
delete model_proto.release();
77-
}
78-
ov_model = CreateOVModel(model, session_context_, const_outputs_map_);
72+
std::string model = model_proto->SerializeAsString();
73+
if (!subgraph_context.has_dynamic_input_shape) {
74+
model_proto.reset()
7975
}
76+
auto ov_model = CreateOVModel(std::move(model), session_context_, const_outputs_map_);
8077
LOGS_DEFAULT(INFO) << log_tag << "IO Buffering Enabled";
8178
exe_network_ = OVCore::Get()->CompileModel(
8279
ov_model, remote_context_, subgraph_context_.subgraph_name);
@@ -108,14 +105,11 @@ BasicBackend::BasicBackend(std::unique_ptr<ONNX_NAMESPACE::ModelProto>& model_pr
108105
subgraph_context_.subgraph_name);
109106
} else { // For all other types use ov::ov_core read_model() to generate OV IR
110107
// followed by ov::ov_core compile_model()
111-
std::shared_ptr<const OVNetwork> ov_model;
112-
{
113-
const std::string model = model_proto->SerializeAsString();
114-
if (!subgraph_context.has_dynamic_input_shape) {
115-
delete model_proto.release();
116-
}
117-
ov_model = CreateOVModel(std::move(model), session_context_, const_outputs_map_);
108+
std::string model = model_proto->SerializeAsString();
109+
if (!subgraph_context.has_dynamic_input_shape) {
110+
model_proto.reset();
118111
}
112+
auto ov_model = CreateOVModel(std::move(model), session_context_, const_outputs_map_);
119113
exe_network_ = OVCore::Get()->CompileModel(
120114
ov_model, hw_target, device_config, subgraph_context_.subgraph_name);
121115
}

onnxruntime/core/providers/openvino/ov_interface.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ void printDebugInfo(const ov::CompiledModel& obj) {
4646
}
4747
#endif
4848

49-
std::shared_ptr<OVNetwork> OVCore::ReadModel(const std::string& model, const std::string& model_path) {
49+
std::shared_ptr<OVNetwork> OVCore::ReadModel(std::string&& model, const std::string& model_path) {
5050
try {
51-
std::istringstream modelStringStream(model);
51+
std::istringstream modelStringStream(std::move(model));
5252
std::istream& modelStream = modelStringStream;
5353
// Try to load with FrontEndManager
5454
ov::frontend::FrontEndManager manager;

onnxruntime/core/providers/openvino/ov_interface.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct OVCore : WeakSingleton<OVCore> {
6767
ov::Core core;
6868

6969
// OV Interface For Reading Model
70-
std::shared_ptr<OVNetwork> ReadModel(const std::string& model_stream, const std::string& model_path);
70+
std::shared_ptr<OVNetwork> ReadModel(std::string&& model_stream, const std::string& model_path);
7171

7272
// OV Interface for Compiling OV Model Type
7373
OVExeNetwork CompileModel(std::shared_ptr<const OVNetwork>& ie_cnn_network,

0 commit comments

Comments
 (0)