sysinfo.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #define CACHELINE_SIZE 64
  18. #if !defined(PAGE_SIZE)
  19. #define PAGE_SIZE 4096
  20. #endif
  21. #define PAGE_SIZE_2M (2*1024*1024)
  22. #define PAGE_SIZE_4K (4*1024)
  23. #include "platform.h"
  24. /* define isa namespace and ISA bitvector */
  25. #if defined (__AVX512VL__)
  26. # define isa avx512skx
  27. # define ISA AVX512SKX
  28. # define ISA_STR "AVX512SKX"
  29. #elif defined (__AVX512F__)
  30. # define isa avx512knl
  31. # define ISA AVX512KNL
  32. # define ISA_STR "AVX512KNL"
  33. #elif defined (__AVX2__)
  34. # define isa avx2
  35. # define ISA AVX2
  36. # define ISA_STR "AVX2"
  37. #elif defined(__AVXI__)
  38. # define isa avxi
  39. # define ISA AVXI
  40. # define ISA_STR "AVXI"
  41. #elif defined(__AVX__)
  42. # define isa avx
  43. # define ISA AVX
  44. # define ISA_STR "AVX"
  45. #elif defined (__SSE4_2__)
  46. # define isa sse42
  47. # define ISA SSE42
  48. # define ISA_STR "SSE4.2"
  49. #elif defined (__SSE4_1__)
  50. # define isa sse41
  51. # define ISA SSE41
  52. # define ISA_STR "SSE4.1"
  53. #elif defined(__SSSE3__)
  54. # define isa ssse3
  55. # define ISA SSSE3
  56. # define ISA_STR "SSSE3"
  57. #elif defined(__SSE3__)
  58. # define isa sse3
  59. # define ISA SSE3
  60. # define ISA_STR "SSE3"
  61. #elif defined(__SSE2__)
  62. # define isa sse2
  63. # define ISA SSE2
  64. # define ISA_STR "SSE2"
  65. #elif defined(__SSE__)
  66. # define isa sse
  67. # define ISA SSE
  68. # define ISA_STR "SSE"
  69. #else
  70. #error Unknown ISA
  71. #endif
  72. #if defined (__MACOSX__)
  73. #if defined (__INTEL_COMPILER)
  74. #define DEFAULT_ISA SSSE3
  75. #else
  76. #define DEFAULT_ISA SSE3
  77. #endif
  78. #else
  79. #define DEFAULT_ISA SSE2
  80. #endif
  81. namespace embree
  82. {
  83. enum CPUModel {
  84. CPU_UNKNOWN,
  85. CPU_CORE1,
  86. CPU_CORE2,
  87. CPU_CORE_NEHALEM,
  88. CPU_CORE_SANDYBRIDGE,
  89. CPU_HASWELL,
  90. CPU_KNC,
  91. CPU_KNL
  92. };
  93. /*! get the full path to the running executable */
  94. std::string getExecutableFileName();
  95. /*! return platform name */
  96. std::string getPlatformName();
  97. /*! get the full name of the compiler */
  98. std::string getCompilerName();
  99. /*! return the name of the CPU */
  100. std::string getCPUVendor();
  101. /*! get microprocessor model */
  102. CPUModel getCPUModel();
  103. /*! converts CPU model into string */
  104. std::string stringOfCPUModel(CPUModel model);
  105. /*! CPU features */
  106. static const int CPU_FEATURE_SSE = 1 << 0;
  107. static const int CPU_FEATURE_SSE2 = 1 << 1;
  108. static const int CPU_FEATURE_SSE3 = 1 << 2;
  109. static const int CPU_FEATURE_SSSE3 = 1 << 3;
  110. static const int CPU_FEATURE_SSE41 = 1 << 4;
  111. static const int CPU_FEATURE_SSE42 = 1 << 5;
  112. static const int CPU_FEATURE_POPCNT = 1 << 6;
  113. static const int CPU_FEATURE_AVX = 1 << 7;
  114. static const int CPU_FEATURE_F16C = 1 << 8;
  115. static const int CPU_FEATURE_RDRAND = 1 << 9;
  116. static const int CPU_FEATURE_AVX2 = 1 << 10;
  117. static const int CPU_FEATURE_FMA3 = 1 << 11;
  118. static const int CPU_FEATURE_LZCNT = 1 << 12;
  119. static const int CPU_FEATURE_BMI1 = 1 << 13;
  120. static const int CPU_FEATURE_BMI2 = 1 << 14;
  121. static const int CPU_FEATURE_KNC = 1 << 15;
  122. static const int CPU_FEATURE_AVX512F = 1 << 16;
  123. static const int CPU_FEATURE_AVX512DQ = 1 << 17;
  124. static const int CPU_FEATURE_AVX512PF = 1 << 18;
  125. static const int CPU_FEATURE_AVX512ER = 1 << 19;
  126. static const int CPU_FEATURE_AVX512CD = 1 << 20;
  127. static const int CPU_FEATURE_AVX512BW = 1 << 21;
  128. static const int CPU_FEATURE_AVX512VL = 1 << 22;
  129. static const int CPU_FEATURE_AVX512IFMA = 1 << 23;
  130. static const int CPU_FEATURE_AVX512VBMI = 1 << 24;
  131. /*! get CPU features */
  132. int getCPUFeatures();
  133. /*! convert CPU features into a string */
  134. std::string stringOfCPUFeatures(int features);
  135. /*! creates a string of all supported targets that are supported */
  136. std::string supportedTargetList (int isa);
  137. /*! ISAs */
  138. static const int SSE = CPU_FEATURE_SSE;
  139. static const int SSE2 = SSE | CPU_FEATURE_SSE2;
  140. static const int SSE3 = SSE2 | CPU_FEATURE_SSE3;
  141. static const int SSSE3 = SSE3 | CPU_FEATURE_SSSE3;
  142. static const int SSE41 = SSSE3 | CPU_FEATURE_SSE41;
  143. static const int SSE42 = SSE41 | CPU_FEATURE_SSE42 | CPU_FEATURE_POPCNT;
  144. static const int AVX = SSE42 | CPU_FEATURE_AVX;
  145. static const int AVXI = AVX | CPU_FEATURE_F16C | CPU_FEATURE_RDRAND;
  146. static const int AVX2 = AVXI | CPU_FEATURE_AVX2 | CPU_FEATURE_FMA3 | CPU_FEATURE_BMI1 | CPU_FEATURE_BMI2 | CPU_FEATURE_LZCNT;
  147. static const int AVX512KNL = AVX2 | CPU_FEATURE_AVX512F | CPU_FEATURE_AVX512PF | CPU_FEATURE_AVX512ER | CPU_FEATURE_AVX512CD;
  148. static const int AVX512SKX = AVX2 | CPU_FEATURE_AVX512F | CPU_FEATURE_AVX512DQ | CPU_FEATURE_AVX512CD | CPU_FEATURE_AVX512BW | CPU_FEATURE_AVX512VL;
  149. static const int KNC = CPU_FEATURE_KNC;
  150. /*! converts ISA bitvector into a string */
  151. std::string stringOfISA(int features);
  152. /*! return the number of logical threads of the system */
  153. unsigned int getNumberOfLogicalThreads();
  154. /*! returns the size of the terminal window in characters */
  155. int getTerminalWidth();
  156. /*! returns performance counter in seconds */
  157. double getSeconds();
  158. /*! sleeps the specified number of seconds */
  159. void sleepSeconds(double t);
  160. }