Skip to content

Commit f155d23

Browse files
threading: disable SetThreadInfo() calls for older Windows versions
1 parent 8b5b727 commit f155d23

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,19 +2426,21 @@ static bool ggml_thread_apply_priority(int32_t prio) {
24262426

24272427
if (prio != GGML_SCHED_PRIO_LOW) {
24282428
// Tell Windows that this thread should not be throttled (needs its own CPU core).
2429-
// Newer Windows 11 ARM64 versions aggresively park (offline) CPU cores and often place
2429+
// Newer Windows 11 versions aggresively park (offline) CPU cores and often place
24302430
// all our threads onto the first 4 cores which results in terrible performance with
24312431
// n_threads > 4
2432-
THREAD_POWER_THROTTLING_STATE p;
2433-
ZeroMemory(&p, sizeof(p));
2434-
p.Version = THREAD_POWER_THROTTLING_CURRENT_VERSION;
2435-
p.ControlMask = THREAD_POWER_THROTTLING_EXECUTION_SPEED;
2436-
p.StateMask = 0;
2437-
2438-
if (!SetThreadInformation(GetCurrentThread(), ThreadPowerThrottling, &p, sizeof(p))) {
2432+
#if _WIN32_WINNT >= 0x0602
2433+
THREAD_POWER_THROTTLING_STATE t;
2434+
ZeroMemory(&t, sizeof(t));
2435+
t.Version = THREAD_POWER_THROTTLING_CURRENT_VERSION;
2436+
t.ControlMask = THREAD_POWER_THROTTLING_EXECUTION_SPEED;
2437+
t.StateMask = 0;
2438+
2439+
if (!SetThreadInformation(GetCurrentThread(), ThreadPowerThrottling, &t, sizeof(t))) {
24392440
GGML_LOG_DEBUG("failed to disable thread power throttling %d : (%d)\n", prio, (int) GetLastError());
24402441
return false;
24412442
}
2443+
#endif
24422444
}
24432445

24442446
if (prio == GGML_SCHED_PRIO_NORMAL) {

0 commit comments

Comments
 (0)