@@ -76,7 +76,12 @@ BackendManager::BackendManager(SessionContext& session_context,
76
76
ptr_stream_t model_stream;
77
77
std::unique_ptr<onnx::ModelProto> model_proto;
78
78
if (subgraph_context_.is_ep_ctx_graph ) {
79
- model_stream = ep_ctx_handle_.GetModelBlobStream (subgraph);
79
+ std::cout << " inside is_ep_ctx_graph " << std::endl;
80
+ std::string model_name = onnxruntime::openvino_ep::BackendManager::stripAfterFirstDot (session_context_.onnx_model_path_name .filename ().string ());
81
+ auto subgraph_name = model_name + " _" +subgraph_context_.subgraph_name ;
82
+ model_stream = ep_ctx_handle_.GetModelBlobStream (shared_context_,
83
+ subgraph_name,
84
+ subgraph);
80
85
} else {
81
86
model_proto = GetModelProtoFromFusedNode (fused_node, subgraph, logger);
82
87
}
@@ -96,7 +101,9 @@ BackendManager::BackendManager(SessionContext& session_context,
96
101
if (!sw.mapped_weights ) {
97
102
sw.mapped_weights = std::make_unique<SharedContext::SharedWeights::WeightsFile>(weight_filename);
98
103
}
104
+ std::cout << " Call createOVTensors in backend_manager.cc" << std::endl;
99
105
backend_utils::CreateOVTensors (session_context_.device_type , sw.metadata , *sw.mapped_weights );
106
+ std::cout << " create OVTensors successful " << std::endl;
100
107
}
101
108
}
102
109
@@ -197,6 +204,14 @@ BackendManager::BackendManager(SessionContext& session_context,
197
204
}
198
205
}
199
206
207
+ std::string BackendManager::stripAfterFirstDot (std::string filename) {
208
+ size_t dotPos = filename.find (' .' ); // Find first dot
209
+ if (dotPos == std::string::npos) {
210
+ return filename; // No dot found, return full filename
211
+ }
212
+ return filename.substr (0 , dotPos); // Return everything before first dot
213
+ }
214
+
200
215
// Call EPContext model exporter here if the provider option for exporting
201
216
// precompiled blob is set. If that's the case:
202
217
// By default, create model in embed mode where the blob stream is exported as data within
@@ -210,27 +225,33 @@ Status BackendManager::ExportCompiledBlobAsEPCtxNode(const onnxruntime::GraphVie
210
225
ORT_THROW (exception_str);
211
226
}
212
227
228
+ std::cout << " inside export compiled model " << std::endl;
229
+
213
230
// If embed_mode, then pass on the serialized blob
214
231
// If not embed_mode, dump the blob here and only pass on the path to the blob
215
232
std::string model_blob_str;
216
233
auto compiled_model = concrete_backend_->GetOVCompiledModel ();
217
234
if (session_context_.so_share_ep_contexts ){
218
- // std::ostringstream model_blob_stream;
219
- // compiled_model.export_model(model_blob_stream);
235
+ std::ostringstream model_blob_stream;
236
+ compiled_model.export_model (model_blob_stream);
237
+ std::cout << " inside export compiled model - share ep contexts" << std::endl;
220
238
221
239
// std::ofstream file(metadata_filename, std::ios::app| std::ios::binary);
222
240
// std::cout << " write to metadata bin - " << metadata_filename << std::endl;
223
241
auto & subgraph_metadata = shared_context_.shared_weights .subgraph_metadata ;
224
-
225
- sw::SubgraphMetadata::Map::key_type key{subgraph_context_.subgraph_name };
242
+ std::string model_name = onnxruntime::openvino_ep::BackendManager::stripAfterFirstDot (session_context_.onnx_model_path_name .filename ().string ());
243
+ auto subgraph_name = model_name + " _" +subgraph_context_.subgraph_name ;
244
+ sw::SubgraphMetadata::Map::key_type key{subgraph_name};
226
245
sw::SubgraphMetadata::Map::mapped_type value{};
227
246
228
247
auto & bin_file = shared_context_.shared_weights .shared_bin_file .bin_file_ ;
229
- if (bin_file.is_open ()) {
248
+ std::cout << " subgraph name " << subgraph_name << " key = " << key.name << " For bin write " << std::endl;
249
+ if (!subgraph_metadata.contains (key) && bin_file.is_open ()) {
230
250
// std::cout << "Current offset before "<< subgraph_context_.subgraph_name << " = " << bin_file.tellp() << std::endl;
231
251
value.epctx_offset = bin_file.tellp ();
232
- // bin_file << model_blob_stream.str();
233
- compiled_model.export_model (bin_file);
252
+ std::cout << " bin file location for writing subgraph = " << bin_file.tellp () << std::endl;
253
+ bin_file << model_blob_stream.str ();
254
+ // compiled_model.export_model(bin_file);
234
255
// std::cout << "Current offset after "<< subgraph_context_.subgraph_name << " = " << bin_file.tellp() << std::endl;
235
256
value.epctx_length = static_cast <size_t >(static_cast <std::streamoff>(bin_file.tellp ()) - value.epctx_offset );
236
257
// std::cout << "Key = " << key.name << " Offset = " << value.epctx_offset << " , length = " << value.epctx_length << std::endl;
0 commit comments