Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
srirammaswamy-intel committed Sep 4, 2024
1 parent 574e82a commit 4203dcb
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions onnxruntime/core/providers/openvino/backend_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ BackendManager::BackendManager(const GlobalContext& global_context,
ep_ctx_handle_);
} catch (const OnnxRuntimeException& ex) {
std::string exception_str = ex.what();
bool enable_cpu_fallback = !GetGlobalContext().disable_cpu_fallback;
bool eligible_for_cpu_fallback = device_type.find("NPU") != std::string::npos &&
!GetGlobalContext().disable_cpu_fallback &&
!ep_ctx_handle_.IsValidOVEPCtxGraph();
#if defined(OPENVINO_DISABLE_NPU_FALLBACK)
enable_cpu_fallback = false;
#endif
if (device_type.find("NPU") != std::string::npos &&
enable_cpu_fallback && !ep_ctx_handle_.IsValidOVEPCtxGraph()) {
LOGS_DEFAULT(WARNING) << exception_str;
eligible_for_cpu_fallback = false;
#else
if (eligible_for_cpu_fallback) {
LOGS_DEFAULT(VERBOSE) << exception_str;
LOGS_DEFAULT(WARNING) << "Model compilation failed at OV NPU."
<< "Falling back to OV CPU for execution";
GetGlobalContext().device_type = "CPU";
Expand All @@ -128,26 +129,31 @@ BackendManager::BackendManager(const GlobalContext& global_context,
} catch (std::string const& msg) {
ORT_THROW(msg);
}
} else if (device_type.find("NPU") != std::string::npos &&
exception_str.find("intel_npu") != std::string::npos) {
// Handle NPU device related errors
}
#endif
if (!eligible_for_cpu_fallback) {
if (device_type.find("NPU") != std::string::npos &&
exception_str.find("intel_npu") != std::string::npos) {
// Handle NPU device related errors
#ifndef NDEBUG
ORT_THROW(exception_str + "\nModel needs to be recompiled\n");
ORT_THROW(exception_str + "\nModel needs to be recompiled\n");
#else
std::string error_message = "UNKNOWN NPU ERROR";
std::string error_code = "code 0x0";
std::regex error_message_pattern(R"(\bZE_\w*\b)");
std::regex error_code_pattern("code 0x[0-9a-fA-F]+");
std::smatch matches;
if (std::regex_search(exception_str, matches, error_message_pattern)) {
error_message = matches[0];
}
if (std::regex_search(exception_str, matches, error_code_pattern)) {
error_code = matches[0];
}
throw std::runtime_error(error_message + ", " + error_code + "\nModel needs to be recompiled\n");
#endif
std::string error_message = "UNKNOWN NPU ERROR";
std::string error_code = "code 0x0";
std::regex error_message_pattern(R"(\bZE_\w*\b)");
std::regex error_code_pattern("code 0x[0-9a-fA-F]+");
std::smatch matches;
if (std::regex_search(exception_str, matches, error_message_pattern)) {
error_message = matches[0];
}
if (std::regex_search(exception_str, matches, error_code_pattern)) {
error_code = matches[0];
} else {
ORT_THROW(exception_str);
}
throw std::runtime_error(error_message + ", " + error_code + "\nModel needs to be recompiled\n");
} else {
ORT_THROW(exception_str);
}
}
}
Expand Down

0 comments on commit 4203dcb

Please sign in to comment.