runtime_base.h 1.18 KB
Newer Older
1 2
/*!
 *  Copyright (c) 2016 by Contributors
3 4
 * \file runtime_base.h
 * \brief Base of all C APIs
5
 */
6 7
#ifndef TVM_RUNTIME_RUNTIME_BASE_H_
#define TVM_RUNTIME_RUNTIME_BASE_H_
8

9
#include <tvm/runtime/c_runtime_api.h>
10
#include <stdexcept>
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

/*! \brief  macro to guard beginning and end section of all functions */
#define API_BEGIN() try {
/*! \brief every function starts with API_BEGIN();
     and finishes with API_END() or API_END_HANDLE_ERROR */
#define API_END() } catch(std::runtime_error &_except_) { return TVMAPIHandleException(_except_); } return 0;  // NOLINT(*)
/*!
 * \brief every function starts with API_BEGIN();
 *   and finishes with API_END() or API_END_HANDLE_ERROR
 *   The finally clause contains procedure to cleanup states when an error happens.
 */
#define API_END_HANDLE_ERROR(Finalize) } catch(std::runtime_error &_except_) { Finalize; return TVMAPIHandleException(_except_); } return 0; // NOLINT(*)

/*!
 * \brief handle exception throwed out
 * \param e the exception
 * \return the return value of API after exception is handled
 */
inline int TVMAPIHandleException(const std::runtime_error &e) {
  TVMAPISetLastError(e.what());
  return -1;
}

34
#endif  // TVM_RUNTIME_RUNTIME_BASE_H_