Caffe2 - C++ API
A deep learning, cross platform ML framework
cpuid.cc
1 #include "caffe2/utils/cpuid.h"
2 
3 namespace caffe2 {
4 
5 const CpuId& GetCpuId() {
6  static CpuId cpuid_singleton;
7  return cpuid_singleton;
8 }
9 
10 CAFFE2_API uint32_t CpuId::f1c_ = 0;
11 CAFFE2_API uint32_t CpuId::f1d_ = 0;
12 CAFFE2_API uint32_t CpuId::f7b_ = 0;
13 CAFFE2_API uint32_t CpuId::f7c_ = 0;
14 
15 CpuId::CpuId() {
16 #ifdef _MSC_VER
17  int reg[4];
18  __cpuid(static_cast<int*>(reg), 0);
19  const int n = reg[0];
20  if (n >= 1) {
21  __cpuid(static_cast<int*>(reg), 1);
22  f1c_ = uint32_t(reg[2]);
23  f1d_ = uint32_t(reg[3]);
24  }
25  if (n >= 7) {
26  __cpuidex(static_cast<int*>(reg), 7, 0);
27  f7b_ = uint32_t(reg[1]);
28  f7c_ = uint32_t(reg[2]);
29  }
30 #elif defined(__i386__) && defined(__PIC__) && !defined(__clang__) && \
31  defined(__GNUC__)
32  // The following block like the normal cpuid branch below, but gcc
33  // reserves ebx for use of its pic register so we must specially
34  // handle the save and restore to avoid clobbering the register
35  uint32_t n;
36  __asm__(
37  "pushl %%ebx\n\t"
38  "cpuid\n\t"
39  "popl %%ebx\n\t"
40  : "=a"(n)
41  : "a"(0)
42  : "ecx", "edx");
43  if (n >= 1) {
44  uint32_t f1a;
45  __asm__(
46  "pushl %%ebx\n\t"
47  "cpuid\n\t"
48  "popl %%ebx\n\t"
49  : "=a"(f1a), "=c"(f1c_), "=d"(f1d_)
50  : "a"(1)
51  :);
52  }
53  if (n >= 7) {
54  __asm__(
55  "pushl %%ebx\n\t"
56  "cpuid\n\t"
57  "movl %%ebx, %%eax\n\r"
58  "popl %%ebx"
59  : "=a"(f7b_), "=c"(f7c_)
60  : "a"(7), "c"(0)
61  : "edx");
62  }
63 #elif defined(__x86_64__) || defined(_M_X64) || defined(__i386__)
64  uint32_t n;
65  __asm__("cpuid" : "=a"(n) : "a"(0) : "ebx", "ecx", "edx");
66  if (n >= 1) {
67  uint32_t f1a;
68  __asm__("cpuid" : "=a"(f1a), "=c"(f1c_), "=d"(f1d_) : "a"(1) : "ebx");
69  }
70  if (n >= 7) {
71  uint32_t f7a;
72  __asm__("cpuid"
73  : "=a"(f7a), "=b"(f7b_), "=c"(f7c_)
74  : "a"(7), "c"(0)
75  : "edx");
76  }
77 #endif
78 }
79 
80 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13