You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.h 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * \file lite-c/src/common.h
  3. *
  4. * This file is part of MegEngine, a deep learning framework developed by
  5. * Megvii.
  6. *
  7. * \copyright Copyright (c) 2020-2021 Megvii Inc. All rights reserved.
  8. */
  9. #ifndef LITE_C_COMMON_H_
  10. #define LITE_C_COMMON_H_
  11. #include "../src/misc.h"
  12. #include "lite-c/network_c.h"
  13. #include "lite-c/tensor_c.h"
  14. #include "lite/network.h"
  15. #include <exception>
  16. #include <stdexcept>
  17. //! convert c Layout to lite::Layout
  18. lite::Layout convert_to_layout(const LiteLayout& layout);
  19. //! convert lite::Layout to C Layout
  20. LiteLayout convert_to_clayout(const lite::Layout& layout);
  21. //! convert c config to lite::config
  22. lite::Config convert_to_lite_config(const LiteConfig c_config);
  23. //! convert C NetworkIO io to lite::NetworkIO
  24. lite::NetworkIO convert_to_lite_io(const LiteNetworkIO c_network_io);
  25. /*!
  26. * \brief handle exception
  27. * \param e the exception
  28. * \return the return value of the error
  29. */
  30. int LiteHandleException(const std::exception& e);
  31. #if LITE_ENABLE_EXCEPTION
  32. /*! \brief macro to guard a function */
  33. #define LITE_CAPI_BEGIN() try {
  34. /*! \brief every function starts with LITE_CAPI_BEGIN();
  35. * ends with LITE_CAPI_END or LITE_CAPI_END_WITH_STMS
  36. */
  37. #define LITE_CAPI_END() \
  38. } \
  39. catch (std::exception & _except_) { \
  40. return LiteHandleException(_except_); \
  41. } \
  42. return 0;
  43. #else
  44. /*! \brief macro to guard a function */
  45. #define LITE_CAPI_BEGIN() {
  46. /*! \brief every function starts with LITE_CAPI_BEGIN();
  47. * ends with LITE_CAPI_END or LITE_CAPI_END_WITH_STMS
  48. */
  49. #define LITE_CAPI_END() \
  50. } \
  51. return 0;
  52. #endif
  53. /*!
  54. * \brief catch the exception with stms
  55. */
  56. #define LITE_CAPI_END_WITH_STMS(_stms) \
  57. } \
  58. catch (std::exception & _except_) { \
  59. _stms; \
  60. return LiteHandleException(_except_); \
  61. } \
  62. return 0;
  63. #endif
  64. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台