2
0

sysinfo.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #else
  53. #error Unknown ISA
  54. #endif
  55. namespace embree
  56. {
  57. enum class CPU
  58. {
  59. XEON_ICE_LAKE,
  60. CORE_ICE_LAKE,
  61. CORE_TIGER_LAKE,
  62. CORE_COMET_LAKE,
  63. CORE_CANNON_LAKE,
  64. CORE_KABY_LAKE,
  65. XEON_SKY_LAKE,
  66. CORE_SKY_LAKE,
  67. XEON_PHI_KNIGHTS_MILL,
  68. XEON_PHI_KNIGHTS_LANDING,
  69. XEON_BROADWELL,
  70. CORE_BROADWELL,
  71. XEON_HASWELL,
  72. CORE_HASWELL,
  73. XEON_IVY_BRIDGE,
  74. CORE_IVY_BRIDGE,
  75. SANDY_BRIDGE,
  76. NEHALEM,
  77. CORE2,
  78. CORE1,
  79. ARM,
  80. UNKNOWN,
  81. };
  82. /*! get the full path to the running executable */
  83. std::string getExecutableFileName();
  84. /*! return platform name */
  85. std::string getPlatformName();
  86. /*! get the full name of the compiler */
  87. std::string getCompilerName();
  88. /*! return the name of the CPU */
  89. std::string getCPUVendor();
  90. /*! get microprocessor model */
  91. CPU getCPUModel();
  92. /*! converts CPU model into string */
  93. std::string stringOfCPUModel(CPU model);
  94. /*! CPU features */
  95. static const int CPU_FEATURE_SSE = 1 << 0;
  96. static const int CPU_FEATURE_SSE2 = 1 << 1;
  97. static const int CPU_FEATURE_SSE3 = 1 << 2;
  98. static const int CPU_FEATURE_SSSE3 = 1 << 3;
  99. static const int CPU_FEATURE_SSE41 = 1 << 4;
  100. static const int CPU_FEATURE_SSE42 = 1 << 5;
  101. static const int CPU_FEATURE_POPCNT = 1 << 6;
  102. static const int CPU_FEATURE_AVX = 1 << 7;
  103. static const int CPU_FEATURE_F16C = 1 << 8;
  104. static const int CPU_FEATURE_RDRAND = 1 << 9;
  105. static const int CPU_FEATURE_AVX2 = 1 << 10;
  106. static const int CPU_FEATURE_FMA3 = 1 << 11;
  107. static const int CPU_FEATURE_LZCNT = 1 << 12;
  108. static const int CPU_FEATURE_BMI1 = 1 << 13;
  109. static const int CPU_FEATURE_BMI2 = 1 << 14;
  110. static const int CPU_FEATURE_AVX512F = 1 << 16;
  111. static const int CPU_FEATURE_AVX512DQ = 1 << 17;
  112. static const int CPU_FEATURE_AVX512PF = 1 << 18;
  113. static const int CPU_FEATURE_AVX512ER = 1 << 19;
  114. static const int CPU_FEATURE_AVX512CD = 1 << 20;
  115. static const int CPU_FEATURE_AVX512BW = 1 << 21;
  116. static const int CPU_FEATURE_AVX512VL = 1 << 22;
  117. static const int CPU_FEATURE_AVX512IFMA = 1 << 23;
  118. static const int CPU_FEATURE_AVX512VBMI = 1 << 24;
  119. static const int CPU_FEATURE_XMM_ENABLED = 1 << 25;
  120. static const int CPU_FEATURE_YMM_ENABLED = 1 << 26;
  121. static const int CPU_FEATURE_ZMM_ENABLED = 1 << 27;
  122. /*! get CPU features */
  123. int getCPUFeatures();
  124. /*! convert CPU features into a string */
  125. std::string stringOfCPUFeatures(int features);
  126. /*! creates a string of all supported targets that are supported */
  127. std::string supportedTargetList (int isa);
  128. /*! ISAs */
  129. static const int SSE = CPU_FEATURE_SSE | CPU_FEATURE_XMM_ENABLED;
  130. static const int SSE2 = SSE | CPU_FEATURE_SSE2;
  131. static const int SSE3 = SSE2 | CPU_FEATURE_SSE3;
  132. static const int SSSE3 = SSE3 | CPU_FEATURE_SSSE3;
  133. static const int SSE41 = SSSE3 | CPU_FEATURE_SSE41;
  134. static const int SSE42 = SSE41 | CPU_FEATURE_SSE42 | CPU_FEATURE_POPCNT;
  135. static const int AVX = SSE42 | CPU_FEATURE_AVX | CPU_FEATURE_YMM_ENABLED;
  136. static const int AVXI = AVX | CPU_FEATURE_F16C | CPU_FEATURE_RDRAND;
  137. static const int AVX2 = AVXI | CPU_FEATURE_AVX2 | CPU_FEATURE_FMA3 | CPU_FEATURE_BMI1 | CPU_FEATURE_BMI2 | CPU_FEATURE_LZCNT;
  138. static const int AVX512 = AVX2 | CPU_FEATURE_AVX512F | CPU_FEATURE_AVX512DQ | CPU_FEATURE_AVX512CD | CPU_FEATURE_AVX512BW | CPU_FEATURE_AVX512VL | CPU_FEATURE_ZMM_ENABLED;
  139. /*! converts ISA bitvector into a string */
  140. std::string stringOfISA(int features);
  141. /*! return the number of logical threads of the system */
  142. unsigned int getNumberOfLogicalThreads();
  143. /*! returns the size of the terminal window in characters */
  144. int getTerminalWidth();
  145. /*! returns performance counter in seconds */
  146. double getSeconds();
  147. /*! sleeps the specified number of seconds */
  148. void sleepSeconds(double t);
  149. /*! returns virtual address space occupied by process */
  150. size_t getVirtualMemoryBytes();
  151. /*! returns resident memory required by process */
  152. size_t getResidentMemoryBytes();
  153. }