1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_PLATFORM_CPU_INFO_H_ 17 #define TENSORFLOW_CORE_PLATFORM_CPU_INFO_H_ 18 19 #include <string> 20 21 // TODO(ahentz): This is not strictly required here but, for historical 22 // reasons, many people depend on cpu_info.h in order to use kLittleEndian. 23 #include "tensorflow/core/platform/byte_order.h" 24 25 #if defined(_MSC_VER) 26 #include "tensorflow/core/platform/windows/cpu_info.h" 27 #endif 28 29 namespace tensorflow { 30 namespace port { 31 32 // Returns an estimate of the number of schedulable CPUs for this 33 // process. Usually, it's constant throughout the lifetime of a 34 // process, but it might change if the underlying cluster management 35 // software can change it dynamically. If the underlying call fails, a default 36 // value (e.g. `4`) may be returned. 37 int NumSchedulableCPUs(); 38 39 // Returns the total number of CPUs on the system. This number should 40 // not change even if the underlying cluster management software may 41 // change the number of schedulable CPUs. Unlike `NumSchedulableCPUs`, if the 42 // underlying call fails, an invalid value of -1 will be returned; 43 // the user must check for validity. 44 static constexpr int kUnknownCPU = -1; 45 int NumTotalCPUs(); 46 47 // Returns the id of the current CPU. Returns -1 if the current CPU cannot be 48 // identified. If successful, the return value will be in [0, NumTotalCPUs()). 49 int GetCurrentCPU(); 50 51 // Returns an estimate of the number of hyperthreads per physical core 52 // on the CPU 53 int NumHyperthreadsPerCore(); 54 55 // Mostly ISA related features that we care about 56 enum CPUFeature { 57 // Do not change numeric assignments. 58 MMX = 0, 59 SSE = 1, 60 SSE2 = 2, 61 SSE3 = 3, 62 SSSE3 = 4, 63 SSE4_1 = 5, 64 SSE4_2 = 6, 65 CMOV = 7, 66 CMPXCHG8B = 8, 67 CMPXCHG16B = 9, 68 POPCNT = 10, 69 AES = 11, 70 AVX = 12, 71 RDRAND = 13, 72 AVX2 = 14, 73 FMA = 15, 74 F16C = 16, 75 PCLMULQDQ = 17, 76 RDSEED = 18, 77 ADX = 19, 78 SMAP = 20, 79 80 // Prefetch Vector Data Into Caches with Intent to Write and T1 Hint 81 // http://www.felixcloutier.com/x86/PREFETCHWT1.html. 82 // You probably want PREFETCHW instead. 83 PREFETCHWT1 = 21, 84 85 BMI1 = 22, 86 BMI2 = 23, 87 HYPERVISOR = 25, // 0 when on a real CPU, 1 on (well-behaved) hypervisor. 88 89 // Prefetch Data into Caches in Anticipation of a Write (3D Now!). 90 // http://www.felixcloutier.com/x86/PREFETCHW.html 91 PREFETCHW = 26, 92 93 // AVX-512: 512-bit vectors (plus masking, etc.) in Knights Landing, 94 // Skylake 95 // Xeon, etc.; each of these entries is a different subset of 96 // instructions, 97 // various combinations of which occur on various CPU types. 98 AVX512F = 27, // Foundation 99 AVX512CD = 28, // Conflict detection 100 AVX512ER = 29, // Exponential and reciprocal 101 AVX512PF = 30, // Prefetching 102 AVX512VL = 31, // Shorter vector lengths 103 AVX512BW = 32, // Byte and word 104 AVX512DQ = 33, // Dword and qword 105 AVX512VBMI = 34, // Bit manipulation 106 AVX512IFMA = 35, // Integer multiply-add 107 AVX512_4VNNIW = 36, // Integer neural network 108 AVX512_4FMAPS = 37, // Floating point neural network 109 }; 110 111 // Checks whether the current processor supports one of the features above. 112 // Checks CPU registers to return hardware capabilities. 113 bool TestCPUFeature(CPUFeature feature); 114 115 // Returns CPU Vendor string (i.e. 'GenuineIntel', 'AuthenticAMD', etc.) 116 std::string CPUVendorIDString(); 117 118 // Returns CPU family. 119 int CPUFamily(); 120 121 // Returns CPU model number. 122 int CPUModelNum(); 123 124 // Returns nominal core processor cycles per second of each processor. 125 double NominalCPUFrequency(); 126 127 // Returns num of hyperthreads per physical core 128 int CPUIDNumSMT(); 129 130 } // namespace port 131 } // namespace tensorflow 132 133 #endif // TENSORFLOW_CORE_PLATFORM_CPU_INFO_H_ 134