You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
common : add support for cpu_get_num_physical_cores() on Windows (#8771)
* Add support for cpu_get_num_phsical_cores() on Windows
* fix build bug on msys2-clang64 and ucrt64
* avoid adding new function
* add new macros to avoid windows+mingw64
* Add error checking to return default value
if (!GetLogicalProcessorInformationEx(RelationProcessorCore, nullptr, &buffer_size)) {
120
+
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
121
+
return default_threads;
122
+
}
123
+
}
124
+
125
+
std::vector<char> buffer(buffer_size);
126
+
if (!GetLogicalProcessorInformationEx(RelationProcessorCore, reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(buffer.data()), &buffer_size)) {
127
+
return default_threads;
128
+
}
129
+
130
+
int32_t num_physical_cores = 0;
131
+
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX info = reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(buffer.data());
132
+
while (buffer_size > 0) {
133
+
if (info->Relationship == RelationProcessorCore) {
134
+
num_physical_cores += info->Processor.GroupCount;
135
+
}
136
+
buffer_size -= info->Size;
137
+
info = reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(reinterpret_cast<char*>(info) + info->Size);
0 commit comments