1 | /* |
---|---|
2 | * SPDX-License-Identifier: Apache-2.0 |
3 | */ |
4 | |
5 | // ATTENTION: The code in this file is highly EXPERIMENTAL. |
6 | // Adventurous users should note that the APIs will probably change. |
7 | |
8 | #pragma once |
9 | #include "onnx/common/common.h" |
10 | #include "onnx/common/ir.h" |
11 | #include "onnx/onnx_pb.h" |
12 | |
13 | namespace ONNX_NAMESPACE { |
14 | |
15 | class ConvertError final : public std::runtime_error { |
16 | public: |
17 | using std::runtime_error::runtime_error; |
18 | |
19 | explicit ConvertError(const std::string& message) : std::runtime_error(message) {} |
20 | |
21 | const char* what() const noexcept override { |
22 | if (!expanded_message_.empty()) { |
23 | return expanded_message_.c_str(); |
24 | } |
25 | return std::runtime_error::what(); |
26 | } |
27 | |
28 | void AppendContext(const std::string& context) { |
29 | expanded_message_ = MakeString(std::runtime_error::what(), "\n\n==> Context: ", context); |
30 | } |
31 | |
32 | private: |
33 | std::string expanded_message_; |
34 | }; |
35 | |
36 | #define fail_convert(...) ONNX_THROW_EX(ConvertError(MakeString(__VA_ARGS__))); |
37 | |
38 | void ExportModelProto(ModelProto* p_m, const std::shared_ptr<Graph>& g); |
39 | |
40 | std::unique_ptr<Graph> ImportModelProto(const ModelProto& mp); |
41 | |
42 | ModelProto PrepareOutput(const ModelProto& mp_in); |
43 | |
44 | void assertNonNull(const std::shared_ptr<Graph>& g); |
45 | } // namespace ONNX_NAMESPACE |
46 |