Skip to content

Commit 4ce358f

Browse files
committed
Address review comments
1 parent ba2f69a commit 4ce358f

File tree

3 files changed

+360
-390
lines changed

3 files changed

+360
-390
lines changed

onnxruntime/core/providers/openvino/backend_manager.cc

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -158,39 +158,11 @@ BackendManager::BackendManager(SessionContext& session_context,
158158
subgraph_context_.has_dynamic_input_shape = false;
159159

160160
// OV NPU plugin is supported with fallback to OV CPU upon compilation failures.
161-
try {
162-
concrete_backend_ = BackendFactory::MakeBackend(model_proto,
163-
session_context_,
164-
subgraph_context_,
165-
*shared_context_,
166-
model_stream);
167-
} catch (const ovep_exception& ex) {
168-
#ifndef OPENVINO_DISABLE_NPU_FALLBACK
169-
bool eligible_for_cpu_fallback = session_context_.device_type.find("NPU") != std::string::npos &&
170-
!session_context_.so_disable_cpu_ep_fallback &&
171-
!subgraph_context_.is_ep_ctx_graph;
172-
if (eligible_for_cpu_fallback) {
173-
std::string exception_str = ex.what();
174-
LOGS_DEFAULT(VERBOSE) << exception_str;
175-
LOGS_DEFAULT(WARNING) << "Model compilation failed at OV NPU."
176-
<< "Falling back to OV CPU for execution";
177-
session_context_.device_type = "CPU";
178-
session_context_.precision = "FP32";
179-
try {
180-
concrete_backend_ = BackendFactory::MakeBackend(model_proto,
181-
session_context_,
182-
subgraph_context_,
183-
shared_context_,
184-
model_stream);
185-
} catch (std::string const& msg) {
186-
ORT_THROW(msg);
187-
}
188-
} else
189-
#endif
190-
{
191-
throw ex;
192-
}
193-
}
161+
concrete_backend_ = BackendFactory::MakeBackend(model_proto,
162+
session_context_,
163+
subgraph_context_,
164+
*shared_context_,
165+
model_stream);
194166
}
195167

196168
if (ShouldExportEpContext(session_context_, subgraph_context_)) {

onnxruntime/core/providers/openvino/exceptions.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ struct ovep_exception : public std::exception {
2121
unknown,
2222
};
2323

24-
ovep_exception(const std::string& message,
25-
enum class type type) : message_{message},
26-
type_{type},
27-
error_code_{ze_result_code_from_string(message)},
28-
error_name_{ze_result_name_from_string(message)} {}
24+
ovep_exception(const std::exception& ex, enum class type exception_type)
25+
: message_{ex.what()},
26+
type_{exception_type},
27+
error_code_{ze_result_code_from_string(message_)},
28+
error_name_{ze_result_name_from_string(message_)} {}
29+
30+
ovep_exception(const std::string& message, enum class type exception_type)
31+
: message_{message},
32+
type_{exception_type},
33+
error_code_{ze_result_code_from_string(message)},
34+
error_name_{ze_result_name_from_string(message)} {}
2935

3036
const char* what() const noexcept override {
3137
return message_.data();
@@ -48,7 +54,7 @@ struct ovep_exception : public std::exception {
4854
}
4955

5056
std::string error_message = "Unhandled exception type: " + std::to_string(static_cast<int>(type_));
51-
return {category_ort, common::FAIL, error_message};
57+
return {category_ort, common::EP_FAIL, error_message};
5258
}
5359

5460
protected:

0 commit comments

Comments
 (0)