1+ #pragma once
2+
3+ #include " onnxruntime_cxx_api.h"
4+
5+ #include " flatbuffers/idl.h"
6+ #include " ort_trt_int8_cal_table.fbs.h"
7+ #include " make_string.h"
8+ // #include "core/providers/cuda/cuda_pch.h"
9+ // #include "core/common/path_string.h"
10+ // #include "core/framework/murmurhash3.h"
11+
12+ // #include"nv_includes.h"
13+ #include " gsl/narrow"
14+
15+ #include < fstream>
16+ #include < unordered_map>
17+ #include < string>
18+ #include < vector>
19+ #include < sstream>
20+ #include < iostream>
21+ #include < filesystem>
22+
23+ struct ApiPtrs {
24+ const OrtApi& ort_api;
25+ const OrtEpApi& ep_api;
26+ const OrtModelEditorApi& model_editor_api;
27+ };
28+
29+ #define ENFORCE (condition, ...) \
30+ do { \
31+ if (!(condition)) { \
32+ throw std::runtime_error (MakeString (__VA_ARGS__)); \
33+ } \
34+ } while (false )
35+
36+ #define THROW (...) \
37+ throw std::runtime_error (MakeString(__VA_ARGS__));
38+
39+ #define RETURN_IF_ERROR (fn ) \
40+ do { \
41+ OrtStatus* _status = (fn); \
42+ if (_status != nullptr ) { \
43+ return _status; \
44+ } \
45+ } while (0 )
46+
47+ /*
48+ template <typename... Args>
49+ std::string ComposeString(Args&&... args) {
50+ std::ostringstream oss;
51+ (oss << ... << args);
52+ return oss.str();
53+ };
54+ */
55+
56+ #define RETURN_IF (cond, ...) \
57+ do { \
58+ if ((cond)) { \
59+ return Ort::GetApi ().CreateStatus (ORT_EP_FAIL, MakeString (__VA_ARGS__).c_str ()); \
60+ } \
61+ } while (0 )
62+
63+ #define RETURN_IF_NOT (condition, ...) RETURN_IF(!(condition), __VA_ARGS__)
64+
65+ #define MAKE_STATUS (error_code, msg ) \
66+ Ort::GetApi ().CreateStatus(error_code, (msg));
67+
68+ #define THROW_IF_ERROR (expr ) \
69+ do { \
70+ auto _status = (expr); \
71+ if (_status != nullptr ) { \
72+ std::ostringstream oss; \
73+ oss << Ort::GetApi ().GetErrorMessage (_status); \
74+ Ort::GetApi ().ReleaseStatus (_status); \
75+ throw std::runtime_error (oss.str ()); \
76+ } \
77+ } while (0 )
78+
79+ #define RETURN_FALSE_AND_PRINT_IF_ERROR (fn ) \
80+ do { \
81+ OrtStatus* status = (fn); \
82+ if (status != nullptr ) { \
83+ std::cerr << Ort::GetApi ().GetErrorMessage (status) << std::endl; \
84+ return false ; \
85+ } \
86+ } while (0 )
87+
88+ // Helper to release Ort one or more objects obtained from the public C API at the end of their scope.
89+ template <typename T>
90+ struct DeferOrtRelease {
91+ DeferOrtRelease (T** object_ptr, std::function<void (T*)> release_func)
92+ : objects_(object_ptr), count_(1 ), release_func_(release_func) {}
93+
94+ DeferOrtRelease (T** objects, size_t count, std::function<void (T*)> release_func)
95+ : objects_(objects), count_(count), release_func_(release_func) {}
96+
97+ ~DeferOrtRelease () {
98+ if (objects_ != nullptr && count_ > 0 ) {
99+ for (size_t i = 0 ; i < count_; ++i) {
100+ if (objects_[i] != nullptr ) {
101+ release_func_ (objects_[i]);
102+ objects_[i] = nullptr ;
103+ }
104+ }
105+ }
106+ }
107+ T** objects_ = nullptr ;
108+ size_t count_ = 0 ;
109+ std::function<void (T*)> release_func_ = nullptr ;
110+ };
111+
112+ template <typename T>
113+ using AllocatorUniquePtr = std::unique_ptr<T, std::function<void (T*)>>;
0 commit comments