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.

arch.h 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #pragma once
  2. // include general build configurations
  3. #include "megdnn/config/config.h"
  4. #if defined(__GNUC__) || defined(__clang__)
  5. #if !defined(__clang__)
  6. // gcc specific
  7. #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
  8. #if GCC_VERSION < 40800
  9. #error "GCC version should be at least 4.8.0."
  10. #endif // GCC_VERSION < 40800
  11. #endif // !defined(__clang__)
  12. #ifndef megdnn_trap
  13. #define megdnn_trap() __builtin_trap()
  14. #endif
  15. #define megdnn_likely(v) __builtin_expect(bool(v), 1)
  16. #define megdnn_unlikely(v) __builtin_expect(bool(v), 0)
  17. #if !defined(__clang__) && MEGDNN_ARMV7 && !defined(NDEBUG)
  18. //! Thumb2 limit code length
  19. #define MEGDNN_ALWAYS_INLINE
  20. #else
  21. #define MEGDNN_ALWAYS_INLINE inline __attribute__((__always_inline__))
  22. #endif
  23. #define MEGDNN_DEPRECATED __attribute__((deprecated))
  24. #define MEGDNN_PACKED __attribute__((packed))
  25. #define MEGDNN_CONSTEXPR constexpr
  26. #define MEGDNN_NOEXCEPT noexcept
  27. #define MEGDNN_STATIC_ASSERT(cond, msg) static_assert(cond, msg);
  28. #define MEGDNN_FINAL final
  29. #define MEGDNN_NORETURN __attribute__((noreturn))
  30. #define MEGDNN_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  31. #define MEGDNN_ATTRIBUTE_TARGET(simd) __attribute__((target(simd)))
  32. #if defined(__clang_major__) && (__clang_major__ >= 7)
  33. #define MEGDNN_LAMBDA_ATTRIBUTE_TARGET(simd) __attribute__((target(simd)))
  34. #else
  35. #define MEGDNN_LAMBDA_ATTRIBUTE_TARGET(simd) [[gnu::target(simd)]]
  36. #endif
  37. #define MEGDNN_NOINLINE __attribute__((noinline))
  38. #define megdnn_isatty(x) isatty(x)
  39. #elif defined(__INTEL_COMPILER) || defined(_MSC_VER)
  40. #ifndef megdnn_trap
  41. #define megdnn_trap() __debugbreak()
  42. #endif
  43. #define megdnn_likely(v) (bool(v))
  44. #define megdnn_unlikely(v) (bool(v))
  45. #define MEGDNN_DEPRECATED
  46. #define MEGDNN_PACKED
  47. #define MEGDNN_CONSTEXPR constexpr
  48. #define MEGDNN_NOEXCEPT noexcept
  49. #define MEGDNN_STATIC_ASSERT(cond, msg) static_assert(cond, msg);
  50. #define MEGDNN_FINAL final
  51. #if defined(_MSC_VER)
  52. #define MEGDNN_NORETURN __declspec(noreturn)
  53. #define MEGDNN_NOINLINE __declspec(noinline)
  54. #else
  55. #define MEGDNN_NORETURN
  56. #define MEGDNN_FORCE_NOINLINE
  57. #endif // _MSC_VER
  58. #define MEGDNN_WARN_UNUSED_RESULT
  59. #define megdnn_isatty(x) _isatty(x)
  60. #else
  61. #error "unknown compiler"
  62. #endif // __GNUC__
  63. // __cpp_exceptions and __cpp_rtti is referred from
  64. // https://isocpp.org/std/standing-documentssd-6-sg10-feature-test-recommendations
  65. // gcc < 5 does not define __cpp_exceptions but __EXCEPTIONS,
  66. // similar for __GXX_RTTI
  67. // _CPPUNWIND and _CPPRTTI is used by MSVC, see
  68. // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macrosview=vs-2019
  69. #ifndef MEGDNN_ENABLE_EXCEPTIONS
  70. #if __cpp_exceptions || __EXCEPTIONS || (defined(_MSC_VER) && defined(_CPPUNWIND))
  71. #define MEGDNN_ENABLE_EXCEPTIONS 1
  72. #else
  73. #define MEGDNN_ENABLE_EXCEPTIONS 0
  74. #endif
  75. #endif
  76. #ifndef MEGDNN_ENABLE_RTTI
  77. #if __cpp_rtti || __GXX_RTTI || (defined(_MSC_VER) && defined(_CPPRTTI))
  78. #define MEGDNN_ENABLE_RTTI 1
  79. #else
  80. #define MEGDNN_ENABLE_RTTI 0
  81. #endif
  82. #endif
  83. #ifdef __CUDACC__
  84. #define MEGDNN_CC_CUDA 1
  85. #undef MEGDNN_CONSTEXPR
  86. #define MEGDNN_CONSTEXPR const
  87. #if defined(__CUDACC_VER_MAJOR__)
  88. #if __CUDACC_VER_MAJOR__ >= 9
  89. #undef MEGDNN_STATIC_ASSERT
  90. #define MEGDNN_STATIC_ASSERT(cond, msg) static_assert(cond, msg);
  91. #else
  92. #undef MEGDNN_STATIC_ASSERT
  93. #define MEGDNN_STATIC_ASSERT(cond, msg)
  94. #endif
  95. #endif
  96. #define nullptr NULL
  97. #undef MEGDNN_FINAL
  98. #define MEGDNN_FINAL
  99. #elif defined(__HIPCC__)
  100. #define MEGDNN_CC_CUDA 1
  101. #else
  102. #define MEGDNN_CC_HOST 1
  103. #endif // __CUDACC__
  104. // MEGDNN_HOST and MEGDNN_DEVICE
  105. #if MEGDNN_CC_CUDA
  106. #define MEGDNN_HOST __host__
  107. #define MEGDNN_DEVICE __device__
  108. #else
  109. #define MEGDNN_HOST
  110. #define MEGDNN_DEVICE
  111. #endif
  112. #if MEGDNN_CC_CUDA
  113. #define MEGDNN_FORCE_INLINE __forceinline__
  114. #else
  115. #if __GNUC__ || __has_attribute(always_inline)
  116. #define MEGDNN_FORCE_INLINE inline __attribute__((always_inline))
  117. #else
  118. #define MEGDNN_FORCE_INLINE inline
  119. #endif
  120. #endif
  121. #if defined(_MSC_VER) || defined(WIN32)
  122. #define ATTR_ALIGNED(v) __declspec(align(v))
  123. #else
  124. #define ATTR_ALIGNED(v) __attribute__((aligned(v)))
  125. #endif
  126. // vim: syntax=cpp.doxygen