sysinfo.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #define CACHELINE_SIZE 64
  5. #if !defined(PAGE_SIZE)
  6. #define PAGE_SIZE 4096
  7. #endif
  8. #define PAGE_SIZE_2M (2*1024*1024)
  9. #define PAGE_SIZE_4K (4*1024)
  10. #include "platform.h"
  11. /* define isa namespace and ISA bitvector */
  12. #if defined (__AVX512VL__)
  13. # define isa avx512
  14. # define ISA AVX512
  15. # define ISA_STR "AVX512"
  16. #elif defined (__AVX2__)
  17. # define isa avx2
  18. # define ISA AVX2
  19. # define ISA_STR "AVX2"
  20. #elif defined(__AVXI__)
  21. # define isa avxi
  22. # define ISA AVXI
  23. # define ISA_STR "AVXI"
  24. #elif defined(__AVX__)
  25. # define isa avx
  26. # define ISA AVX
  27. # define ISA_STR "AVX"
  28. #elif defined (__SSE4_2__)
  29. # define isa sse42
  30. # define ISA SSE42
  31. # define ISA_STR "SSE4.2"
  32. //#elif defined (__SSE4_1__) // we demote this to SSE2, MacOSX code compiles with SSE41 by default with XCode 11
  33. //# define isa sse41
  34. //# define ISA SSE41
  35. //# define ISA_STR "SSE4.1"
  36. //#elif defined(__SSSE3__) // we demote this to SSE2, MacOSX code compiles with SSSE3 by default with ICC
  37. //# define isa ssse3
  38. //# define ISA SSSE3
  39. //# define ISA_STR "SSSE3"
  40. //#elif defined(__SSE3__) // we demote this to SSE2, MacOSX code compiles with SSE3 by default with clang
  41. //# define isa sse3
  42. //# define ISA SSE3
  43. //# define ISA_STR "SSE3"
  44. #elif defined(__SSE2__) || defined(__SSE3__) || defined(__SSSE3__)
  45. # define isa sse2
  46. # define ISA SSE2
  47. # define ISA_STR "SSE2"
  48. #elif defined(__SSE__)
  49. # define isa sse
  50. # define ISA SSE
  51. # define ISA_STR "SSE"
  52. #elif defined(__ARM_NEON)
  53. // NOTE(LTE): Use sse2 for `isa` for the compatibility at the moment.
  54. #define isa sse2
  55. #define ISA NEON
  56. #define ISA_STR "NEON"
  57. #else
  58. #error Unknown ISA
  59. #endif
  60. namespace embree
  61. {
  62. enum class CPU
  63. {
  64. XEON_ICE_LAKE,
  65. CORE_ICE_LAKE,
  66. CORE_TIGER_LAKE,
  67. CORE_COMET_LAKE,
  68. CORE_CANNON_LAKE,
  69. CORE_KABY_LAKE,
  70. XEON_SKY_LAKE,
  71. CORE_SKY_LAKE,
  72. XEON_PHI_KNIGHTS_MILL,
  73. XEON_PHI_KNIGHTS_LANDING,
  74. XEON_BROADWELL,
  75. CORE_BROADWELL,
  76. XEON_HASWELL,
  77. CORE_HASWELL,
  78. XEON_IVY_BRIDGE,
  79. CORE_IVY_BRIDGE,
  80. SANDY_BRIDGE,
  81. NEHALEM,
  82. CORE2,
  83. CORE1,
  84. ARM,
  85. UNKNOWN,
  86. };
  87. /*! get the full path to the running executable */
  88. std::string getExecutableFileName();
  89. /*! return platform name */
  90. std::string getPlatformName();
  91. /*! get the full name of the compiler */
  92. std::string getCompilerName();
  93. /*! return the name of the CPU */
  94. std::string getCPUVendor();
  95. /*! get microprocessor model */
  96. CPU getCPUModel();
  97. /*! converts CPU model into string */
  98. std::string stringOfCPUModel(CPU model);
  99. /*! CPU features */
  100. static const int CPU_FEATURE_SSE = 1 << 0;
  101. static const int CPU_FEATURE_SSE2 = 1 << 1;
  102. static const int CPU_FEATURE_SSE3 = 1 << 2;
  103. static const int CPU_FEATURE_SSSE3 = 1 << 3;
  104. static const int CPU_FEATURE_SSE41 = 1 << 4;
  105. static const int CPU_FEATURE_SSE42 = 1 << 5;
  106. static const int CPU_FEATURE_POPCNT = 1 << 6;
  107. static const int CPU_FEATURE_AVX = 1 << 7;
  108. static const int CPU_FEATURE_F16C = 1 << 8;
  109. static const int CPU_FEATURE_RDRAND = 1 << 9;
  110. static const int CPU_FEATURE_AVX2 = 1 << 10;
  111. static const int CPU_FEATURE_FMA3 = 1 << 11;
  112. static const int CPU_FEATURE_LZCNT = 1 << 12;
  113. static const int CPU_FEATURE_BMI1 = 1 << 13;
  114. static const int CPU_FEATURE_BMI2 = 1 << 14;
  115. static const int CPU_FEATURE_AVX512F = 1 << 16;
  116. static const int CPU_FEATURE_AVX512DQ = 1 << 17;
  117. static const int CPU_FEATURE_AVX512PF = 1 << 18;
  118. static const int CPU_FEATURE_AVX512ER = 1 << 19;
  119. static const int CPU_FEATURE_AVX512CD = 1 << 20;
  120. static const int CPU_FEATURE_AVX512BW = 1 << 21;
  121. static const int CPU_FEATURE_AVX512VL = 1 << 22;
  122. static const int CPU_FEATURE_AVX512IFMA = 1 << 23;
  123. static const int CPU_FEATURE_AVX512VBMI = 1 << 24;
  124. static const int CPU_FEATURE_XMM_ENABLED = 1 << 25;
  125. static const int CPU_FEATURE_YMM_ENABLED = 1 << 26;
  126. static const int CPU_FEATURE_ZMM_ENABLED = 1 << 27;
  127. static const int CPU_FEATURE_NEON = 1 << 28;
  128. static const int CPU_FEATURE_NEON_2X = 1 << 29;
  129. /*! get CPU features */
  130. int getCPUFeatures();
  131. /*! convert CPU features into a string */
  132. std::string stringOfCPUFeatures(int features);
  133. /*! creates a string of all supported targets that are supported */
  134. std::string supportedTargetList (int isa);
  135. /*! ISAs */
  136. static const int SSE = CPU_FEATURE_SSE | CPU_FEATURE_XMM_ENABLED;
  137. static const int SSE2 = SSE | CPU_FEATURE_SSE2;
  138. static const int SSE3 = SSE2 | CPU_FEATURE_SSE3;
  139. static const int SSSE3 = SSE3 | CPU_FEATURE_SSSE3;
  140. static const int SSE41 = SSSE3 | CPU_FEATURE_SSE41;
  141. static const int SSE42 = SSE41 | CPU_FEATURE_SSE42 | CPU_FEATURE_POPCNT;
  142. static const int AVX = SSE42 | CPU_FEATURE_AVX | CPU_FEATURE_YMM_ENABLED;
  143. static const int AVXI = AVX | CPU_FEATURE_F16C | CPU_FEATURE_RDRAND;
  144. static const int AVX2 = AVXI | CPU_FEATURE_AVX2 | CPU_FEATURE_FMA3 | CPU_FEATURE_BMI1 | CPU_FEATURE_BMI2 | CPU_FEATURE_LZCNT;
  145. static const int AVX512 = AVX2 | CPU_FEATURE_AVX512F | CPU_FEATURE_AVX512DQ | CPU_FEATURE_AVX512CD | CPU_FEATURE_AVX512BW | CPU_FEATURE_AVX512VL | CPU_FEATURE_ZMM_ENABLED;
  146. static const int NEON = CPU_FEATURE_NEON | CPU_FEATURE_SSE | CPU_FEATURE_SSE2;
  147. static const int NEON_2X = CPU_FEATURE_NEON_2X | AVX2;
  148. /*! converts ISA bitvector into a string */
  149. std::string stringOfISA(int features);
  150. /*! return the number of logical threads of the system */
  151. unsigned int getNumberOfLogicalThreads();
  152. /*! returns the size of the terminal window in characters */
  153. int getTerminalWidth();
  154. /*! returns performance counter in seconds */
  155. double getSeconds();
  156. /*! sleeps the specified number of seconds */
  157. void sleepSeconds(double t);
  158. /*! returns virtual address space occupied by process */
  159. size_t getVirtualMemoryBytes();
  160. /*! returns resident memory required by process */
  161. size_t getResidentMemoryBytes();
  162. }