Skip to content

Commit

Permalink
fix ice lake server and tiger lake detection; add sapphire rapids
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffhammond committed Apr 10, 2022
1 parent 7f37feb commit 24d11ba
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CFLAGS = -Wall -g3 -O3 -fopenmp -std=c99
INTEL_STATIC = -static-intel -no-intel-extensions

CFLAGS += -DDEBUG
CFLAGS += -DSUPPORT_SAPPHIRE_RAPIDS
CFLAGS += -DSUPPORT_TIGERLAKE
CFLAGS += -DSUPPORT_ICELAKE
CFLAGS += -DSUPPORT_ICELAKE_SERVER
Expand Down
91 changes: 76 additions & 15 deletions vpu-count.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,51 @@ bool is_icelake_server(void)
PDEBUG("ext model: %#04x=%d\n", xmodel, xmodel);
//PDEBUG("ext family: %#08x=%d\n", xfamily, xfamily);

bool icelake = ( (model == 0x8c) || /* 140 in binary */
(model == 0x8d) ); /* 141 in binary */
bool icelake = ( (model == 0x6a) || /* 106 in binary */
(model == 0x6c) ); /* 108 in binary */
PDEBUG("Ice Lake server? %s\n", icelake ? "yes" : "no");

return (icelake);
}

bool is_sapphire_rapids(void)
{
/* leaf 1 - Model, Family, etc. */
uint32_t leaf1[4]={0x1,0x0,0x0,0x0};

__cpuid(leaf1[0], leaf1[0], leaf1[1], leaf1[2], leaf1[3]);
PDEBUG("0x1: %x,%x,%x,%x\n", leaf1[0], leaf1[1], leaf1[2], leaf1[3]);

//uint32_t stepping = (leaf1[0] ) & 0x0f;
uint32_t model = (leaf1[0] >> 4) & 0x0f;
uint32_t family = (leaf1[0] >> 8) & 0x0f;
//uint32_t proctype = (leaf1[0] >> 12) & 0x03;
uint32_t xmodel = (leaf1[0] >> 16) & 0x0f;
//uint32_t xfamily = (leaf1[0] >> 20) & 0xff;

if (family == 0x06) {
model += (xmodel << 4);
}
else if (family == 0x0f) {
model += (xmodel << 4);
//family += xfamily;
}

PDEBUG("signature: %#08x\n", (leaf1[0]) );
//PDEBUG("stepping: %#04x=%d\n", stepping, stepping);
PDEBUG("model: %#04x=%d\n", model, model);
PDEBUG("family: %#04x=%d\n", family, family);
//PDEBUG("proc type: %#04x=%d\n", proctype, proctype);
PDEBUG("ext model: %#04x=%d\n", xmodel, xmodel);
//PDEBUG("ext family: %#08x=%d\n", xfamily, xfamily);

// https://en.wikichip.org/wiki/intel/cpuid says 143
bool sapphire_rapids = (model == 0x8f); /* 143 in binary */
PDEBUG("Sapphire Rapids server? %s\n", sapphire_rapids ? "yes" : "no");

return (sapphire_rapids);
}

bool is_tigerlake_client(void)
{
/* leaf 1 - Model, Family, etc. */
Expand Down Expand Up @@ -329,7 +367,7 @@ bool is_tigerlake_client(void)
PDEBUG("ext model: %#04x=%d\n", xmodel, xmodel);
//PDEBUG("ext family: %#08x=%d\n", xfamily, xfamily);

bool tigerlake = (model == 0x8f);
bool tigerlake = (model == 0x8c); /* 140 in binary */
PDEBUG("Tiger Lake client? %s\n", tigerlake ? "yes" : "no");

return (tigerlake);
Expand Down Expand Up @@ -525,8 +563,8 @@ int vpu_count(void)
/* Note that Skylake, Cascade Lake and Cooper Lake all share the same
* CPUID bits for model and extended model. */
if ( is_skylake_server() && has_avx512_skx() ) {
char cpu_name[32] = {0};
get_cpu_name32(cpu_name);
char cpu_name[48] = {0};
get_cpu_name48(cpu_name);

PDEBUG("Skylake AVX-512 detected\n");
PDEBUG("cpu_name = %s\n", cpu_name);
Expand Down Expand Up @@ -603,13 +641,36 @@ int vpu_count(void)
return 2;
}
}
#ifdef SUPPORT_SAPPHIRE_RAPIDS
else if ( is_sapphire_rapids() ) {
PDEBUG("Sapphire Rapids server detected\n");

#ifdef DEBUG
char cpu_name[48] = {0};
get_cpu_name48(cpu_name);
PDEBUG("cpu_name = %s\n", cpu_name);

if ( has_avx512_skx() ) {
PDEBUG("AVX-512 F,CD,DQ,BW,VL detected\n");
}
if ( has_avx512_vpopcntdq() ) {
PDEBUG("AVX-512 VPOPCNTDQ detected\n");
}
if ( has_avx512_snc() ) {
PDEBUG("AVX-512 VBMI2,GFNI,VAES,VPCLMULQDQ,BITALG detected\n");
}
#endif

return 2; // assume same as Ice Lake server
}
#endif /* SUPPORT_SAPPHIRE_RAPIDS */
#ifdef SUPPORT_TIGERLAKE
else if ( is_tigerlake_client() ) {
PDEBUG("Tiger Lake client detected\n");

#ifdef DEBUG
char cpu_name[32] = {0};
get_cpu_name32(cpu_name);
char cpu_name[48] = {0};
get_cpu_name48(cpu_name);
PDEBUG("cpu_name = %s\n", cpu_name);

if ( has_avx512_skx() ) {
Expand All @@ -631,8 +692,8 @@ int vpu_count(void)
PDEBUG("Ice Lake client detected\n");

#ifdef DEBUG
char cpu_name[32] = {0};
get_cpu_name32(cpu_name);
char cpu_name[48] = {0};
get_cpu_name48(cpu_name);
PDEBUG("cpu_name = %s\n", cpu_name);

if ( has_avx512_skx() ) {
Expand All @@ -657,8 +718,8 @@ int vpu_count(void)
PDEBUG("Ice Lake server detected\n");

#ifdef DEBUG
char cpu_name[32] = {0};
get_cpu_name32(cpu_name);
char cpu_name[48] = {0};
get_cpu_name48(cpu_name);
PDEBUG("cpu_name = %s\n", cpu_name);

if ( has_avx512_skx() ) {
Expand All @@ -680,8 +741,8 @@ int vpu_count(void)
PDEBUG("Cannon Lake client detected\n");

#ifdef DEBUG
char cpu_name[32] = {0};
get_cpu_name32(cpu_name);
char cpu_name[48] = {0};
get_cpu_name48(cpu_name);
PDEBUG("cpu_name = %s\n", cpu_name);

if ( has_avx512_skx() ) {
Expand All @@ -704,8 +765,8 @@ int vpu_count(void)
PDEBUG("AVX2 detected\n");

#ifdef DEBUG
char cpu_name[32] = {0};
get_cpu_name32(cpu_name);
char cpu_name[48] = {0};
get_cpu_name48(cpu_name);
PDEBUG("cpu_name = %s\n", cpu_name);

if ( has_fma3() ) {
Expand Down

0 comments on commit 24d11ba

Please sign in to comment.