@@ -43,30 +43,18 @@ static bool ShouldExportEpContext(const SessionContext& session_context, const S
4343}
4444
4545BackendManager::BackendManager (SessionContext& session_context,
46- SharedContextManager& shared_context_manager ,
46+ SharedContext& shared_context ,
4747 const onnxruntime::Node& fused_node,
4848 const onnxruntime::GraphViewer& subgraph,
4949 const logging::Logger& logger,
5050 EPCtxHandler& ep_ctx_handle) : ep_ctx_handle_(ep_ctx_handle),
5151 session_context_ (session_context),
52- shared_context_manager_(shared_context_manager ) {
52+ shared_context_(shared_context ) {
5353 subgraph_context_.is_ep_ctx_graph = ep_ctx_handle_.CheckForOVEPCtxNodeInGraph (subgraph);
5454 // If the graph contains a OVIR wrapped node, we check if it has matching xml file name attribute
5555 subgraph_context_.is_ep_ctx_ovir_encapsulated = ep_ctx_handle_.CheckEPCacheContextAttribute (subgraph,
5656 session_context_.onnx_model_path_name .filename ().replace_extension (" xml" ).string ());
5757
58- if (subgraph_context_.is_ep_ctx_graph && !subgraph_context_.is_ep_ctx_ovir_encapsulated ) {
59- shared_context_ = ep_ctx_handle.GetSharedContextForEpContextSubgraph (subgraph,
60- session_context_.GetModelPath ());
61- } else if (session_context_.so_context_enable && session_context_.so_share_ep_contexts ) {
62- shared_context_ = shared_context_manager_.GetOrCreateActiveSharedContext (session_context_.GetOutputBinPath ());
63- } else {
64- // Creating a shared context to satisfy backend. It won't be used for weight sharing.
65- // Don't make it the active share context since we don't actually want to share it.
66- shared_context_ = shared_context_manager_.GetOrCreateSharedContext (session_context_.GetOutputBinPath ());
67- }
68- ORT_ENFORCE (shared_context_, " Could not create a shared context." );
69-
7058 subgraph_context_.model_precision = [&](const GraphViewer& graph_viewer) {
7159 // return empty if graph has no inputs or if types are not one of FP32/FP16
7260 // else assume the type of the first input
@@ -138,7 +126,7 @@ BackendManager::BackendManager(SessionContext& session_context,
138126 concrete_backend_ = BackendFactory::MakeBackend (model_proto,
139127 session_context_,
140128 subgraph_context_,
141- * shared_context_,
129+ shared_context_,
142130 model_stream);
143131 } catch (std::string const & msg) {
144132 ORT_THROW (msg);
@@ -161,13 +149,13 @@ BackendManager::BackendManager(SessionContext& session_context,
161149 concrete_backend_ = BackendFactory::MakeBackend (model_proto,
162150 session_context_,
163151 subgraph_context_,
164- * shared_context_,
152+ shared_context_,
165153 model_stream);
166154 }
167155
168156 if (ShouldExportEpContext (session_context_, subgraph_context_)) {
169157 if (concrete_backend_) {
170- shared_context_-> AddNativeBlob (subgraph_context_.subgraph_name , concrete_backend_->GetOVCompiledModel ());
158+ shared_context_. AddNativeBlob (subgraph_context_.subgraph_name , concrete_backend_->GetOVCompiledModel ());
171159 } else {
172160 ORT_THROW (
173161 " Exporting dynamically compiled models at runtime is not supported. "
@@ -193,19 +181,11 @@ void BackendManager::TryExportCompiledBlobAsEPCtxNode(const onnxruntime::GraphVi
193181 if (session_context_.so_context_embed_mode ) { // Internal blob
194182 if (include_embed_data) {
195183 std::stringstream ss;
196- shared_context_-> Serialize (ss);
184+ shared_context_. Serialize (ss);
197185 model_blob_str = std::move (ss).str ();
198186 }
199187 } else { // External blob
200- // Build name by combining EpCtx model name (if available) and subgraph name. Model
201- // name is not available in when creating a session from memory
202- auto name = session_context_.so_context_file_path .stem ().string ();
203- if (name.empty () && !graph_body_viewer.ModelPath ().empty ()) {
204- name = graph_body_viewer.ModelPath ().stem ().string ();
205- }
206- ORT_ENFORCE (!name.empty ());
207-
208- model_blob_str = shared_context_->GetBinPath ().filename ().string ();
188+ model_blob_str = shared_context_.GetBinPath ().filename ().string ();
209189 }
210190
211191 auto status = ep_ctx_handle_.AddOVEPCtxNodeToGraph (graph_body_viewer,
@@ -521,7 +501,7 @@ BackendManager::GetModelProtoFromFusedNode(const onnxruntime::Node& fused_node,
521501 if ((session_context_.device_type .find (" NPU" ) != std::string::npos) &&
522502 (enable_ovep_qdq_optimizer || session_context_.so_share_ep_contexts )) {
523503 std::unique_ptr<onnxruntime::Model> model;
524- Status status = CreateModelWithStrippedQDQNodes (subgraph, logger, session_context_.so_share_ep_contexts , enable_ovep_qdq_optimizer, model, * shared_context_);
504+ Status status = CreateModelWithStrippedQDQNodes (subgraph, logger, session_context_.so_share_ep_contexts , enable_ovep_qdq_optimizer, model, shared_context_);
525505 auto model_proto = model->ToProto ();
526506 model_proto->set_ir_version (ONNX_NAMESPACE::Version::IR_VERSION);
527507 print_model_proto_duration ();
@@ -788,7 +768,7 @@ void BackendManager::Compute(OrtKernelContext* context) {
788768 dynamic_backend = BackendFactory::MakeBackend (modelproto_with_concrete_shapes,
789769 session_context_,
790770 subgraph_context_,
791- * shared_context_,
771+ shared_context_,
792772 model_stream);
793773 } catch (const OnnxRuntimeException& ex) {
794774 // Build option disables fallback to CPU on compilation failures with NPU.
@@ -808,7 +788,7 @@ void BackendManager::Compute(OrtKernelContext* context) {
808788 dynamic_backend = BackendFactory::MakeBackend (modelproto_with_concrete_shapes,
809789 session_context_,
810790 subgraph_context_,
811- * shared_context_,
791+ shared_context_,
812792 model_stream);
813793 } catch (std::string const & msg) {
814794 ORT_THROW (msg);
0 commit comments