30 #include <type_traits> 
   31 #include <unordered_map> 
   40 namespace onnxruntime {
 
   42 using TimePoint = std::chrono::high_resolution_clock::time_point;
 
   45 #define ORT_UNUSED_PARAMETER(x) (x) 
   47 #define ORT_UNUSED_PARAMETER(x) (void)(x) 
   50 #ifndef ORT_HAVE_ATTRIBUTE 
   51 #ifdef __has_attribute 
   52 #define ORT_HAVE_ATTRIBUTE(x) __has_attribute(x) 
   54 #define ORT_HAVE_ATTRIBUTE(x) 0 
   62 #if ORT_HAVE_ATTRIBUTE(unused) || (defined(__GNUC__) && !defined(__clang__)) 
   63 #undef ORT_ATTRIBUTE_UNUSED 
   64 #define ORT_ATTRIBUTE_UNUSED __attribute__((__unused__)) 
   66 #define ORT_ATTRIBUTE_UNUSED 
   69 #ifdef ORT_NO_EXCEPTIONS 
   74 void PrintFinalMessage(
const char* msg);
 
   78 #define ORT_IGNORE_RETURN_VALUE(fn) \ 
   84                      const char* 
function, uint32_t line);
 
   88 #if (_MSC_VER && !defined(__PRETTY_FUNCTION__)) 
   89 #define __PRETTY_FUNCTION__ __FUNCTION__ 
   93 #define ORT_WHERE ::onnxruntime::CodeLocation(__FILE__, __LINE__, static_cast<const char*>(__FUNCTION__)) 
   95 #define ORT_WHERE_WITH_STACK \ 
   96   ::onnxruntime::CodeLocation(__FILE__, __LINE__, static_cast<const char*>(__PRETTY_FUNCTION__), ::onnxruntime::GetStackTrace()) 
   98 #ifdef ORT_NO_EXCEPTIONS 
  100 #define ORT_TRY if (true) 
  101 #define ORT_CATCH(x) else if (false) 
  107 #define ORT_HANDLE_EXCEPTION(func) 
  112 #define ORT_THROW(...)                                                    \ 
  114     ::onnxruntime::PrintFinalMessage(                                     \ 
  115         ::onnxruntime::OnnxRuntimeException(                              \ 
  116             ORT_WHERE_WITH_STACK, ::onnxruntime::MakeString(__VA_ARGS__)) \ 
  122 #define ORT_NOT_IMPLEMENTED(...)                                                       \ 
  124     ::onnxruntime::PrintFinalMessage(                                                  \ 
  125         ::onnxruntime::NotImplementedException(::onnxruntime::MakeString(__VA_ARGS__)) \ 
  133 #define ORT_ENFORCE(condition, ...)                                                   \ 
  135     if (!(condition)) {                                                               \ 
  136       ::onnxruntime::PrintFinalMessage(                                               \ 
  137           ::onnxruntime::OnnxRuntimeException(ORT_WHERE_WITH_STACK, #condition,       \ 
  138                                               ::onnxruntime::MakeString(__VA_ARGS__)) \ 
  144 #define ORT_THROW_EX(ex, ...)                                                                      \ 
  146     ::onnxruntime::PrintFinalMessage(                                                              \ 
  147         ::onnxruntime::MakeString(#ex, "(", ::onnxruntime::MakeString(__VA_ARGS__), ")").c_str()); \ 
  154 #define ORT_CATCH(x) catch (x) 
  155 #define ORT_RETHROW throw; 
  157 #define ORT_HANDLE_EXCEPTION(func) func() 
  162 #define ORT_THROW(...) \ 
  163   throw ::onnxruntime::OnnxRuntimeException(ORT_WHERE_WITH_STACK, ::onnxruntime::MakeString(__VA_ARGS__)) 
  166 #define ORT_NOT_IMPLEMENTED(...) \ 
  167   throw ::onnxruntime::NotImplementedException(::onnxruntime::MakeString(__VA_ARGS__)) 
  172 #define ORT_ENFORCE(condition, ...)                                                      \ 
  174     if (!(condition)) {                                                                  \ 
  175       throw ::onnxruntime::OnnxRuntimeException(ORT_WHERE_WITH_STACK, #condition,        \ 
  176                                                 ::onnxruntime::MakeString(__VA_ARGS__)); \ 
  180 #define ORT_THROW_EX(ex, ...) \ 
  181   throw ex(__VA_ARGS__) 
  185 #define ORT_MAKE_STATUS(category, code, ...)                     \ 
  186   ::onnxruntime::common::Status(::onnxruntime::common::category, \ 
  187                                 ::onnxruntime::common::code,     \ 
  188                                 ::onnxruntime::MakeString(__VA_ARGS__)) 
  191 #define ORT_RETURN_IF(condition, ...)                                                                          \ 
  194       return ::onnxruntime::common::Status(::onnxruntime::common::ONNXRUNTIME,                                 \ 
  195                                            ::onnxruntime::common::FAIL,                                        \ 
  196                                            ::onnxruntime::MakeString(ORT_WHERE.ToString(), " ", __VA_ARGS__)); \ 
  201 #define ORT_RETURN_IF_NOT(condition, ...) \ 
  202   ORT_RETURN_IF(!(condition), __VA_ARGS__) 
  207 #define ORT_DISALLOW_COPY(TypeName) TypeName(const TypeName&) = delete 
  209 #define ORT_DISALLOW_ASSIGNMENT(TypeName) TypeName& operator=(const TypeName&) = delete 
  211 #define ORT_DISALLOW_COPY_AND_ASSIGNMENT(TypeName) \ 
  212   ORT_DISALLOW_COPY(TypeName);                     \ 
  213   ORT_DISALLOW_ASSIGNMENT(TypeName) 
  215 #define ORT_DISALLOW_MOVE(TypeName) \ 
  216   TypeName(TypeName&&) = delete;    \ 
  217   TypeName& operator=(TypeName&&) = delete 
  219 #define ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(TypeName) \ 
  220   ORT_DISALLOW_COPY_AND_ASSIGNMENT(TypeName);           \ 
  221   ORT_DISALLOW_MOVE(TypeName) 
  223 #define ORT_RETURN_IF_ERROR_SESSIONID(expr, session_id)                                                                \ 
  225     auto _status = (expr);                                                                                             \ 
  226     if ((!_status.IsOK())) {                                                                                           \ 
  227       ::onnxruntime::LogRuntimeError(session_id, _status, __FILE__, static_cast<const char*>(__FUNCTION__), __LINE__); \ 
  232 #define ORT_RETURN_IF_ERROR_SESSIONID_(expr) ORT_RETURN_IF_ERROR_SESSIONID(expr, session_id_) 
  233 #define ORT_RETURN_IF_ERROR(expr) ORT_RETURN_IF_ERROR_SESSIONID(expr, 0) 
  235 #define ORT_THROW_IF_ERROR(expr)                                                                              \ 
  237     auto _status = (expr);                                                                                    \ 
  238     if ((!_status.IsOK())) {                                                                                  \ 
  239       ::onnxruntime::LogRuntimeError(0, _status, __FILE__, static_cast<const char*>(__FUNCTION__), __LINE__); \ 
  240       ORT_THROW(_status);                                                                                     \ 
  245 #define ORT_CHECK_AND_SET_RETVAL(expr) \ 
  247     if (retval.IsOK()) {               \ 
  253   auto end_time = std::chrono::high_resolution_clock::now();
 
  254   return std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).
count();
 
  258   return std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).
count();
 
  270 inline std::wstring 
ToWideString(
const std::wstring& 
s) { 
return s; }
 
  279 template <
typename Key, 
typename... OtherContainerArgs,
 
  280           template <
typename...> 
typename AssociativeContainer,
 
  282 inline bool Contains(
const AssociativeContainer<Key, OtherContainerArgs...>& container, LookupKey&& key) {
 
  283   return container.find(std::forward<LookupKey>(key)) != container.end();
 
bool Contains(const AssociativeContainer< Key, OtherContainerArgs...> &container, LookupKey &&key)
 
long long TimeDiffMicroSeconds(TimePoint start_time)
 
std::chrono::high_resolution_clock::time_point TimePoint
 
std::string ToWideString(const std::string &s)
 
void LogRuntimeError(uint32_t session_id, const common::Status &status, const char *file, const char *function, uint32_t line)
 
std::string ToUTF8String(const std::string &s)
 
constexpr size_t kMaxStrLen
 
std::vector< std::string > GetStackTrace()