Skip to content

Commit

Permalink
Update NPU device exception handling approach
Browse files Browse the repository at this point in the history
* Changes failure status code to exception (std::runtime_error)

* Capture all NPU related errors

* Throw minimal error message with error type and error code
  • Loading branch information
srirammaswamy-intel committed Aug 30, 2024
1 parent 55d4fac commit 539c7d1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions onnxruntime/core/providers/openvino/openvino_execution_provider.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (C) Intel Corporation
// Licensed under the MIT License
#include <filesystem>
#include <regex>

Check notice on line 4 in onnxruntime/core/providers/openvino/openvino_execution_provider.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] onnxruntime/core/providers/openvino/openvino_execution_provider.cc#L4

<regex> is an unapproved C++11 header. [build/c++11] [5]
Raw output
onnxruntime/core/providers/openvino/openvino_execution_provider.cc:4:  <regex> is an unapproved C++11 header.  [build/c++11] [5]
#include <utility>

#include "core/providers/shared_library/provider_api.h"
Expand Down Expand Up @@ -176,9 +177,20 @@ common::Status OpenVINOExecutionProvider::Compile(
node_compute_funcs.push_back(compute_info);
} catch (const OnnxRuntimeException& ex) {
std::string exception_str = ex.what();
if (exception_str.find("ZE_RESULT_ERROR_UNKNOWN") != std::string::npos ||
exception_str.find("ZE_RESULT_ERROR_UNINITIALIZED") != std::string::npos) {
return Status(common::ONNXRUNTIME, common::EP_FAIL, "Model needs to be recompiled");
// handle NPU device related errors
if (exception_str.find("intel_npu") != std::string::npos) {
std::string error_message = "UNKNOWN";
std::string error_code = "UNKNOWN";
std::regex error_message_pattern(R"(\b\w*ZE_\w*\b)");
std::regex error_code_pattern(R"(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");
} else {
ORT_THROW(exception_str);
}
Expand Down

0 comments on commit 539c7d1

Please sign in to comment.