forked from microsoft/onnxruntime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request microsoft#23 from NonStatic2014/bohu/generate_prot…
…obuf_status Create a mapping from ONNX Runtime Status to Protobuf Status
- Loading branch information
Showing
4 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#include <sstream> | ||
#include <google/protobuf/stubs/status.h> | ||
|
||
#include "core/common/status.h" | ||
#include "util.h" | ||
|
||
namespace onnxruntime { | ||
namespace hosting { | ||
|
||
namespace protobufutil = google::protobuf::util; | ||
|
||
protobufutil::Status GenerateProtoBufStatus(const onnxruntime::common::Status& onnx_status, const std::string& message) { | ||
protobufutil::error::Code code = protobufutil::error::Code::UNKNOWN; | ||
switch (onnx_status.Code()) { | ||
case onnxruntime::common::StatusCode::OK: | ||
case onnxruntime::common::StatusCode::MODEL_LOADED: | ||
code = protobufutil::error::Code::OK; | ||
break; | ||
case onnxruntime::common::StatusCode::INVALID_ARGUMENT: | ||
case onnxruntime::common::StatusCode::INVALID_PROTOBUF: | ||
case onnxruntime::common::StatusCode::INVALID_GRAPH: | ||
case onnxruntime::common::StatusCode::SHAPE_INFERENCE_NOT_REGISTERED: | ||
case onnxruntime::common::StatusCode::REQUIREMENT_NOT_REGISTERED: | ||
case onnxruntime::common::StatusCode::NO_SUCHFILE: | ||
case onnxruntime::common::StatusCode::NO_MODEL: | ||
code = protobufutil::error::Code::INVALID_ARGUMENT; | ||
break; | ||
case onnxruntime::common::StatusCode::NOT_IMPLEMENTED: | ||
code = protobufutil::error::Code::UNIMPLEMENTED; | ||
break; | ||
case onnxruntime::common::StatusCode::FAIL: | ||
case onnxruntime::common::StatusCode::RUNTIME_EXCEPTION: | ||
code = protobufutil::error::Code::INTERNAL; | ||
break; | ||
default: | ||
code = protobufutil::error::Code::UNKNOWN; | ||
} | ||
|
||
std::ostringstream oss; | ||
oss << "ONNX Runtime Status Code: " << onnx_status.Code() << ". " << message; | ||
return protobufutil::Status(code, oss.str()); | ||
} | ||
|
||
} // namespace hosting | ||
} // namespace onnxruntime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#ifndef ONNXRUNTIME_HOSTING_UTIL_H | ||
#define ONNXRUNTIME_HOSTING_UTIL_H | ||
|
||
#include <google/protobuf/stubs/status.h> | ||
|
||
#include "core/common/status.h" | ||
|
||
namespace onnxruntime { | ||
namespace hosting { | ||
|
||
// Generate proper protobuf status from ONNX Runtime status | ||
google::protobuf::util::Status GenerateProtoBufStatus(const onnxruntime::common::Status& onnx_status, const std::string& message); | ||
|
||
} // namespace hosting | ||
} // namespace onnxruntime | ||
|
||
#endif //ONNXRUNTIME_HOSTING_UTIL_H |