Skip to content

Commit 9087dd2

Browse files
threading: disable SetThreadInfo() calls for older Windows versions
1 parent 199a838 commit 9087dd2

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
@@ -2427,19 +2427,21 @@ static bool ggml_thread_apply_priority(int32_t prio) {
24272427

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

24452447
if (prio == GGML_SCHED_PRIO_NORMAL) {

0 commit comments

Comments
 (0)