Skip to content

Commit f0a3551

Browse files
committed
avoid adding new function
1 parent 1d1e6e8 commit f0a3551

File tree

2 files changed

+21
-37
lines changed

2 files changed

+21
-37
lines changed

common/common.cpp

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,6 @@ using json = nlohmann::ordered_json;
8080
//
8181
// CPU utils
8282
//
83-
#ifdef _WIN32
84-
int32_t cpu_get_num_cores_win(bool print_physical_core_num) {
85-
DWORD buffer_size = 0;
86-
GetLogicalProcessorInformationEx(RelationProcessorCore, nullptr, &buffer_size);
87-
std::vector<char> buffer(buffer_size);
88-
if (!GetLogicalProcessorInformationEx(RelationProcessorCore, reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(buffer.data()), &buffer_size)) {
89-
return 0;
90-
}
91-
92-
int num_cores_win = 0;
93-
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX info = reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(buffer.data());
94-
while (buffer_size > 0) {
95-
if (info->Relationship == RelationProcessorCore) {
96-
if (print_physical_core_num) {
97-
num_cores_win += info->Processor.GroupCount;
98-
} else {
99-
for (WORD i = 0; i < info->Processor.GroupCount; ++i) {
100-
#ifdef _MSC_VER
101-
num_cores_win += __popcnt64(info->Processor.GroupMask[i].Mask);
102-
#else
103-
num_cores_win += _popcnt64(info->Processor.GroupMask[i].Mask);
104-
#endif
105-
}
106-
}
107-
}
108-
buffer_size -= info->Size;
109-
info = reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(reinterpret_cast<char*>(info) + info->Size);
110-
}
111-
112-
return num_cores_win;
113-
}
114-
#endif
11583

11684
int32_t cpu_get_num_physical_cores() {
11785
#ifdef __linux__
@@ -143,7 +111,24 @@ int32_t cpu_get_num_physical_cores() {
143111
return num_physical_cores;
144112
}
145113
#elif defined(_WIN32)
146-
return cpu_get_num_cores_win(true);
114+
DWORD buffer_size = 0;
115+
GetLogicalProcessorInformationEx(RelationProcessorCore, nullptr, &buffer_size);
116+
std::vector<char> buffer(buffer_size);
117+
if (!GetLogicalProcessorInformationEx(RelationProcessorCore, reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(buffer.data()), &buffer_size)) {
118+
return 0;
119+
}
120+
121+
int32_t num_physical_cores = 0;
122+
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX info = reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(buffer.data());
123+
while (buffer_size > 0) {
124+
if (info->Relationship == RelationProcessorCore) {
125+
num_physical_cores += info->Processor.GroupCount;
126+
}
127+
buffer_size -= info->Size;
128+
info = reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(reinterpret_cast<char*>(info) + info->Size);
129+
}
130+
131+
return num_physical_cores;
147132
#endif
148133
unsigned int n_threads = std::thread::hardware_concurrency();
149134
return n_threads > 0 ? (n_threads <= 4 ? n_threads : n_threads / 2) : 4;
@@ -1749,7 +1734,8 @@ std::string gpt_params_get_system_info(const gpt_params & params) {
17491734
os << " (n_threads_batch = " << params.n_threads_batch << ")";
17501735
}
17511736
#ifdef _WIN32
1752-
os << " / " << cpu_get_num_cores_win(false) << " | " << llama_print_system_info();
1737+
DWORD logicalProcessorCount = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
1738+
os << " / " << logicalProcessorCount << " | " << llama_print_system_info();
17531739
#else
17541740
os << " / " << std::thread::hardware_concurrency() << " | " << llama_print_system_info();
17551741
#endif

common/common.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ struct llama_control_vector_load_info;
4444
//
4545
// CPU utils
4646
//
47-
#ifdef _WIN32
48-
int32_t cpu_get_num_cores_win(bool print_physical_core_num);
49-
#endif
47+
5048
int32_t cpu_get_num_physical_cores();
5149
int32_t cpu_get_num_math();
5250

0 commit comments

Comments
 (0)