Skip to content

Commit

Permalink
Remove redundant core enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheil Kumar committed Nov 13, 2023
1 parent 24fd2df commit 9b28fc7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
43 changes: 12 additions & 31 deletions winml/lib/Api/HardwareCoreEnumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,12 @@ static LogicalProcessorInformation GetLogicalProcessorInfos(LOGICAL_PROCESSOR_RE
return {std::move(processorInformationBytes), length};

Check warning on line 34 in winml/lib/Api/HardwareCoreEnumerator.cpp

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] winml/lib/Api/HardwareCoreEnumerator.cpp#L34

Add #include <utility> for move [build/include_what_you_use] [4]
Raw output
winml/lib/Api/HardwareCoreEnumerator.cpp:34:  Add #include <utility> for move  [build/include_what_you_use] [4]
}

static long long GetNumberOfSoCDieCores() {
DWORD dwLevel2GroupMask = 0;
DWORD dwLevel3GroupMask = 0;
DWORD dwSoCGroupMask = 0;

auto logicalProcessorInformation = GetLogicalProcessorInfos(RelationAll);
auto processorInformation = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)logicalProcessorInformation.Buffer.get();

size_t read = 0;
while (read <= logicalProcessorInformation.Length) {
switch (processorInformation->Relationship) {
case RelationCache:
if (processorInformation->Cache.Level == 2) {
dwLevel2GroupMask |= processorInformation->Cache.GroupMask.Mask;
} else if (processorInformation->Cache.Level == 3) {
dwLevel3GroupMask |= processorInformation->Cache.GroupMask.Mask;
}
break;
}

read += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX);
processorInformation++;
}

dwSoCGroupMask = (dwLevel2GroupMask & ~dwLevel3GroupMask);

return __popcnt(dwSoCGroupMask);
}

static CoreCounter GetNumberOPhysicalAndEngineeringCores() {
auto logicalProcessorInformation = GetLogicalProcessorInfos(RelationProcessorCore);
auto logicalProcessorInformation = GetLogicalProcessorInfos(RelationAll);

CoreCounter cores;
DWORD dwLevel2GroupMask = 0;
DWORD dwLevel3GroupMask = 0;
size_t read = 0;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX currentProcessorInfo = NULL;

Expand All @@ -80,19 +53,27 @@ static CoreCounter GetNumberOPhysicalAndEngineeringCores() {
case RelationProcessorCore:
cores.PhysicalCores++;
break;
case RelationCache:
if (currentProcessorInfo->Cache.Level == 2) {
dwLevel2GroupMask |= currentProcessorInfo->Cache.GroupMask.Mask;
} else if (currentProcessorInfo->Cache.Level == 3) {
dwLevel3GroupMask |= currentProcessorInfo->Cache.GroupMask.Mask;
}
break;
}

read += currentProcessorInfo->Size;
}

cores.SocDieCores = GetNumberOfSoCDieCores();
cores.SocDieCores = __popcnt(dwLevel2GroupMask & ~dwLevel3GroupMask);
return cores;
}

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 pysical cores, but exclude soc cores
return static_cast<uint32_t>(cores.PhysicalCores - cores.SocDieCores);
}

Expand Down
1 change: 0 additions & 1 deletion winml/lib/Api/LearningModelDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ LearningModelDevice::CacheThreadPool(_winml::IThreading* thread_pool) {
return S_OK;
}


uint32_t LearningModelDevice::NumberOfIntraOpThreads() {
if (IsCpuDevice()) {
return HardwareCoreEnumerator::DefaultIntraOpNumThreads();
Expand Down
1 change: 0 additions & 1 deletion winml/lib/Api/LearningModelSessionOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ LearningModelSessionOptions::LearningModelSessionOptions()
intra_op_num_threads_override_ = HardwareCoreEnumerator::DefaultIntraOpNumThreads();
}


LearningModelSessionOptions::LearningModelSessionOptions(const LearningModelSessionOptions& options)
: batch_size_override_(options.batch_size_override_),
close_model_on_session_creation_(options.close_model_on_session_creation_),
Expand Down

0 comments on commit 9b28fc7

Please sign in to comment.