From 06657281a192d01c56b6998f94384c8419e8ea95 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Wed, 7 Feb 2024 11:38:34 -0800 Subject: [PATCH 1/3] Add intel check --- winml/lib/Api/HardwareCoreEnumerator.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/winml/lib/Api/HardwareCoreEnumerator.cpp b/winml/lib/Api/HardwareCoreEnumerator.cpp index a89ac561f8860..308b0dbe86d21 100644 --- a/winml/lib/Api/HardwareCoreEnumerator.cpp +++ b/winml/lib/Api/HardwareCoreEnumerator.cpp @@ -14,7 +14,7 @@ struct LogicalProcessorInformation { struct CoreCounter { uint32_t PhysicalCores = 0; - uint32_t SocDieCores = 0; + uint32_t Num2CacheCores = 0; }; static LogicalProcessorInformation GetLogicalProcessorInfos(LOGICAL_PROCESSOR_RELATIONSHIP relationship) { @@ -75,7 +75,7 @@ static CoreCounter GetNumberOPhysicalAndEngineeringCores() { read += currentProcessorInfo->Size; } - cores.SocDieCores = CountSetBits(dwLevel2GroupMask & ~dwLevel3GroupMask); + cores.Num2CacheCores = CountSetBits(dwLevel2GroupMask & ~dwLevel3GroupMask); return cores; } @@ -83,8 +83,20 @@ uint32_t HardwareCoreEnumerator::DefaultIntraOpNumThreads() { // # of physical cores = # of P cores + # of E Cores + # of Soc Cores. // # of logical cores = # of P cores x 2 (if hyper threading is enabled) + # of E cores + # of Soc Cores. auto cores = GetNumberOPhysicalAndEngineeringCores(); - // We want to use the number of physical cores, but exclude soc cores - return cores.PhysicalCores - cores.SocDieCores; + + const int kVendorID_Intel[3] = { 0x756e6547, 0x6c65746e, 0x49656e69 }; // "GenuntelineI" + int regs_leaf0[4]; + int regs_leaf7[4]; + __cpuid(regs_leaf0, 0); + __cpuid(regs_leaf7, 0x7); + bool bIsIntel_and_IsHybrid = (kVendorID_Intel[0] == regs_leaf0[1]) && (kVendorID_Intel[1] == regs_leaf0[2]) && (kVendorID_Intel[2] == regs_leaf0[3]) && ( regs_leaf7[3] & (1 << 15)); + + if (bIsIntel_and_IsHybrid) { + // We want to use the number of physical cores, but exclude soc cores + return cores.PhysicalCores - cores.Num2CacheCores; + } + + return cores.PhysicalCores; } } // namespace WINMLP From b8c871a3f577fefde06dfe3865c165f540dece34 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Wed, 7 Feb 2024 11:47:07 -0800 Subject: [PATCH 2/3] Small changes --- winml/lib/Api/HardwareCoreEnumerator.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/winml/lib/Api/HardwareCoreEnumerator.cpp b/winml/lib/Api/HardwareCoreEnumerator.cpp index 308b0dbe86d21..7e24a4206e53c 100644 --- a/winml/lib/Api/HardwareCoreEnumerator.cpp +++ b/winml/lib/Api/HardwareCoreEnumerator.cpp @@ -89,10 +89,17 @@ uint32_t HardwareCoreEnumerator::DefaultIntraOpNumThreads() { int regs_leaf7[4]; __cpuid(regs_leaf0, 0); __cpuid(regs_leaf7, 0x7); - bool bIsIntel_and_IsHybrid = (kVendorID_Intel[0] == regs_leaf0[1]) && (kVendorID_Intel[1] == regs_leaf0[2]) && (kVendorID_Intel[2] == regs_leaf0[3]) && ( regs_leaf7[3] & (1 << 15)); - if (bIsIntel_and_IsHybrid) { + auto isIntel = + (kVendorID_Intel[0] == regs_leaf0[1]) && + (kVendorID_Intel[1] == regs_leaf0[2]) && + (kVendorID_Intel[2] == regs_leaf0[3]); + + auto isHybrid = (regs_leaf7[3] & (1 << 15)); + + if (isIntel && isHybrid) { // We want to use the number of physical cores, but exclude soc cores + // On Intel Hybrid processors, numSocCores == cores.Num2CacheCores return cores.PhysicalCores - cores.Num2CacheCores; } From 77f387284b08b7ab69a90a2f6f60613370324130 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Fri, 9 Feb 2024 19:53:09 -0800 Subject: [PATCH 3/3] lintrunner --- winml/lib/Api/HardwareCoreEnumerator.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/winml/lib/Api/HardwareCoreEnumerator.cpp b/winml/lib/Api/HardwareCoreEnumerator.cpp index 7e24a4206e53c..fa069c7fb66a7 100644 --- a/winml/lib/Api/HardwareCoreEnumerator.cpp +++ b/winml/lib/Api/HardwareCoreEnumerator.cpp @@ -84,15 +84,13 @@ uint32_t HardwareCoreEnumerator::DefaultIntraOpNumThreads() { // # of logical cores = # of P cores x 2 (if hyper threading is enabled) + # of E cores + # of Soc Cores. auto cores = GetNumberOPhysicalAndEngineeringCores(); - const int kVendorID_Intel[3] = { 0x756e6547, 0x6c65746e, 0x49656e69 }; // "GenuntelineI" - int regs_leaf0[4]; - int regs_leaf7[4]; + const int kVendorID_Intel[3] = {0x756e6547, 0x6c65746e, 0x49656e69}; // "GenuntelineI" + int regs_leaf0[4]; + int regs_leaf7[4]; __cpuid(regs_leaf0, 0); __cpuid(regs_leaf7, 0x7); - auto isIntel = - (kVendorID_Intel[0] == regs_leaf0[1]) && - (kVendorID_Intel[1] == regs_leaf0[2]) && + auto isIntel = (kVendorID_Intel[0] == regs_leaf0[1]) && (kVendorID_Intel[1] == regs_leaf0[2]) && (kVendorID_Intel[2] == regs_leaf0[3]); auto isHybrid = (regs_leaf7[3] & (1 << 15));