@@ -76,8 +76,15 @@ BackendManager::BackendManager(SessionContext& session_context,
7676 ptr_stream_t model_stream;
7777 std::unique_ptr<onnx::ModelProto> model_proto;
7878 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);
8188 auto subgraph_name = model_name + " _" + subgraph_context_.subgraph_name ;
8289 model_stream = ep_ctx_handle_.GetModelBlobStream (shared_context_,
8390 session_context_.so_context_file_path ,
@@ -102,9 +109,9 @@ BackendManager::BackendManager(SessionContext& session_context,
102109 if (!sw.mapped_weights ) {
103110 sw.mapped_weights = std::make_unique<SharedContext::SharedWeights::WeightsFile>(weight_filename);
104111 }
105- std::cout << " Call createOVTensors in backend_manager.cc" << std::endl;
106112 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 " );
108115 }
109116 }
110117
@@ -206,11 +213,16 @@ BackendManager::BackendManager(SessionContext& session_context,
206213}
207214
208215std::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) {
211219 return filename; // No dot found, return full filename
212220 }
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;
214226}
215227
216228// Call EPContext model exporter here if the provider option for exporting
@@ -226,36 +238,33 @@ Status BackendManager::ExportCompiledBlobAsEPCtxNode(const onnxruntime::GraphVie
226238 ORT_THROW (exception_str);
227239 }
228240
229- std::cout << " inside export compiled model " << std::endl;
230-
231241 // If embed_mode, then pass on the serialized blob
232242 // If not embed_mode, dump the blob here and only pass on the path to the blob
233243 std::string model_blob_str;
234244 auto compiled_model = concrete_backend_->GetOVCompiledModel ();
235245 if (session_context_.so_share_ep_contexts ) {
236246 std::ostringstream model_blob_stream;
237247 compiled_model.export_model (model_blob_stream);
238- std::cout << " inside export compiled model - share ep contexts" << std::endl;
239248
240- // std::ofstream file(metadata_filename, std::ios::app| std::ios::binary);
241- // std::cout << " write to metadata bin - " << metadata_filename << std::endl;
242249 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);
244259 auto subgraph_name = model_name + " _" + subgraph_context_.subgraph_name ;
245260 sw::SubgraphMetadata::Map::key_type key{subgraph_name};
246261 sw::SubgraphMetadata::Map::mapped_type value{};
247262
248263 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;
250264 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 ());
254266 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 );
259268 subgraph_metadata.emplace (key, std::move (value));
260269 }
261270
0 commit comments