@@ -44,10 +44,6 @@ BackendManager::BackendManager(SessionContext& session_context,
44
44
shared_context_{shared_context} {
45
45
subgraph_context_.is_ep_ctx_graph = ep_ctx_handle_.CheckForOVEPCtxNodeInGraph (subgraph);
46
46
47
- bool cpu_or_gpu = session_context_.device_type .find (" CPU" ) != std::string::npos ||
48
- session_context_.device_type .find (" GPU" ) != std::string::npos;
49
- bool npu = session_context_.device_type .find (" NPU" ) != std::string::npos;
50
-
51
47
subgraph_context_.model_precision = [&](const GraphViewer& graph_viewer) {
52
48
// return empty if graph has no inputs or if types are not one of FP32/FP16
53
49
// else assume the type of the first input
@@ -112,8 +108,7 @@ BackendManager::BackendManager(SessionContext& session_context,
112
108
if (ModelHasSymbolicInputDims (subgraph)) {
113
109
subgraph_context_.has_dynamic_input_shape = true ;
114
110
LOGS_DEFAULT (INFO) << " [OpenVINO-EP] Model has symbolic input dims" ;
115
- if (cpu_or_gpu || (npu && session_context_.enable_causallm ) &&
116
- !session_context_.disable_dynamic_shapes ) {
111
+ if (!session_context_.disable_dynamic_shapes ) {
117
112
LOGS_DEFAULT (INFO) << " [OpenVINO-EP] Starting backend initialization. "
118
113
<< " Creating backend Dynamic Shapes" ;
119
114
try {
@@ -579,30 +574,34 @@ void BackendManager::ValidateInputShapes(const reshape_t& shapes,
579
574
void BackendManager::Compute (OrtKernelContext* context) {
580
575
Ort::KernelContext ctx (context);
581
576
std::chrono::high_resolution_clock::time_point start_compute, end_compute;
582
- bool cpu_or_gpu = session_context_.device_type .find (" CPU" ) != std::string::npos ||
583
- session_context_.device_type .find (" GPU" ) != std::string::npos;
584
- bool npu = session_context_.device_type .find (" NPU" ) != std::string::npos;
577
+
585
578
#ifdef OPENVINO_FIL_ENABLED
586
579
static bool fil_enabled = true ;
587
580
if (fil_enabled) {
588
581
start_compute = std::chrono::high_resolution_clock::now ();
589
582
LOGS_DEFAULT (INFO) << " Start Compute" ;
590
583
}
591
584
#endif
592
- // OV NPU doesn't support dynamic shaped model inference.
585
+
593
586
// if disable_dynamic_shapes is set to true then execution of dynamic model is done
594
587
// by rewriting the model to static shaped model at runtime based on input shape.
595
- // disable_dynamic_shapes is always set to true for OV NPU plugin.
596
- if (subgraph_context_.has_dynamic_input_shape &&
597
- !session_context_.disable_dynamic_shapes &&
598
- (cpu_or_gpu || (npu && session_context_.enable_causallm ))) {
588
+ // disable_dynamic_shapes should be set for devices that don't support dynamic shapes.
589
+ bool need_dynamic_backend = subgraph_context_.has_dynamic_input_shape &&
590
+ session_context_.disable_dynamic_shapes ;
591
+
592
+ if (!need_dynamic_backend) {
599
593
concrete_backend_->Infer (context);
600
- } else if (subgraph_context_. has_dynamic_input_shape ) {
594
+ } else {
601
595
std::vector<std::vector<int64_t >> tensor_shapes = GetInputTensorShapes (ctx);
602
596
auto key = MakeMapKeyString (tensor_shapes, session_context_.device_type );
603
597
std::shared_ptr<IBackend> dynamic_backend;
604
- auto search = backend_map_.find (key);
605
- if (search == backend_map_.end ()) {
598
+
599
+ {
600
+ std::unique_lock<std::mutex> lock (mutex_);
601
+ dynamic_backend = backend_map_[key];
602
+ }
603
+
604
+ if (!dynamic_backend) {
606
605
ptr_stream_t model_stream;
607
606
LOGS_DEFAULT (INFO) << " [OpenVINO-EP] "
608
607
<< " Creating dynamic backend for key: " << key;
@@ -643,14 +642,11 @@ void BackendManager::Compute(OrtKernelContext* context) {
643
642
}
644
643
#endif
645
644
}
645
+ std::unique_lock<std::mutex> lock (mutex_);
646
646
backend_map_.insert ({key, dynamic_backend});
647
- } else {
648
- dynamic_backend = search->second ;
649
647
}
650
648
651
649
dynamic_backend->Infer (context);
652
- } else {
653
- concrete_backend_->Infer (context);
654
650
}
655
651
#ifdef OPENVINO_FIL_ENABLED
656
652
if (fil_enabled) {
0 commit comments