@@ -76,8 +76,15 @@ 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
- 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 ());
79
+ std::string filename;
80
+ if (!session_context_.so_context_file_path .empty ()) {
81
+ filename = session_context_.so_context_file_path .filename ().string ();
82
+ } else if (!session_context_.onnx_model_path_name .empty ()) {
83
+ filename = session_context_.onnx_model_path_name .filename ().string ();
84
+ } else {
85
+ ORT_THROW (" Either Session_options ep.context_file_path or model path must be specified" );
86
+ }
87
+ std::string model_name = onnxruntime::openvino_ep::BackendManager::stripAfterFirstDot (filename);
81
88
auto subgraph_name = model_name + " _" + subgraph_context_.subgraph_name ;
82
89
model_stream = ep_ctx_handle_.GetModelBlobStream (shared_context_,
83
90
session_context_.so_context_file_path ,
@@ -102,9 +109,9 @@ BackendManager::BackendManager(SessionContext& session_context,
102
109
if (!sw.mapped_weights ) {
103
110
sw.mapped_weights = std::make_unique<SharedContext::SharedWeights::WeightsFile>(weight_filename);
104
111
}
105
- std::cout << " Call createOVTensors in backend_manager.cc" << std::endl;
106
112
backend_utils::CreateOVTensors (session_context_.device_type , sw.metadata , *sw.mapped_weights );
107
- std::cout << " create OVTensors successful " << std::endl;
113
+ } else {
114
+ ORT_THROW (" External weight file is not found " );
108
115
}
109
116
}
110
117
@@ -206,11 +213,16 @@ BackendManager::BackendManager(SessionContext& session_context,
206
213
}
207
214
208
215
std::string BackendManager::stripAfterFirstDot (std::string filename) {
209
- size_t dotPos = filename.find (' .' ); // Find first dot
210
- if (dotPos == std::string::npos) {
216
+ size_t dotPos = filename.find (' .' ); // Find first dot
217
+ size_t ctxPos = filename.find (" _ctx" ); // Find first dot
218
+ if (dotPos == std::string::npos && ctxPos == std::string::npos) {
211
219
return filename; // No dot found, return full filename
212
220
}
213
- return filename.substr (0 , dotPos); // Return everything before first dot
221
+ if (dotPos != std::string::npos)
222
+ filename = filename.substr (0 , dotPos); // strip everything after first dot
223
+ if (ctxPos != std::string::npos)
224
+ filename = filename.substr (0 , ctxPos); // strip everything after _ctx
225
+ return filename;
214
226
}
215
227
216
228
// Call EPContext model exporter here if the provider option for exporting
@@ -226,36 +238,33 @@ Status BackendManager::ExportCompiledBlobAsEPCtxNode(const onnxruntime::GraphVie
226
238
ORT_THROW (exception_str);
227
239
}
228
240
229
- std::cout << " inside export compiled model " << std::endl;
230
-
231
241
// If embed_mode, then pass on the serialized blob
232
242
// If not embed_mode, dump the blob here and only pass on the path to the blob
233
243
std::string model_blob_str;
234
244
auto compiled_model = concrete_backend_->GetOVCompiledModel ();
235
245
if (session_context_.so_share_ep_contexts ) {
236
246
std::ostringstream model_blob_stream;
237
247
compiled_model.export_model (model_blob_stream);
238
- std::cout << " inside export compiled model - share ep contexts" << std::endl;
239
248
240
- // std::ofstream file(metadata_filename, std::ios::app| std::ios::binary);
241
- // std::cout << " write to metadata bin - " << metadata_filename << std::endl;
242
249
auto & subgraph_metadata = shared_context_.shared_weights .subgraph_metadata ;
243
- std::string model_name = onnxruntime::openvino_ep::BackendManager::stripAfterFirstDot (session_context_.onnx_model_path_name .filename ().string ());
250
+ std::string filename = " " ;
251
+ if (!session_context_.so_context_file_path .empty ()) {
252
+ filename = session_context_.so_context_file_path .filename ().string ();
253
+ } else if (!session_context_.onnx_model_path_name .empty ()) {
254
+ filename = session_context_.onnx_model_path_name .filename ().string ();
255
+ } else {
256
+ ORT_THROW (" Either Session_options ep.context_file_path or model path must be specified" );
257
+ }
258
+ std::string model_name = onnxruntime::openvino_ep::BackendManager::stripAfterFirstDot (filename);
244
259
auto subgraph_name = model_name + " _" + subgraph_context_.subgraph_name ;
245
260
sw::SubgraphMetadata::Map::key_type key{subgraph_name};
246
261
sw::SubgraphMetadata::Map::mapped_type value{};
247
262
248
263
auto & bin_file = shared_context_.shared_weights .shared_bin_file .bin_file_ ;
249
- std::cout << " subgraph name " << subgraph_name << " key = " << key.name << " For bin write " << std::endl;
250
264
if (!subgraph_metadata.contains (key) && bin_file.is_open ()) {
251
- // std::cout << "Current offset before "<< subgraph_context_.subgraph_name << " = " << bin_file.tellp() << std::endl;
252
- value.epctx_offset = bin_file.tellp ();
253
- std::cout << " bin file location for writing subgraph = " << bin_file.tellp () << std::endl;
265
+ value.epctx_offset = static_cast <uint64_t >(bin_file.tellp ());
254
266
bin_file << model_blob_stream.str ();
255
- // compiled_model.export_model(bin_file);
256
- // std::cout << "Current offset after "<< subgraph_context_.subgraph_name << " = " << bin_file.tellp() << std::endl;
257
- value.epctx_length = static_cast <size_t >(static_cast <std::streamoff>(bin_file.tellp ()) - value.epctx_offset );
258
- // std::cout << "Key = " << key.name << " Offset = " << value.epctx_offset << " , length = " << value.epctx_length << std::endl;
267
+ value.epctx_length = static_cast <size_t >(static_cast <uint64_t >(bin_file.tellp ()) - value.epctx_offset );
259
268
subgraph_metadata.emplace (key, std::move (value));
260
269
}
261
270
0 commit comments