@@ -77,8 +77,15 @@ BackendManager::BackendManager(SessionContext& session_context,
7777 ptr_stream_t model_stream;
7878 std::unique_ptr<onnx::ModelProto> model_proto;
7979 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);
8289 auto subgraph_name = model_name + " _" + subgraph_context_.subgraph_name ;
8390 model_stream = ep_ctx_handle_.GetModelBlobStream (shared_context_,
8491 session_context_.so_context_file_path ,
@@ -103,9 +110,9 @@ BackendManager::BackendManager(SessionContext& session_context,
103110 if (!sw.mapped_weights ) {
104111 sw.mapped_weights = std::make_unique<SharedContext::SharedWeights::WeightsFile>(weight_filename);
105112 }
106- std::cout << " Call createOVTensors in backend_manager.cc" << std::endl;
107113 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 " );
109116 }
110117 }
111118
@@ -207,11 +214,16 @@ BackendManager::BackendManager(SessionContext& session_context,
207214}
208215
209216std::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) {
212220 return filename; // No dot found, return full filename
213221 }
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;
215227}
216228
217229// Call EPContext model exporter here if the provider option for exporting
@@ -227,36 +239,33 @@ Status BackendManager::ExportCompiledBlobAsEPCtxNode(const onnxruntime::GraphVie
227239 ORT_THROW (exception_str);
228240 }
229241
230- std::cout << " inside export compiled model " << std::endl;
231-
232242 // If embed_mode, then pass on the serialized blob
233243 // If not embed_mode, dump the blob here and only pass on the path to the blob
234244 std::string model_blob_str;
235245 auto compiled_model = concrete_backend_->GetOVCompiledModel ();
236246 if (session_context_.so_share_ep_contexts ) {
237247 std::ostringstream model_blob_stream;
238248 compiled_model.export_model (model_blob_stream);
239- std::cout << " inside export compiled model - share ep contexts" << std::endl;
240249
241- // std::ofstream file(metadata_filename, std::ios::app| std::ios::binary);
242- // std::cout << " write to metadata bin - " << metadata_filename << std::endl;
243250 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);
245260 auto subgraph_name = model_name + " _" + subgraph_context_.subgraph_name ;
246261 sw::SubgraphMetadata::Map::key_type key{subgraph_name};
247262 sw::SubgraphMetadata::Map::mapped_type value{};
248263
249264 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;
251265 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 ());
255267 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 );
260269 subgraph_metadata.emplace (key, std::move (value));
261270 }
262271
0 commit comments