Skip to content

Commit b602f47

Browse files
Support workload type for dynamic shaped models (#690)
1 parent 1a22a57 commit b602f47

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

onnxruntime/core/providers/openvino/backend_manager.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ SessionContext& BackendManager::GetSessionContext() {
2828
return session_context_;
2929
}
3030

31-
ov::CompiledModel& BackendManager::GetOVCompiledModel() {
32-
ov::CompiledModel& ov_ptr = concrete_backend_->GetOVCompiledModel();
33-
return (ov_ptr);
31+
ov::CompiledModel BackendManager::GetOVCompiledModel() {
32+
if (concrete_backend_)
33+
return concrete_backend_->GetOVCompiledModel();
34+
return ov::CompiledModel();
3435
}
3536

3637
BackendManager::BackendManager(SessionContext& session_context,

onnxruntime/core/providers/openvino/backend_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BackendManager {
2929
void ShutdownBackendManager();
3030
SessionContext& GetSessionContext();
3131
Status ExportCompiledBlobAsEPCtxNode(const onnxruntime::GraphViewer& subgraph);
32-
ov::CompiledModel& GetOVCompiledModel();
32+
ov::CompiledModel GetOVCompiledModel();
3333

3434
private:
3535
std::unique_ptr<ONNX_NAMESPACE::ModelProto> GetModelProtoFromFusedNode(

onnxruntime/core/providers/openvino/backends/basic_backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class BasicBackend : public IBackend {
8282

8383
void Infer(OrtKernelContext* context) override;
8484
~BasicBackend() override = default;
85-
ov::CompiledModel& GetOVCompiledModel() override {
85+
ov::CompiledModel GetOVCompiledModel() override {
8686
return exe_network_.Get();
8787
}
8888

onnxruntime/core/providers/openvino/ibackend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace openvino_ep {
1515
class IBackend {
1616
public:
1717
virtual void Infer(OrtKernelContext* context) = 0;
18-
virtual ov::CompiledModel& GetOVCompiledModel() = 0;
18+
virtual ov::CompiledModel GetOVCompiledModel() = 0;
1919
virtual ~IBackend() = default;
2020
};
2121
using ptr_stream_t = std::unique_ptr<std::istream>;

onnxruntime/core/providers/openvino/openvino_execution_provider.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,20 @@ common::Status OpenVINOExecutionProvider::SetEpDynamicOptions(gsl::span<const ch
238238
LOGS_DEFAULT(WARNING) << "Supported types are 'Efficient' and 'Default' \n";
239239
}
240240
if (workload_type != "") {
241-
LOGS_DEFAULT(INFO) << "SetEpDynamicOptions - modifying: " << key << "/" << value;
241+
LOGS_DEFAULT(VERBOSE) << "SetEpDynamicOptions - modifying: " << key << "/" << value;
242242
for (auto& backend : backend_managers_) {
243-
ov::CompiledModel& ov_compiled_model = backend.GetOVCompiledModel();
244-
ov_compiled_model.set_property(ov::workload_type(workload_type));
243+
ov::CompiledModel ov_compiled_model = backend.GetOVCompiledModel();
244+
if(ov_compiled_model) {
245+
ov_compiled_model.set_property(ov::workload_type(workload_type));
246+
} else {
247+
LOGS_DEFAULT(VERBOSE) << "Model is not compiled in OV as its dynamic";
248+
ov::AnyMap map;
249+
map["WORKLOAD_TYPE"] = workload_type;
250+
if (session_context_.device_type == "NPU")
251+
session_context_.load_config["NPU"] = std::move(map);
252+
else
253+
ORT_THROW(" WORKLOAD_TYPE property is supported only for NPU");
254+
}
245255
}
246256
}
247257
} else {

0 commit comments

Comments
 (0)