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