Neko  0.8.1
A portable framework for high-order spectral element flow simulations
cpuid.c
Go to the documentation of this file.
1 #if defined(__APPLE__)
2 #include <sys/ioctl.h>
3 #include <sys/sysctl.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6 #elif defined(__x86_64__)
7 #if defined(HAVE_CPUID_H)
8 #include <cpuid.h>
9 #endif
10 #endif
11 
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdint.h>
15 
16 #define MAXLEN 2048
17 
21 void system_cpuid(char *name, int len) {
22 #if defined(__APPLE__)
23  sysctlbyname("machdep.cpu.brand_string", name,(size_t *) &len, NULL, 0);
24 #elif defined(__x86_64__) && defined(HAVE_CPUID_H)
25  uint32_t brand[12];
26  __get_cpuid(0x80000002, brand+0x0, brand+0x1, brand+0x2, brand+0x3);
27  __get_cpuid(0x80000003, brand+0x4, brand+0x5, brand+0x6, brand+0x7);
28  __get_cpuid(0x80000004, brand+0x8, brand+0x9, brand+0xa, brand+0xb);
29  strncpy(name, (char *) brand, len);
30 #elif defined(_ARCH_PPC64) || defined(__aarch64__)
31  FILE *fp = fopen("/proc/cpuinfo", "r");
32  char buf[MAXLEN];
33  const char *delim = ":\n";
34 #if defined(__aarch64__)
35  /* Generic ARM unless we found something known */
36  strncpy(name, "ARM", len);
37  int cpufj = 0;
38  int cpuarm = 0;
39 #endif
40  while (fgets (buf, MAXLEN, fp)) {
41 #if defined(_ARCH_PPC64)
42  if(strstr(buf, "cpu")) {
43  char *token = strtok (buf, delim);
44  token = strtok (NULL, delim);
45  strncpy(name, token+1, len);
46  break;
47  }
48 #elif defined(__aarch64__)
49  if (strstr(buf, "CPU implementer")) {
50  char *token = strtok (buf, delim);
51  token = strtok (NULL, delim);
52  if (strstr(token, "0x46")) {
53  cpufj = 1;
54  continue;
55  }
56  else if(strstr(token, "0x41")) {
57  cpuarm = 1;
58  continue;
59  }
60  }
61 
62  if (strstr(buf, "CPU part") && cpufj) {
63  char *token = strtok (buf, delim);
64  token = strtok (NULL, delim);
65  if (strstr(token, "0x001")) {
66  strncpy(name, "A64FX", len);
67  break;
68  }
69  }
70 
71  if (strstr(buf, "CPU part") && cpuarm) {
72  char *token = strtok (buf, delim);
73  token = strtok (NULL, delim);
74  if (strstr(token, "0xd4f")) {
75  strncpy(name, "ARM Neoverse V2", len);
76  break;
77  }
78  }
79 #endif
80  }
81  fclose(fp);
82 #else
83  strncpy(name, "Unknown CPU", len);
84 #endif
85 }
86 
void system_cpuid(char *name, int len)
Definition: cpuid.c:21
#define MAXLEN
Definition: cpuid.c:16
real * buf
Definition: pipecg_aux.cu:42