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.6 kB

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

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