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 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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-2020 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. #define MEGDNN_DEPRECATED __attribute__((deprecated))
  28. #define MEGDNN_PACKED __attribute__((packed))
  29. #define MEGDNN_CONSTEXPR constexpr
  30. #define MEGDNN_NOEXCEPT noexcept
  31. #define MEGDNN_STATIC_ASSERT static_assert
  32. #define MEGDNN_FINAL final
  33. #define MEGDNN_NORETURN __attribute__((noreturn))
  34. #define MEGDNN_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  35. #define MEGDNN_ATTRIBUTE_TARGET(simd) __attribute__((target(simd)))
  36. #if defined(__clang_major__) && (__clang_major__ >= 7)
  37. #define MEGDNN_LAMBDA_ATTRIBUTE_TARGET(simd) __attribute__((target(simd)))
  38. #else
  39. #define MEGDNN_LAMBDA_ATTRIBUTE_TARGET(simd) [[gnu::target(simd)]]
  40. #endif
  41. #define MEGDNN_NOINLINE __attribute__((noinline))
  42. #define megdnn_isatty(x) isatty(x)
  43. #elif defined(__INTEL_COMPILER) || defined(_MSC_VER)
  44. #ifndef megdnn_trap
  45. #define megdnn_trap() __debugbreak()
  46. #endif
  47. #define megdnn_likely(v) (bool(v))
  48. #define megdnn_unlikely(v) (bool(v))
  49. #define MEGDNN_DEPRECATED
  50. #define MEGDNN_PACKED
  51. #define MEGDNN_CONSTEXPR constexpr
  52. #define MEGDNN_NOEXCEPT noexcept
  53. #define MEGDNN_STATIC_ASSERT static_assert
  54. #define MEGDNN_FINAL final
  55. #if defined(_MSC_VER)
  56. #define MEGDNN_NORETURN __declspec(noreturn)
  57. #define MEGDNN_NOINLINE __declspec(noinline)
  58. #else
  59. #define MEGDNN_NORETURN
  60. #define MEGDNN_FORCE_NOINLINE
  61. #endif // _MSC_VER
  62. #define MEGDNN_WARN_UNUSED_RESULT
  63. #define megdnn_isatty(x) _isatty(x)
  64. #else
  65. #error "unknown compiler"
  66. #endif // __GNUC__
  67. // __cpp_exceptions and __cpp_rtti is referred from
  68. // https://isocpp.org/std/standing-documentssd-6-sg10-feature-test-recommendations
  69. // gcc < 5 does not define __cpp_exceptions but __EXCEPTIONS,
  70. // similar for __GXX_RTTI
  71. // _CPPUNWIND and _CPPRTTI is used by MSVC, see
  72. // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macrosview=vs-2019
  73. #ifndef MEGDNN_ENABLE_EXCEPTIONS
  74. #if __cpp_exceptions || __EXCEPTIONS || \
  75. (defined(_MSC_VER) && defined(_CPPUNWIND))
  76. #define MEGDNN_ENABLE_EXCEPTIONS 1
  77. #else
  78. #define MEGDNN_ENABLE_EXCEPTIONS 0
  79. #endif
  80. #endif
  81. #ifndef MEGDNN_ENABLE_RTTI
  82. #if __cpp_rtti || __GXX_RTTI || (defined(_MSC_VER) && defined(_CPPRTTI))
  83. #define MEGDNN_ENABLE_RTTI 1
  84. #else
  85. #define MEGDNN_ENABLE_RTTI 0
  86. #endif
  87. #endif
  88. #ifdef __CUDACC__
  89. #define MEGDNN_CC_CUDA 1
  90. #undef MEGDNN_CONSTEXPR
  91. #define MEGDNN_CONSTEXPR const
  92. #if defined(__CUDACC_VER_MAJOR__)
  93. #if __CUDACC_VER_MAJOR__ >= 9
  94. #undef MEGDNN_STATIC_ASSERT
  95. #define MEGDNN_STATIC_ASSERT(cond, msg) static_assert(cond, msg);
  96. #else
  97. #undef MEGDNN_STATIC_ASSERT
  98. #define MEGDNN_STATIC_ASSERT(cond, msg)
  99. #endif
  100. #endif
  101. #define nullptr NULL
  102. #undef MEGDNN_FINAL
  103. #define MEGDNN_FINAL
  104. #elif defined(__HIPCC__)
  105. #define MEGDNN_CC_CUDA 1
  106. #else
  107. #define MEGDNN_CC_HOST 1
  108. #endif // __CUDACC__
  109. // MEGDNN_HOST and MEGDNN_DEVICE
  110. #if MEGDNN_CC_CUDA
  111. #define MEGDNN_HOST __host__
  112. #define MEGDNN_DEVICE __device__
  113. #else
  114. #define MEGDNN_HOST
  115. #define MEGDNN_DEVICE
  116. #endif
  117. // vim: syntax=cpp.doxygen

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

Contributors (1)